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 test_resolution(self): # Away Team wins lookup = LookupBettingMarketGroupResolve(self.bmg, [2, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "win"], # ["1.21.2951", "not_win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "win"]) self.assertEqual(res[1], ["1.21.2951", "not_win"]) # Draw lookup = LookupBettingMarketGroupResolve(self.bmg, [3, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "not_win"], # ["1.21.2951", "not_win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "not_win"]) self.assertEqual(res[1], ["1.21.2951", "not_win"]) # Home Team wins lookup = LookupBettingMarketGroupResolve(self.bmg, [4, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "not_win"], # ["1.21.2951", "win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "not_win"]) self.assertEqual(res[1], ["1.21.2951", "win"])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) fixture_data() self.event = lookup_test_event(event_id) self.bmg = next(self.event.bettingmarketgroups) # overwrite the BMG id since we cannot look on the chain self.bmg["id"] = bmg_id self.lookup = LookupBettingMarketGroupResolve(self.bmg, test_result)
def test_result_20_on_10(self): resolve = LookupBettingMarketGroupResolve(self.lookup, [2, 0], handicaps=[1, 0]) self.assertEqual(resolve._metric, '(2 + 0) - (0 + 1)') self.assertEqual(resolve.metric, 1) self.assertResult(resolve.resolutions, ['1.21.2952', 'win'], ['1.21.2953', 'not_win'])
def test_result_20_on_10(self): resolve = LookupBettingMarketGroupResolve(self.lookup, [2, 0], handicaps=[1, 0]) self.assertEqual(resolve._metric, "(2 + 0) - (0 + 1)") self.assertEqual(resolve.metric, 1) self.assertResult( resolve.resolutions, ["1.25.2952", "win"], ["1.25.2953", "not_win"] )
def test_result_00_on_20(self): self.lookup.set_handicaps(home=2) resolve = LookupBettingMarketGroupResolve(self.lookup, [0, 0], handicaps=[2, 0]) self.assertEqual(resolve._metric, '(0 + 0) - (0 + 2)') self.assertEqual(resolve.metric, -2) self.assertResult(resolve.resolutions, ['1.21.2954', 'not_win'], ['1.21.2955', 'win'])
def test_result_20_on_10(self): resolve = LookupBettingMarketGroupResolve(self.lookup, [2, 0], handicaps=[1, 0]) self.assertEqual(resolve.bmg["handicaps"], [1.5, -1.5]) self.assertEqual(resolve._metric, '(2 + 0) - (0 + 1.5)') self.assertEqual(resolve.metric, 0.5) self.assertResult(resolve.resolutions, ['1.21.3000', 'win'], ['1.21.3001', 'not_win'])
def test_result_20_on_10(self): resolve = LookupBettingMarketGroupResolve(self.lookup, [2, 0], handicaps=[1, 0]) self.assertEqual(resolve.bmg["handicaps"], [1.5, -1.5]) self.assertEqual(resolve._metric, "(2 + 0) - (0 + 1.5)") self.assertEqual(resolve.metric, 0.5) self.assertResult( resolve.resolutions, ["1.25.3000", "win"], ["1.25.3001", "not_win"] )
def test_result_00_on_20(self): self.lookup.set_handicaps(home=2) resolve = LookupBettingMarketGroupResolve(self.lookup, [0, 0], handicaps=[2, 0]) self.assertEqual(resolve._metric, "(0 + 0) - (0 + 2)") self.assertEqual(resolve.metric, -2) self.assertResult( resolve.resolutions, ["1.25.2954", "not_win"], ["1.25.2955", "win"] )
def test_result_10_on_15(self): resolve = LookupBettingMarketGroupResolve(self.lookup, [1, 0], overunder=1.5) self.assertEqual(resolve.metric, 1.0) self.assertResult( resolve.resolutions, ["1.25.2962", "not_win"], # over ["1.25.2963", "win"], # under )
class Testcases(unittest.TestCase): def setUp(self): fixture_data() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) fixture_data() self.event = lookup_test_event(event_id) self.bmg = next(self.event.bettingmarketgroups) # overwrite the BMG id since we cannot look on the chain self.bmg["id"] = bmg_id self.lookup = LookupBettingMarketGroupResolve(self.bmg, test_result) def test_init(self): self.assertIsInstance(self.lookup, LookupBettingMarketGroupResolve) def test_sport(self): self.assertEqual(self.lookup.sport["identifier"], self.event.sport["identifier"]) def test_rules(self): self.assertIsInstance(self.lookup.rules, LookupRules) def test_test_operation_equal(self): def mock_result(*args, **kwargs): return test_operation_dict["resolutions"] with mock.patch("bookied_sync.bettingmarketgroupresolve." + "LookupBettingMarketGroupResolve.resolutions", new_callable=mock_result): self.assertTrue( self.lookup.test_operation_equal(test_operation_dict)) def test_propose_new(self): from peerplaysbase.operationids import operations self.lookup.clear_proposal_buffer() tx = self.lookup.propose_new() tx = tx.json() self.assertIsInstance(tx, dict) self.assertIn("operations", tx) self.assertIn("ref_block_num", tx) self.assertEqual(tx["operations"][0][0], 22) self.assertEqual(tx["operations"][0][1]["proposed_ops"][0]["op"][0], operations[self.lookup.operation_create]) def test_resolution(self): # Away Team wins lookup = LookupBettingMarketGroupResolve(self.bmg, [2, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "win"], # ["1.21.2951", "not_win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "win"]) self.assertEqual(res[1], ["1.21.2951", "not_win"]) # Draw lookup = LookupBettingMarketGroupResolve(self.bmg, [3, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "not_win"], # ["1.21.2951", "not_win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "not_win"]) self.assertEqual(res[1], ["1.21.2951", "not_win"]) # Home Team wins lookup = LookupBettingMarketGroupResolve(self.bmg, [4, 3]) res = lookup.resolutions # should be: # [["1.21.2950", "not_win"], # ["1.21.2951", "win"]] # self.assertNotEqual(res[0][0], res[1][0]) self.assertEqual(res[0], ["1.21.2950", "not_win"]) self.assertEqual(res[1], ["1.21.2951", "win"]) def test_approve_proposal(self): # We need an approver account self.lookup.set_approving_account("init0") # We need to delete id else, bos-sync will not try to create self.lookup["id"] = None self.lookup.clear_proposal_buffer() tx = self.lookup.propose_new() tx = tx.json() propops = tx["operations"][0][1]["proposed_ops"][0]["op"] Proposals.cache["1.2.1"] = [{ 'available_active_approvals': [], 'available_key_approvals': [], 'available_owner_approvals': [], 'expiration_time': '2018-05-17T15:20:25', 'id': '1.10.2413', 'proposed_transaction': { 'expiration': '2018-05-17T15:17:48', 'extensions': [], 'operations': [propops], 'ref_block_num': 0, 'ref_block_prefix': 0 }, 'proposer': '1.2.8', 'required_active_approvals': ['1.2.1'], 'required_owner_approvals': [] }] # import logging # logging.basicConfig(level=logging.DEBUG) pending_propos = list(self.lookup.has_pending_new()) self.assertIn(pending_propos[0]["pid"], self.lookup.approval_map) self.assertFalse(self.lookup.is_synced()) self.assertEqual(len(pending_propos), 1) self.assertEqual(pending_propos[0]["pid"], "1.10.2413") self.lookup.approve(**pending_propos[0]) self.assertNotIn(pending_propos[0]["pid"], self.lookup.approval_map)