-
Notifications
You must be signed in to change notification settings - Fork 4
/
counts.py
212 lines (182 loc) · 5.46 KB
/
counts.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import pandas as pd
import numpy as np
import os, time
def get_survey(csvfile):
if csvfile.find('A1') > 0:
return 'A1'
elif csvfile.find('A2') > 0:
return 'A2'
elif csvfile.find('A3') > 0:
return 'A3'
elif csvfile.find('A4') > 0:
return 'A4'
elif csvfile.find('B1') > 0:
return 'B1'
elif csvfile.find('B2') > 0:
return 'B2'
elif csvfile.find('B3') > 0:
return 'B3'
elif csvfile.find('C2') > 0:
return 'C2'
elif csvfile.find('C3') > 0:
return 'C3'
elif csvfile.find('D4') > 0:
return 'D4'
else:
return 'OTHER'
def ytd_tonum(datestring):
split=datestring.split('-')
month=split[1]
day=split[2]
year=split[0]
# all the years are the same, so ignore this
# taken from https://www.timeanddate.com/calendar/months/
if month == '01':
# days in the month prior
days=0
elif month == '02':
days=31
elif month == '03':
days=31+28
elif month == '04':
days=31+28+31
elif month == '05':
days=31+28+31+30
elif month == '06':
days=31+28+31+30+31
elif month == '07':
days=31+28+31+30+31+30
elif month == '08':
days=31+28+31+30+31+30+31
elif month == '09':
days=31+28+31+30+31+30+31+31
elif month == '10':
days=31+28+31+30+31+30+31+31+30
elif month == '11':
days=31+28+31+30+31+30+31+31+30+31
elif month == '12':
days=31+28+31+30+31+30+31+31+30+31+30
if year == '2020':
days=int(day)+days
elif year == '2019':
days=int(day)+days-365
return days
listdir=os.listdir()
csv_files=list()
for i in range(len(listdir)):
if listdir[i].endswith('.csv'):
csv_files.append(listdir[i])
count=0
id_dict=dict()
id_list=list()
for i in range(len(csv_files)):
g=pd.read_csv(csv_files[i])
ids_=g['mTurk worker ID']
starts=g['startTime']
survey=get_survey(csv_files[i])
for j in range(len(g)):
row=g.iloc[j,:]
null_num=sum(pd.isnull(row))
if null_num > 50:
count=count+1
else:
if ids_[j] in id_list:
if {survey:ytd_tonum(starts[j][0:10])} not in id_dict[ids_[j]]:
id_dict[ids_[j]]=id_dict[ids_[j]]+[{survey:ytd_tonum(starts[j][0:10])}]
else:
id_dict[ids_[j]]=[{survey:ytd_tonum(starts[j][0:10])}]
id_list.append(ids_[j])
print(count)
print(len(set(id_list)))
print(id_dict)
ids_=list(id_dict)
values_=list(id_dict.values())
yes=list()
day_difs=list()
paths=list()
# get average distance between days
for i in range(len(values_)):
if len(values_[i]) == 1:
print(values_[i])
paths.append(list(values_[i][0])[0][0])
if len(values_[i]) == 2:
print(values_[i])
day_dif=abs(list(values_[i][0].values())[0]-list(values_[i][1].values())[0])
day_difs.append(day_dif)
paths.append(list(values_[i][0])[0][0]+list(values_[i][1])[0][0])
elif len(values_[i]) == 3:
print(values_[i])
day_dif=abs(list(values_[i][0].values())[0]-list(values_[i][1].values())[0])
day_difs.append(day_dif)
day_dif=abs(list(values_[i][1].values())[0]-list(values_[i][2].values())[0])
day_difs.append(day_dif)
paths.append(list(values_[i][0])[0][0]+list(values_[i][1])[0][0]+list(values_[i][2])[0][0])
elif len(values_[i]) == 4:
print(values_[i])
day_dif=abs(list(values_[i][0].values())[0]-list(values_[i][1].values())[0])
day_difs.append(day_dif)
day_dif=abs(list(values_[i][1].values())[0]-list(values_[i][2].values())[0])
day_difs.append(day_dif)
day_dif=abs(list(values_[i][2].values())[0]-list(values_[i][3].values())[0])
day_difs.append(day_dif)
paths.append(list(values_[i][0])[0][0]+list(values_[i][1])[0][0]+list(values_[i][2])[0][0]+list(values_[i][3])[0][0])
elif len(values_[i]) == 4:
print(values_[i])
day_dif=abs(list(values_[i][0].values())[0]-list(values_[i][1].values())[0])
day_difs.append(day_dif)
day_dif=abs(list(values_[i][1].values())[0]-list(values_[i][2].values())[0])
day_difs.append(day_dif)
day_dif=abs(list(values_[i][2].values())[0]-list(values_[i][3].values())[0])
day_difs.append(day_dif)
paths.append(list(values_[i][0])[0][0]+list(values_[i][1])[0][0]+list(values_[i][2])[0][0]+list(values_[i][3])[0][0])
print(np.mean(np.array(day_difs)))
print(np.std(np.array(day_difs)))
print(paths)
count=0
print('A')
print(paths.count('A'))
count=count+paths.count('A')
print('B')
print(paths.count('B'))
count=count+paths.count('B')
print('C')
print(paths.count('C'))
count=count+paths.count('C')
print('D')
print(paths.count('D'))
count=count+paths.count('D')
print('AA')
print(paths.count('AA'))
count=count+paths.count('AA')
print('AB')
print(paths.count('AB'))
count=count+paths.count('AB')
print('AC')
print(paths.count('AC'))
count=count+paths.count('AC')
print('AAA')
print(paths.count('AAA'))
count=count+paths.count('AAA')
print('ABA')
print(paths.count('ABA'))
count=count+paths.count('ABA')
print('ABC')
print(paths.count('ABC'))
count=count+paths.count('ABC')
print('ACB')
print(paths.count('ACB'))
count=count+paths.count('ACB')
print('AAAA')
print(paths.count('AAAA'))
count=count+paths.count('AAAA')
print('ABAB')
print(paths.count('ABAB'))
count=count+paths.count('ABAB')
print('ABCD')
print(paths.count('ABCD'))
count=count+paths.count('ABCD')
print('ACBD')
print(paths.count('ACBD'))
count=count+paths.count('ACBD')
print('OTHER')
print(len(paths)-count)