forked from hcc226/UrbanMotionAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrcDstCountByGrid.py
More file actions
69 lines (54 loc) · 1.98 KB
/
Copy pathsrcDstCountByGrid.py
File metadata and controls
69 lines (54 loc) · 1.98 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
65
66
67
68
69
import sys;
import string;
import time;
from util.tripFlow.base import getFormatGID
readPath = '/datahouse/tripflow/SRCDST-TJ/tj-byhour-tf/';
writePath = '/datahouse/tripflow/SRCDST-TJ/tj-byhour-res/';
startIndex = 0;
endIndex = 2087;
# from_array=[0]*10000000;
#to_array=[0]*10000000;
MAX_INDEX = 0;
def main():
start_time = time.time();
global MAX_INDEX;
from_array = [0] * 10000000;
to_array = [0] * 10000000;
for file_index in range(startIndex, endIndex + 1):
filename_r = "traveldata-" + str(file_index);
filename_w = str(file_index % 24) + "-" + str(file_index);
content = file(readPath + filename_r, 'r').read();
records = content.split("\n");
for record_index in range(len(records) - 1):
record = records[record_index];
columns = record.split(",");
gridId = getFormatGID([columns[4], columns[3]],0.0064,0.005, {
'north': 40.2500,
'south': 38.5667,
'west': 116.7167,
'east': 118.3233,
})["gid"]
if gridId > MAX_INDEX:
MAX_INDEX = gridId;
if columns[5] == "src":
from_array[gridId] = from_array[gridId] + 1;
elif columns[5] == "dst":
to_array[gridId] = to_array[gridId] + 1;
resultFile = file(writePath + filename_w, 'w');
for i in range(MAX_INDEX + 1):
resultFile.write(str(i) + "," + str(from_array[i]) + "," + str(to_array[i]) + "\n");
from_array[i] = 0;
to_array[i] = 0;
resultFile.close();
MAX_INDEX = 0;
# filename_w = str(4017) + "-" + str(4017);
# resultFile = file(writePath + filename_w, 'w');
# for i in range(MAX_INDEX + 1):
# resultFile.write(str(i) + "," + str(from_array[i]) + "," + str(to_array[i]) + "\n");
# from_array[i] = 0;
# to_array[i] = 0;
# resultFile.close();
# MAX_INDEX = 0;
print "Complete Time:" + str(time.time() - start_time);
if __name__ == '__main__':
main()