示例#1
0
 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")
             ]))
示例#2
0
    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)
示例#3
0
    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"] = [
            ["display_name", "Over/Under 3.5 pts"],
            ["en", "Over/Under 3.5 pts"],
            ["sen", "Total Points"],
            ["_dynamic", "FAKE"],
            ["_ou", "FAKE"],
        ]
        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_descriptions(["en", "display_name"])
                ],
            ))

        self.assertTrue(
            self.lookup.test_operation_equal(
                t2,
                test_operation_equal_search=[
                    comparators.cmp_langs("description",
                                          langs=lambda x: x[0] != "_")
                ],
            ))
示例#5
0
    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")))