-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_xp_chimera_create_auto.py
86 lines (62 loc) · 2.69 KB
/
user_xp_chimera_create_auto.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
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"ActiveTeachingServer.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
import datetime
from pytz import timezone
import pandas as pd
from user.authentication import sign_up
from user.models.user import User
from experimental_condition.models.experiment \
import ThresholdCondition, RecursiveCondition
def main():
df = pd.read_csv(os.path.join("subscriptions", "active-teaching-data.csv"),
index_col=[0], sep=';')
assert len(df["AnonName"].unique()) == len(df["AnonName"])
conditions = {
# Condition name, item specific
0: (RecursiveCondition.__name__, True),
1: (RecursiveCondition.__name__, False),
2: (ThresholdCondition.__name__, True),
3: (ThresholdCondition.__name__, False)}
cd_idx = 0
begin_with_active = True
for idx_row, row in df.iterrows():
email = f"{row['AnonName']}@aalto.fi"
if User.objects.filter(email=email).first() is None:
day, month, year = row["StartDate"].split(".")
hour, minute = row["SessionStartTime"].split(":")
hour = f"{int(hour):02d}"
minute = f"{int(minute):02d}"
day = f"{int(day):02d}"
month = f"{int(month):02d}"
first_session_string = f"{year}-{month}-{day} {hour}:{minute}"
first_session = datetime.datetime.fromisoformat(first_session_string)
first_session = timezone("Europe/Helsinki").localize(first_session)
first_session = first_session.astimezone(timezone('UTC'))
password = str(row["Password"])
cd, is_item_specific = conditions[cd_idx]
user = sign_up(
email=email,
password=password,
condition=cd,
first_session=first_session,
begin_with_active=begin_with_active,
is_item_specific=is_item_specific,
experiment_name="2020-09-04")
if user is not None:
print(f"user '{email}' created with success! \n"
f"first session: {first_session_string} "
f"Helsinki Time\n"
f"password: {password}")
else:
raise ValueError("WARNING!!! Something went wrong!")
else:
print(f"I will skip the user '{email}', "
f"he/she is already existing!")
cd_idx += 1
cd_idx %= len(conditions)
begin_with_active = not begin_with_active
if __name__ == "__main__":
main()