def getQuestion(client): awake = client.get("sound", 0) > 10000 or client["accel"] > .3 if awake:# and random() < .1: responses = filter(lambda response: response.clientID == client["clientID"], allOf(SurveyResponse)) if len(responses) == 0: answeredRecently = False else: answeredRecently = datetime.now() - responses[-1].time < timedelta(0, 8 * 60 * 60) if not answeredRecently: return q1
def tabulate(): indices = range(len(Question.questions)) columns = map(lambda i: "Response to question #%s" % str(i + 1), indices) csv = "RespondentIDNum, %s\n" % ', '.join(columns) surveys = defaultdict(list) for response in allOf(SurveyResponse): surveys[response.survey].append(response) for survey in surveys.values(): answers = ["No answer"] * len(Question.questions) for response in survey: answers[response.question] = str(response.answer) csv += ', '.join([survey[0].clientID] + answers) + '\n' return csv
#!/usr/bin/python from datetime import datetime, timedelta from schemas import Request, allOf oneHour = timedelta(0, 60 * 60) print set([request.ip for request in allOf(Request) if datetime.now() - request.time < 2 * oneHour])