def resolve_bgms(self, event): """ Resolve the BMGs """ for bmg in event.bettingmarketgroups: if bmg["dynamic"]: # Update and crate BMs fuzzy_args = { "test_operation_equal_search": [ comparators.cmp_event(), comparators.cmp_description("_dynamic"), ], "find_id_search": [ comparators.cmp_event(), comparators.cmp_description("_dynamic"), ] } else: fuzzy_args = {} # Let's try find an id with fuzzy # This also sets the dynamic parameters in the bmg object! _ = bmg.find_id(**fuzzy_args) # Skip those bmgs that coudn't be found if not bmg.find_id(): log.error("BMG could not be found: {}".format( str(bmg.identifier))) continue settle = LookupBettingMarketGroupResolve( bmg, [self.home_score, self.away_score]) settle.update()
def updateHandicapBMg(self, bmg, incident_type): """ This method creates a BMG for Hanidcap """ log.debug("BMG is dynamic Handicap: {}".format(bmg.identifier)) # Identify which player has the handicap side = obtain_participant_side(incident_type["participant"], self.teams) # Set handicap handicap = round(self.median_value("hc", side=side)) bmg.set_handicaps(**{side: handicap}) # We use fuzzy arguments by defining and injecting our own # test_operation_equal_search and find_id_search comparators. # This allows us to select what to actually look for. fuzzy_args = { "test_operation_equal_search": [ # The following keys are required comparators.cmp_required_keys( [ # other for updates with new_* "betting_market_group_id", "new_description", "new_event_id", "new_rules_id", ], [ # or as actual creates "betting_market_group_id", "description", "event_id", "rules_id", ], ), # The status needs to match, if not update comparators.cmp_status(), # The status needs to match comparators.cmp_event(), # The description must have a _dynamic attribute comparators.cmp_description("_dynamic"), # The fuzzy comparator takes the fuzzyness from config # and tries to find the bmgs for handicap and over # under dynamic factors but allows some fuzzyness for # the actual value comparators.cmp_dynamic_bmg_fuzzy( config["dynamic"]["handicap"]["fuzzy_value"]), ], # We identify the bmg by comparing "find_id_search": [ # parent event id comparators.cmp_event(), # comparing type of dynamic comparators.cmp_description("_dynamic"), # fuzzy matching of dynamic value comparators.cmp_dynamic_bmg_fuzzy( config["dynamic"]["handicap"]["fuzzy_value"]), ], } bmg.update(**fuzzy_args)
def updateOverUnderBMg(self, bmg): """ This method creates a BMG for OverUnder """ log.debug("BMG is dynamic Over/Under: {}".format(bmg.identifier)) # Let's obtain the overunder value overunder = self.median_value("ou") # Set Overunder bmg.set_overunder(overunder) # We use fuzzy arguments by defining and injecting our own # test_operation_equal_search and find_id_search comparators. # This allows us to select what to actually look for. fuzzy_args = { "test_operation_equal_search": [ # The following keys are required comparators.cmp_required_keys( [ # other for updates with new_* "betting_market_group_id", "new_description", "new_event_id", "new_rules_id", ], [ # or as actual creates "betting_market_group_id", "description", "event_id", "rules_id", ], ), # The status needs to match, if not update comparators.cmp_status(), # The status needs to match comparators.cmp_event(), # The description must have a _dynamic attribute comparators.cmp_description("_dynamic"), # The fuzzy comparator takes the fuzzyness from config # and tries to find the bmgs for handicap and over # under dynamic factors but allows some fuzzyness for # the actual value comparators.cmp_dynamic_bmg_fuzzy( config["dynamic"]["overunder"]["fuzzy_value"]), ], # We identify the bmg by comparing "find_id_search": [ # parent event id comparators.cmp_event(), # comparing type of dynamic comparators.cmp_description("_dynamic"), # fuzzy matching of dynamic value comparators.cmp_dynamic_bmg_fuzzy( config["dynamic"]["overunder"]["fuzzy_value"]), ], } bmg.update(**fuzzy_args)
def test_fuzzy_operation_compare(self): self.assertTrue( self.lookup.test_operation_equal( test_operation_dict, test_operation_equal_search=[ comparators.cmp_required_keys( ["description", "event_id", "rules_id"]), comparators.cmp_status(), comparators.cmp_event(), comparators.cmp_all_description() ])) t2 = deepcopy(test_operation_dict) t2["description"] = [ ["en", "Handicap (0:1)"], ] self.assertFalse( self.lookup.test_operation_equal( t2, test_operation_equal_search=[ comparators.cmp_all_description() ])) self.assertTrue( self.lookup.test_operation_equal( t2, test_operation_equal_search=[ comparators.cmp_description("en") ]))
def createBmgs(self, event, incident_type): """ Go through all Betting Market groups and create them """ assert "type" in incident_type assert "value" in incident_type typ = incident_type["type"] # Let's find the BM according to bookiesports bmgs = list(event.bettingmarketgroups) log.info("Expected number of BMGs: {}".format(len(bmgs))) for bmg in bmgs: # Only do dynamic ones here if (not bmg["dynamic"] or not LookupBettingMarketGroup.is_dynamic_type( bmg["dynamic"], typ)): log.info("BMG is not dynamic: {}".format(bmg.identifier)) continue # If this is a Overunder BMG if (LookupBettingMarketGroup.is_ou_type(bmg.get("dynamic")) and LookupBettingMarketGroup.is_ou_type(typ)): log.info("BMG is dynamic Over/Under: {}".format( bmg.identifier)) # Let's obtain the overunder value # overunder = math.floor(self.median_value("ou")) + 0.5 overunder = self.median_value( "ou") # The rounding will need to happen somewhere else! # Set Overunder bmg.set_overunder(overunder) # Update and crate BMs fuzzy_args = { "test_operation_equal_search": [ comparators.cmp_required_keys([ "betting_market_group_id", "new_description", "new_event_id", "new_rules_id" ], [ "betting_market_group_id", "description", "event_id", "rules_id" ]), comparators.cmp_status(), comparators.cmp_event(), comparators.cmp_description("_dynamic"), comparators.cmp_fuzzy( config["dynamic"]["overunder"]["fuzzy_value"]), ], "find_id_search": [ comparators.cmp_event(), comparators.cmp_fuzzy( config["dynamic"]["overunder"]["fuzzy_value"]), comparators.cmp_description("_dynamic"), ] } bmg.update(**fuzzy_args) self.createBms(bmg) return # If this is a Handicap BMG elif (LookupBettingMarketGroup.is_hc_type(bmg.get("dynamic")) and LookupBettingMarketGroup.is_hc_type(typ)): log.info("BMG is dynamic Handicap: {}".format(bmg.identifier)) # Identify which player has the handicap side = obtain_participant_side(incident_type["participant"], self.teams) # Set handicap handicap = round(self.median_value("hc", side=side)) bmg.set_handicaps(**{side: handicap}) # Update and crate BMs fuzzy_args = { "test_operation_equal_search": [ comparators.cmp_required_keys([ "betting_market_group_id", "new_description", "new_event_id", "new_rules_id" ], [ "betting_market_group_id", "description", "event_id", "rules_id" ]), comparators.cmp_status(), comparators.cmp_event(), comparators.cmp_description("_dynamic"), comparators.cmp_fuzzy( config["dynamic"]["handicap"]["fuzzy_value"]), ], "find_id_search": [ comparators.cmp_event(), comparators.cmp_fuzzy( config["dynamic"]["handicap"]["fuzzy_value"]), comparators.cmp_description("_dynamic"), ] } bmg.update(**fuzzy_args) self.createBms(bmg) return else: log.error( "BMG is could not be classified: {} - Type: {}".format( bmg.identifier, (typ or "empty string")))