diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 14:48:24 +0200 |
|---|---|---|
| committer | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 14:48:24 +0200 |
| commit | ff31029e732dd56743690dc608f535163a0548ff (patch) | |
| tree | 04fe8e4a17816d93db386b5b6c560be654cdee86 /opendc/models_old/task_duration.py | |
| parent | c2706e023070211f8ac992b800353807a1f10886 (diff) | |
Experiment
Diffstat (limited to 'opendc/models_old/task_duration.py')
| -rw-r--r-- | opendc/models_old/task_duration.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/opendc/models_old/task_duration.py b/opendc/models_old/task_duration.py new file mode 100644 index 00000000..5058e8de --- /dev/null +++ b/opendc/models_old/task_duration.py @@ -0,0 +1,39 @@ +from opendc.models_old.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 |
