This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·183 lines (161 loc) · 6.33 KB
/
run.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
from coding_tool import create_app
from coding_tool.models import *
from coding_tool import db
import pandas as pd
import os
app = create_app()
static_file_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)))
def seed_publication():
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'publications.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
engine = db.get_engine()
for index, row in df.iterrows():
pub_id = int(row['pub_id'])
title = row['title']
year = int(row['year'])
venue = row['venue']
authors = row['authors']
institution = row['institution']
keywords = row['keywords']
e = Publication(pub_id=pub_id, title=title, year=year,
venue=venue, authors=authors, institution=institution,
keywords=keywords)
db.session.add(e)
db.session.commit()
def seed_experiments():
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'experiment_map.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
for index, row in df.iterrows():
exp_id = int(row['exp_id'])
pub_id = int(row['pub_id'])
lab_settings = int(row['lab_settings'])
p = Publication.query.get(pub_id)
e = Experiment(exp_id=exp_id, lab_settings=lab_settings, exp_pub=p)
db.session.add(e)
db.session.commit()
def seed_guidelines():
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'guidelines.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
for index, row in df.iterrows():
guide_id = int(row['guide_id'])
paper_id = int(row['paper_id'])
title = row['title']
year = row['year']
authors = row['authors']
address = row['address']
g = Guideline.query.get(guide_id)
p = Publication.query.get(int(paper_id))
if not g:
g = Guideline(guide_id=guide_id, title=title, year=year,
authors=authors, address=address)
g.referenced_by.append(p)
db.session.add(g)
db.session.commit()
db.session.commit()
def seed_sampling():
list_e = Experiment.query.all()
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'sampling.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
for index, row in df.iterrows():
sample_id = int(row['sample_id'])
pub_id = int(row['pub_id'])
sample_profile = row['sample_profile']
sample_characteristics = row['sample_characteristics']
recruiting_strategy = row['recruiting_strategy']
power_analysis = row['power_analysis']
total = 0
p = Experiment.query.get(int(sample_id))
s = Sampling(sample_id=sample_id, sample_total=total,
power_analysis=power_analysis)
s.exp_id = int(sample_id)
if isinstance(recruiting_strategy, str):
for strategy in recruiting_strategy.split(';'):
r = Recruting(recruiting_strategy=RecrutingType(
strategy.capitalize()), parent_recru=s)
r.parent = s
for profile in sample_profile.split(';'):
p = profile.replace(" ", "").split(':')
a = SamplingProfile(profile=ProfileType(
p[0].capitalize()), quantity=int(p[1]), parent_profile=s)
total += int(p[1])
s.profiles.append(a)
if isinstance(sample_characteristics, str):
for charac in sample_characteristics.lower().split(';'):
p = charac.replace(" ", "").split(':')
if len(p) > 1:
a = SamplingCharacteristic(
charac=p[0], info=p[1], parent_charac=s)
else:
a = SamplingCharacteristic(charac=p[0], parent_charac=s)
s.sample_total = total
db.session.add(s)
db.session.commit()
def seed_design():
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'doe.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
for index, row in df.iterrows():
exp_id = int(row['exp_id'])
factor_quantity = int(row['factor_quantity'])
design = row['design']
explicity_design = row['explicity_design']
tasks = row['tasks']
trial_duration = row['trial_duration']
s = ExperimentDesign(factor_quantity=factor_quantity, design=design,
is_explicity_design=explicity_design)
p = Experiment.query.get(int(exp_id))
p.design = s
for profile in tasks.split(';'):
p = profile.replace(" ", "").split(':')
a = Task(task_type=TaskType(
p[0].capitalize()), quantity=int(p[1]), task_parent=s)
db.session.add(a)
if isinstance(trial_duration, str):
data = trial_duration.split(':')
amount = data[1].split('-')
d = Duration(durantion_type=DurationType(data[0]), dura_parent=s)
d.set_amount(metric=amount[1], data=float(amount[0]))
db.session.add(d)
db.session.add(s)
db.session.commit()
def seed_measuriments():
file_name = os.path.join(
static_file_dir, 'coding_tool', 'static', 'csv', 'measurements.csv')
# Read CSV with Pandas
with open(file_name, 'r') as file:
df = pd.read_csv(file, sep='|')
for index, row in df.iterrows():
exp_id = int(row['exp_id'])
m_type = row['type']
m_instrument = row['instrument']
p = Experiment.query.get(exp_id)
m = Measurement(measurement_instruments=m_instrument,
measurement_type=NatureOfDataSource(m_type),
measu_parent=p.design)
db.session.add(m)
db.session.commit()
@app.before_first_request
def before_first_request_func():
seed_publication()
seed_guidelines()
seed_experiments()
seed_sampling()
seed_design()
seed_measuriments()
if __name__ == '__main__':
app.run(debug=True)