buses.py

changeset 26
69cc75506d4f
parent 24
e6bdb9c54096
child 28
670ffa424ded
equal deleted inserted replaced
25:cb423946cf33 26:69cc75506d4f
356 assert cluster.url_name not in clusters_by_name 356 assert cluster.url_name not in clusters_by_name
357 clusters_by_name[cluster.url_name] = cluster 357 clusters_by_name[cluster.url_name] = cluster
358 358
359 print('Ladataan aikataulut... ', end = '', flush = True, file = stderr) 359 print('Ladataan aikataulut... ', end = '', flush = True, file = stderr)
360 with open('gtfs/stop_times.txt') as file: 360 with open('gtfs/stop_times.txt') as file:
361 rivimäärä = sum(line.count('\n') for line in file) 361 row_count = sum(line.count('\n') for line in file)
362 progress = 0 362 progress = 0
363 file.seek(0) 363 file.seek(0)
364 for row in read_csv(file): 364 for row in read_csv(file):
365 trip = all_trips[transform_trip_reference(row['trip_id'])] 365 trip = all_trips[transform_trip_reference(row['trip_id'])]
366 arrival_time = read_time(row['arrival_time']) 366 arrival_time = read_time(row['arrival_time'])
368 stop = bus_stops[row['stop_id']] 368 stop = bus_stops[row['stop_id']]
369 traveled_distance = float(row['shape_dist_traveled']) 369 traveled_distance = float(row['shape_dist_traveled'])
370 trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance)) 370 trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance))
371 progress += 1 371 progress += 1
372 if progress % 1000 == 0: 372 if progress % 1000 == 0:
373 print('\rLadataan aikataulut... %.1f%%' % (progress * 100 / rivimäärä), end = ' ', file = stderr) 373 print('\rLadataan aikataulut... %.1f%%' % (progress * 100 / row_count), end = ' ', file = stderr)
374 print('\rLadataan aikataulut... ladattu', file = stderr) 374 print('\rLadataan aikataulut... ladattu', file = stderr)

mercurial