def isInterventionUser(userId): # redis 中获取, 存储在 dizhuaccount.loginGame 中 roundsShareTimes = segmentdata.getSegmentAttr(userId, DIZHU_GAMEID, 'roundsShareTimes') if ftlog.is_debug(): ftlog.debug('user_share_behavior.isInterventionUser', 'userId=', userId, 'roundsShareTimes=', roundsShareTimes) if getUserShareBehaviorConf().get('test_roundsShareTimes'): roundsShareTimes = getUserShareBehaviorConf().get( 'test_roundsShareTimes') if roundsShareTimes: try: timeStr, playTimes, shareTimes = roundsShareTimes.split(':') if isValidDatetime(timeStr): shareRate = float(shareTimes) / float(playTimes) if ftlog.is_debug(): ftlog.debug('user_share_behavior.isInterventionUser', 'userId=', userId, 'timeStr=', timeStr, 'playTimes=', playTimes, 'shareTimes=', shareTimes, 'shareRate=', shareRate, 'roundsShareTimes=', roundsShareTimes) if shareRate < 0.2: return 1 except Exception, e: ftlog.error('user_share_behavior.isInterventionUser error', 'userId=', userId, 'error=', e.message) return 0
def getNoInvitedDiamond(userId): # redis 中获取, 存储在 dizhuaccount.loginGame 中 noInvitedGetDiamond = segmentdata.getSegmentAttr(userId, DIZHU_GAMEID, 'noInvitedGetDiamond') burialId = getUserShareBehaviorConf().get('noInvitedGetDiamondBurialId') if ftlog.is_debug(): ftlog.debug('user_share_behavior.getNoInvitedDiamond', 'userId=', userId, 'noInvitedGetDiamond=', noInvitedGetDiamond) if getUserShareBehaviorConf().get('test_noInvitedGetDiamond'): noInvitedGetDiamond = getUserShareBehaviorConf().get( 'test_noInvitedGetDiamond') if noInvitedGetDiamond: # 目标用户是7日内带来0新增,通过分享领钻石 > 3,非3天内注册用户。 # 我们将这部分特征写入了特征库 # 字段:no_invited_get_diamond # 值:有效期:实际领钻石的数量 # 说明:天还是以凌晨4:00 - 次日凌晨4:00 # 为一天 # # 示例: # 2018-07-18:4 # 表示2018-07-18 4:00-2018-07-19 4:00该字段有效,该用户在之前7日共通过分享领钻石获得了4个钻石。 try: timeStr, _ = noInvitedGetDiamond.split(':') if not isValidDatetime(timeStr): return 0, burialId return 1, burialId except Exception: return 0, burialId else: return 0, burialId
def getUserWatchAdData(userId): dataStr = segmentdata.getSegmentAttr(userId, DIZHU_GAMEID, buildUserWatchAdDataKey()) if dataStr: return UserWatchAdData(userId).fromDict(json.loads(dataStr)) else: return UserWatchAdData(userId)
def processUserBehavior(userId): # 进一步优化,存储过期时间,每2小时刷一次 shareBehaviorFeatureTimestamp = segmentdata.getSegmentAttr(userId, DIZHU_GAMEID, 'shareBehaviorFeatureTimestamp') if not shareBehaviorFeatureTimestamp: shareBehaviorFeatureTimestamp = pktimestamp.getCurrentTimestamp() segmentdata.setSegmentAttr(userId, DIZHU_GAMEID, 'shareBehaviorFeatureTimestamp', shareBehaviorFeatureTimestamp) if pktimestamp.getCurrentTimestamp() - shareBehaviorFeatureTimestamp > 3600 * 2 + random.randint(0, 300): segmentdata.setSegmentAttr(userId, DIZHU_GAMEID, 'shareBehaviorFeatureTimestamp', pktimestamp.getCurrentTimestamp()) # 存储用户行为特征库数据 params = { 'user_id': userId, 'cloud_id': 29, 'game_id': 6, 'time': int(time.time()) } ec, datas = analysis_api.requestAnalysis('api.getUserFeature', params) if ftlog.is_debug(): ftlog.debug('dizhuaccount.loginGame setUserBehaviourFeature', 'userId=', userId, 'ec=', ec, 'datas=', datas) share_behavior = datas.get('sharing_behavior', None) if ec == 1 else None if share_behavior: segmentdata.setSegmentAttr(userId, DIZHU_GAMEID, 'shareBehaviorFeature', share_behavior) noInvitedDiamond = datas.get('no_invited_get_diamond', None) if ec == 1 else None if noInvitedDiamond: segmentdata.setSegmentAttr(userId, DIZHU_GAMEID, 'noInvitedGetDiamond', noInvitedDiamond) roundsShareTimes = datas.get('rounds_share_times', None) if ec == 1 else None if roundsShareTimes: segmentdata.setSegmentAttr(userId, DIZHU_GAMEID, 'roundsShareTimes', roundsShareTimes)
def processEnterGame(cls, evt): # # 检查当前已结束赛季并发放赛季奖励, 只发放上一期的 if ftlog.is_debug(): ftlog.debug('============= processEnterGame userId=', evt.userId) _, intClientId = sessiondata.getClientIdNum(evt.userId) if intClientId == 24105: latestTwoIssues = SegmentMatchHelper.getIssueStateList()[-2:] for issuestate in reversed(latestTwoIssues): if issuestate['state'] == 0: continue # 判断用户有没有结算此赛季 userData = SegmentMatchHelper.getUserSegmentDataIssue( evt.userId, issuestate['issue']) or UserSegmentDataIssue() if userData and userData.segmentRewardsState == UserSegmentDataIssue.IDEAL: # 结算 发奖 settlementRanking(evt.userId, issuestate['issue']) segmentConf = getSegmentConf() if segmentConf.closed: return if evt.dayFirst: # 检查用户是否已经发送 if not gamedata.getGameAttrInt(evt.userId, DIZHU_GAMEID, 'wxNotice'): # 保存消息记录 gamedata.setGameAttr(evt.userId, DIZHU_GAMEID, 'wxNotice', 1) # 新用户发送一条额外消息 mailstr = '游戏公告#如有任何意见建议,欢迎加客服微信:Tuyoo_taozi,进入官方群反馈' message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM, evt.userId, mailstr) # 同步钻石为用户道具 if not segmentdata.getSegmentAttr(evt.userId, DIZHU_GAMEID, 'diamondConvert'): segmentdata.setSegmentAttr(evt.userId, DIZHU_GAMEID, 'diamondConvert', 1) userDiamond = userdata.getAttr(evt.userId, 'diamond') if userDiamond: # count user_remote.consumeAssets(DIZHU_GAMEID, evt.userId, [{ 'itemId': 'user:diamond', 'count': userDiamond }], 'DIZHU_SEGMENT_DIAMOND_CONVERT', 0) contentItems = TYContentItem.decodeList([{ 'itemId': 'item:1311', 'count': userDiamond }]) from dizhu.entity import dizhu_util dizhu_util.sendRewardItems(evt.userId, contentItems, None, 'DIZHU_SEGMENT_DIAMOND_CONVERT', 0) ftlog.info('DizhuSegmentRewardsHelper diamondConvert userId=', evt.userId, 'userDiamond=', userDiamond)
def doGetUserShareBehaviorInfo(userId): # redis 中获取, 存储在 dizhuaccount.loginGame 中 share_behavior = segmentdata.getSegmentAttr(userId, DIZHU_GAMEID, 'shareBehaviorFeature') if ftlog.is_debug(): ftlog.debug('user_share_behavior.doGetUserShareBehaviorInfo', 'userId=', userId, 'share_behavior=', share_behavior) burial_list = [] if getUserShareBehaviorConf().get('test_sharing_behavior'): share_behavior = getUserShareBehaviorConf().get( 'test_sharing_behavior') if share_behavior: # 特征库中字段名share_behavior # 格式: # YYYY - MM - DD:[0 | 1]: % d: % d # 例子: # 2018 - 06 - 13:1:5:7 # 第一个字段表示这是2018年6月13日凌晨4点到2018年6月14日凌晨4点有效的数据 # 第二个字段位0表示这个用户有过分享,1 # 表示这个用户没有分享过,例子中为1 # 第三个字段表示这个用户前7天总共拉来的新增,例子中为5 # 第四个字段表示这个用户前7天总共唤醒数量,例子中为7 try: timeStr, isShare, _, _ = share_behavior.split(':') if not isValidDatetime(timeStr): return {} if isShare: # 加载用户数据 dataStr = loadUserBehaviorData(userId) if dataStr: userData = UserShareBehaviorData(userId).fromDict( json.loads(dataStr)) if userData.dateTimeStr != timeStr: userData.dateTimeStr = timeStr userData.burialList = [] else: userData = UserShareBehaviorData(userId) userData.dateTimeStr = timeStr conf = getUserShareBehaviorConf() videoOrBanner = conf.get('videoOrBanner', '') for burialConfInfo in conf.get('burialIdList', []): leftCount = userData.getBurialLeftCount(burialConfInfo) burial_list.append({ 'burialId': burialConfInfo.get('burialId'), 'dailyCount': burialConfInfo.get('dailyCount'), 'leftCount': leftCount }) if ftlog.is_debug(): ftlog.debug( 'user_share_behavior.doGetUserShareBehaviorInfo result', 'userId=', userId, 'burial_list=', burial_list, 'isShare=', isShare) saveUserBehaviorData(userId, json.dumps(userData.toDict())) return { 'burial_list': burial_list, 'isShare': isShare, 'videoOrBanner': videoOrBanner } return {} except Exception: return {} else: return {}