Пример #1
0
    def test_sets_itm_payoffs_and_program_numbers_basic(self):
        payouts = [('Bella Fabiela', '4', None, None, 2.1), ('Kendini', '2', None, 3.2, 2.1),
                   ('Latitudefortytwo', '5', 3.4, 2.4, 2.1)]
        self.db.generate_query.return_value = 'This is a SQL query string'
        self.db.query_db.return_value = payouts

        winner: HorseID = HorseID('Latitudefortytwo')
        placer: HorseID = HorseID('Kendini')
        shower: HorseID = HorseID('Bella Fabiela')

        race_id: RaceID = RaceID(date(2018, 1, 1), 'CD', 2)
        sut: Payouts = Payouts(race_id, self.db)

        # Run the method under test
        sut._get_payout_info()

        # Check the output state: W/P/S dicts should have entries for each horse
        self.assertTrue(sut.win_payouts[winner] == 3.4)
        self.assertTrue(sut.win_payouts[shower] == 0)
        self.assertTrue(sut.win_payouts[placer] == 0)
        self.assertTrue(sut.place_payouts[winner] == 2.4)
        self.assertTrue(sut.place_payouts[placer] == 3.2)
        self.assertTrue(sut.place_payouts[shower] == 0)
        self.assertTrue(sut.show_payouts[winner] == 2.1)
        self.assertTrue(sut.show_payouts[placer] == 2.1)
        self.assertTrue(sut.show_payouts[shower] == 2.1)
        # Check the output state: program_num dict should have entries mapping program numbers to HorseIDs
        self.assertTrue(sut.program_num_to_horse_id[2] == placer)
        self.assertTrue(sut.program_num_to_horse_id[4] == shower)
        self.assertTrue(sut.program_num_to_horse_id[5] == winner)
Пример #2
0
    def _get_placed_horses(self):
        place_spots: Dict = {
            1: 'win',
            2: 'place',
            3: 'show',
            4: 'fourth_place',
            5: 'fifth_place',
        }

        # Set to use consolidated races db
        self.db.set_db(consolidated_races_db)
        sql = self.db.generate_query(
            consolidated_performances_table,
            ['horse_name', 'horse_id', f'position_{self.distance}'],
            where=self._generate_where_for_race(),
            other=f'AND position_{self.distance} IN (1, 2, 3, 4, 5)')
        horses = self.db.query_db(sql)

        # Set win/place/show/4th/5th attributes based on horse's finish position
        for horse in horses:
            # Check if there's a horse already found for that finish position
            if getattr(self, place_spots[horse[2]]) is not None:
                raise DuplicateHorseException(
                    getattr(self, place_spots[horse[2]]),
                    HorseID(horse[0], horse[1]))

            setattr(self, place_spots[horse[2]], HorseID(horse[0], horse[1]))

        # After going through horses, check if any of win/place/etc. are empty
        # If so, put generic unknown horse in there

        for place in place_spots.keys():
            if getattr(self, place_spots[place]) is None:
                setattr(self, place_spots[place], HorseID.unknown_horse())
Пример #3
0
    def _get_race_performance(self, race_id: RaceID,
                              fields: list) -> HorsePerformance:
        # Get performance data from db
        sql = self.db.generate_query(
            horse_performance_table,
            fields,
            where=self._generate_where_for_race(race_id))
        results, columns = self.db.query_db(sql, return_col_names=True)

        # Raise PerformanceNotFoundException if no race data in db--these are tracked in self.performance_not_found_list
        if len(results) == 0:
            raise PerformanceNotFoundException(race_id,
                                               HorseID(self.horse_name))

        horse_performance = HorsePerformance(race_id)
        for value, column in zip(results[0], columns):
            key = attribute_map[column][0]
            distance = attribute_map[column][1]
            if key == 'position':
                horse_performance.position[distance] = value
            elif key == 'lead_or_beaten':
                horse_performance.lead_or_beaten[distance] = value
            else:
                raise Exception  #todo better error handling
        return horse_performance
Пример #4
0
    def test_gets_horses_in_race(self):
        """Checks that horses from DB are pulled and placed into Race.horses_in_race. Doesn't check that all horses
        are accounted for. Doesn't check for no results.
        """
        races = [
            [("Emery's Visualizer", '11010448', 1), ('Gotta B Quick', '13011522', 99), ('Louie Move', '13008915', 4),
             ('Maslow', '12018527', 7), ('Nineties Nieto', '12018033', 99), ('O Sole Mio', '13001233', 99),
             ('Perfect Summer', '13020069', 6), ('Pure Bingo', '13003414', 8), ('Sands of Time', '13024400', 3),
             ('U S S Hawk', '12022887', 5)],
            [('Kenzie Carolina', '9000648', 4), ('Lasting Rose', '10009231', 99), ("Maggie's Special", '7044751', 5),
             ('Seventyprcentcocoa', '8035306', 3), ("Smokin' Grey", '9006008', 2), ('Whiskey Miner', '9006184', 1)],
            [('Blue Chip Prospect', '15003296', 1), ('Candymankando', '15005700', 6), ('Disruptor', '14004085', 99),
             ('Enasoit', '14009674', 99), ('Hidalgo', '13007539', 2), ('Majestic Dunhill', '15014431', 5),
             ('McErin', '15004611', 7),
             ("New York's Finest", '14001917', 8), ('Psychoanalyze', '15021630', 4),
             ('Snake Oil Charlie', '12025664', 10), ('Spirit Special', '14002244', 99), ('Versed', '13013186', 3),
             ('Vital', '15018113', 9)],
            [('Boxwood', '16014866', None), ('Comic Kitten', '16001537', 1), ('Fun Paddy', '16022433', 2),
             ('Hard Legacy', '16000160', 3), ('Irish Willow', '16020681', 4), ("Julia's Ready", '16006089', 5),
             ('Lancelots Lady', '16005088', None), ('No Mo Temper', '16011079', 7), ('Silent Surprise', '16000453', 8),
             ('Speedy Solution', '16001377', 9), ('Support', '16003308', 10), ("The Beauty's Tale", '16014057', 11),
             ('Unapologetic Me', '16005275', 12)]
        ]

        race_id = RaceID(date(self.year, self.month, self.day), self.track, self.race_num)
        race = Race(race_id, self.db_handler, test_mode=True)

        for race_data in races:
            self.db_handler.generate_query.return_value = 'This is a SQL query string'
            self.db_handler.query_db.return_value = race_data

            race._get_horses_in_race()

            for horse in race_data:
                horse_id = HorseID(horse[0], horse[1])
                post_position = horse[2]

                # Make sure horse is populating in Race.horses_in_race
                self.assertTrue(horse_id in race.horses_in_race, f'Not populating horses in race (Horse {horse_id})')


                # Make sure that each Horse's post position is populating or it is assigned to Race.horses_scratched
                # or it's assigned to Race.post_position_missing if we don't have any info for it.
                if horse[2] == 99:
                    self.assertTrue(horse_id in race.horses_scratched,
                                    f'Scratched horse ({horse_id}) not put into Race.horses_scratched')
                elif horse[2] is None:
                    self.assertTrue(horse_id in race.post_position_missing,
                                    f'Horse ({horse_id}) with missing post position not assigned to post position 0')
                else:
                    if post_position not in race.post_positions:
                        self.fail(f'No post position in Race.post_positions--should have been populated for {horse_id}')
                    self.assertTrue(race.post_positions[post_position] == horse_id,
                                    f'Horse ({horse_id}) not assigned correct post position.')
Пример #5
0
    def _get_payout_info(self):
        self.db.set_db(payouts_db)
        sql = self.db.generate_query(payouts_wps_table, ['horse_name', 'program_num', 'payout_win',
                                                         'payout_place', 'payout_show'],
                                     where=self.race_id.generate_sql_where())
        itm_horses = self.db.query_db(sql)

        for horse in itm_horses:
            horse_id = HorseID(horse[0])
            self.program_num_to_horse_id[int(horse[1])] = horse_id
            self.win_payouts[horse_id] = horse[2] if horse[2] is not None else 0
            self.place_payouts[horse_id] = horse[3] if horse[3] is not None else 0
            self.show_payouts[horse_id] = horse[4] if horse[4] is not None else 0
Пример #6
0
    def test_get_win_place_show_info_basic(self):
        # Set up data
        self.db_handler.generate_query.return_value = 'This is a SQL query string'
        self.db_handler.query_db.return_value = [('Dark Artist', '15001360', 1), ('Lisa Limon', '15000251', 4),
                                                 ('So Hi Society (IRE)', 'F0044820', 3),
                                                 ('Stormologist', '15007318', 5), ('Too Charming', '15001119', 2)]



        # Set up the SUT
        race_id = RaceID(date(self.year, self.month, self.day), self.track, self.race_num)
        race = Race(race_id, self.db_handler, test_mode=True)

        # Run the SUT
        race._get_placed_horses()

        # Check the output
        self.assertTrue(race.win == HorseID('Dark Artist', '15001360'))
        self.assertTrue(race.place == HorseID('Too Charming', '15001119'))
        self.assertTrue(race.show == HorseID('So Hi Society (IRE)', 'F0044820'))
        self.assertTrue(race.fourth_place == HorseID('Lisa Limon', '15000251'))
        self.assertTrue(race.fifth_place == HorseID('Stormologist', '15007318'))
Пример #7
0
    def test_get_win_place_show_info_missing_some(self):
        # Set up data with no place horse in db
        self.db_handler.generate_query.return_value = 'This is a SQL query string'
        self.db_handler.query_db.return_value = [('Dark Artist', '15001360', 1), ('Lisa Limon', '15000251', 4),
                                                 ('So Hi Society (IRE)', 'F0044820', 3),
                                                 ('Stormologist', '15007318', 5)]
        # Set up the SUT
        race_id = RaceID(date(self.year, self.month, self.day), self.track, self.race_num)
        race = Race(race_id, self.db_handler, test_mode=True)

        # Run the SUT
        race._get_placed_horses()

        # Check the output state. Race.place should have a Horse.unknown_horse() in it
        self.assertEqual(race.place, HorseID.unknown_horse())
Пример #8
0
    def _get_horses_in_race(self) -> None:
        """Populates Race.horses_in_race, Race.horses_scratched, and Race.post_positions from db data"""

        # Get data from db
        self.db.set_db(consolidated_races_db)
        sql = self.db.generate_query(
            'horses_consolidated_performances',
            ['horse_name', 'horse_id', 'post_position'],
            where=self._generate_where_for_race())
        horses = self.db.query_db(sql)

        for horse in horses:
            horse_id = HorseID(horse[0], horse[1])
            # Populate Race.horses_in_race
            self.horses_in_race.append(horse_id)

            # Populate post positions. Send to scratches if 99, and send to post_position_missing if no info
            if horse[2] == 99:
                self.horses_scratched.append(horse_id)
            elif horse[2] is None:
                self.post_position_missing.append(horse_id)
            else:
                self.post_positions[horse[2]] = horse_id