Advertisement
Alihaydar

Untitled

Apr 10th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.02 KB | None | 0 0
  1. from functools import reduce
  2.  
  3.  
  4. class LiveBetDataFactory:
  5.     handicap_codes = {'471', '489', '501', '539', '541'}
  6.     game_codes_with_checks = {
  7.         '501': 'md_bt_45', '502': 'md_bt_45', '412': 'md_bt_45', '413': 'md_bt_45',
  8.         '414': 'md_bt_45', '406': 'md_lte_45', '407': 'md_lte_45', '408': 'md_lte_45', '489': 'md_lte_45',
  9.         '490': 'md_lte_45', '418': [8, 13], '419': [8, 13], '420': [8, 13], '421': [9, 14], '422': [9, 14],
  10.         '423': [9, 14], '424': [10, 15], '425': [10, 15], '426': [10, 15], '427': [11, 16], '428': [11, 16],
  11.         '429': [11, 16], '430': [12], '432': [12], '539': [8], '540': [8], '541': [9], '542': [9],
  12.     }
  13.     game_codes_and_dict_paths = {
  14.         'current_half_result.home': ['412', '406', '418', '421', '424', '427', '430'],
  15.         'current_half_result.draw': ['413', '407', '419', '422', '425', '428'],
  16.         'current_half_result.away': ['414', '408', '420', '423', '426', '429', '432'],
  17.         'current_half_over_under.$1_5.under': ['489', '501', '539', '541'],
  18.         'current_half_over_under.$1_5.over': ['490', '502', '540', '542'],
  19.         'next_goal.home': ['607', ], 'next_goal.no_goal': ['608', ], 'next_goal.away': ['609', ],
  20.         'full_time_result.home': ['400', ], 'full_time_result.draw': ['401', ], 'full_time_result.away': ['402', ],
  21.         'full_time_over_under.$2_5.under': ['471', ], 'full_time_over_under.$2_5.over': ['472', ]
  22.     }
  23.  
  24.     def __init__(self, game_data_db, ignored_bets, min_diff, game_inst):
  25.         """
  26.        :param game_data_db:
  27.        :param ignored_bets:
  28.        :param min_diff:
  29.        :param game_inst: game_instance
  30.        """
  31.         self.gd_db, self.ignored_bets = game_data_db, ignored_bets
  32.         self.min_diff, self.game_instance = min_diff, game_inst
  33.         template_dict = {
  34.             "value": "",
  35.             "isIncreased": False,
  36.             "isDecreased": False
  37.         }
  38.         self.dict = {
  39.             "current_half_result": {},
  40.             "current_half_over_under": {
  41.                 "$1_5": {
  42.                     "over": template_dict,
  43.                     "under": template_dict
  44.                 },
  45.                 "handicap": ""
  46.             },
  47.             "full_time_over_under": {
  48.                 "$2_5": {
  49.                     "over": template_dict,
  50.                     "under": template_dict
  51.                 },
  52.                 "handicap": ""
  53.             },
  54.             "next_goal": {
  55.                 "home": template_dict,
  56.                 "no_goal": template_dict,
  57.                 "away": template_dict
  58.             }
  59.         }
  60.  
  61.     def set_game_data_values(self, path_str, game_code):
  62.         if game_code in self.gd_db['odds'] and self.gd_db['odds'][game_code]['odd'] not in self.ignored_bets:
  63.             if game_code in self.game_codes_with_checks.keys():
  64.                 # t.run('cp2')
  65.                 check = self.game_codes_with_checks[game_code]
  66.                 if (check == 'md_bt_45' and not self.min_diff > 45) or (
  67.                         check == 'md_lte_45' and not self.min_diff <= 45):
  68.                     return
  69.                 if self.game_instance.betradar_status not in check:
  70.                     return
  71.             path_list = path_str.split('.')
  72.             path = path_list
  73.             update_dict = {
  74.                 'value': self.gd_db['odds'][game_code].get('odd', ''),
  75.                 'isIncreased': self.gd_db['odds'][game_code].get('is_increased', False),
  76.                 'isDecreased': self.gd_db['odds'][game_code].get('is_decreased', False)
  77.             }
  78.             reduce(dict.setdefault, path, self.dict).update(update_dict)
  79.             if game_code in self.handicap_codes and 'handicap_value' in self.gd_db['odds'][game_code]:
  80.                 self.dict[path_list[0]]['handicap'] = self.gd_db['odds'][game_code]['handicap_value']
  81.  
  82.     def set_game_data_db(self):
  83.         for key in self.game_codes_and_dict_paths.keys():
  84.             for game_code in self.game_codes_and_dict_paths[key]:
  85.                 self.set_game_data_values(key, game_code)
  86.         return self.dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement