Changed average_latlon
This commit is contained in:
parent
7f73035b02
commit
b8a21a8baa
@ -92,8 +92,9 @@ class Place (models.Model):
|
|||||||
|
|
||||||
tags = TaggableManager(blank=True)
|
tags = TaggableManager(blank=True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
# Get center position of LP-geocoordinates.
|
# Get center position of LP-geocoordinates.
|
||||||
def average_latlon(place_list):
|
def average_latlon(cls, place_list):
|
||||||
amount = len(place_list)
|
amount = len(place_list)
|
||||||
# Init fill values to prevent None
|
# Init fill values to prevent None
|
||||||
longitude = 0
|
longitude = 0
|
||||||
@ -103,9 +104,9 @@ class Place (models.Model):
|
|||||||
for place in place_list:
|
for place in place_list:
|
||||||
longitude += place.longitude
|
longitude += place.longitude
|
||||||
latitude += place.latitude
|
latitude += place.latitude
|
||||||
return (latitude / amount, longitude / amount)
|
return {'latitude':latitude / amount, 'longitude': longitude / amount}
|
||||||
|
|
||||||
return (latitude, longitude)
|
return {'latitude': latitude, 'longitude': longitude}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -84,12 +84,20 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
place_list.append(place)
|
place_list.append(place)
|
||||||
|
|
||||||
avg_latlon = Place.average_latlon(place_list)
|
avg_latlon = Place.average_latlon(place_list)
|
||||||
self.assertEqual(avg_latlon[0], 5.5,
|
|
||||||
|
self.assertTrue('latitude' in avg_latlon,
|
||||||
|
msg='Expecting avg_latlon dict to have an \'latitude\' key'
|
||||||
|
)
|
||||||
|
self.assertTrue('longitude' in avg_latlon,
|
||||||
|
msg='Expecting avg_latlon dict to have an \'longitude\' key'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(avg_latlon['latitude'], 5.5,
|
||||||
msg='%s: average latitude missmatch' % (
|
msg='%s: average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon[1], 14.5,
|
self.assertEqual(avg_latlon['longitude'], 14.5,
|
||||||
msg='%s: average longitude missmatch' % (
|
msg='%s: average longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
@ -102,12 +110,12 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
'''
|
'''
|
||||||
place = Place.objects.get(id=1)
|
place = Place.objects.get(id=1)
|
||||||
avg_latlon = Place.average_latlon([place])
|
avg_latlon = Place.average_latlon([place])
|
||||||
self.assertEqual(avg_latlon[0], place.latitude,
|
self.assertEqual(avg_latlon['latitude'], place.latitude,
|
||||||
msg='%s:(one place) average latitude missmatch' % (
|
msg='%s:(one place) average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon[1], place.longitude,
|
self.assertEqual(avg_latlon['longitude'], place.longitude,
|
||||||
msg='%s: (one place) average longitude missmatch' % (
|
msg='%s: (one place) average longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
@ -119,12 +127,12 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
an empty list
|
an empty list
|
||||||
'''
|
'''
|
||||||
avg_latlon = Place.average_latlon([])
|
avg_latlon = Place.average_latlon([])
|
||||||
self.assertEqual(avg_latlon[0], 0,
|
self.assertEqual(avg_latlon['latitude'], 0,
|
||||||
msg='%s: (no places) average latitude missmatch' % (
|
msg='%s: (no places) average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon[1], 0,
|
self.assertEqual(avg_latlon['longitude'], 0,
|
||||||
msg='%s: a(no places) verage longitude missmatch' % (
|
msg='%s: a(no places) verage longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user