Ejemplo n.º 1
0
 def _handle_powerball(self, date, record):
     existing = LotteryDraw.objects.filter(component=self._powerball, 
         date=date)
     
     result = dumps(json.loads(record.winnings))
     
     # Check Data Conflicts
     if existing:
         existing = existing[0]
         if existing.result and existing.result != result:
             raise RuntimeError("Data Mismatch -%s- -%s-" % (existing.result, result))
     
     # Check Data
     handler = GameManager.get(self._powerball.parent.name)
     _result = handler.decode(record.winnings)
     handler.validate_numbers(json.loads(record.winnings))
     
     # Create
     try:
         draw = LotteryDraw.objects.get(component=self._powerball, date=date)
     except LotteryDraw.DoesNotExist:
         draw, created = LotteryDraw.objects.get_or_create(
             component=self._powerball, date=date)
     finally:
         draw.result = _result
         draw.official = True
         draw.save()
Ejemplo n.º 2
0
 def _handle_megamillions(self, date, record):
     winnings = json.loads(record.winnings)
     
     _base = winnings[:-1]
     _mega = winnings[-1:]
     
     base = dumps(_base)
     mega = dumps(_mega)
     
     # Check Existing
     existing = LotteryDraw.objects.filter(component=self._megamillions, 
         date=date)
     if existing:
         existing = existing[0]
         if existing.result and existing.result != base:
             raise RuntimeError("Data Mismatch -%s- -%s-" % (existing.result, base))
     
     # Check Existing (Megaplier)
     existing = LotteryDraw.objects.filter(component=self._megaplier, 
         date=date)
     if existing:
         existing = existing[0]
         if existing.result and existing.result != mega:
             raise RuntimeError("Data Mismatch -%s- -%s-" % (existing.result, mega))
         
     # Check Data
     handler = GameManager.get(self._megamillions.parent.code)
     handler.validate_numbers(_base)
     result_base = handler.decode(base)
     result_mega = handler.decode(mega, "Megaplier")
     
     
     # Create
     try:
         draw = LotteryDraw.objects.get(component=self._megamillions, date=date)
     except LotteryDraw.DoesNotExist:
         draw, created = LotteryDraw.objects.get_or_create(
             component=self._megamillions, date=date)
     finally:
         draw.result = result_base
         draw.official = True
         draw.save()
     
     # Create Megaplier
     try:
         draw = LotteryDraw.objects.get(component=self._megaplier, date=date)
     except LotteryDraw.DoesNotExist:
         draw, created = LotteryDraw.objects.get_or_create(
             component=self._megaplier, date=date)
     finally:
         draw.result = result_mega
         draw.official = True
         draw.save()
Ejemplo n.º 3
0
    def update_winnings(self, save=True):
        from yoolotto.lottery.game.manager import GameManager
        
        self.winnings = None
        
        if self.ticket.draw.result:
            game = GameManager.get(self.ticket.draw.component.parent.code)
            _winnings = game.earnings(self)
            if not isinstance(_winnings, list):
                winnings = _winnings
            else:
                winnings = _winnings[0]
            
            if winnings == game.JACKPOT:
                winnings = self.ticket.draw.jackpot

            try:

                if game.NAME == "Powerball":
                    winnings = \
                    self.calculate_powerball_winnings(winnings, self.ticket.draw, game)
                # check earnings for Mega Millions
                if game.NAME == "MegaMillions":
                    winnings = \
                    self.calculate_megamillion_winnings(winnings, self.ticket.draw, game)
               
            except Exception as e:
                print e
                pass
                
            self.winnings = winnings
            
            if not isinstance(_winnings, list):
                self.winnings_base = winnings
            else:
                try:
                    self.winnings_base = _winnings[1]
                except:
                    pass
                try:
                    self.winnings_sum = _winnings[2]
                except:
                    self.winnings_sum = _winnings[1]
                
        if save:
            self.save()
Ejemplo n.º 4
0
    def run(self):
        
        # Debug / Logging of Imports
        log_path=os.path.join(settings.IMPORT_LOG_PATH,self.log_draw_folder)
        if not os.path.exists(log_path):
            os.mkdir(log_path)
            
        path = os.path.join(log_path,datetime.datetime.now().strftime("draw-%Y-%m-%dT%H-%M-%S"))
        if not os.path.exists(path):
            os.mkdir(path)
            
        file_dump = os.path.join(path, "common_draw_import.xml")
        file_log = os.path.join(path, "common_draw_import.log")
                
        data = self._provider()
        
        fp_dump = open(file_dump, "w")
        self.log_file = open(file_log, "w")
        
        fp_dump.write(data)
        fp_dump.close()
        
        # Start Import
        xml = ElementTree.fromstring(data)
          
        self.informer(self.name,"started :"+str(datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"))+" \n",log=True)
        for k,v in self.COMMON_GAMES.iteritems():
            self.informer(self.name,"    Picked Game Parent :%s\n" %k,log=True)
            for component_name,_setting in v["components"].iteritems():
                self.informer(self.name,"        Picked Game Component :%s\n" %component_name,log=True)
                for remote_id,current_state in v['common_states']:
                    if component_name=="Megaplier" and remote_id not in ["TX"]:
                        #skip Megaplier for all states except (TX) 
                        continue
                    
                    found_state=xml.find(".//*[@stateprov_name='"+current_state+"']")
                    if found_state is not None:
                        self.informer(self.name,"            fill for state :%s\n" %current_state,log=True)
                        
                        #self.log_file.write("Found Game %s\n" % game_meta)
#                         print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
#                         print found_state.get("stateprov_name").strip()
#                         print found_state.get("stateprov_id").strip()
#                         print found_state.get("country").strip()
#                         print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
                        division, _ = LotteryCountryDivision.objects.get_or_create(
                                                                                   name__iexact=found_state.get("stateprov_name").strip(),
                                                                                   remote_id__iexact=found_state.get("stateprov_id").strip(),
                                                                                   remote_country__iexact=found_state.get("country").strip()
                                                                                   )
                        division.save()
                        if _:self.informer(self.name,"            created division :%s\n" %division,color="cyan",log=True)
                        else:
                            self.informer(self.name,"            get division :%s\n" %division,log=True)
                                
                        found_component_game=found_state.find(".//*[@game_name='"+component_name+"']")
                        if found_component_game is not None:
                            self.informer(self.name,"            Is valid component for state ? :%s\n" %True,log=True)
                            component_meta = self._filter_game(comp_name=found_component_game.get("game_name"),parent_code=k)#get game component name
                            if component_meta:
                                self.informer(self.name,"            Has component meta ? :%s\n" %True,log=True)                          
                                
                                parent_game,_= LotteryGame.objects.get_or_create(
                                            name=component_meta["game_name"],
                                            code=component_meta["game_format"]
                                            )
                                
                                if _:self.informer(self.name,"            created new parent :%s\n" %parent_game,color="cyan",log=True)
                                else:
                                    self.informer(self.name,"            got component parent :%s\n" %parent_game,log=True)
                                
                                
#                                 if remote_id=="CA":
#                                     print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
#                                     print "REMOTE ID:",found_component_game.get("game_id")
#                                     print "REMOTE ID:",component_meta.get("comp_name")
#                                     print "REMOTE ID:",component_meta.get("comp_format")
#                                     print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
                                    
                                component,_ = LotteryGameComponent.objects.get_or_create(
                                                remote_id=found_component_game.get("game_id"),
                                                name=component_meta["comp_name"],
                                                format=component_meta["comp_format"]
                                                )
                                
                                if _:self.informer(self.name,"            created new component :%s\n" %component,color="cyan",log=True)
                                else:
                                    self.informer(self.name,"            got component :%s\n" %component,log=True)
                                
                                component.parent = parent_game
                                component.division.add(division)
                                component.format = component_meta["comp_format"]
                                component.identifier = component_meta["comp_identifier"]
                                component.save()
                                
                                handler = GameManager.get(component_meta["game_format"])#common handler for all types of component for single game 
                                self.informer(self.name,"            handler picked up :%s\n" %handler,log=True)
                                
                                # Load Jackpot
                                jackpot = found_component_game.find("jackpot")
                                jackpot_date = None
                                jackpot_prize = None
                                                
                                if jackpot is not None:
                                    jackpot_date = datetime.datetime.strptime(jackpot.get("date").strip(), "%m/%d/%Y").date()
                                    jackpot_prize = int(jackpot.text)
                                    self.informer(self.name,"            Found Jackpot tag with prize (%s) and attrib date (%s) \n" %(jackpot_prize,jackpot_date),log=True)
                                else:
                                    self.informer(self.name,"            Jackpot tag not found.(assume normal) \n",color="yellow",log=True)
                                
                                # Load Last Draw
                                last_draw_date = found_component_game.find("lastdraw_date")
                                last_draw_numbers = found_component_game.find("lastdraw_numbers")
                                self.informer(self.name,"            result available (%s) for last draw date (%s). \n" %(last_draw_numbers.text,last_draw_date.text),log=True)
                                
                                
                                if last_draw_date is not None and last_draw_numbers is not None:
                                    last_draw_date = datetime.datetime.strptime(last_draw_date.text, "%m/%d/%Y").date()
                                    
                                    if component_meta["game_name"] in ["All or Nothing"] and not jackpot:
                                        jackpot_prize = 250000
                                        jackpot_date = last_draw_date
                                        self.informer(self.name,"          handler picked up :<cl  Assume fix jackpot prize of (%s). \n" %(250000),color="yellow",log=True)
                                    
                                    _notification = False
                                    
                                    # Find Draw Object
                                    
                                    try:
                                        draw, created = \
                                        LotteryDraw.objects.get_or_create(component=component,
                                                                         date=last_draw_date,
                                                                         division_id=division.id)
                                    except Exception as e:
                                        self.informer(self.name,"            exception in retrieving draw for last draw date (%s) ,exception :%s \n"%(last_draw_date,e),color="red",log=True)
                                    
                                    if created:self.informer(self.name,"            created LotteryDraw id=(%s) for last draw date (%s)\n"%(draw.id,last_draw_date),color="yellow",log=True)
                                    else:
                                        self.informer(self.name,"            draw already exist LotteryDraw id=(%s) of last draw date (%s)\n"%(draw.id,last_draw_date),log=True)
                                    
                                    
                                    if not draw.result:
                                        _notification = True
                                        self.informer(self.name,"            prepared for draw result available notification for date (%s) \n"%(last_draw_date),log=True)
                                    draw.result = handler.decode(last_draw_numbers.text,format=component_meta["comp_format"])
                                    
                                    #daily derby racetime has came through jackpot xml not from winning xml
                                    # filling race time for component has name=="Daily Derby" and (if future daily derby has more than one component)identifier=="Daily Derby"  
                                    if component_name=="Daily Derby" and component_meta.get("comp_identifier")=="Daily Derby":
                                        try:
                                            draw.race_time = handler.decode_race_time(last_draw_numbers.text, format=component_meta["comp_format"])
                                            draw.save()
                                        except Exception as e:
                                            self.informer(self.name,"            ( Daily Derby ) race time not filled for draw id = (%s) \n"%(draw.id),color="red",log=True)
                                    if component_meta["game_name"] == "Powerball":
                                        if len(literal_eval(draw.result)) != 7:
                                            raise ValueError("Unexpected Result Value for powerball: %s" % draw.result)
                                        else:
                                            draw.powerplay = literal_eval(draw.result)[-1]
                                            
                                    #If the draw object was created OR the draw became official, 
                                    #fire a notification for Draw Results
                                    if created or not draw.official:
                                        _notification = True
                                     
                                    draw.official = True
                                     
                                    #if jackpot is old update old draw jackpot
                                    if jackpot_prize is not None and jackpot_date == last_draw_date:
                                        draw.jackpot = jackpot_prize
                                        self.informer(self.name,"            found old jackpot of last draw date (%s) \n"%(last_draw_date),color="yellow",log=True)
                                     
                                    draw.save()#valid data hasn't store yet. 
                                    
                                    #search for powerplay and create it
                                    if component_meta["game_name"] == "Powerball" and len(ast.literal_eval(draw.result)) == 7 and remote_id=="TX":
                                        #For last_draw_date
                 
                                        powerplay = ast.literal_eval(draw.result)[6:7]
                                        self.informer(self.name,"            found powerplay :%s\n"%(powerplay),log=True)
                                        
                                        # first create a fake powerplay game component
                                        
                                        powerplay_component, _ = LotteryGameComponent.objects.get_or_create(
                                                        remote_id=found_component_game.get("game_id").strip(),#powerplay has same remote_id as powerball
                                                        name="Powerplay"
                                                        )
                                        powerplay_component.parent = parent_game
                                        powerplay_component.division.add(division)
                                        powerplay_component.format = "Powerplay"
                                        powerplay_component.identifier = "Powerplay"
                                        powerplay_component.save()
                                        
                                        #creating draw object for Powerplay
                                        powerplay_draw, powerplay_created = LotteryDraw.objects.get_or_create(
                                                                component=powerplay_component,
                                                                date=last_draw_date,
                                                                division_id=division.id,
                                                                result=powerplay
                                                                )
                                        if powerplay_created:
                                            self.informer(self.name,"            powerplay draw (id=%s) created for existing last draw date :%s\n"%(powerplay_draw.id,last_draw_date),log=True)
                                        
                                            
                                        #If the draw object was created OR the draw became official, 
                                        #fire a notification for Draw Results
                                        if powerplay_created or not powerplay_draw.official:
                                            _notification = True
                                            self.informer(self.name,"            (powerplay)prepared for draw result available notification for date (%s) \n"%last_draw_date,log=True)
                 
                                        powerplay_draw.official = True
                                        powerplay_draw.save()
                                        self.informer(self.name,"            powerplay draw (id=%s) updated for existing last draw date :%s\n"%(powerplay_draw.id,last_draw_date),log=True)
                                        
                                        
                                        
                                        #Finally Storing the draw result without powerplay
                                        draw.result = str(ast.literal_eval(draw.result)[0:6])
                                        draw.save()
                                        self.informer(self.name,"            powerball draw result saved (draw id=%s) \n"%draw.id,log=True)
                                    
                                    #set other states result for powerball to 6 length
                                    if component_meta["game_name"] == "Powerball" and len(ast.literal_eval(draw.result)) == 7:
                                        draw.result = str(ast.literal_eval(draw.result)[0:6])
                                        draw.save()
                                    if _notification:
                                        try:
                                            self.informer(self.name,"            started sending draw result notification for old draw (id=%s) \n"%draw.id,log=True)
                                            notify_draw_result_all.apply_async(countdown=0,
                                                                           kwargs={"draw_id": draw.pk})
                                            
                                        except Exception as e:
                                            self.informer(self.name,"            Exception in sending draw result notification for old draw (id=%s)  :%s\n"%(draw.id,e),color="red",log=True)
                                 
                                
                                
                                # Load Current Draw
                                next_draw_date = found_component_game.find("nextdraw_date")
                                if next_draw_date is not None:
                                    self.informer(self.name,"            Next draw available for date :%s \n"%next_draw_date.text,log=True) 
                                else:
                                    self.informer(self.name,"            Next draw tag missing \n",color="yellow",log=True)
        
                                
                                 
                                if next_draw_date is not None:
                                    next_draw_date = datetime.datetime.strptime(next_draw_date.text, "%m/%d/%Y").date()
                                    _notification = False
                                     
                                    # Find Draw Object
                                    draw, created = LotteryDraw.objects.get_or_create(component=component,
                                                                                     date=next_draw_date,
                                                                                     division_id=division.id)
                                     
                                    
                                    if created:self.informer(self.name,"            created LotteryDraw id=(%s) of next draw date (%s) \n"%(draw.id,next_draw_date),log=True)
                                    else:
                                        self.informer(self.name,"            draw already exist LotteryDraw id=(%s) for next draw date (%s) \n"%(draw.id,next_draw_date),log=True)
                                        
                                    #If the draw object was created OR the draw became official, 
                                    #fire a notification for Draw Results
                                    if created or not draw.official:
                                        _notification = True
                                                    
                                    draw.official = True
                                     
                                    self.informer(self.name,"            prepared for frenzy notification for next draw date (%s) \n"%next_draw_date,log=True)
                                    
                                                                         
                                    if jackpot_date == next_draw_date:
                                        draw.jackpot = jackpot_prize
                                        self.informer(self.name,"            next draw jackpot available :%s\n"%jackpot_prize,log=True)
                                    else:
                                        self.informer(self.name,"            next draw jackpot not filled \n",color="yellow",log=True)
                                        
                                    
                                    if draw.jackpot and _notification:
                                        try:
                                            self.informer(self.name,"            started sending frenzy notification for new draw (id=%s) \n"%draw.id,log=True)
#                                             notify_frenzy_all.apply_async(countdown=300,
#                                                                           kwargs={"draw_id": draw.pk})
                                        except Exception as e:
                                            self.informer(self.name,"            Exception in sending frenzy notification for new draw (id=%s) :%s\n"%(draw.id,e),color="red",log=True)
                                    
                                    
                                    draw.save()
                                    self.informer(self.name,"            next draw saved \n",log=True)
                                    
                                self.informer(self.name,"\n                --------------------------------------------\n",log=True)
                            else:
                                self.informer(self.name,"           (auto skip) Has component meta ? :%s\n" %False,log=True,color="red")
                        else:
                            self.informer(self.name,"           (auto skip) Is valid component for state ? :%s\n" %False,log=True,color="red")
                    else:
                        self.informer(self.name,"            (auto skip) state not found :%s\n" %current_state,log=True,color="red")
                        self.informer(self.name,"\n            --------------------------------------------\n",log=True)
                        #print colored(e,'red','on_white',attrs=['bold'])
            self.informer(self.name,"\n        --------------------------------------------\n",log=True)
        self.informer(self.name,"\n------------------------DONE--------------------\n",log=True)
                    
            
        # Close Logger
        self.log_file.close()
Ejemplo n.º 5
0
                last = _play
                processed.append(_play)
            else:
                _play["sum"] = play["numbers"][0]
                _play["sumWager"] = currency.format(play["amount"])
                
                last = None
        record["lines"] = processed        
        return record
    
    @classmethod
    def postprocess_play(cls, record):
        enum = None
        try:
            for k, v in cls.ENUM.iteritems():
                 if v == record["lineType"]:
                     record["lineType"] = k
                     break
        except:
            import ast
            t = ast.literal_eval(record)
            for k, v in cls.ENUM.iteritems():
                 if v == t["lineType"]:
                     t["lineType"] = k
                     break
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(PickThreeGame)
Ejemplo n.º 6
0
        
        if data["multiplier"] not in (True, False):
            raise LotteryPlayInvalidException("Invalid Multiplier %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(PowerBallGame)
Ejemplo n.º 7
0
    def update_winnings(self, save=True):
        from yoolotto.lottery.game.manager import GameManager
        
        self.winnings = None
        
        if self.ticket.draw.result:
            game = GameManager.get(self.ticket.draw.component.parent.code)
            _winnings = game.earnings(self)
            if not isinstance(_winnings, list):
                winnings = _winnings
            else:
                winnings = _winnings[0]
            
            if winnings == game.JACKPOT:
                winnings = self.ticket.draw.jackpot

            try:
                if game.NAME == 'FantasyFive':
                    winnings = \
                    self.calculate_fantasyfive_winnings(winnings, self.ticket.draw, game)
                # check earnings for SuperlottoPlus
                if game.NAME == 'SuperLottoPlus':
                    winnings = \
                    self.calculate_superlottoplus_winnings(winnings, self.ticket.draw, game)
                # check earnings for Powerball
                if game.NAME == "PowerballCA":
                    winnings = \
                    self.calculate_powerballca_winnings(winnings, self.ticket.draw, game)

                if game.NAME == "Powerball":
                    winnings = \
                    self.calculate_powerball_winnings(winnings, self.ticket.draw, game)
                # check earnings for Mega Millions
                if game.NAME == "MegaMillions":
                    winnings = \
                    self.calculate_megamillion_winnings(winnings, self.ticket.draw, game)
                if game.NAME == "MegaMillionsCA":
                    winnings = \
                    self.calculate_megamillionca_winnings(winnings, self.ticket.draw, game)
                    
                # check earnings for DailyDerby
                if game.NAME == "DailyDerby":
                    winnings = \
                    self.calculate_dailyderby_winnings(winnings, self.ticket.draw, game)
                # check earnings for DailyFor
                if game.NAME == "DailyFor":
                    
                    winnings = \
                    self.calculate_dailyfor_winnings(winnings, self.ticket.draw, game)
                    
                # check earnings for DailyThree
                if game.NAME == "DailyThree":
                    winnings = \
                    self.calculate_dailythree_winnings(winnings, self.ticket.draw, game)

                # check earnings for DailyThree
                if game.NAME == "AllOrNothing":
                    winnings = \
                    self.calculate_allornothing_winnings(winnings, self.ticket.draw, game)

                if game.NAME == "Lotto":
                    winnings = \
                    self.calculate_lotto_winnings(winnings, self.ticket.draw, game)

                if game.NAME == "TwoStep":
                    winnings = \
                    self.calculate_twostep_winnings(winnings, self.ticket.draw, game)
            except Exception as e:
                print e
                pass
                
            self.winnings = winnings
            
            if not isinstance(_winnings, list):
                self.winnings_base = winnings
            else:
                try:
                    self.winnings_base = _winnings[1]
                except:
                    pass
                try:
                    self.winnings_sum = _winnings[2]
                except:
                    self.winnings_sum = _winnings[1]
                
        if save:
            self.save()
Ejemplo n.º 8
0
        order = [morning_component,day_component,evening_component,night_component]
        index = order.index(component)
        draws_list = [order[item] for item in range(len(order)) if item >= index]
        return draws_list

    @classmethod
    def get_previous_components(cls,component):
        day_component = LotteryGameComponent.objects.get(identifier="DailyFourDay")
        morning_component = LotteryGameComponent.objects.get(identifier="DailyFourMorning")
        evening_component = LotteryGameComponent.objects.get(identifier="DailyFourEvening")
        night_component = LotteryGameComponent.objects.get(identifier="DailyFourNight")

        order = [morning_component,day_component,evening_component,night_component]
        index = order.index(component)
        draws_list = [order[item] for item in range(len(order)) if item <= index]
        return draws_list

    @classmethod
    def get_all_components(cls):
        day_component = LotteryGameComponent.objects.get(identifier="DailyFourDay")
        morning_component = LotteryGameComponent.objects.get(identifier="DailyFourMorning")
        evening_component = LotteryGameComponent.objects.get(identifier="DailyFourEvening")
        night_component = LotteryGameComponent.objects.get(identifier="DailyFourNight")

        draws_list = [morning_component,day_component,evening_component,night_component]
        return draws_list
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(DailyFourGame)
Ejemplo n.º 9
0
    def validate_play(cls, data):
        if "numbers" not in data:
            raise LotteryPlayInvalidException("Invalid Format %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(CashFiveGame)
Ejemplo n.º 10
0
                
        raise RuntimeError("Unknown Win State?")
            
    @classmethod
    def preprocess_ticket(cls, record):
        
        processed = []
        #validate_ball_number_from_dates(record['drawingDate'], record[''])
        try:
            drawingDate = record['drawingDate']
        except:
            drawingDate = record['drawdate']

        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers"]:
                if field in play:
                    cls.validate_ball_number_from_dates(play['numbers'], drawingDate)
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(FantasyMegaMillionsGame)
Ejemplo n.º 11
0
    def validate_play(cls, data):
        if "numbers" not in data:
            raise LotteryPlayInvalidException("Invalid Format %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(FantasyFiveGame)
Ejemplo n.º 12
0
    @classmethod
    def get_all_components(cls):
        day_component = LotteryGameComponent.objects.get(identifier="AllOrNothingDay")
        morning_component = LotteryGameComponent.objects.get(identifier="AllOrNothingMorning")
        evening_component = LotteryGameComponent.objects.get(identifier="DailyFourEvening")
        night_component = LotteryGameComponent.objects.get(identifier="AllOrNothingNight")

        draws_list = [morning_component,day_component,evening_component,night_component]
        return draws_list
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(AllOrNothingGame)
Ejemplo n.º 13
0
        # except LotteryResultsInvalidException as e:
        #     raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        
        processed = []
        #validate_ball_number_from_dates(record['drawingDate'], record[''])
        try:
            drawingDate = record['drawingDate']
        except:
            drawingDate = record['drawdate']
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    cls.validate_ball_number_from_dates(play['numbers'], drawingDate)
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(CAMegaMillionsGame)
Ejemplo n.º 14
0
        
        if record["drawTime"] == 6:
            return LotteryGameComponent.objects.get(identifier="Daily Derby")
        
    @classmethod
    def get_game_meta(cls, component):
        if component.identifier == "DailyDerby":
            return {"drawTime": 6}
        
        return {"drawTime": 6}

    @classmethod
    def preprocess_ticket(cls, record):
        processed = []

        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "raceTime"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
     
from yoolotto.lottery.game.manager import GameManager
GameManager.register(DailyDerbyGame)
Ejemplo n.º 15
0
        
        if data["multiplier"] not in (True, False):
            raise LotteryPlayInvalidException("Invalid Multiplier %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(SuperLottoPlusGame)
Ejemplo n.º 16
0
                if _play["lineType"] == "COMBO":
                    _play["baseWager"] = currency.format(float(play["amount"]) / len(set(itertools.permutations(play["numbers"]))))
                elif _play["lineType"] in ["STRBOX", "EXTANY"]:
                    _play["baseWager"] = currency.format(float(play["amount"]) / 2)
                else:
                    _play["baseWager"] = currency.format(play["amount"])
                
                last = _play
                processed.append(_play)
            else:
                _play["sum"] = play["numbers"][0]
                _play["sumWager"] = currency.format(play["amount"])
                
                last = None
                        
        record["lines"] = processed        
        return record
    
    @classmethod
    def postprocess_play(cls, record):
        enum = None
        for k, v in cls.ENUM.iteritems():
             if v == record["lineType"]:
                 record["lineType"] = k
                 break
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(DailyThreeGame)
Ejemplo n.º 17
0
        
        if data["multiplier"] not in (True, False):
            raise LotteryPlayInvalidException("Invalid Multiplier %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(LottoCaliforniaGame)
Ejemplo n.º 18
0
        
        if data["multiplier"] not in (True, False):
            raise LotteryPlayInvalidException("Invalid Multiplier %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(LottoTexasGame)
Ejemplo n.º 19
0
    @classmethod
    def validate_play(cls, data):
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))

        return True

    @classmethod
    def preprocess_ticket(cls, record):
        processed = []

        for i, play in enumerate(record["lines"]):
            _play = {}

            for field in ["numbers"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)

        record["lines"] = processed

        return record


from yoolotto.lottery.game.manager import GameManager

GameManager.register(FantasyPowerBallGame)
Ejemplo n.º 20
0
    def run(self):
        # Debug / Logging of Imports
        if not os.path.exists(settings.IMPORT_LOG_PATH):
            os.mkdir(settings.IMPORT_LOG_PATH)
            
        path = os.path.join(settings.IMPORT_LOG_PATH, datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S"))
        if not os.path.exists(path):
            os.mkdir(path)
            
        file_dump = os.path.join(path, "import.xml")
        file_log = os.path.join(path, "import.log")
                
        data = self._provider()
        
        fp_dump = open(file_dump, "w")
        fp_log = open(file_log, "w")
        
        fp_dump.write(data)
        fp_dump.close()
        
        # Start Import
        xml = ElementTree.fromstring(data)
        
        for state in xml.findall("StateProv"):
            if state.get("stateprov_name") != "Texas":
                continue
                        
            division, _ = LotteryCountryDivision.objects.get_or_create(
                name=state.get("stateprov_name"), remote_id=state.get("stateprov_id"), \
                remote_country=state.get("country"))
            division.save()
                            
            for _game in state.findall("game"):
                _meta = self._filter_game(_game.get("game_name"))
                if not _meta:
                    continue
                
                fp_log.write("Found Game %s\n" % _meta)
                
                # game, _ = LotteryGame.objects.get_or_create(name=_meta["game_name"], code=_meta["game_format"])
                                
                # component, _ = LotteryGameComponent.objects.get_or_create(remote_id=_game.get("game_id"), name=_meta["comp_name"])
                game, _ = LotteryGame.objects.get_or_create(
                            name=_meta["game_name"],
                            code=_meta["game_format"]
                            ) 
                component, _ = LotteryGameComponent.objects.get_or_create(
                                remote_id=_game.get("game_id"),
                                name=_meta["comp_name"],
                                format=_meta["comp_format"]
                                )
                component.parent = game
                component.division.add(division)
                component.format = _meta["comp_format"]
                component.identifier = _meta["comp_identifier"]
                component.save()
                
                handler = GameManager.get(_meta["game_format"])
                fp_log.write("\tUsing Handler %s\n" % handler)
                
                # Load Jackpot
                jackpot = _game.find("jackpot")
                jackpot_date = None
                jackpot_prize = None
                                
                if jackpot is not None:
                    jackpot_date = datetime.datetime.strptime(jackpot.get("date"), "%m/%d/%Y").date()
                    jackpot_prize = int(jackpot.text)
                    fp_log.write("\t[jackpot] Found Jackpot %s\n" % jackpot_prize)
                    fp_log.write("\t[jackpot] Jackpot Date %s\n" % jackpot_date)
                else:
                    fp_log.write("\t[jackpot] No Jackpot\n")
                
                # Load Last Draw
                last_draw_date = _game.find("lastdraw_date")
                last_draw_numbers = _game.find("lastdraw_numbers")
                
                fp_log.write("\n\t[last] last_draw_date %s\n" % last_draw_date.text if last_draw_date is not None else None )
                fp_log.write("\t[last] last_draw_numbers %s\n" % last_draw_numbers.text if last_draw_numbers is not None else None)
                
                if last_draw_date is not None and last_draw_numbers is not None:
                    last_draw_date = datetime.datetime.strptime(last_draw_date.text, "%m/%d/%Y").date()
                    fp_log.write("\t[last] last_draw_date %s\n" % last_draw_date)
                    
                    if _meta["game_name"] in ["All or Nothing"] and not jackpot:
                        jackpot_prize = 250000
                        jackpot_date = last_draw_date
                    
                    _notification = False
                    
                    # Find Draw Object
                    try:
                        draw, created = \
                        LotteryDraw.objects.get_or_create(component=component,
                                                         date=last_draw_date,
                                                         division_id=1)
                    except Exception as e:
                        print e
                    if not draw.result:
                        _notification = True
                        
                    draw.result = handler.decode(last_draw_numbers.text, format=_meta["comp_format"])
                    if _meta["game_name"] == "Powerball":
                        if len(literal_eval(draw.result)) != 7:
                            raise ValueError("Unexpected Result Value: %s" % draw.result)
                        else:
                            draw.powerplay = literal_eval(draw.result)[-1]
                    
                    fp_log.write("\t[last] draw id %s, created: %s \n" % (draw.pk, created))
                    
                    # If the draw object was created OR the draw became official, 
                    # fire a notification for Draw Results
                    if created or not draw.official:
                        _notification = True
                    
                    draw.official = True
                    
                    if jackpot_prize is not None and jackpot_date == last_draw_date:
                        draw.jackpot = jackpot_prize
                    
                    draw.save()
                    print "Draw ID %s of state %s" % (draw.id, draw.division.remote_id)
                    fp_log.write("\t[last] draw id %s SAVED\n" % draw.pk)
                    fp_log.write("\t[last] %s\n" % draw.representation())
                    fp_log.write("\t[last] Firing Notification: %s\n" % _notification)
                    
                    if _meta["game_name"] == "Powerball" and len(ast.literal_eval(draw.result)) == 7:
                        # For last_draw_date

                        powerplay = ast.literal_eval(draw.result)[6:7]
                        fp_log.write("\t[last] Found Powerplay %s \n" % powerplay)
                        # first create a fake powerplay game component
                        fp_log.write("\t[last] Creating Fake Powerplay Component with value %s \n" % powerplay)
                        powerplay_component, _ = LotteryGameComponent.objects.get_or_create(
                                        remote_id=_game.get("game_id"),
                                        name="Powerplay"
                                        )
                        powerplay_component.parent = game
                        powerplay_component.division.add(division)
                        powerplay_component.format = "Powerplay"
                        powerplay_component.identifier = "Powerplay"
                        powerplay_component.save()
                        fp_log.write("\t[last] Fake Powerplay Object Saved %s \n" % powerplay_component.id)
                        # creating draw object for Powerplay
                        fp_log.write("\t[last] Creating Powerplay Draw \n")
                        powerplay_draw, powerplay_created = LotteryDraw.objects.get_or_create(
                                                component=powerplay_component,
                                                date=last_draw_date,
                                                division_id=1,
                                                result=powerplay
                                                )
                        # If the draw object was created OR the draw became official, 
                        # fire a notification for Draw Results
                        if powerplay_created or not powerplay_draw.official:
                            _notification = True

                        powerplay_draw.official = True
                        powerplay_draw.save()
                        fp_log.write("\t[last] Powerplay Object Saved %s \n" % powerplay_draw.id)
                        # Finally Storing the draw result without powerplay
                        draw.result = str(ast.literal_eval(draw.result)[0:6])
                        draw.save()

                    if _notification:
                        notify_draw_result_all.apply_async(countdown=0, 
                            kwargs={"draw_id": draw.pk})
                
                # Load Current Draw
                next_draw_date = _game.find("nextdraw_date")
                
                fp_log.write("\n\t[next] Processing NEXT Draw\n")
                fp_log.write("\t[next] next_draw_date %s\n" % next_draw_date.text if next_draw_date is not None else None)
                
                if next_draw_date is not None:
                    next_draw_date = datetime.datetime.strptime(next_draw_date.text, "%m/%d/%Y").date()
                    fp_log.write("\t[next] next_draw_date %s\n" % next_draw_date)
                    
                    _notification = False
                    
                    # Find Draw Object
                    draw, created = LotteryDraw.objects.get_or_create(component=component,
                                                                     date=next_draw_date,
                                                                     division_id=1)
                    
                    # If the draw object was created OR the draw became official, 
                    # fire a notification for Draw Results
                    if created or not draw.official:
                        _notification = True
                                   
                    draw.official = True
                    
                    fp_log.write("\t[next] draw id %s, created: %s \n" % (draw.pk, created))
                    
                    if jackpot_date == next_draw_date:
                        draw.jackpot = jackpot_prize
                        fp_log.write("\t[next] draw prize %s\n" % jackpot_prize)
                    
#                    fp_log.write("\t[last] Firing Notification: %s\n" % (draw.jackpot and _notification,))
#                    if draw.jackpot and _notification:
#                        notify_frenzy_all.apply_async(countdown=300, 
#                            kwargs={"draw_id": draw.pk})
                    
                    fp_log.write("\t[next] %s" % draw.representation())
                    draw.save()
                    
                fp_log.write("\n\n-----------------------------------------\n\n")
                
        # Close Logger
        fp_log.close()
Ejemplo n.º 21
0
 def handler(self):
     from yoolotto.lottery.game.manager import GameManager
     return GameManager.get(self.code)
Ejemplo n.º 22
0
            return cls.ZERO_OF_BONUS
        
        if len(white) == 1 and bonus:
            return cls.ONE_OF_FOUR_BONUS
        
        if len(white) == 2 and bonus:
            return cls.TWO_OF_FOUR_BONUS
        
        if len(white) == 3:
            return cls.THREE_OF_FOUR_BONUS if bonus else cls.THREE_OF_FOUR
        
        if len(white) == 4:
            return cls.JACKPOT if bonus else cls.FOUR_OF_FOUR
        
        return 0
                
    @classmethod
    def validate_play(cls, data):
        if "numbers" not in data:
            raise LotteryPlayInvalidException("Invalid Format %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(TwoStepGame)
Ejemplo n.º 23
0
            
        if data["multiplier"] not in (True, False):
            raise LotteryPlayInvalidException("Invalid Multiplier %s" % data)
        
        try:
            cls.validate_numbers(data["numbers"])
        except LotteryResultsInvalidException as e:
            raise LotteryPlayInvalidException(str(e))
        
        return True
    
    @classmethod
    def preprocess_ticket(cls, record):
        processed = []
        
        for i, play in enumerate(record["lines"]):
            _play = {}
            
            for field in ["numbers", "multiplier"]:
                if field in play:
                    _play[field] = play[field]

            processed.append(_play)
            
        record["lines"] = processed
        
        return record
    
from yoolotto.lottery.game.manager import GameManager
GameManager.register(CAPowerballGame)
Ejemplo n.º 24
0
    def run(self):
        files = []
        
        for item in os.listdir(os.path.join(settings.SITE_ROOT, "lottery/data/history")):
            _path = os.path.join(settings.SITE_ROOT, "lottery/data/history", item)
            files.append(_path)
            
        data = []
        
        handlers = {}
        components = {}
            
        for file in files:
            fp = open(file, "r")
            reader = csv.reader(fp)
            
            for row in reader:
                if row[0] not in self.GAMES.keys():
                    continue
                
                _meta = self.GAMES[row[0]]["components"].values()[0]

                if _meta[0] not in handlers:
                    handlers[_meta[0]] = GameManager.get(_meta[0])
                
                if _meta[1] not in components:
                    components[_meta[1]] = LotteryGameComponent.objects.get(identifier=_meta[1])
                
                component = components[_meta[1]]
                handler = handlers[_meta[0]]
                   
                result = map(int, row[2:])
                parsed = handler.decode("-".join(map(str, result)), _meta[0])
                
                if _meta[0] != "Megaplier":
                    handler.validate_numbers(result)          
                   
                _data = {
                    "format": _meta[0],
                    "component": component,
                    "handler": handler,
                    "date": datetime.datetime.strptime(row[1], "%Y%m%d"),
                    "raw": result,
                    "result": parsed,
                }
                   
                data.append(_data)
                
            fp.close()
        
        # Validate no Conflicts
        for row in data:
            try:
                draw = LotteryDraw.objects.get(component=row["component"], date=row["date"])
            except LotteryDraw.DoesNotExist:
                continue
            
            if draw and draw.result != None and draw.result != row["result"]:
                if set(json.loads(draw.result)) != set(json.loads(row["result"])):
                    pprint.pprint(row)
                    pprint.pprint(draw.__dict__)
                    raise RuntimeError("Data Mismatch!")
                else:
                    pass
            elif draw.result != None and draw.result == row["result"]:
                pass
        
        # Insert Data
        for row in data:
            try:
                draw = LotteryDraw.objects.get(component=row["component"], date=row["date"])
                
                if draw.result and draw.official:
                    continue
            except LotteryDraw.DoesNotExist:
                draw = LotteryDraw(component=row["component"], date=row["date"])
                
            draw.official = True
            draw.result = row["result"]
            draw.save()
            
            
            
        
       # pprint.pprint(components)
       # pprint.pprint(handlers)
Ejemplo n.º 25
0
    def update_winnings(self, save=True):
        from yoolotto.lottery.game.manager import GameManager

        self.winnings = None
        if self.ticket.fantasy == False:
            if self.ticket.draw.result:
                game = GameManager.get(self.ticket.draw.component.parent.code)
                _winnings = game.earnings(self)
                if not isinstance(_winnings, list):
                    winnings = _winnings
                else:
                    winnings = _winnings[0]

                if winnings == game.JACKPOT:
                    winnings = self.ticket.draw.jackpot

                try:
                    if game.NAME == "FantasyFive":
                        winnings = self.calculate_fantasyfive_winnings(winnings, self.ticket.draw, game)
                    # check earnings for SuperlottoPlus
                    if game.NAME == "SuperLottoPlus":
                        winnings = self.calculate_superlottoplus_winnings(winnings, self.ticket.draw, game)
                    # check earnings for Powerball
                    if game.NAME == "PowerballCA":
                        winnings = self.calculate_powerballca_winnings(winnings, self.ticket.draw, game)

                    if game.NAME == "Powerball":
                        winnings = self.calculate_powerball_winnings(winnings, self.ticket.draw, game)
                    # check earnings for Mega Millions
                    if game.NAME == "MegaMillions":
                        winnings = self.calculate_megamillion_winnings(winnings, self.ticket.draw, game)
                    if game.NAME == "MegaMillionsCA":
                        winnings = self.calculate_megamillionca_winnings(winnings, self.ticket.draw, game)

                    # check earnings for DailyDerby
                    if game.NAME == "DailyDerby":
                        winnings = self.calculate_dailyderby_winnings(winnings, self.ticket.draw, game)
                    # check earnings for DailyFor
                    if game.NAME == "DailyFor":

                        winnings = self.calculate_dailyfor_winnings(winnings, self.ticket.draw, game)

                    # check earnings for DailyThree
                    if game.NAME == "DailyThree":
                        winnings = self.calculate_dailythree_winnings(winnings, self.ticket.draw, game)

                    # check earnings for DailyThree
                    if game.NAME == "AllOrNothing":
                        winnings = self.calculate_allornothing_winnings(winnings, self.ticket.draw, game)

                    if game.NAME == "Lotto":
                        winnings = self.calculate_lotto_winnings(winnings, self.ticket.draw, game)

                    if game.NAME == "TwoStep":
                        winnings = self.calculate_twostep_winnings(winnings, self.ticket.draw, game)
                except Exception as e:
                    print e
                    pass

                self.winnings = winnings

                if not isinstance(_winnings, list):
                    self.winnings_base = winnings
                else:
                    try:
                        self.winnings_base = _winnings[1]
                    except:
                        pass
                    try:
                        self.winnings_sum = _winnings[2]
                    except:
                        self.winnings_sum = _winnings[1]

            if save:
                self.save()
        else:
            print "in update winnings False"
            if self.ticket.draw.result:
                print self.ticket.ticket_submissions.all()
                game_type = self.ticket.ticket_submissions.all()[0].gameType
                print "gcfffffffffffffffffffffffff", game_type
                _winnings = self.fantasy_earnings(self, game_type)
                print "_winnings", _winnings
                print "_winnings", _winnings
                if not isinstance(_winnings, list):
                    winnings = _winnings
                else:
                    winnings = _winnings[0]
                print "printing winningssssssssssss", winnings
                try:
                    print "innnnnnnnnnn calculate winngs"
                    if int(game_type) == 0 or int(game_type) == 13:
                        print "in gametype megamillion"
                        winnings_cal = self.calculate_fantasymegamillion_winnings(_winnings)
                    elif int(game_type) == 1 or int(game_type) == 11:
                        print "in gametype powerball"
                        winnings_cal = self.calculate_fantasypowerball_winnings(_winnings)
                    # except:
                    # pass
                    print "winningvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvs", winnings_cal
                    if "@" in winnings_cal:
                        winningss = winnings_cal.split("@")
                        self.winnings_coins = winningss[0]

                    elif "$" in winnings_cal:
                        winningss = winnings_cal.split("$")
                        self.winnings = winningss[0]
                    print "wingggsss afte cal", winnings
                except:
                    pass
            if save:
                print "in save"
                self.save()

            print "play", self.winnings