-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup2.py
More file actions
148 lines (134 loc) · 4.58 KB
/
setup2.py
File metadata and controls
148 lines (134 loc) · 4.58 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
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
import os
import glob
import shutil
import subprocess
from openpyxl import *
del open
from pandas import *
path = os.getcwd()
if os.name == "nt":
sep = "\\"
else:
sep = "/"
input_path = path + "/INPUT/"
output_path = path + "/OUTPUT/"
combined_file = glob.glob(os.path.join(input_path, "*.xlsx"))
third_code = glob.glob(os.path.join(input_path, "*.csv"))
# get input files
if len(combined_file) == 0:
print("ERROR: no combined file found")
exit(1)
if len(third_code) == 0:
print("ERROR: no third coder file found")
exit(1)
if len(combined_file) > 2:
print("ERROR: multiple combined files found")
exit(1)
if len(third_code) > 2:
print("ERROR: multiple third coder files found")
exit(1)
combined_file = combined_file[0]
combined_file_name = combined_file.split(sep)[-1]
third_code = third_code[0]
third_code_name = third_code.split(sep)[-1]
os.chdir(input_path)
dts_input_path = path + "/DatavyuToSupercoder/Input/"
dts_output_path = path + "/DatavyuToSupercoder/Output/"
# move DTS output file to main output
third_code = glob.glob(os.path.join(dts_output_path, "*.xls"))[0]
third_code_name = third_code.split(sep)[-1]
os.chdir(dts_output_path)
shutil.copyfile(third_code_name, output_path + third_code_name)
# move combined file to output
os.chdir(input_path)
shutil.copyfile(combined_file_name, output_path + combined_file_name)
os.chdir(output_path)
combined_file = glob.glob(os.path.join(output_path, "*.xlsx"))[0]
third_code = glob.glob(os.path.join(output_path, "*.xls"))[0]
os.chdir(path)
with open('config.txt') as f:
lines = f.readlines()
try:
line2 = lines[5]
except:
print("No trials given in config file")
exit(1)
trials_and_times = line2.split(",")
trials = []
for trial_and_time in trials_and_times:
trial_and_time= trial_and_time.strip()
trials.append(trial_and_time.split(" ")[0])
data = read_excel(third_code, header = 1)
if not (len(trials) == list(data["Code"]).count("B")):
print("ERROR: Number of trials to reconcile doesn't match number of B's in 3rd coder sheet")
exit(1)
if not (len(trials) == list(data["Code"]).count("S")):
print("ERROR: Number of trials to reconcile doesn't match number of S's in 3rd coder sheet")
exit(1)
# finds the locations of B's in 3rd coder sheet
b_locations = []
s_locations = []
index = 0
while len(s_locations) < len(trials):
if data["Code"][index] == "B":
b_locations.append(index)
if data["Code"][index] == "S":
s_locations.append(index)
index += 1
os.chdir(output_path)
wb = Workbook()
wb.remove(wb.active)
# create sheets for each trial
for trial in trials:
name = "Trial " + trial
wb.create_sheet(name)
wb.save('reconciling.xlsx')
# add 3rd coder trials
for i in range(0, len(trials)):
index = 2
for j in range(b_locations[i], s_locations[i]+1):
name = "Trial " + trials[i]
sheet = wb[name]
sheet["A1"] = "3rd coder data for " + name
sheet["A" + str(index)] = data["Code"][j]
sheet["B" + str(index)] = data["Onset"][j]
sheet["C" + str(index)] = data["Offset"][j]
index += 1
wb.save('reconciling.xlsx')
wb2 = load_workbook(combined_file)
for i in range(0, 2):
# finds the B's and S's in the combined file
sheet2 = wb2.worksheets[i]
coder = sheet2.title
locations = {}
trial_num = 1
for j in range(1, sheet2.max_row+1):
cell = sheet2["A" + str(j)]
if cell.value == "B":
locations[trial_num] = {}
locations[trial_num]["B"] = j
if cell.value == "S":
locations[trial_num]["S"] = j
trial_num += 1
# adds the combined file trials to the sheet
for sheet in wb:
index = 2
trial = int(sheet.title.split()[1])
b_loc = locations[trial]["B"]
s_loc = locations[trial]["S"]
if i == 0:
sheet["E1"] = coder
else:
sheet["I1"] = coder
for j in range(b_loc, s_loc+1):
if i == 0:
sheet["E"+str(index)].value = sheet2["A"+str(j)].value
sheet["F"+str(index)].value = sheet2["B"+str(j)].value
sheet["G"+str(index)].value = sheet2["C"+str(j)].value
else:
sheet["I"+str(index)].value = sheet2["A"+str(j)].value
sheet["J"+str(index)].value = sheet2["B"+str(j)].value
sheet["K"+str(index)].value = sheet2["C"+str(j)].value
index += 1
wb.save('reconciling.xlsx')
print("Complete")