buses.py

changeset 134
4ac0f2e2ec4e
parent 127
2bc0529d44a5
child 136
27324a81beca
--- a/buses.py	Thu Dec 06 20:47:19 2018 +0200
+++ b/buses.py	Thu Dec 06 23:39:20 2018 +0200
@@ -5,7 +5,6 @@
 from copy import copy
 from misc import *
 from geometry import *
-import uuid
 
 def transform_trip_reference(reference):
 	return reference
@@ -153,11 +152,11 @@
 			return 'bus-stop'
 
 class BusHalt:
-	def __init__(self, arrival_time, departure_time, stop, trip, traveled_distance):
+	def __init__(self, arrival_time, departure_time, stop, trip, traveled_distance, visitnumber):
 		self.arrival_time, self.departure_time, self.stop, self.trip = arrival_time, departure_time, \
 			stop, trip
 		self.traveled_distance = traveled_distance
-		self.uuid = uuid.uuid4()
+		self.visitnumber = visitnumber
 	@property
 	def is_arrival(self):
 		if profile['regions']['use-regions']:
@@ -185,7 +184,7 @@
 		import datetime
 		return datetime.datetime.combine(date, datetime.time()) + self.arrival_time
 	def __repr__(self):
-		return 'BusHalt(%r, %r, %r, %r)' % (self.arrival_time, self.departure_time, self.stop, self.trip)
+		return 'BusHalt(%r, %r, %r, %r, %r, %r)' % (self.arrival_time, self.departure_time, self.stop, self.trip, self.traveled_distance, self.visitnumber)
 	def sign(self, long = False):
 		from busroute import reduce_schedule
 		return reduce_schedule(
@@ -193,6 +192,10 @@
 			trip_length = self.trip.length - self.traveled_distance,
 			long = long,
 		)
+	@property
+	def primary_key(self):
+		arrival_time = self.trip.schedule[0].arrival_time;
+		return self.trip.block_id + '-' + str(int(arrival_time.seconds)) + '-' + str(self.visitnumber)
 
 class BusStopCluster:
 	def __init__(self):
@@ -502,7 +505,8 @@
 				departure_time = read_time(row['departure_time'])
 				stop = bus_stops[row['stop_id']]
 				traveled_distance = float(row.get('shape_dist_traveled', 1)) * float(profile['metrics']['shape-modifier'])
-				trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance))
+				visitnumber = len(trip.schedule) + 1
+				trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance, visitnumber))
 				stop.involved_trips.add(trip)
 				progress += 1
 				if progress % 1000 == 0:
@@ -552,10 +556,6 @@
 					last_leg_distance = trip.schedule[-1].traveled_distance - trip.schedule[-2].traveled_distance
 					trip.schedule[-1].arrival_time = trip.schedule[-2].departure_time + timedelta(minutes = last_leg_distance / bus_speed_coefficient)
 
-		global trips_by_vehicle_info
-		trips_by_vehicle_info = {}
-		for trip in all_trips.values():
-			trips_by_vehicle_info[(trip.block_id, trip.schedule[0].arrival_time)] = trip
 		# Add services to all bus stops
 		for route in routes.values():
 			for trip in route.trips:

mercurial