-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar_Dict_Get.py
146 lines (133 loc) · 5.31 KB
/
Car_Dict_Get.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import pickle
# 初始的算法测试代码
'''
MinCSpace = {}
MinCTime = {}
MinESpace = {}
MinETime = {}
with open("D:\\Python\\Datas\\Data_VLPR\\VLPR\\2015\\Bayonet20150801", encoding="utf-8") as f:
MinCTime.setdefault("0801", {})
MinCSpace.setdefault("0801", {})
MinETime.setdefault("0801", {})
MinESpace.setdefault("0801", {})
for line in f:
lines = line.split(",")
if "闽C" in lines[8]:
if lines[8] in MinCTime["0801"] and lines[10] in MinCTime["0801"][lines[8]]:
continue
else:
MinCSpace["0801"].setdefault(lines[8], []).append(lines[6])
MinCTime["0801"].setdefault(lines[8], []).append(lines[10])
elif "闽E" in lines[8]:
if lines[8] in MinETime["0801"] and lines[10] in MinETime["0801"][lines[8]]:
continue
else:
MinESpace["0801"].setdefault(lines[8], []).append(lines[6])
MinETime["0801"].setdefault(lines[8], []).append(lines[10])
print(MinCTime)
print(MinETime)
print(MinC)
with open("2015\\MinC.pkl", "wb") as f:
pickle.dump(MinC, f, pickle.HIGHEST_PROTOCOL)
with open("2015\\MinD.pkl", "wb") as f:
pickle.dump(MinD, f, pickle.HIGHEST_PROTOCOL)
with open("2015\\MinE.pkl", "wb") as f:
pickle.dump(MinE, f, pickle.HIGHEST_PROTOCOL)
'''
path2015 = []
path2016 = []
# 读取地址 下面的两个txt应该是最初数据文件的地址
with open("Source2015.txt") as f:
for line in f:
path2015.append(line.replace("\n", ""))
with open("Source2016.txt") as f:
for line in f:
path2016.append(line.replace("\n", ""))
# 对每个数据处理,闽C、闽E三个月数据做一组,闽D每天一个单独数据
# 需求的部分变量
i = 0
MinCSpace = {}
MinCTime = {}
MinESpace = {}
MinETime = {}
MinDSpace = {}
MinDTime = {}
# 对2016年的闽D 时间空间处理,由于存储格式不同,与闽C 闽E 的处理分开,2015年处理同样修改相关文件名即可
i = 0
for file_path in path2016:
date = file_path[-4:]
new_path_space = "2016\\Space\\MinDSpace" + date + ".pkl"
new_path_time = "2016\\Time\\MinDTime" + date + ".pkl"
with open(file_path, encoding="utf-8") as file_obj:
for line in file_obj:
lines = line.split(",")
if "闽D" in lines[8]:
if lines[8] in MinDTime and lines[10] in MinDTime[lines[8]]:
continue
else:
MinDSpace.setdefault(lines[8], []).append(lines[6])
MinDTime.setdefault(lines[8], []).append(lines[10])
with open(new_path_space, "wb") as f:
pickle.dump(MinDSpace, f, pickle.HIGHEST_PROTOCOL)
with open(new_path_time, "wb") as f:
pickle.dump(MinDTime, f, pickle.HIGHEST_PROTOCOL)
MinDSpace.clear()
MinDTime.clear()
i += 1
print(i)
print("End2")
# 20161030的文件编码异常,作为测试补充文件使用
'''
with open("D:\\Python\\Datas\\Data_VLPR\\VLPR\\2016\\Bayonet20161030", encoding="utf-8") as file_obj:
for line in file_obj:
lines = line.split(",")
if "闽D" in lines[8]:
if lines[8] in MinDTime and lines[10] in MinDTime[lines[8]]:
continue
else:
MinDSpace.setdefault(lines[8], []).append(lines[6])
MinDTime.setdefault(lines[8], []).append(lines[10])
with open("2016\\Space\\MinDSpace1030.pkl", "wb") as f:
pickle.dump(MinDSpace, f, pickle.HIGHEST_PROTOCOL)
with open("2016\\Time\\MinDTime1030.pkl", "wb") as f:
pickle.dump(MinDTime, f, pickle.HIGHEST_PROTOCOL)
MinDSpace.clear()
MinDTime.clear()
print("End2")
'''
# 对2016年的闽C 闽E的时间空间做处理,2015的话修改相关文件地址即可
for file_path in path2016:
date = file_path[-4:]
MinETime.setdefault(date, {})
MinESpace.setdefault(date, {})
MinCTime.setdefault(date, {})
MinCSpace.setdefault(date, {})
with open(file_path, encoding="utf-8") as file_obj:
for line in file_obj:
lines = line.split(",")
if "闽C" in lines[8]:
if lines[8] in MinCTime[date] and lines[10] in MinCTime[date][lines[8]]:
continue
else:
MinCSpace[date].setdefault(lines[8], []).append(lines[6])
MinCTime[date].setdefault(lines[8], []).append(lines[10])
elif "闽E" in lines[8]:
if lines[8] in MinETime[date] and lines[10] in MinETime[date][lines[8]]:
continue
else:
MinESpace[date].setdefault(lines[8], []).append(lines[6])
MinETime[date].setdefault(lines[8], []).append(lines[10])
i = i + 1
print(i)
print(len(MinESpace))
print(len(MinCSpace))
print(len(MinCTime))
print(len(MinETime))
with open("2016\\Space\\MinCSpace.pkl", "wb") as f:
pickle.dump(MinCSpace, f, pickle.HIGHEST_PROTOCOL)
with open("2016\\Time\\MinCTime.pkl", "wb") as f:
pickle.dump(MinCTime, f, pickle.HIGHEST_PROTOCOL)
with open("2016\\Space\\MinESpace.pkl", "wb") as f:
pickle.dump(MinESpace, f, pickle.HIGHEST_PROTOCOL)
with open("2016\\Time\\MinETime.pkl", "wb") as f:
pickle.dump(MinETime, f, pickle.HIGHEST_PROTOCOL)