summaryrefslogtreecommitdiff
path: root/opendc/models/task_duration.py
diff options
context:
space:
mode:
authorleonoverweel <l.overweel@gmail.com>2017-01-24 12:05:15 +0100
committerleonoverweel <l.overweel@gmail.com>2017-01-24 12:05:15 +0100
commit86a50a4f6df9ece982743a3b7ca510846d248909 (patch)
tree79edc0478908b7fee9e5dca2088e562c7a62038b /opendc/models/task_duration.py
Initial commit
Diffstat (limited to 'opendc/models/task_duration.py')
-rw-r--r--opendc/models/task_duration.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/opendc/models/task_duration.py b/opendc/models/task_duration.py
new file mode 100644
index 00000000..31334040
--- /dev/null
+++ b/opendc/models/task_duration.py
@@ -0,0 +1,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 = ?
+ GROUP BY task_id
+ '''
+
+ results = database.fetchall(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