def test_multipleraces_upload(self): #===================================================== # Validate Race Details #===================================================== # Validate the race details have been uploaded. raceobj1 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=1, roundnumber=1, racelength=6, winninglapcount=12, mainevent=3) raceobj3 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=3, roundnumber=1, racelength=6, winninglapcount=12, mainevent=1) #===================================================== # Validate Ranking #===================================================== # Create a RankedClass rnk_class = RankedClass(trackkey = self.trackname_obj, raceclass = "RankingTestClass", startdate = '2010-01-01 01:01:01', lastdate = '2010-01-01 01:01:01', experation = 10, requiredraces = 1) rnk_class.save() # Run ranking for that class process_ranking(rnk_class) # We want their to be only one ranking for each of these racers (there events should # have been collapsed into a single race). racer1 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer One').id) racer2 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Two').id) racer3 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Three').id) racer4 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Four').id) racer5 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Five').id) racer6 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Six').id) racer7 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Seven').id) self.assertAlmostEqual(racer1.displayrank, 17.1445048619, places=4) self.assertAlmostEqual(racer7.displayrank, -3.91463635265, places=4)
def test_multipleraces_upload(self): #===================================================== # Validate Race Details #===================================================== # Validate the race details have been uploaded. raceobj1 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=1, roundnumber=1, racelength=6, winninglapcount=12, mainevent=1) #===================================================== # Validate Ranking #===================================================== # Create a RankedClass rnk_class = RankedClass(trackkey = self.trackname_obj, raceclass = "RankingTestClass", startdate = '2010-01-01 01:01:01', lastdate = '2010-01-01 01:01:01', experation = 10, requiredraces = 1) rnk_class.save() # Run ranking for that class process_ranking(rnk_class) # Validate that the three racers are now ranked. racer1 = Ranking.objects.get(raceridkey = RacerId.objects.filter(racerpreferredname='RankedRacer One')[0].id) racer2 = Ranking.objects.get(raceridkey = RacerId.objects.filter(racerpreferredname='RankedRacer Two')[0].id) racer3 = Ranking.objects.get(raceridkey = RacerId.objects.filter(racerpreferredname='RankedRacer Three')[0].id) self.assertAlmostEqual(racer1.displayrank, 11.6069655461, places=4) self.assertAlmostEqual(racer2.displayrank, 6.22000799505, places=4) self.assertAlmostEqual(racer3.displayrank, -1.89718140627, places=4)
def test_multipleraces_upload(self): #===================================================== # Validate Race Details #===================================================== # Validate the race details have been uploaded. raceobj1 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=1, roundnumber=1, racelength=6, winninglapcount=12, mainevent=2) raceobj2 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=2, roundnumber=1, racelength=6, winninglapcount=12, mainevent=1, maineventroundnum=1) raceobj3 = SingleRaceDetails.objects.get(trackkey=self.trackname_obj, racedata="RankingTestClass", racenumber=1, roundnumber=2, racelength=6, winninglapcount=12, mainevent=1, maineventroundnum=2) #===================================================== # Validate Ranking #===================================================== # Create a RankedClass rnk_class = RankedClass(trackkey = self.trackname_obj, raceclass = "RankingTestClass", startdate = '2010-01-01 01:01:01', lastdate = '2010-01-01 01:01:01', experation = 10, requiredraces = 1) rnk_class.save() # Run ranking for that class process_ranking(rnk_class) rnk_event1 = RankEvent.objects.get(rankedclasskey=rnk_class.id, eventcount=1) rnk_event2 = RankEvent.objects.get(rankedclasskey=rnk_class.id, eventcount=2) racer4 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Four').id, racecount=1, rankeventkey=rnk_event2) # Validate racer five's rank does not change after the first event. racer5 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Five').id, racecount=1, rankeventkey=rnk_event1) self.assertAlmostEqual(racer5.displayrank, -3.03089030448, places=4) racer5 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Five').id, racecount=1, rankeventkey=rnk_event2) self.assertAlmostEqual(racer5.displayrank, -3.03089030448, places=4) # Validate racer one's rank before A2 main racer1 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer One').id, racecount=1, rankeventkey=rnk_event1) self.assertAlmostEqual(racer1.displayrank, 15.910124731, places=4) # Validate racer one and three after A2 main. racer1 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer One').id, racecount=2, rankeventkey=rnk_event2) self.assertAlmostEqual(racer1.displayrank, 21.1014540971, places=4) racer3 = Ranking.objects.get(raceridkey = RacerId.objects.get(racerpreferredname='RankedRacer Three').id, racecount=2, rankeventkey=rnk_event2) classes = get_ranked_classes_by_track(self.trackname_obj.id) # There should only be one class, we will take it and the top racer ranked_class_id, top_racers = classes[0] self.assertEqual(ranked_class_id, rnk_class.id) self.assertAlmostEqual(top_racers[0].displayrank, 21.1014540971, places=4) self.assertAlmostEqual(top_racers[2].displayrank, 7.91634267877, places=4)