コード例 #1
0
 def to_representation(self, value):
     if self.min_timestamp is None and self.max_timestamp is None:
         return str(value)
     min_timestamp = self.min_timestamp or float('-inf')
     max_timestamp = self.max_timestamp or float('inf')
     ret = GeoLocationSeries('')
     for point in value:
         if point.timestamp < min_timestamp:
             continue
         elif point.timestamp > max_timestamp:
             continue
         else:
             ret.insert(point)
     return str(ret)
コード例 #2
0
ファイル: serializers.py プロジェクト: Maasik/django-seuranta
 def to_representation(self, value):
     if self.min_timestamp is None and self.max_timestamp is None:
         return str(value)
     min_timestamp = self.min_timestamp or float('-inf')
     max_timestamp = self.max_timestamp or float('inf')
     ret = GeoLocationSeries('')
     for point in value:
         if point.timestamp < min_timestamp:
             continue
         elif point.timestamp > max_timestamp:
             continue
         else:
             ret.insert(point)
     return str(ret)
コード例 #3
0
 def update_competitors(self):
     competitors = self.competition.approved_competitors.all()
     for ii, competitor in enumerate(competitors):
         time_offset = (now() - competitor.start_time).total_seconds()
         angle = (2 * math.pi * time_offset) / 300
         lat = 62 + .001 * (ii+1) * math.cos(angle)
         lon = 22 + .001 * (ii+1) * math.sin(angle)
         pos = GeoLocation(time.time(), [lat, lon])
         history = GeoLocationSeries([pos])
         route = Route(competitor=competitor, encoded_data=str(history))
         route.save()
コード例 #4
0
 def test_geo(self):
     gp1 = GeoCoordinates(self.valid_lat_lon_str)
     gp2 = GeoCoordinates(self.valid_lat_str, self.valid_lon_str)
     gp3 = GeoCoordinates(self.valid_lat_dec, self.valid_lon_dec)
     gp4 = GeoCoordinates(self.valid_lat_float, self.valid_lon_float)
     gp5 = GeoCoordinates([self.valid_lat_str, self.valid_lon_str])
     gp6 = GeoCoordinates([self.valid_lat_dec, self.valid_lon_dec])
     gp7 = GeoCoordinates([self.valid_lat_float, self.valid_lon_float])
     gp8 = GeoCoordinates(self.valid_lat_neg, self.valid_lon_neg)
     gp8.latitude = self.valid_lat_str
     gp8.longitude = self.valid_lon_dec
     self.assertEqual(gp1.latitude, self.valid_lat_dec)
     self.assertEqual(gp1.longitude, self.valid_lon_dec)
     self.assertEqual(gp1, gp2)
     self.assertEqual(gp1, gp3)
     self.assertEqual(gp1, gp4)
     self.assertEqual(gp1, gp5)
     self.assertEqual(gp1, gp6)
     self.assertEqual(gp1, gp7)
     self.assertEqual(gp1, gp8)
     tgl = GeoLocation(Decimal('99999.9'),
                       (Decimal('52.5'), Decimal('13.4')))
     tgl2 = GeoLocation(Decimal('99999.9'),
                        GeoCoordinates(Decimal('52.5'),
                                       Decimal('13.4')))
     tgl3 = GeoLocation(Decimal('99998.9'),
                        GeoCoordinates(Decimal('52.5'),
                                       Decimal('13.4')))
     self.assertEqual(tgl.timestamp, Decimal('99999.9'))
     self.assertEqual(tgl.coordinates.latitude, Decimal('52.5'))
     self.assertEqual(tgl.coordinates.longitude, Decimal('13.4'))
     self.assertEqual(tgl, tgl2)
     self.assertNotEqual(tgl, tgl3)
     self.assertTrue(tgl > tgl3)
     s = GeoLocationSeries([tgl, tgl3])
     joined_route = s.union(
         GeoLocationSeries([GeoLocation(100000.9, [23, 67]), ])
     )
     self.assertEqual("`m}mlw@_|l_I_expAA??A~u`sD_wcfI",
                      str(joined_route))
コード例 #5
0
 def test_geo(self):
     gp1 = GeoCoordinates(self.valid_lat_lon_str)
     gp2 = GeoCoordinates(self.valid_lat_str, self.valid_lon_str)
     gp3 = GeoCoordinates(self.valid_lat_dec, self.valid_lon_dec)
     gp4 = GeoCoordinates(self.valid_lat_float, self.valid_lon_float)
     gp5 = GeoCoordinates([self.valid_lat_str, self.valid_lon_str])
     gp6 = GeoCoordinates([self.valid_lat_dec, self.valid_lon_dec])
     gp7 = GeoCoordinates([self.valid_lat_float, self.valid_lon_float])
     gp8 = GeoCoordinates(self.valid_lat_neg, self.valid_lon_neg)
     gp8.latitude = self.valid_lat_str
     gp8.longitude = self.valid_lon_dec
     self.assertEqual(gp1.latitude, self.valid_lat_dec)
     self.assertEqual(gp1.longitude, self.valid_lon_dec)
     self.assertEqual(gp1, gp2)
     self.assertEqual(gp1, gp3)
     self.assertEqual(gp1, gp4)
     self.assertEqual(gp1, gp5)
     self.assertEqual(gp1, gp6)
     self.assertEqual(gp1, gp7)
     self.assertEqual(gp1, gp8)
     tgl = GeoLocation(Decimal('99999.9'),
                       (Decimal('52.5'), Decimal('13.4')))
     tgl2 = GeoLocation(Decimal('99999.9'),
                        GeoCoordinates(Decimal('52.5'), Decimal('13.4')))
     tgl3 = GeoLocation(Decimal('99998.9'),
                        GeoCoordinates(Decimal('52.5'), Decimal('13.4')))
     self.assertEqual(tgl.timestamp, Decimal('99999.9'))
     self.assertEqual(tgl.coordinates.latitude, Decimal('52.5'))
     self.assertEqual(tgl.coordinates.longitude, Decimal('13.4'))
     self.assertEqual(tgl, tgl2)
     self.assertNotEqual(tgl, tgl3)
     self.assertTrue(tgl > tgl3)
     s = GeoLocationSeries([tgl, tgl3])
     joined_route = s.union(
         GeoLocationSeries([
             GeoLocation(100000.9, [23, 67]),
         ]))
     self.assertEqual("`m}mlw@_|l_I_expAA??A~u`sD_wcfI", str(joined_route))
コード例 #6
0
ファイル: models.py プロジェクト: ichem/django-seuranta
 def data(self, value):
     if not isinstance(value, GeoLocationSeries):
         value = GeoLocationSeries(value)
     self.encoded_data = str(value)
コード例 #7
0
ファイル: models.py プロジェクト: ichem/django-seuranta
 def data(self):
     return GeoLocationSeries(self.encoded_data)
コード例 #8
0
ファイル: models.py プロジェクト: ichem/django-seuranta
 def get_full_route(self):
     result = GeoLocationSeries('')
     for route in self.defined_routes.all():
         result = result.union(route.data)
     return result
コード例 #9
0
 def to_internal_value(self, data):
     return GeoLocationSeries(data)
コード例 #10
0
ファイル: models.py プロジェクト: Maasik/django-seuranta
 def get_full_route(self):
     result = GeoLocationSeries('')
     for route in self.defined_routes.all():
         result = result.union(route.data)
     return result