def get_survey_results(surveyQuestion): resultsDict = defaultdict(int) collection = database.getCurrentCollection() results = collection.find({surveyQuestion:{'$exists': True}}) for result in results: answer = result[surveyQuestion][0] #TODO: Questions with multiple answers? resultsDict[answer] += 1 return resultsDict
def getLastSurveys(amount): results = list(database.getCurrentCollection().find().sort("_id", -1).limit(int(amount))) return make_response(json.dumps(results, default=json_util.default), 200)
def getSurveyCount(): count = database.getCurrentCollection().count() return make_response(str(count), 200)
def completedSurvey(): database.getCurrentCollection().insert(dict(request.form)) return make_response("OK", 200)