def test_calc_times(self):
        self.r.save()

        sess = Session()
        sess.name = "AM"
        sess.event = self.e
        sess.club = self.c
        sess.save()

        res = Result()
        res.reg = self.r
        res.session = sess
        res.club = self.c
        res.save()

        r = Run()
        r.base_time = 10.0
        r.result = res
        r.club = self.c
        r.save()

        res = Result()
        res.reg = self.r
        res.session = sess
        res.club = self.c
        res.save()

        r = Run()
        r.base_time = 10.0
        r.result = res
        r.club = self.c
        r.save()

        self.r.save()
        self.r.calc_times()

        self.assertEqual(self.r.total_raw_time, 20.0)
        self.assertEqual(self.r.total_index_time,
                         self.r.total_raw_time * self.race_class.pax)
    def test_calc_times(self):
        self.r.save()

        sess = Session()
        sess.name = "AM"
        sess.event = self.e
        sess.club = self.c
        sess.save()

        res = Result()
        res.reg = self.r
        res.session = sess
        res.club = self.c
        res.save()

        r = Run()
        r.base_time = 10.0
        r.result = res
        r.club = self.c
        r.save()

        res = Result()
        res.reg = self.r
        res.session = sess
        res.club = self.c
        res.save()

        r = Run()
        r.base_time = 10.0
        r.result = res
        r.club = self.c
        r.save()

        self.r.save()
        self.r.calc_times()

        self.assertEqual(self.r.total_raw_time, 20.0)
        self.assertEqual(self.r.total_index_time, self.r.total_raw_time * self.race_class.pax)
Пример #3
0
 def test_no_dibs(self): 
     reg = Registration()
     up = UserProfile.objects.get(user=self.u1)
     reg.user_profile = up
     reg.number = 15
     reg.race_class = self.race_class
     reg.pax_class = None
     reg.event = self.e4
     reg.club = self.c
     reg.save()   
     
     s = Session()
     s.event = self.e4
     s.name = "AM"
     s.club = self.c
     s.save()
     
     result = Result()
     result.reg = reg
     result.session = s
     result.club = self.c
     result.save()
     
     for k in range(0, 3):
         r = Run()
         r.base_time = 10.0
         r.calc_time = 10.0
         r.index_time = 10.0
         r.result = result
         r.club = self.c
         r.save()        
     
     self.c.assign_dibs()
     self.assertEqual(len(Dibs.objects.all()), 0) 
                     
     reg.delete()
     s.delete()
Пример #4
0
def upload_results(request, event_id): 
    validate_error = dict()

    event = Event.objects.get(pk=event_id)
    admin = is_club_admin(request.user, event.club)
    if not admin: 
        return HttpResponseForbidden()

    try: 
        name = request.POST.get('name') 
        if not name: 
            validate_error['name'] = "you must name the session"
            raise ValueError

        session = Session()
        session.club = event.club
        session.event = event
        session.save()

        f = StringIO.StringIO(request.FILES['results_file'].read())

        results = parse_axtime(event, session, f)

        if isinstance(results, dict): #some kind of error happened
            validate_error = results
            raise ValueError

        transaction.rollback()    
        return HttpResponse(content=json.dumps({'msg': "success"}), mimetype="application/json", status=200)
        
    except Exception:
        #import traceback
        #tb = traceback.format_exc()
        session.delete()
        transaction.rollback()
        print json.dumps(validate_error)
        return HttpResponse(content=json.dumps(validate_error), mimetype="application/json", status=400)
Пример #5
0
 def setUp(self): 
     
     self.today = datetime.date.today()
     
     self.c = Club()
     self.c.name = "test"
     self.c.events_for_dibs = 2
     self.c.save()
     
     self.race_class = RaceClass()
     self.race_class.name = "CSP"
     self.race_class.pax = .875
     self.race_class.club = self.c
     self.race_class.save()
     
     self.s = Season()
     self.s.year = 2011
     self.s.club = self.c
     self.s.save()
     
     self.e1 = Event()
     self.e1.name = "event1"
     self.e1.date = self.today-datetime.timedelta(days=10)
     self.e1.season = self.s
     self.e1.club = self.c
     self.e1.save()
     
     self.e2 = Event()
     self.e2.name = "event2"
     self.e2.date = self.today-datetime.timedelta(days=8)
     self.e2.season = self.s
     self.e2.club = self.c
     self.e2.save()
     
     self.e3 = Event()
     self.e3.name = "event3"
     self.e3.date = self.today-datetime.timedelta(days=5)
     self.e3.season = self.s
     self.e3.club = self.c
     self.e3.save()
     
     self.e4 = Event()
     self.e4.name = "event4"
     self.e4.date = self.today+datetime.timedelta(days=10)
     self.e4.season = self.s
     self.e4.club = self.c
     self.e4.save()
     
     self.events = [self.e1, self.e2, self.e3]       
     
     for event in self.events: 
         s = Session()
         s.event = event
         s.name = "AM"
         s.club = self.c
         s.save()
     
     self.u1 = User()
     self.u1.username = "******"
     self.u1.save()
     
     self.u2 = User()
     self.u2.username = "******"
     self.u2.save()
     
     self.u3 = User()
     self.u3.username = "******"
     self.u3.save()
     
     self.users = [self.u1, self.u2, self.u3]
     
     for i, user in enumerate(self.users): 
         up = user.get_profile()
         for j, event in enumerate(self.events): 
             if j<=i: 
                 r = Registration()
                 r.number = "%d"%(i+1)
                 r.race_class = self.race_class
                 r.pax_class = None
                 r.event = event    
                 r.user_profile = up
                 r.club = self.c
                 r.save()
                 
                 result = Result()
                 result.reg = r
                 result.session = event.sessions.all()[0]
                 result.club = self.c
                 result.save()
                 
                 for k in range(0, 3):
                     r = Run()
                     r.base_time = 10.0
                     r.calc_time = 10.0
                     r.index_time = 10.0
                     r.result = result
                     r.club = self.c
                     r.save()