-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreparation.py
114 lines (89 loc) · 2.67 KB
/
preparation.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
import csv
import utilities
def searchTime(table, module):
course = ''
for line in table:
if line[1] == module:
course = line[0]
if line[3].find(module)!=-1:
if line[4]!='null':
return line[4]
else:
return searchTime(table, line[1])
return 'null'
def objectTime():
table_old = []
table_new = []
csvfile = open('object.csv', 'rt')
csvfile.readline()
lines_csv = csv.reader(csvfile)
for line in lines_csv:
table_old.append(line)
for line in table_old:
module = line[1]
time = line[4]
if time == 'null':
time = searchTime(table_old, module)
table_new.append([module,time])
# print([module, time])
csvfile = open('objectTime_2.csv', 'w', newline='')
writer = csv.writer(csvfile)
writer.writerows(table_new)
csvfile.close()
def logLag(logfile):
object_time = {}
log_new = []
log_new.append(['','','','',''])
csvfile = open('objectTime.csv', 'rt')
lines_csv = csv.reader(csvfile)
for line in lines_csv:
object_time[line[0]] = line[1]
csvfile.close()
csvfile = open(logfile, 'rt')
csvfile.readline()
lines_csv = csv.reader(csvfile)
csvfile_w = open("new_%s_2" % logfile, 'w', newline='')
writer = csv.writer(csvfile_w)
writer.writerow(['','','','',''])
for line in lines_csv:
if line[4] in object_time:
if object_time[line[4]] != 'null':
line[4] = utilities.timeSubtract(line[1], object_time[line[4]])
else:
line[4] = 'null'
else:
line[4] = 'null'
writer.writerow(line)
# log_new.append(line)
csvfile.close()
csvfile_w.close()
def endTime():
end_time = [ ['0'] for i in range (200905) ]
csvfile = open('date.csv', 'rt')
csvfile.readline()
date=csv.reader(csvfile)
datebyid={}
for line in date:
datebyid[line[0]]=line[2]
csvfile = open('enrollment_test.csv', 'rt')
csvfile.readline()
log = csv.reader(csvfile)
for line in log:
line_idx = int(line[0]) - 1
end_time[line_idx][0] = datebyid[line[2]]
csvfile.close()
csvfile = open('enrollment_train.csv', 'rt')
csvfile.readline()
log = csv.reader(csvfile)
for line in log:
line_idx = int(line[0]) - 1
end_time[line_idx][0] = datebyid[line[2]]
csvfile.close()
csvfile = open("end_time.csv", 'w', newline='')
writer = csv.writer(csvfile)
writer.writerows(end_time)
if __name__ == '__main__':
# objectTime()
logLag('log_train.csv')
logLag('log_test.csv')
# endTime()