-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.py
131 lines (103 loc) · 4.23 KB
/
tables.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
import datetime
import sqlalchemy as sqa
from sqlalchemy.dialects.sqlite import INTEGER, VARCHAR, TIME, \
DATETIME, SMALLINT, BOOLEAN
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
Base = declarative_base()
COL = sqa.Column
class Experiment(Base):
__tablename__ = 'experiment'
id = COL(INTEGER, primary_key=True)
# hash = COL(VARCHAR(64))
name = COL(VARCHAR(64))
numPeople = COL(SMALLINT)
timeGroup = COL(TIME())
group = COL(VARCHAR(10))
outlier = COL(VARCHAR(1))
friendship = COL(SMALLINT)
notes = COL(VARCHAR(2048))
status = COL(VARCHAR(20))
def __init__(self, name, numPeople, timeGroup, group, outlier, friendship, notes):
# m = hashlib.sha512()
# m.update(str(id))
# self.hash = m.hexdigest()
self.name = name
self.numPeople = int(numPeople)
self.timeGroup = datetime.datetime.strptime(timeGroup, "%I:%M %p").time()
self.group = group
self.outlier = outlier
self.friendship = friendship
self.notes = notes
self.status = "Created" # or Running or Done
def __repr__(self):
return str(self.id)
class Annotation(Base):
__tablename__ = 'annotation'
id = COL(INTEGER, primary_key=True)
annotatorName = COL(VARCHAR(64))
personID = COL(INTEGER, sqa.ForeignKey('person.id'))
person = relationship('Person', backref='annotations', uselist=False)
__table_args__ = (sqa.UniqueConstraint('annotatorName', 'personID'),)
def __init__(self, annotatorName, experiment):
self.annotatorName = annotatorName
self.experiment = experiment
class Person(Base):
__tablename__ = 'person'
id = COL(INTEGER, primary_key=True)
gender = COL(VARCHAR(1))
age = COL(INTEGER)
idInExperiment = COL(INTEGER)
experimentID = COL(INTEGER, sqa.ForeignKey('experiment.id'))
experiment = relationship('Experiment', backref=backref('people', lazy='dynamic'))
def __init__(self, gender, age, idInExperiment, experiment):
self.gender = gender
self.age = age
self.experiment = experiment
self.idInExperiment = idInExperiment
def __repr__(self):
return str(self.id)
class PersonStatus(Base):
__tablename__ = 'person_status'
id = COL(INTEGER, primary_key=True)
timestamp = COL(DATETIME, default=datetime.datetime.utcnow)
engaged = COL(BOOLEAN)
usingTablet = COL(BOOLEAN)
currentTask = COL(VARCHAR(20))
personID = COL(INTEGER, sqa.ForeignKey('person.id'))
person = relationship('Person', backref=backref('personStatuses', lazy='dynamic'))
annotationID = COL(INTEGER, sqa.ForeignKey('annotation.id'))
annotation = relationship('Annotation', backref=backref('experimentStatuses', lazy='dynamic'))
def __init__(self, engaged, usingTablet, currentTask, person, annotation):
self.engaged = engaged
self.usingTablet = usingTablet
self.currentTask = currentTask
self.person = person
self.annotation = annotation
def __repr__(self):
return str(self.id)
class PostExperimentData(Base):
__tablename__ = 'post_experiment_data'
id = COL(INTEGER, primary_key=True)
timestamp = COL(DATETIME, default=datetime.datetime.utcnow)
annotationID = COL(INTEGER, sqa.ForeignKey('annotation.id'))
annotation = relationship('Annotation', backref=backref('post_experiment_response', uselist=False))
finalTime = COL(TIME)
rankNum = COL(INTEGER)
rankDenom = COL(INTEGER)
solved = COL(BOOLEAN)
howMuchSolved = COL(VARCHAR(100))
notes = COL(VARCHAR(2048))
def __init__(self, finalTimeMins, finalTimeSecs, rankNum, rankDenom, solved, howMuchSolved, notes, annotation):
self.finalTime = datetime.datetime.strptime(str(finalTimeMins) + " " + str(finalTimeSecs), "%M %S").time()
self.rankNum = rankNum
self.rankDenom = rankDenom
self.solved = True if (solved == "Yes") else False
self.howMuchSolved = howMuchSolved
self.notes = notes
self.annotation = annotation
def __repr__(self):
return str(self.id)
@property
def rank(self):
return round(self.rankNum / float(self.rankDenom), 3)