def check(self): url = self.response.get('redirect_url') if not url: raise AppTestError(u'リダイレクト先が設定されていない') elif url.find('/battleeventtop/') == -1: raise AppTestError(u'イベントTOPに遷移していない') model_mgr = ModelRequestMgr() rankrecord = BackendApi.get_battleevent_rankrecord(model_mgr, self.__eventmaster.id, self.__player0.id) if rankrecord is None: raise AppTestError(u'ランク情報が保存されていない') elif not rankrecord.groups: raise AppTestError(u'グループが設定されていない') groupid = rankrecord.groups[-1] group = BackendApi.get_battleevent_group(model_mgr, groupid) logintime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) today = datetime.date(logintime.year, logintime.month, logintime.day) if group is None: raise AppTestError(u'グループが存在しない') elif not self.__player0.id in group.useridlist: raise AppTestError(u'グループに参加設定されていない') elif not self.__player0.id in group.useridlist: raise AppTestError(u'グループに参加設定されていない') elif group.cdate != today: raise AppTestError(u'グループの日付がおかしい')
def __procGoukon(self, eventmaster): """合コンバトルイベント. """ model_mgr = self.getModelMgr() eventid = eventmaster.id basetime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) cdate = datetime.date(basetime.year, basetime.month, basetime.day) cur_group = self.getCurrentBattleGroup(do_search_log=False) # 設定済みの場合はイベントTOPへリダイレクト. if cur_group and cur_group.cdate == cdate: url = UrlMaker.battleevent_top(eventmaster.id) self.appRedirect(self.makeAppLinkUrlRedirect(url)) return # 最大ランク. config = BackendApi.get_current_battleeventconfig( model_mgr, using=settings.DB_READONLY) # 公開中のランク. rankmaster_list = BackendApi.get_battleevent_rankmaster_by_eventid( model_mgr, eventid, using=settings.DB_READONLY) rankmaster_list.sort(key=lambda x: x.rank) # 未設定で引数がある場合は書き込み. rank = str(self.request.get(Defines.URLQUERY_ID)) if rank.isdigit(): rank = int(rank) # ランクの公開確認. target_rankmaster = None for rankmaster in rankmaster_list: if rankmaster.rank == rank: target_rankmaster = rankmaster break if target_rankmaster: # 登録書き込み. v_player = self.getViewerPlayer() uid = v_player.id try: db_util.run_in_transaction(self.tr_write, config, eventmaster, uid, v_player.level, rankmaster_list, rank).write_end() except CabaretError, err: if err.code == CabaretError.Code.ALREADY_RECEIVED: pass elif settings_sub.IS_DEV: raise else: url = UrlMaker.mypage() self.appRedirect(self.makeAppLinkUrlRedirect(url)) return # 書き込み後はイベントTOPへ. url = UrlMaker.battleevent_top(eventmaster.id) self.appRedirect(self.makeAppLinkUrlRedirect(url)) return
def __set_save_event_join(self, uid, now, is_pc): """日別イベント参加数. イベントTOPとルール説明を見たUU. """ self.__set_save( EventJoinDaily.create( DateTimeUtil.toLoginTime(now or OSAUtil.get_now()), uid, is_pc)) return self
def __set_save_event_play(self, uid, now, is_pc): """日別イベントプレイ数. イベントポイントを自分で稼いだユーザ数. """ self.__set_save( EventPlayDaily.create( DateTimeUtil.toLoginTime(now or OSAUtil.get_now()), uid, is_pc)) return self
def set_increment_battleevent_member_count(self, rank, cnt=1, now=None): """バトルイベントランク別所属人数. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) def func(pipe): BattleEventMemberCount.incrby(logintime, rank, cnt, pipe) self.__append_process(BattleEventMemberCount.getDBName(), func) return self
def set_save_battleevent_result(self, uid, rank, grouprank, point, now=None): """イベント結果. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) self.__set_save( BattleEventResult.create(logintime, uid, rank, grouprank, point)) return self
def set_save_shop_buy(self, uid, is_pc, point, now=None): """日別イベントショップ購入数と消費ポイント. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) # 購入数. self.__set_save(EventShopPaymentUUDaily.create(logintime, uid, is_pc)) # 消費ポイント. def func(pipe, uid, date, point, is_pc): EventShopPaymentPointDaily.incrby(date, point, is_pc, pipe) DailyPaymentPointSet.incrby(uid, date, point, pipe) self.__append_process(EventShopPaymentPointDaily.getDBName(), func, uid, logintime, point, is_pc) return self
def checkAggregateEnd(self, targettime): redisdb = RedisModel.getDB() ALREADY_KEY = "battleevent_aggregate:end" # 対象の日付(月). logintime = DateTimeUtil.toLoginTime(targettime) cdate = datetime.date(logintime.year, logintime.month, logintime.day) str_cdate_pre = redisdb.get(ALREADY_KEY) if str_cdate_pre: dt = DateTimeUtil.strToDateTime(str_cdate_pre, "%Y%m%d") cdate_pre = datetime.date(dt.year, dt.month, dt.day) if cdate_pre == cdate: # 集計が正常に終わっている. return True return False
def process(self): args = self.getUrlArgs('/battleeventgrouplog/list/') eventid = args.getInt(0) model_mgr = self.getModelMgr() eventmaster = None if eventid: eventmaster = BackendApi.get_battleevent_master( model_mgr, eventid, using=settings.DB_READONLY) if eventmaster is None: self.redirectToTop() return cur_eventmaster = self.getCurrentBattleEvent(quiet=True) v_player = self.getViewerPlayer() uid = v_player.id basetime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) cdate_max = datetime.date(basetime.year, basetime.month, basetime.day) if cur_eventmaster and cur_eventmaster.id == eventid: cdate_max -= datetime.timedelta(days=1) # グループ履歴ID. rankrecord = BackendApi.get_battleevent_rankrecord( model_mgr, eventid, uid, using=settings.DB_READONLY) obj_list = [] if rankrecord and rankrecord.groups: groupidlist = rankrecord.groups[:] num = len(groupidlist) for idx in xrange(num): obj = self.makeRankRecordObj(rankrecord, groupidlist[-(idx + 1)], logonly=True, cdate_max=cdate_max) if obj: obj_list.append(obj) self.html_param['battleevent_rank_list'] = obj_list self.putEventTopic(eventmaster.id) if eventmaster.is_goukon: self.writeAppHtml('gcevent/rankloglist') else: self.writeAppHtml('btevent/rankloglist')
def getCurrentBattleGroup(self, do_search_log=False): """現在発生中のイベントで参加しているグループを取得. """ if self.__current_event_group is None: basetime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) cdate = datetime.date(basetime.year, basetime.month, basetime.day) rankrecord = self.getCurrentBattleRankRecord() if rankrecord and rankrecord.groups: model_mgr = self.getModelMgr() groupid = rankrecord.groups[-1] group = BackendApi.get_battleevent_group(model_mgr, groupid, using=settings.DB_READONLY) if do_search_log and (group is None or group.cdate != cdate): grouplog_dict = BackendApi.get_battleevent_grouplog_dict(model_mgr, rankrecord.groups, using=settings.DB_READONLY) for groupid in rankrecord.groups[::1]: group = grouplog_dict.get(groupid) if group: break self.__current_event_group = group return self.__current_event_group
def set_increment_battleevent_battlecount(self, uid, rank, cnt_add, is_attack, is_win, now=None): """バトル回数を加算. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) if is_attack: battlecount_cls, battlewincount_cls = ( BattleEventBattleCountAttack, BattleEventBattleCountAttackWin) else: battlecount_cls, battlewincount_cls = ( BattleEventBattleCountDefense, BattleEventBattleCountDefenseWin) def func_battlecount(pipe): battlecount_cls.incrby(logintime, uid, cnt_add, pipe) self.__append_process(battlecount_cls.getDBName(), func_battlecount) if is_win: def func_wincount(pipe): battlewincount_cls.incrby(logintime, uid, cnt_add, pipe) self.__append_process(battlewincount_cls.getDBName(), func_wincount) self.__set_save( BattleEventDailyUserRankSet.create(logintime, uid, rank)) return self
def makeRankRecordObj(self, rankrecord, groupid=None, logonly=False, player_num=0, do_execute=True, cdate_max=None): """ランク情報. """ if cdate_max is None: basetime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) cdate_max = datetime.date(basetime.year, basetime.month, basetime.day) if groupid is None: groupid = rankrecord.groups[-1] model_mgr = self.getModelMgr() if logonly: # 履歴から. group = BackendApi.get_battleevent_grouplog(model_mgr, groupid, using=settings.DB_READONLY) else: group = BackendApi.get_battleevent_group(model_mgr, groupid, using=settings.DB_READONLY) if group is None: # 履歴から. group = BackendApi.get_battleevent_grouplog(model_mgr, groupid, using=settings.DB_READONLY) if group is None or cdate_max < group.cdate: return None now = OSAUtil.get_now() func_execute_end = BackendApi.make_battleevent_grouprankingdata(self, group, rankrecord.uid, now, do_execute, player_num, using=settings.DB_READONLY) rankid = group.rankid rankmaster = BackendApi.get_battleevent_rankmaster_byId(model_mgr, rankid, using=settings.DB_READONLY) def execute_end(): rankingdata = func_execute_end if do_execute else func_execute_end() return Objects.battleevent_rank(self, rankrecord, rankmaster, group, rankingdata) if do_execute: return execute_end() else: return execute_end
def set_save_gacha_laststep(self, uid, mid, step, now=None): """連続ログインが5以上の課金ユーザーを記録. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) self.__set_save(GachaLastStepSortSet.create(logintime, uid, mid, step)) return self
def set_save_payment_fq5(self, uid, mid, now=None): """連続ログインが5以上の課金ユーザーを記録. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) self.__set_save(FQ5PaymentSet.create(logintime, uid, mid)) return self
def set_save_weeklylogin(self, uid, is_pc, now=None): """過去1週間のログインUU算出のために当日ログインを記録. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) self.__set_save(WeeklyLoginSet.create(logintime, uid, is_pc)) return self
def set_save_battleevent_piece_collect(self, rare): """日別バトルイベントのピース獲得数. """ logintime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) self.__set_save(BattleEventPieceCollect.create(logintime, rare)) return self
def handle(self, *args, **options): print '================================' print 'battleevent_aggregate' print '================================' now = OSAUtil.get_now() model_mgr = ModelRequestMgr() is_battle_open = BackendApi.is_battleevent_battle_open( model_mgr, settings.DB_READONLY, now, do_check_emergency=False) if is_battle_open: # こっちは緊急で修復する場合.. tomorrow = now now = tomorrow - datetime.timedelta(days=1) else: tomorrow = now + datetime.timedelta(days=1) config = BackendApi.get_current_battleeventconfig(model_mgr) if config.mid == 0: print 'イベントが設定されていません.' return elif now < config.starttime: print 'イベントが始まっていません.' return elif config.endtime <= now: print 'イベントが終わっています.' return elif is_battle_open and not config.is_emergency: print 'バトル中です.' return eventmaster = BackendApi.get_battleevent_master( model_mgr, config.mid, using=settings.DB_READONLY) if eventmaster is None: print 'イベントが見つかりません.' return print 'check eventmaster...OK' redisdb = RedisModel.getDB() ALREADY_KEY = "battleevent_aggregate:end" # 対象の日付(月). logintime = DateTimeUtil.toLoginTime(tomorrow) cdate = datetime.date(logintime.year, logintime.month, logintime.day) print cdate.strftime("Create %Y/%m/%d") str_cdate_pre = redisdb.get(ALREADY_KEY) if str_cdate_pre: dt = DateTimeUtil.strToDateTime(str_cdate_pre, "%Y%m%d") cdate_pre = datetime.date(dt.year, dt.month, dt.day) if cdate_pre == cdate: print "already..." return rankmaster_dict = dict([ (master.id, master) for master in BattleEventRankMaster.fetchValues( filters={'eventid': config.mid}, fetch_deleted=True, using=settings.DB_READONLY) ]) print '================================' print 'check rankmax' rank_max = config.getRankMax(logintime) print 'rankmax=%s' % rank_max if rank_max is None: rankmaster_list = rankmaster_dict.values() else: rankmaster_list = [ rankmaster for rankmaster in rankmaster_dict.values() if rankmaster.rank <= rank_max ] if not rankmaster_list: print 'rank:all closed' return print '================================' print 'send groupranking prizes.' # 未受け取りのグループ内ランキング報酬を配布. BackendApi.battleevent_send_groupranking_prizes(eventmaster) print '================================' print 'reset daily ranking.' logintime_today = DateTimeUtil.toLoginTime(now) keylist = [ BattleEventDailyRanking.makeKey( BattleEventDailyRanking.makeRankingId(logintime_today, config.mid, rankmaster.rank)) for rankmaster in rankmaster_dict.values() ] if keylist: redisdb.delete(*keylist) offset = 0 LIMIT = 500 while True: grouplist = BattleEventGroupLog.fetchValues(filters={ 'eventid': config.mid, 'cdate': datetime.date(logintime_today.year, logintime_today.month, logintime_today.day) }, order_by='id', offset=offset, limit=LIMIT) if not grouplist: break offset += LIMIT for group in grouplist: rankmaster = rankmaster_dict.get(group.rankid) rankingid = BattleEventDailyRanking.makeRankingId( logintime_today, config.mid, rankmaster.rank) pipe = redisdb.pipeline() for userdata in group.userdata: if 0 < userdata.point: BattleEventDailyRanking.create( rankingid, userdata.uid, userdata.point).save(pipe) pipe.execute() print '================================' print 'close group.' while True: grouplist = BattleEventGroup.fetchValues( filters={'eventid': config.mid}, order_by='cdate', limit=500) if not grouplist or cdate <= grouplist[0].cdate: break for group in grouplist: if cdate <= group.cdate: break eventrankmaster = rankmaster_dict[group.rankid] model_mgr = db_util.run_in_transaction(Command.tr_close, eventmaster, eventrankmaster, group.id, now, rank_max) model_mgr.write_end() print 'close %s' % group.id print '================================' print 'send rankingprizes.' date_today = datetime.date(logintime_today.year, logintime_today.month, logintime_today.day) rankmasterlist = rankmaster_dict.values() rankmasterlist.sort(key=lambda x: x.rank) for rankmaster in rankmasterlist: # 報酬を渡す. rankingid = BattleEventDailyRanking.makeRankingId( logintime_today, config.mid, rankmaster.rank) rankingprizes = rankmaster.rankingprizes textid = rankmaster.rankingprize_text for idx, data in enumerate(rankingprizes): prize_flag = (rankmaster.rank << 16) + idx pre_prize_flag = config.getDailyPrizeFlag(date_today) if prize_flag < pre_prize_flag: print 'skip...%d' % idx continue prizeidlist = data['prize'] rank_min = data['rank_min'] rank_max = data['rank_max'] prizelist = BackendApi.get_prizelist(model_mgr, prizeidlist) uidlist = [] for rank in xrange(rank_min, rank_max + 1): data = BattleEventDailyRanking.fetchByRank(rankingid, rank, zero=False) dic = dict(data) uidlist.extend(dic.keys()) if len(set(uidlist)) != len(uidlist): raise CabaretError(u'ランキング取得がなにかおかしい..%d' % rank) def tr(): model_mgr = ModelRequestMgr() config = CurrentBattleEventConfig.getByKeyForUpdate( CurrentBattleEventConfig.SINGLE_ID) if config.getDailyPrizeFlag(date_today) != pre_prize_flag: raise CabaretError(u'整合が取れていないので終了します') for uid in uidlist: BackendApi.tr_add_prize(model_mgr, uid, prizelist, textid) config.daily_prize_flag = prize_flag + 1 config.daily_prize_date = date_today model_mgr.set_save(config) model_mgr.write_all() return model_mgr, config try: tmp_model_mgr, wrote_config = db_util.run_in_transaction( tr) except CabaretError, err: print 'error...%s' % err.value return print 'save end...%d' % idx tmp_model_mgr.write_end() print 'cache end...%d' % idx config = wrote_config
def set_save_battleevent_battle_join(self, uid, rank, now=None): """イベントバトルに参加. """ logintime = DateTimeUtil.toLoginTime(now or OSAUtil.get_now()) self.__set_save(BattleEventJoin.create(logintime, uid, rank)) return self
def handle(self, *args, **options): print '================================' print 'battleevent_preparation' print '================================' now = OSAUtil.get_now() model_mgr = ModelRequestMgr() # メンテナンス確認. appconfig = BackendApi.get_appconfig(model_mgr) if not appconfig.is_maintenance(): print u'メンテナンスモードにしてください' return print 'check maintenance...OK' config = BackendApi.get_current_battleeventconfig(model_mgr) if config.mid == 0: print 'Event is not set.' return elif config.starttime <= now: print 'Event has already beguns.' return eventmaster = BackendApi.get_battleevent_master( model_mgr, config.mid, using=settings.DB_READONLY) if eventmaster is None: print 'Event is not found.' return print 'check eventmaster...OK' rankmaster_dict = dict([ (master.rank, master) for master in BattleEventRankMaster.fetchValues( filters={'eventid': config.mid}, fetch_deleted=True, using=settings.DB_READONLY) ]) eventrankmaster = rankmaster_dict.get(eventmaster.rankstart) if eventrankmaster is None: print 'BattleEventMaster.rankstart is not set.' return print 'check eventrankmaster...OK' # 対象の日付(月). logintime = DateTimeUtil.toLoginTime(now) cdate = datetime.date(logintime.year, logintime.month, logintime.day) print cdate.strftime("Create %Y/%m/%d") if not eventmaster.is_goukon: print '================================' print 'delete battleeventdata.' # Redisのバトルイベント関係を削除. RedisBattleEvent.getDB().flushdb() print 'delete...redis' BattleEventRanking.getDB().delete( BattleEventRanking.makeKey(eventmaster.id)) BattleEventRankingBeginer.getDB().delete( BattleEventRankingBeginer.makeKey(eventmaster.id)) print 'delete...ranking' tmp_time = config.starttime while tmp_time < config.endtime: keys = [ BattleEventDailyRanking.makeKey( BattleEventDailyRanking.makeRankingId( tmp_time, eventmaster.id, rankmaster.rank)) for rankmaster in rankmaster_dict.values() ] BattleEventDailyRanking.getDB().delete(*keys) tmp_time += datetime.timedelta(days=1) print 'delete...daily_ranking' delete_target_model_cls_list = ( BattleEventFlags, BattleEventRank, BattleEventScore, BattleEventGroup, BattleEventGroupLog, BattleEventRevenge, BattleEventBattleLog, BattleEventGroupRankingPrize, BattleEventPresentData, BattleEventPresentCounts, UserLogBattleEventPresent, ) def tr(): for model_cls in delete_target_model_cls_list: tablename = model_cls.get_tablename() query_string = "truncate table `%s`;" % tablename Query.execute_update(query_string, [], False) print 'delete...%s' % tablename db_util.run_in_transaction(tr) OSAUtil.get_cache_client().flush() redisdb = RedisModel.getDB() if eventmaster.is_goukon: self.__proc_goukon(model_mgr, redisdb, config, eventmaster, rankmaster_dict, now, logintime, cdate) else: self.__proc_normal(model_mgr, redisdb, config, eventmaster, rankmaster_dict, now, logintime, cdate)
def handle(self, *args, **options): print '================================' print 'close_battleevent' print '================================' now = OSAUtil.get_now() model_mgr = ModelRequestMgr() redisdb = RedisModel.getDB() config = BackendApi.get_current_battleeventconfig(model_mgr) eventmaster = BackendApi.get_battleevent_master(model_mgr, config.mid) if eventmaster is None: print u'イベントが設定されていません' return print 'check eventmaster...OK' # イベント設定. if now < config.endtime: print u'イベントがまだ終了していません' return print 'check event endtime...OK' # メンテナンス確認. appconfig = BackendApi.get_appconfig(model_mgr) if not appconfig.is_maintenance(): print u'メンテナンスモードにしてください' return print 'check maintenance...OK' rankmaster_dict = dict([ (master.id, master) for master in BattleEventRankMaster.fetchValues( filters={'eventid': config.mid}, fetch_deleted=True, using=settings.DB_READONLY) ]) print '================================' print 'send groupranking prizes.' # 未受け取りのグループ内ランキング報酬を配布. BackendApi.battleevent_send_groupranking_prizes(eventmaster) print '================================' print 'reset daily ranking.' logintime_today = DateTimeUtil.toLoginTime(now) keylist = [ BattleEventDailyRanking.makeKey( BattleEventDailyRanking.makeRankingId(logintime_today, config.mid, rankmaster.rank)) for rankmaster in rankmaster_dict.values() ] if keylist: redisdb.delete(*keylist) offset = 0 LIMIT = 500 while True: grouplist = BattleEventGroupLog.fetchValues(filters={ 'eventid': config.mid, 'cdate': datetime.date(logintime_today.year, logintime_today.month, logintime_today.day) }, order_by='id', offset=offset, limit=LIMIT) if not grouplist: break offset += LIMIT for group in grouplist: rankmaster = rankmaster_dict.get(group.rankid) rankingid = BattleEventDailyRanking.makeRankingId( logintime_today, config.mid, rankmaster.rank) pipe = redisdb.pipeline() for userdata in group.userdata: if 0 < userdata.point: BattleEventDailyRanking.create( rankingid, userdata.uid, userdata.point).save(pipe) pipe.execute() print '================================' print 'close group.' while True: grouplist = BattleEventGroup.fetchValues( filters={'eventid': config.mid}, order_by='cdate', limit=500) if not grouplist: break for group in grouplist: eventrankmaster = rankmaster_dict[group.rankid] model_mgr = db_util.run_in_transaction(Command.tr_close, eventmaster, eventrankmaster, group.id, now) model_mgr.write_end() print 'close %s' % group.id print '================================' print 'send daily ranking prizes.' date_today = datetime.date(logintime_today.year, logintime_today.month, logintime_today.day) rankmasterlist = rankmaster_dict.values() rankmasterlist.sort(key=lambda x: x.rank) for rankmaster in rankmasterlist: # 報酬を渡す. rankingid = BattleEventDailyRanking.makeRankingId( logintime_today, config.mid, rankmaster.rank) rankingprizes = rankmaster.rankingprizes textid = rankmaster.rankingprize_text for idx, data in enumerate(rankingprizes): prize_flag = (rankmaster.rank << 16) + idx pre_prize_flag = config.getDailyPrizeFlag(date_today) if prize_flag < pre_prize_flag: print 'skip...%d' % idx continue prizeidlist = data['prize'] rank_min = data['rank_min'] rank_max = data['rank_max'] prizelist = BackendApi.get_prizelist(model_mgr, prizeidlist) uidlist = [] for rank in xrange(rank_min, rank_max + 1): data = BattleEventDailyRanking.fetchByRank(rankingid, rank, zero=False) dic = dict(data) uidlist.extend(dic.keys()) if len(set(uidlist)) != len(uidlist): raise CabaretError(u'ランキング取得がなにかおかしい..%d' % rank) def tr(): model_mgr = ModelRequestMgr() config = CurrentBattleEventConfig.getByKeyForUpdate( CurrentBattleEventConfig.SINGLE_ID) if config.getDailyPrizeFlag(date_today) != pre_prize_flag: raise CabaretError(u'整合が取れていないので終了します') for uid in uidlist: BackendApi.tr_add_prize(model_mgr, uid, prizelist, textid) config.daily_prize_flag = prize_flag + 1 config.daily_prize_date = date_today model_mgr.set_save(config) model_mgr.write_all() return model_mgr, config try: tmp_model_mgr, wrote_config = db_util.run_in_transaction( tr) except CabaretError, err: print 'error...%s' % err.value return print 'save end...%d' % idx tmp_model_mgr.write_end() print 'cache end...%d' % idx config = wrote_config
using=settings.DB_READONLY) if rankmaster: fame = 0 for data in group_yesterday.userdata: if data.uid == uid: fame = data.fame break received_data = { 'fame': rankrecord.fame - fame, 'fame_next': rankrecord.fame, 'rank': rankmaster.rank, 'rank_next': rankrecord.rank, } basetime = DateTimeUtil.toLoginTime(OSAUtil.get_now()) yesterday = datetime.date(basetime.year, basetime.month, basetime.day) - datetime.timedelta(days=1) target_grouplog = None for grouplog in BackendApi.get_battleevent_grouplog_dict( model_mgr, rankrecord.groups, using=settings.DB_READONLY).values(): if grouplog.cdate == yesterday: target_grouplog = grouplog break if target_grouplog is None: url = self.makeAppLinkUrlRedirect( UrlMaker.battleevent_top(eventmaster.id)) self.appRedirect(url) return elif eventmaster.is_goukon:
def e_time(self): return DateTimeUtil.toLoginTime( DateTimeUtil.dateToDateTime(self.e_date))
def handle(self, *args, **options): print '================================' print 'create_presenteveryone_schedule' print '================================' DATE_FORMAT = "%Y%m%d" now = OSAUtil.get_now() today = DateTimeUtil.datetimeToDate(now) # 対象の日付. if args: target_dates = [ DateTimeUtil.datetimeToDate(datetime.datetime.strptime( v, DATE_FORMAT), logintime=False) for v in args ] else: start_date = DateTimeUtil.datetimeToDate( now, logintime=True) + datetime.timedelta(days=1) target_dates = [ start_date + datetime.timedelta(days=i) for i in xrange(7) ] # 既にあるかを検証. model_dict = dict([ (model.date, model) for model in PresentEveryoneRecord.fetchValues( filters={'date__in': target_dates}, fetch_deleted=True) ]) save_list = [] for target_date in target_dates: result = '' if target_date < today: print 'old' else: target_datetime = DateTimeUtil.dateToDateTime( target_date) + datetime.timedelta( seconds=Defines.DATE_CHANGE_TIME * 3600) # マスターデータを検索. filters = { 'e_date__gte': target_date, } login_mid_list = [ master.id for master in PresentEveryoneLoginBonusMaster.fetchValues( filters=filters) if master.s_date <= target_date ] filters = { 'etime__gte': target_datetime, } scheduleidlist = [ schedule.id for schedule in ScheduleMaster.fetchValues(filters=filters) if DateTimeUtil.toLoginTime(schedule.stime) <= target_datetime ] scheduleidlist.insert(0, 0) filters = { 'schedule__in': scheduleidlist, } mypage_mid_list = [ master.id for master in PresentEveryoneMypageMaster.fetchValues( filters=filters) ] if model_dict.has_key(target_date): model = model_dict[target_date] update = False if today < target_date and (len( set(model.mid_loginbonus) - set(login_mid_list)) != 0 or len( set(login_mid_list) - set(model.mid_loginbonus)) != 0): # 現在よりも後ならログインボーナスを受け取っていないからだいじょうぶ. model.mid_loginbonus = list(set(login_mid_list)) update = True if len(set(model.mid_mypage) - set(mypage_mid_list)) != 0 or len( set(mypage_mid_list) - set(model.mid_mypage)) != 0: model.mid_mypage = list(set(mypage_mid_list)) update = True if update: save_list.append(model) result = 'update' else: result = 'no change' else: model = PresentEveryoneRecord() model.date = target_date model.mid_loginbonus = list(set(login_mid_list)) model.mid_mypage = list(set(mypage_mid_list)) save_list.append(model) result = 'create' print '%s...%s' % (target_date.strftime("%Y%m%d"), result) # レコード作成. db_util.run_in_transaction(Command.tr_write, save_list, today).write_end() print '================================' print 'all done.'