blob: 14cbc31a0e839ee9588635b20b3faf5a06f87693 (
plain)
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
|
from opendc.models.model import Model
from opendc.util import database
class TaskDuration(Model):
JSON_TO_PYTHON_DICT = {
'TaskDuration': {
'taskId': 'task_id',
'duration': 'duration'
}
}
@classmethod
def _from_database_row(cls, row):
"""Instantiate a RoomState from a database row."""
return cls(
task_id=row[0],
duration=row[1]
)
@classmethod
def from_experiment_id(cls, experiment_id):
"""Query RoomStates by their Experiment id."""
room_states = []
statement = '''
SELECT task_id, MAX(tick) - MIN(tick) as duration FROM task_states
WHERE experiment_id = %s
GROUP BY task_id
'''
results = database.fetch_all(statement, (experiment_id,))
for row in results:
room_states.append(cls._from_database_row(row))
return room_states
def google_id_has_at_least(self, google_id, authorization_level):
"""Return True if the User has at least the given auth level over this TaskDuration."""
if authorization_level in ['EDIT', 'OWN']:
return False
return True
|