Created
June 11, 2014 18:47
-
-
Save berryp/6fd3926ae55d5445195c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/panoptic/handlers/questions.py b/panoptic/handlers/questions.py | |
index 479aad7..7d3e236 100644 | |
--- a/panoptic/handlers/questions.py | |
+++ b/panoptic/handlers/questions.py | |
@@ -1065,6 +1065,23 @@ class ExportProfiles(BaseHandler): | |
] | |
+class Timings(BaseHandler): | |
+ | |
+ @shoji.cherrypy.tools.value() | |
+ def GET(self): | |
+ qx = cherrypy.serving.request.qx | |
+ qx.require() | |
+ | |
+ print list(qx.get_survey_timings())[0] | |
+ return [{ | |
+ 'survey_id': survey.id, | |
+ 'total_start': survey.startdate, | |
+ 'total_end': survey.enddate, | |
+ 'field_start': survey.startfieldtimestamp, | |
+ 'field_end': survey.endfieldtimestamp, | |
+ } for survey in qx.get_survey_timings()] | |
+ | |
+ | |
class Questionnaire(BaseHandler): | |
"""/questionnaires/{name}/""" | |
@@ -1075,6 +1092,7 @@ class Questionnaire(BaseHandler): | |
cases = Cases() | |
counters = Counters() | |
profiles = ExportProfiles() | |
+ timings = Timings() | |
@shoji.cherrypy.tools.entity( | |
description="A questionnaire. Visit the 'versions' catalog to see " | |
@@ -1094,6 +1112,7 @@ class Questionnaire(BaseHandler): | |
"counters": "counters/", | |
"profiles": "profiles/", | |
}, | |
+ views={'timings': 'timings/'}, | |
) | |
@cherrypy.tools.cache_control(days=1) | |
def GET(self): | |
diff --git a/panoptic/models/questions.py b/panoptic/models/questions.py | |
index d8c32cc..5a0c83a 100644 | |
--- a/panoptic/models/questions.py | |
+++ b/panoptic/models/questions.py | |
@@ -683,6 +683,10 @@ class QuestionnaireEntity(mongo.Entity): | |
surveys = gsas_qx.get_surveys() | |
return surveys | |
+ def get_survey_timings(self): | |
+ timings = SurveyEntity.timings([s.id for s in self.get_surveys()]) | |
+ return timings | |
+ | |
def get_counters(self): | |
qx_name = self.obj['name'] | |
counters = QuestionnaireCountersEntity.get_counters(qx_name=qx_name) | |
diff --git a/panoptic/models/surveys.py b/panoptic/models/surveys.py | |
index 981af34..5f18edd 100644 | |
--- a/panoptic/models/surveys.py | |
+++ b/panoptic/models/surveys.py | |
@@ -290,6 +290,22 @@ class SurveyEntity(db.Entity): | |
";", term='%' + term + '%', limit=limit, offset=offset) | |
return (SurveyEntity(row=row) for row in query.fetchall()) | |
+ @classmethod | |
+ def timings(cls, survey_ids): | |
+ """Given a list of survey ids, return a list of survey entities | |
+ with time data.""" | |
+ ids = (tuple([str(id) for id in survey_ids]),) | |
+ query = db.cluster[cls.dbname].execute( | |
+ "SELECT " | |
+ " id, " | |
+ " startdate, " | |
+ " enddate, " | |
+ " startfieldtimestamp, " | |
+ " endfieldtimestamp " | |
+ "FROM surveys " | |
+ "WHERE id IN %s;", (ids,)) | |
+ return (cls(id=row['id'], row=row) for row in query.fetchall()) | |
+ | |
def assign_treatment(self, name, groups, block): | |
"""Given a treatment name, some group identifiers and a | |
sub-block, return one of the groups randomly, weighted by |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment