-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.py
More file actions
64 lines (47 loc) · 2.02 KB
/
Copy pathdata.py
File metadata and controls
64 lines (47 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pandas as pandas
import datetime
trips = pandas.read_csv("trips.txt")
stop_times = pandas.read_csv("stop_times.txt")
stops = pandas.read_csv("stops.txt")
stop_position_name = stops.loc[:,['stop_id', 'stop_lon', 'stop_lat', 'stop_name']]
route_trip = trips.loc[:,['route_id', 'trip_id']]
trip_stop_time = stop_times.loc[:, ['trip_id', 'arrival_time', 'stop_id']]
route_trip_stop_time = pandas.merge(route_trip, trip_stop_time, on = "trip_id")
final = pandas.merge(route_trip_stop_time, stop_position_name, on = "stop_id")
base_time = datetime.datetime(1900, 1, 1)
final['arrival_time'] = final['arrival_time'].apply(lambda time: (datetime.datetime(1900, 1, 1+int(int(time[:2])/24), int(time[:2])%24, int(time[3:5]), int(time[6:])) - base_time).total_seconds())
#datetime.datetime(0, 0, int(time[:2])/24, int(time[:2])%24, int(time[3:5]), int(time[6:]))
v2 = pandas.pivot_table(final, values = [ "stop_lon", "stop_id", "stop_lat" ], index =["trip_id", "route_id", "arrival_time", "stop_name"])
current_trip_id=''
current_route_id = ''
buf = ""
stop_count = 0
times = [1, 2]
def check(times):
current_time = times[0]
for time in times:
if(time<current_time):
return 0
return 1
f = open('out.csv', 'w')
#f = open(r'E:\OneDrive - stu.hit.edu.cn\codes\software_construction\Lab2-1160501022\test.csv', 'w')
#f = open(r'E:\OneDrive - stu.hit.edu.cn\codes\software_construction\Lab2-1160501022\out.csv', 'w')
test = v2[0:200]
for i, row in v2.iterrows():
if(current_trip_id != i[0]) :
f.write(current_route_id + "," + str(stop_count))
f.write('\n')
f.write(buf)
f.write('\n')
current_route_id = str(i[1])
current_trip_id = i[0]
stop_count = 0
buf = ''
if(check(times) == 0):
print(i, row, '\n')
print("check error\n")
break;
times = [1, 2]
buf += (str(i[3]).replace(',', ' ')+","+str(row['stop_lat'])+"," +str(row['stop_lon']) + "," + str(int(i[2])) + '\n')
stop_count += 1
f.close()