Example #1
0
    def on_get(self):
        try:
            hpc = HazardPerceptionClip.objects
            if self.current_user:
                hpt = HazardPerceptionTest.objects(
                    uid=str(self.current_user.id))

                scores = {}
                for test in hpt:
                    if str(test.id) not in scores:
                        scores[str(test.id)] = test.score
                    else:
                        if scores[str(test.id)] < test.score:
                            scores[str(test.id)] = test.score
                    scores[str(test.cid)] = test.score
            else:
                scores = {}

            self.base_render("ppc/learn-hazard-two-clicks.html",
                             clips=hpc,
                             has_seen=scores.keys(),
                             older_scores=scores)
        except Exception, e:
            print e
            self.log.info("No hazard perception clips were found")
            self.base_render("ppc/learn-hazard-two-clicks.html", clips=None)
Example #2
0
    def wrapper(self, *args, **kwargs):
        from app.handlers.learn import ViewSectionHandler, GetClipPageHandler
        from app.handlers.test import CreateNewTestHandler

        try:
            if self.current_user and self.current_user['has_paid']:
                return method(self, *args, **kwargs)
            elif isinstance(self, ViewSectionHandler) and self.current_user and len(self.current_user['cursors'].keys()) < self.settings['sections_limit']:
                #if the request is to see a new section and the user has not reached the limit allow it
                return method(self, *args, **kwargs)
            elif isinstance(self, CreateNewTestHandler) and self.current_user:
                practice_limit = False
                mock_limit = False
                #if the request is to start a new practice test and the user has not reached the limit allow it
                if len(PractiseTest.objects(user=str(self.current_user.id))) >= self.settings['practice_tests_limit']:
                    practice_limit = True
                if len(MockTest.objects(user=str(self.current_user.id))) >= self.settings['mock_tests_limit']:
                    mock_limit = True

                if mock_limit or practice_limit:
                    self.redirect("/payment")                    
                else:
                    return method(self, *args, **kwargs)
            elif isinstance(self, GetClipPageHandler) and self.current_user and len(HazardPerceptionTest.objects(uid=str(self.current_user.id))) < self.settings['clips_limit']:
                #if the request is to start a new HAZARD test and the user has not reached the limit allow it
                return method(self, *args, **kwargs)
            else:
                #else redirect them to the payment page
                self.redirect("/payment")
        except Exception, e:
            raise tornado.web.HTTPError(403)
Example #3
0
 def wrapper(self, *args, **kwargs):
     from app.handlers.ppc import GetClipPageHandler
     try:
         if self.current_user and self.current_user['has_paid']:
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler):
             #if this is the first time a user requests a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler) and self.current_user and len(HazardPerceptionTest.objects(uid=str(self.current_user.id))) < 2:
             #if the request is to start a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         else:
             #else redirect them to the payment page
             self.redirect("/payment")
     except Exception, e:
         raise tornado.web.HTTPError(403)
Example #4
0
    def on_success(self, cid, score, solution_clip_name, clicks, hits): 
        #Create a new test and save the score
        hpt = HazardPerceptionTest()
        hpt.uid = str(self.current_user.id)
        hpt.cid = cid
        hpt.score = score
        hpt.save()

        #Update user's points
        self.current_user.update_points(score)

        if self.is_xhr:
            if clicks==0: clicks+=1 # Avoid ZeroDivisionError
            html = self.render_string("ui-modules/complete-video.html", clip=solution_clip_name, score=score, accuracy=float(hits)/clicks)
            self.xhr_response.update({"html": html})
            self.write(self.xhr_response) 
Example #5
0
 def wrapper(self, *args, **kwargs):
     from app.handlers.ppc import GetClipPageHandler
     try:
         if self.current_user and self.current_user['has_paid']:
             return method(self, *args, **kwargs)
         elif isinstance(self, GetClipPageHandler):
             #if this is the first time a user requests a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         elif isinstance(self,
                         GetClipPageHandler) and self.current_user and len(
                             HazardPerceptionTest.objects(
                                 uid=str(self.current_user.id))) < 2:
             #if the request is to start a new HAZARD test and the user has not reached the limit allow it
             return method(self, *args, **kwargs)
         else:
             #else redirect them to the payment page
             self.redirect("/payment")
     except Exception, e:
         raise tornado.web.HTTPError(403)
Example #6
0
    def wrapper(self, *args, **kwargs):
        from app.handlers.learn import ViewSectionHandler, GetClipPageHandler
        from app.handlers.test import CreateNewTestHandler

        try:
            if self.current_user and self.current_user['has_paid']:
                return method(self, *args, **kwargs)
            elif isinstance(self,
                            ViewSectionHandler) and self.current_user and len(
                                self.current_user['cursors'].keys(
                                )) < self.settings['sections_limit']:
                #if the request is to see a new section and the user has not reached the limit allow it
                return method(self, *args, **kwargs)
            elif isinstance(self, CreateNewTestHandler) and self.current_user:
                practice_limit = False
                mock_limit = False
                #if the request is to start a new practice test and the user has not reached the limit allow it
                if len(PractiseTest.objects(user=str(self.current_user.id))
                       ) >= self.settings['practice_tests_limit']:
                    practice_limit = True
                if len(MockTest.objects(user=str(self.current_user.id))
                       ) >= self.settings['mock_tests_limit']:
                    mock_limit = True

                if mock_limit or practice_limit:
                    self.redirect("/payment")
                else:
                    return method(self, *args, **kwargs)
            elif isinstance(self,
                            GetClipPageHandler) and self.current_user and len(
                                HazardPerceptionTest.objects(
                                    uid=str(self.current_user.id))
                            ) < self.settings['clips_limit']:
                #if the request is to start a new HAZARD test and the user has not reached the limit allow it
                return method(self, *args, **kwargs)
            else:
                #else redirect them to the payment page
                self.redirect("/payment")
        except Exception, e:
            raise tornado.web.HTTPError(403)
Example #7
0
    def on_get(self):
        try:
            hpc = HazardPerceptionClip.objects

            if self.current_user:
                hpt = HazardPerceptionTest.objects(uid=str(self.current_user.id))

                scores = {}
                for test in hpt:
                    if str(test.id) not in scores: 
                        scores[str(test.id)] = test.score
                    else:
                        if scores[str(test.id)] < test.score:
                            scores[str(test.id)] = test.score
                    scores[str(test.cid)] = test.score
            else:
                scores = {}
            
            self.base_render("learn/learn-hazard.html", clips=hpc, has_seen=scores.keys(), older_scores=scores)
        except Exception, e:
            self.log.info("No hazard perception clips were found")
            self.base_render("learn/learn-hazard.html", clips=None)