Exemple #1
0
    def on_post(self):
        try:
            cid = self.get_argument("cid", None)
            answers = self.get_argument("answers", None)
            if answers:
                answers = tornado.escape.json_decode(answers)
            answers = [float(answer) for answer in answers]
            clip = HazardPerceptionClip.objects(id=cid).get()
            correct_answers = clip.hazards
            score = 0
            hits = 0
            for a in answers:
                for ca in correct_answers:
                    lower_limit = ca.start
                    upper_limit = ca.end
                    if lower_limit <= a <= upper_limit :
                        hits += 1
                        #Simple linear interpolation to get the score. The sooner u spot the hazard the more the points
                        points = 5 * (1 - (a - lower_limit) / (upper_limit-lower_limit))
                        score+= int(math.ceil(points))
                        correct_answers.remove(ca)

            return (cid, score, clip.solution_clip_name, len(answers), hits)
        except Exception, e:
            self.log.warning(str(e))
Exemple #2
0
 def on_get(self):
     try:
         cid = self.get_argument("cid", None)
         hpc = HazardPerceptionClip.objects(id=cid).get()
         self.base_render("learn/learn-clip.html", cid=cid, path= hpc.base_dir + hpc.clip_name)
     except Exception, e:
         self.log.warning("Error while rendering clip page: " + str(e))