subDesTagesMitExtraKaese 2 years ago
parent
commit
1a08e650dd
1 changed files with 4 additions and 3 deletions
  1. 4 3
      workers/points2trips.py

+ 4 - 3
workers/points2trips.py

@@ -39,18 +39,20 @@ class TripConverter:
 def create_trip(markers: list[Marker]) -> Trip:
   print(len(markers), markers[0].timestamp, markers[-1].timestamp)
   trip = Trip.objects.filter(startTime__lte=markers[-1].timestamp, endTime__gte=markers[0].timestamp).first()
+  center = markers[len(markers)//2].location
   if not trip:
     trip = Trip.objects.create(
       startTime = markers[0].timestamp,
       endTime = markers[-1].timestamp,
       name = f"Trip {markers[0].timestamp}",
-      color = get_path_color(markers[0].timestamp)
+      color = get_path_color(markers[0].timestamp),
+      center = Point(center.x, center.y)
     )
   elif trip.startTime == markers[0].timestamp and trip.endTime == markers[-1].timestamp:
     print("Trip already exists")
     return trip
   
-  if not trip.name or "None" in trip.name:
+  if not trip.name or "None" in trip.name or trip.name.startswith("Trip "):
     start = get_location_name(markers[0].location)
     end = get_location_name(markers[-1].location)
     if start != end:
@@ -60,7 +62,6 @@ def create_trip(markers: list[Marker]) -> Trip:
   trip.startTime = markers[0].timestamp
   trip.endTime = markers[-1].timestamp
   trip.totalTime = trip.endTime - trip.startTime
-  center = markers[len(markers)//2].location
   trip.center = Point(center.x, center.y)
 
   total_distance = 0 # m