def __init__(self, start_time, end_time, database, origin=False): if origin: self.start_time = start_time self.end_time = end_time else: self.start_time = time_to_hour(start_time) self.end_time = time_to_hour(end_time) self.db, self.collection, self.host = database
def get_r(alist, time_format, searchCondition, t): for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if t == 2 and item >= today-EXT.NUM_UNIX_A_DAY: continue if t == 7 and item >= today - EXT.NUM_UNIX_A_DAY*7: continue if t == 15 and item >= today - EXT.NUM_UNIX_A_DAY*15: continue r_data = RetentionCountData(item, item+EXT.NUM_UNIX_A_DAY, time_format) ret = r_data.get_r() if not ret: continue if t == 2: rentention = RetentionCount2() if t == 7: rentention = RetentionCount7() if t == 15: rentention = RetentionCount15() rentention.t = item rentention.s = g.GAME_BASEUSER if t == 2 and 2 in ret: rentention.r = ret[2] if t == 7 and 7 in ret: rentention.r = ret[7] if t == 15 and 15 in ret: rentention.r = ret[15] rentention.save()
def get_r(alist, time_format, searchCondition, t): for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if t == 2 and item >= today - EXT.NUM_UNIX_A_DAY: continue if t == 7 and item >= today - EXT.NUM_UNIX_A_DAY * 7: continue if t == 15 and item >= today - EXT.NUM_UNIX_A_DAY * 15: continue r_data = RetentionCountData(item, item + EXT.NUM_UNIX_A_DAY, time_format) ret = r_data.get_r() if not ret: continue if t == 2: rentention = RetentionCount2() if t == 7: rentention = RetentionCount7() if t == 15: rentention = RetentionCount15() rentention.t = item rentention.s = g.GAME_BASEUSER if t == 2 and 2 in ret: rentention.r = ret[2] if t == 7 and 7 in ret: rentention.r = ret[7] if t == 15 and 15 in ret: rentention.r = ret[15] rentention.save()
def NewCCount(alist, time_format, searchCondition): """ 从列表内的时间内创建内容 """ global g_types for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if item >= today: continue from_database = CCountFromDatabase(item, item + EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay(g_types) # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums(g_types) for i in g_types: complex_count = CCount() complex_count.t = item complex_count.s = g.GAME_BASEUSER complex_count.platform = i if create_users and item in create_users: if i in create_users[item]: complex_count.create = create_users[item][i] if login_ret and item in login_ret: if i in login_ret[item]: complex_count.login = login_ret[item][i] complex_count.max_online = online_max[item] complex_count.avg_online = online_avg[item] if item in pay_ret and i in pay_ret[item]: complex_count.pay = pay_ret[item][i] else: complex_count.pay = 0 if item in all_deals and i in all_deals[item]: complex_count.paynums = all_deals[item][i] else: complex_count.paynums = 0 if item in pay_nums and i in pay_nums[item]: complex_count.payusers = pay_nums[item][i] else: complex_count.payusers = 0 if item in new_pay_nums and i in new_pay_nums[item]: complex_count.newnums = new_pay_nums[item][i] else: complex_count.newnums = 0 complex_count.save()
def getLogin(self, query_key, time_format, querys_addition=None, types=None, st=None): """ log_info登陆记录 """ D_U = 'd.u' mongo_user = MongoFive(g.GAME_BASEUSER, EXT.BASEUSER_USER, host=g.mongo_host) mongo_log = MongoFive(self.db, self.collection, self.host) querys = { query_key: { EXT.MONGO_GTE: self.start_time, EXT.MONGO_LTE: self.end_time } } if querys_addition: querys.update(querys_addition) # 获取登录角色 uids = {} ret = {} players = mongo_log.filter(querys) for p in players: if EXT.KEY_D not in p: continue if EXT.KEY_U not in p[EXT.KEY_D]: continue day = time_to_hour(p[query_key], time_format) u = mongo_user.first( {EXT.KEY_MONGO_ID: int(p[EXT.KEY_D][EXT.KEY_U])}) if not u or 'sns' not in u: continue if day in uids and u['sns'] in uids[day] and u['_id'] in uids[day][ u['sns']]: continue if day in ret: if u['sns'] in ret[day]: ret[day][u['sns']] += 1 else: ret[day][u['sns']] = 1 else: ret[day] = {u['sns']: 1} if day in uids: if u['sns'] in uids[day]: uids[day][u['sns']].append(u['_id']) else: uids[day][u['sns']] = [u['_id']] else: uids[day] = {u['sns']: [u['_id']]} for k in uids.keys(): for key in uids[k].keys(): print k, key, uids[k][key] return ret
def NewCCount(alist, time_format, searchCondition): """ 从列表内的时间内创建内容 """ global g_types for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if item >= today: continue from_database = CCountFromDatabase(item, item+EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay(g_types) # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums(g_types) for i in g_types: complex_count = CCount() complex_count.t = item complex_count.s = g.GAME_BASEUSER complex_count.platform = i if create_users and item in create_users: if i in create_users[item]: complex_count.create = create_users[item][i] if login_ret and item in login_ret: if i in login_ret[item]: complex_count.login = login_ret[item][i] complex_count.max_online = online_max[item] complex_count.avg_online = online_avg[item] if item in pay_ret and i in pay_ret[item]: complex_count.pay = pay_ret[item][i] else: complex_count.pay = 0 if item in all_deals and i in all_deals[item]: complex_count.paynums = all_deals[item][i] else: complex_count.paynums = 0 if item in pay_nums and i in pay_nums[item]: complex_count.payusers = pay_nums[item][i] else: complex_count.payusers = 0 if item in new_pay_nums and i in new_pay_nums[item]: complex_count.newnums = new_pay_nums[item][i] else: complex_count.newnums = 0 complex_count.save()
def NewComplexCountToday(time_format, searchCondition): today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) complex_count = ComplexCount() from_database = ComplexCountFromDatabase(today, today + EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay() # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums() try: create_users = create_users[today] except: create_users = 0 try: login_ret = login_ret[today] except: login_ret = 0 try: online_max = online_max[today] except: online_max = 0 try: online_avg = online_avg[today] except: online_avg = 0 try: pay_ret = pay_ret[today] except: pay_ret = 0 try: all_deals = all_deals[today] except: all_deals = 0 try: pay_nums = pay_nums[today] except: pay_nums = 0 try: new_pay_nums = new_pay_nums[today] except: new_pay_nums = 0 if max_login_pid == {}: max_login_pid = 0 # if max_login_uid == {}: # max_login_uid = 0 return (today, create_users, login_ret, online_max, online_avg, max_login_pid, pay_ret, all_deals, pay_nums, new_pay_nums)
def NewComplexCountToday(time_format, searchCondition): today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) complex_count = ComplexCount() from_database = ComplexCountFromDatabase(today, today+EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay() # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums() try: create_users = create_users[today] except: create_users = 0 try: login_ret = login_ret[today] except: login_ret = 0 try: online_max = online_max[today] except: online_max = 0 try: online_avg = online_avg[today] except: online_avg = 0 try: pay_ret = pay_ret[today] except: pay_ret = 0 try: all_deals = all_deals[today] except: all_deals = 0 try: pay_nums = pay_nums[today] except: pay_nums = 0 try: new_pay_nums = new_pay_nums[today] except: new_pay_nums = 0 if max_login_pid == {}: max_login_pid = 0 # if max_login_uid == {}: # max_login_uid = 0 return (today, create_users, login_ret, online_max, online_avg, max_login_pid, pay_ret, all_deals, pay_nums, new_pay_nums)
def hour_count(self, alist, query_key, time_format, return_type='list'): """ 对每小时进行统计 """ ret = {} for item in alist: time_key = time_to_hour(item[query_key], time_format) if time_key in ret: if item['sns'] in ret[time_key]: ret[time_key][item['sns']] += 1 else: ret[time_key][item['sns']] = 1 else: ret[time_key] = {} ret[time_key][item['sns']] = 1 if return_type == 'list': return sorted(ret.items(), key=lambda d:d[0]) if return_type == 'dict': return ret
def hour_count(self, alist, query_key, time_format, return_type='list'): """ 对每小时进行统计 """ ret = {} for item in alist: time_key = time_to_hour(item[query_key], time_format) if time_key in ret: if item['sns'] in ret[time_key]: ret[time_key][item['sns']] += 1 else: ret[time_key][item['sns']] = 1 else: ret[time_key] = {} ret[time_key][item['sns']] = 1 if return_type == 'list': return sorted(ret.items(), key=lambda d: d[0]) if return_type == 'dict': return ret
def getAccumulateCount(self, query_key, count_key, time_format, querys_addition=None): """ 获取支付统计 """ mongo_ret = self.getRetByQuerys(query_key, querys_addition) # return accumulate_count(mongo_ret, query_key, count_key, time_format) ret = {} for item in mongo_ret: time_key = time_to_hour(item[query_key], time_format=time_format) if time_key in ret: if item['t'] in ret[time_key]: ret[time_key][item['t']] += item[EXT.STRING_PRICE] else: ret[time_key][item['t']] = item[EXT.STRING_PRICE] # ret[time_key] += item[EXT.STRING_PRICE] else: ret[time_key] = {} ret[time_key][item['t']] = item[EXT.STRING_PRICE] # ret[time_key] = item[EXT.STRING_PRICE] return ret
def getLogin(self, query_key, time_format, querys_addition=None, types=None, st=None): """ log_info登陆记录 """ D_U = 'd.u' mongo_user = MongoFive(g.GAME_BASEUSER, EXT.BASEUSER_USER, host=g.mongo_host) mongo_log = MongoFive(self.db, self.collection, self.host) querys = {query_key:{EXT.MONGO_GTE:self.start_time, EXT.MONGO_LTE:self.end_time}} if querys_addition: querys.update(querys_addition) # 获取登录角色 uids = {} ret = {} players = mongo_log.filter(querys) for p in players: if EXT.KEY_D not in p: continue if EXT.KEY_U not in p[EXT.KEY_D]: continue day = time_to_hour(p[query_key], time_format) u = mongo_user.first({EXT.KEY_MONGO_ID:int(p[EXT.KEY_D][EXT.KEY_U])}) if not u or 'sns' not in u: continue if day in uids and u['sns'] in uids[day] and u['_id'] in uids[day][u['sns']]: continue if day in ret: if u['sns'] in ret[day]: ret[day][u['sns']] += 1 else: ret[day][u['sns']] = 1 else: ret[day]= {u['sns']:1} if day in uids: if u['sns'] in uids[day]: uids[day][u['sns']].append(u['_id']) else: uids[day][u['sns']] = [u['_id']] else: uids[day] = {u['sns']:[u['_id']]} for k in uids.keys(): for key in uids[k].keys(): print k, key, uids[k][key] return ret
def NewComplexCount(alist, time_format, searchCondition): """ 从列表内的时间内创建内容 """ for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if item >= today: continue complex_count = ComplexCount() from_database = ComplexCountFromDatabase(item, item + EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay() # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums() complex_count.t = item complex_count.s = g.GAME_BASEUSER if item in create_users: complex_count.create = int(create_users[item]) if item in login_ret: complex_count.login = int(login_ret[item]) if item in online_max: complex_count.max_online = int(online_max[item]) if item in online_avg: complex_count.avg_online = int(online_avg[item]) if item in pay_ret: complex_count.pay = int(pay_ret[item]) if item in all_deals: complex_count.paynums = int(all_deals[item]) if item in pay_nums: complex_count.payusers = int(pay_nums[item]) if item in new_pay_nums: complex_count.newnums = int(new_pay_nums[item]) complex_count.max_login_pid = max_login_pid # complex_count.max_login_uid = max_login_uid complex_count.save()
def NewComplexCount(alist, time_format, searchCondition): """ 从列表内的时间内创建内容 """ for item in alist: today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) if item >= today: continue complex_count = ComplexCount() from_database = ComplexCountFromDatabase(item, item+EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay() # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums() complex_count.t = item complex_count.s = g.GAME_BASEUSER if item in create_users: complex_count.create = int(create_users[item]) if item in login_ret: complex_count.login = int(login_ret[item]) if item in online_max: complex_count.max_online = int(online_max[item]) if item in online_avg: complex_count.avg_online = int(online_avg[item]) if item in pay_ret: complex_count.pay = int(pay_ret[item]) if item in all_deals: complex_count.paynums = int(all_deals[item]) if item in pay_nums: complex_count.payusers = int(pay_nums[item]) if item in new_pay_nums: complex_count.newnums = int(new_pay_nums[item]) complex_count.max_login_pid = max_login_pid # complex_count.max_login_uid = max_login_uid complex_count.save()
def NewCCountToday(time_format, searchCondition, st): global g_types today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) complex_count = CCount() from_database = CCountFromDatabase(today, today+EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay(types=g_types, st=st) # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums(types=g_types, st=st) print "**pay_ret, all_deals **", pay_ret, all_deals if create_users: if st != -1: if st in create_users[today]: create_users = create_users[today][st] else: create_users = 0 else: total = 0 for k in create_users[today].keys(): total += create_users[today][k] create_users = total else: create_users = 0 if login_ret: if st != -1: if st in login_ret[today]: login_ret = login_ret[today][st] else: login_ret = 0 else: total = 0 for k in login_ret[today].keys(): total += login_ret[today][k] login_ret = total else: login_ret = 0 try: online_max = online_max[today] except: online_max = 0 try: online_avg = online_avg[today] except: online_avg = 0 if pay_ret: if st != -1: if st in pay_ret[today]: pay_ret = pay_ret[today][st] else: pay_ret = 0 else: total = 0 for k in pay_ret[today].keys(): total += pay_ret[today][k] pay_ret = total else: pay_ret = 0 if all_deals: if st != -1: if st in all_deals[today]: all_deals = all_deals[today][st] else: all_deals = 0 else: total = 0 for k in all_deals[today].keys(): total += all_deals[today][k] all_deals = total else: all_deals = 0 if pay_nums: if st != -1: if st in pay_nums[today]: pay_nums = pay_nums[today][st] else: pay_nums = 0 else: total = 0 for k in pay_nums[today].keys(): total += pay_nums[today][k] pay_nums = total else: pay_nums = 0 if new_pay_nums: if st != -1: if st in new_pay_nums[today]: new_pay_nums = new_pay_nums[today][st] else: new_pay_nums = 0 else: total = 0 for k in new_pay_nums[today].keys(): total += new_pay_nums[today][k] new_pay_nums = total else: new_pay_nums = 0 if max_login_pid == {}: max_login_pid = 0 # if max_login_uid == {}: # max_login_uid = 0 return (today, create_users, login_ret, online_max, online_avg, max_login_pid, pay_ret, all_deals, pay_nums, new_pay_nums)
def NewCCountToday(time_format, searchCondition, st): global g_types today = time_to_hour(time.time(), EXT.UNIX_TIME_YMD_FORMAT) complex_count = CCount() from_database = CCountFromDatabase(today, today + EXT.NUM_UNIX_A_DAY, time_format) # 创建用户数, 登录用户数 create_users, login_ret = from_database.get_create_user() # 最大在线,平均在线 online_max, online_avg = from_database.get_max_avg(searchCondition) # 最大登录数 max_login_pid, max_login_uid = from_database.get_maxlogin() # 充值金额, 充值笔数 pay_ret, all_deals = from_database.get_pay(types=g_types, st=st) # 充值人数, 新增充值人数 pay_nums, new_pay_nums = from_database.get_pay_nums(types=g_types, st=st) print "**pay_ret, all_deals **", pay_ret, all_deals if create_users: if st != -1: if st in create_users[today]: create_users = create_users[today][st] else: create_users = 0 else: total = 0 for k in create_users[today].keys(): total += create_users[today][k] create_users = total else: create_users = 0 if login_ret: if st != -1: if st in login_ret[today]: login_ret = login_ret[today][st] else: login_ret = 0 else: total = 0 for k in login_ret[today].keys(): total += login_ret[today][k] login_ret = total else: login_ret = 0 try: online_max = online_max[today] except: online_max = 0 try: online_avg = online_avg[today] except: online_avg = 0 if pay_ret: if st != -1: if st in pay_ret[today]: pay_ret = pay_ret[today][st] else: pay_ret = 0 else: total = 0 for k in pay_ret[today].keys(): total += pay_ret[today][k] pay_ret = total else: pay_ret = 0 if all_deals: if st != -1: if st in all_deals[today]: all_deals = all_deals[today][st] else: all_deals = 0 else: total = 0 for k in all_deals[today].keys(): total += all_deals[today][k] all_deals = total else: all_deals = 0 if pay_nums: if st != -1: if st in pay_nums[today]: pay_nums = pay_nums[today][st] else: pay_nums = 0 else: total = 0 for k in pay_nums[today].keys(): total += pay_nums[today][k] pay_nums = total else: pay_nums = 0 if new_pay_nums: if st != -1: if st in new_pay_nums[today]: new_pay_nums = new_pay_nums[today][st] else: new_pay_nums = 0 else: total = 0 for k in new_pay_nums[today].keys(): total += new_pay_nums[today][k] new_pay_nums = total else: new_pay_nums = 0 if max_login_pid == {}: max_login_pid = 0 # if max_login_uid == {}: # max_login_uid = 0 return (today, create_users, login_ret, online_max, online_avg, max_login_pid, pay_ret, all_deals, pay_nums, new_pay_nums)