def notify_frenzy_all(draw_id): from yoolotto.lottery.enumerations import EnumerationManager from yoolotto.lottery.models import LotteryDraw, LotteryDrawFrenzy from yoolotto.user.models import YooLottoUser draw = LotteryDraw.objects.get(pk=int(draw_id)) if draw.jackpot < 75000000: return draw.frenzied = True draw.save() frenzy = LotteryDrawFrenzy(draw=draw) frenzy.save() # print "TESTING", draw, frenzy # return component_name = draw.component.name draw_value = "{:,}".format(draw.jackpot) game_type = EnumerationManager.game_reverse(draw.component.parent.pk) for user in YooLottoUser.objects.filter(preferences__jackpot_frenzy=True).values("pk"): notify_frenzy_for_user.apply_async(countdown=random.randrange(60), kwargs={"component_name": component_name, "draw_value": draw_value, "game_type": game_type, "user_id": user["pk"],"draw_id":draw_id})
def representation(self, user=None): from yoolotto.lottery.enumerations import EnumerationManager result = { "name": self.name, "active": self.active, "components": map(lambda x: x.representation(user=user), self.components.all()), "id": self.pk, "gameType": EnumerationManager.game_reverse(self.pk) } if user: tickets = user.tickets.filter(draw__component__parent=self) plays = sum(map(lambda x: x.plays.count(), tickets)) result["tickets"] = tickets.count() result["plays"] = plays tickets = user.tickets.filter(draw__component__parent=self, draw__result__isnull=False) # Game Checkable result["checkable"] = True if sum(map(lambda x: 1 if not x.all_checked else 0, tickets)) > 0 else False # Unchecked Plays result["unchecked"] = sum(map(lambda x: x.unchecked, tickets)) if result["checkable"] and result["unchecked"]: result["gameState"] = 1 elif result["checkable"] and not result["unchecked"]: result["gameState"] = 0 else: result["gameState"] = 2 return result
def representation(self, user=None): from yoolotto.lottery.enumerations import EnumerationManager result = { "name": self.name, "active": self.active, "components": map(lambda x: x.representation(user=user), self.components.all()), "id": self.pk, "gameType": EnumerationManager.game_reverse(self.pk) } if user: tickets = user.tickets.filter(draw__component__parent=self) plays = sum(map(lambda x: x.plays.count(), tickets)) ticket_record = LotteryTicket.objects.filter(user_id = user)[0] ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = ticket_record.id) result["tickets"] = tickets.count() result["plays"] = plays tickets = user.tickets.filter(draw__component__parent=self, draw__result__isnull=False) # Game Checkable result["checkable"] = True if sum(map(lambda x: 1 if not x.all_checked else 0, tickets)) > 0 else False print "checkable",result["checkable"] #print "result chekable",result["checkable"] # Unchecked Plays result["unchecked"] = sum(map(lambda x: x.unchecked, tickets)) print "result",result["unchecked"] #print "draw",ticket_record.draw.result print "ticket_id",ticket_record.id if not result["checkable"] and ticket_record.draw.result: result["gameState"] = 1 elif not result["checkable"] and not ticket_record.draw.result: result["gameState"] = 0 elif result["checkable"] and ticket_record.draw.result and not ticket_available[0].pending: result["gameState"] = 2 elif not ticket_available[0].available and not ticket_available[0].rejected: result["gameState"] = 4 elif not ticket_available[0].rejected: result["gameState"] = 3 print "gamestate",result["gameState"] '''try: if not self.ticket.all_checked and not self.ticket.draw.result: _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result : _result["gameState"] = 1 elif self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: _result["gameState"] = 2 elif self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 3 elif not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 4 except: pass''' return result
def get(self,request): notification_type=request.GET.get('type','result') for_draw=int(request.GET.get('for_draw','0')) for_ticket=int(request.GET.get('for_ticket','0')) for_user=int(request.GET.get('for_user','0')) result="" if notification_type=='result': if LotteryTicket.objects.filter(id=for_ticket).exists(): result=notify_draw_result_for_ticket(for_ticket) elif LotteryDraw.objects.filter(id=for_draw).exists(): result=notify_draw_result_all(for_draw) else: try: #if YooLottoUser.objects.filter(id=for_user).exists(): user = YooLottoUser.objects.get(id=for_user) draw=LotteryDraw.objects.get(id=for_draw) component_name = draw.component.name draw_value = "{:,}".format(draw.jackpot) game_type = EnumerationManager.game_reverse(draw.component.parent.pk) result=notify_frenzy_for_user_without_ticket(component_name, draw_value, game_type, user.id,draw.id) except Exception,e: import traceback result=str(traceback.format_exc())
def __call__(self, *args, **kwargs): import datetime from yoolotto.lottery.enumerations import EnumerationManager from yoolotto.lottery.models import LotteryGameComponent ticket = self.ticket draw = self.ticket.draw plays = self.ticket.plays.exclude(play=None) handler = draw.component.parent.handler lg_obj = LotteryGameComponent.objects.filter(parent=draw.component.parent.pk)[0] state = self.ticket.division.remote_id _result = { "game": { "id": draw.component.parent.pk, "name": draw.component.parent.name, "gameType": EnumerationManager.game_reverse(draw.component.parent.pk), "state":state, }, "current_date":datetime.date.today().strftime("%Y-%m-%d"), #"plays": self.ticket.plays.count(), "plays": [], "draw": draw.representation(ticket=self.ticket), "ticket_id": self.ticket.pk, "winnings": str(self.ticket.winnings) if self.ticket.winnings is not None else None, "coins": self.ticket.coin_representation(), "checked": self.ticket.all_checked, "representation": self.__class__.__name__ } pending = False try: if not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: pending = True except: pending = True if not self.ticket.all_checked and not self.ticket.draw.result: #and not self.ticket.ticket_submissions.all()[0].pending : _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result:# and not self.ticket.ticket_submissions.all()[0].pending : _result["gameState"] = 1 else: _result["gameState"] = 2 _result["game"].update(handler.get_game_meta(draw.component)) for play in plays: ticket_image = self.ticket.ticket_submissions.all() if ticket_image : image = str(ticket_image[0].image_first) else: image = None try: play_data = json.loads(play.play) raw = handler.postprocess_play(play_data) except: play_data = json.loads(json.dumps(play.play)) raw = handler.postprocess_play(play_data) try: raw_data = json.loads(raw) except: raw_data = eval(str(raw)) _play = { "play_id": play.pk, "winnings": str(play.winnings) if play.winnings is not None else None, "play": raw_data, "checked":play.submission.checked, "submission": play.submission_old, "image": image, } _play["baseWinnings"] = str(play.winnings_base) if play.winnings_base else _play["winnings"] _play["sumWinnings"] = str(play.winnings_sum) if play.winnings_sum else None _result["plays"].append(_play) return _result
def __call__(self, *args, **kwargs): import datetime from yoolotto.lottery.enumerations import EnumerationManager from yoolotto.lottery.models import LotteryGameComponent draw = self.ticket.draw plays = self.ticket.plays.exclude(play=None) handler = draw.component.parent.handler lg_obj = LotteryGameComponent.objects.filter(parent=draw.component.parent.pk)[0] state = self.ticket.division.remote_id fantasy = self.ticket.fantasy red_alert = self.ticket.red_alert '''pending = False try: if not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: pending = True except: pending = True''' if fantasy == False: _result = { "game": { "id": draw.component.parent.pk, "name": draw.component.parent.name, "gameType": EnumerationManager.game_reverse(draw.component.parent.pk), "state":state, }, "current_date":datetime.date.today().strftime("%Y-%m-%d"), #"plays": self.ticket.plays.count(), "plays": [], "draw": draw.representation(ticket=self.ticket), "ticket_id": self.ticket.pk, "winnings": str(self.ticket.winnings) if self.ticket.winnings is not None else None, "coins": self.ticket.coin_representation(), "checked": self.ticket.all_checked, "representation": self.__class__.__name__, "fantasy":fantasy } try: if not self.ticket.all_checked and not self.ticket.draw.result: _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result : _result["gameState"] = 1 elif self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: _result["gameState"] = 2 elif self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 3 elif not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 4 except: pass _result["game"].update(handler.get_game_meta(draw.component)) for play in plays: ticket_image = self.ticket.ticket_submissions.all() if ticket_image : image = str(ticket_image[0].image_first) else: image = None try: play_data = json.loads(play.play) raw = handler.postprocess_play(play_data) except: play_data = json.loads(json.dumps(play.play)) raw = handler.postprocess_play(play_data) try: raw_data = json.loads(raw) except: raw_data = eval(str(raw)) _play = { "play_id": play.pk, "winnings": str(play.winnings) if play.winnings is not None else None, "play": raw_data, "checked":play.submission.checked, "submission": play.submission_old, "image": image, } _play["baseWinnings"] = str(play.winnings_base) if play.winnings_base else _play["winnings"] _play["sumWinnings"] = str(play.winnings_sum) if play.winnings_sum else None _result["plays"].append(_play) else: _result = { "game": { "id": draw.component.parent.pk, "name": draw.component.parent.name, "gameType": EnumerationManager.game_reverse(draw.component.parent.pk), "state":state, }, "current_date":datetime.date.today().strftime("%Y-%m-%d"), #"plays": self.ticket.plays.count(), "plays": [], "draw": draw.representation(ticket=self.ticket), "ticket_id": self.ticket.pk, "winnings": str(self.ticket.winnings) if self.ticket.winnings is not None else None, "coins": self.ticket.coin_representation(), "checked": self.ticket.winnings_coins, "representation": self.__class__.__name__, "fantasy":fantasy, "red_alert":red_alert, } print 111111111111111111111111111111 count = 0 for play in plays: try: play_data = json.loads(play.play) raw = handler.postprocess_play(play_data) except: play_data = json.loads(json.dumps(play.play)) raw = handler.postprocess_play(play_data) try: raw_data = json.loads(raw) except: raw_data = eval(str(raw)) _play = { "play_id": play.pk, "winnings": str(play.winnings) if play.winnings is not None else None, "play": raw_data, "checked":play.submission.checked, "submission": play.submission_old, } count = count + 1 print "count", count _result["plays"].append(_play) try: coins_info = EmailCoins.objects.filter(email = self.email)[0] #total_coins = device_coins.coins + coins_info.coins from yoolotto.lottery.models import LotteryTicketAvailable print "pendingggjsjkjj",self.ticket.ticket_submissions.all()[0].pending if self.ticket.ticket_submissions.all()[0].pending != 0: print "gamreeee",int(self.ticket.ticket_submissions.all()[0].gameType) if int(self.ticket.ticket_submissions.all()[0].gameType) == 0 or int(self.ticket.ticket_submissions.all()[0].gameType) == 13: if coins_info.coins >= count *1: coins_info.coins = coins_info.coins - count *1 coins_info.save() ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = self.ticket.id)[0] ticket_available.pending = 0 ticket_available.save() else: if coins_info.coins >= count *2: coins_info.coins = coins_info.coins - count *2 coins_info.save() ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = self.ticket.id)[0] ticket_available.pending = 0 ticket_available.save() #try: #if self.ticket.ticket_submissions.all()[0].available and self.ticket.ticket_submissions.all()[0].pending: # _result["gameState"] = 4 #el if self.ticket.ticket_submissions.all()[0].pending and self.ticket.ticket_submissions.all()[0].available: _result["gameState"] = 4 elif not self.ticket.all_checked and not self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: #and coins complete _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: # coins complete _result["gameState"] = 1 elif self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending and self.ticket.ticket_submissions.all()[0].available: _result["gameState"] = 2 except: pass #print "result of gamestate",_result["gameState"] #except: # pass return _result
def __call__(self, *args, **kwargs): import datetime from yoolotto.lottery.enumerations import EnumerationManager from yoolotto.lottery.models import LotteryGameComponent draw = self.ticket.draw plays = self.ticket.plays.exclude(play=None) handler = draw.component.parent.handler lg_obj = LotteryGameComponent.objects.filter(parent=draw.component.parent.pk)[0] state = self.ticket.division.remote_id fantasy = self.ticket.fantasy _result = { "game": { "id": draw.component.parent.pk, "name": draw.component.parent.name, "gameType": EnumerationManager.game_reverse(draw.component.parent.pk), "state":state, }, "current_date":datetime.date.today().strftime("%Y-%m-%d"), #"plays": self.ticket.plays.count(), "plays": [], "draw": draw.representation(ticket=self.ticket), "ticket_id": self.ticket.pk, "winnings": str(self.ticket.winnings) if self.ticket.winnings is not None else None, "coins": self.ticket.coin_representation(), "checked": self.ticket.all_checked, "representation": self.__class__.__name__, "fantasy":fantasy } '''pending = False try: if not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: pending = True except: pending = True''' if fantasy == False: try: if not self.ticket.all_checked and not self.ticket.draw.result: _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result : _result["gameState"] = 1 elif self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: _result["gameState"] = 2 elif self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 3 elif not self.ticket.ticket_submissions.all()[0].available and not self.ticket.ticket_submissions.all()[0].rejected: _result["gameState"] = 4 except: pass _result["game"].update(handler.get_game_meta(draw.component)) for play in plays: ticket_image = self.ticket.ticket_submissions.all() if ticket_image : image = str(ticket_image[0].image_first) else: image = None try: play_data = json.loads(play.play) raw = handler.postprocess_play(play_data) except: play_data = json.loads(json.dumps(play.play)) raw = handler.postprocess_play(play_data) try: raw_data = json.loads(raw) except: raw_data = eval(str(raw)) _play = { "play_id": play.pk, "winnings": str(play.winnings) if play.winnings is not None else None, "play": raw_data, "checked":play.submission.checked, "submission": play.submission_old, "image": image, } _play["baseWinnings"] = str(play.winnings_base) if play.winnings_base else _play["winnings"] _play["sumWinnings"] = str(play.winnings_sum) if play.winnings_sum else None _result["plays"].append(_play) else: count = 0 for play in plays: try: play_data = json.loads(play.play) raw = handler.postprocess_play(play_data) except: play_data = json.loads(json.dumps(play.play)) raw = handler.postprocess_play(play_data) try: raw_data = json.loads(raw) except: raw_data = eval(str(raw)) _play = { "play_id": play.pk, "winnings": str(play.winnings) if play.winnings is not None else None, "play": raw_data, "checked":play.submission.checked, "submission": play.submission_old, } count = count + 1 _result["plays"].append(_play) device_info = self.ticket.ticket_submissions.all()[0].device print device_info email_info = UserClientLogin.objects.filter(device = device_info)[0] print "email id",email_info.device print "device id is ################################################3", device_info print email_info.client_login device_coins = DeviceCoins.objects.filter(device_id = device_info)[0] coins_info = EmailCoins.objects.filter(email = email_info.client_login)[0] from yoolotto.lottery.models import LotteryTicketAvailable if self.ticket.ticket_submissions.all()[0].pending == 1: if self.ticket.ticket_submissions.all()[0].gameType == 0 or self.ticket.ticket_submissions.all()[0].gameType == 13: if device_coins.coins + coins_info.coins >= count *1: if coins_info.coins >= count * 1: coins_info = F('coins')- count *1 coins_info.save() else: emailcoinsdeducted = coins_info.coins coins_info.coins = 0.0 coins_info.save() device_coins = F('coins') - (count *1 - emailcoinsdeducted) device_coins.save() ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = self.ticket.id)[0] ticket_available.pending = 0 ticket_available.save() else: if device_coins.coins + coins_info.coins >= count *2: if coins_info.coins >= count * 2: coins_info.coins = coins_info.coins - count *2 coins_info.save() ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = self.ticket.id)[0] ticket_available.pending = 0 ticket_available.save() else: emailcoinsdeducted = coins_info.coins coins_info.coins = 0.0 coins_info.save() device_coins.coins = device_coins.coins - (count *2 - emailcoinsdeducted) device_coins.save() ticket_available = LotteryTicketAvailable.objects.filter(ticket_id = self.ticket.id)[0] ticket_available.pending = 0 ticket_available.save() else: pass #try: #if self.ticket.ticket_submissions.all()[0].available and self.ticket.ticket_submissions.all()[0].pending: # _result["gameState"] = 4 #el print "ticket_id",self.ticket.id print "checked",self.ticket.all_checked print "draw result",self.ticket.draw.result print "pending",self.ticket.ticket_submissions.all()[0].pending if self.ticket.ticket_submissions.all()[0].pending and self.ticket.ticket_submissions.all()[0].available: _result["gameState"] = 4 elif not self.ticket.all_checked and not self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: #and coins complete _result["gameState"] = 0 elif not self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending: # coins complete _result["gameState"] = 1 elif self.ticket.all_checked and self.ticket.draw.result and not self.ticket.ticket_submissions.all()[0].pending and self.ticket.ticket_submissions.all()[0].available: _result["gameState"] = 2 #print "result of gamestate",_result["gameState"] #except: # pass return _result