|
print "正在读取VIP用户数据(%s)..." %one_day db_conn = MySQLdb.connect(user=optmap['dbuser'], passwd=optmap['dbpass'], host=optmap['dbhost'], port=optmap['dbport'], db=optmap['dbname'])
db_cursor = db_conn.cursor()
temp_vip_active_user_num_file_name = '/tmp/vipactiveusernumtemp.txt'
command = "cat /dev/null > %s" %(temp_vip_active_user_num_file_name)
os.system(command)
if re.search('haoren', optmap['logdir']):
print '外网环境'
log_dir_name_list = get_files(optmap['logdir'], one_day[2:])
for log_dir_name_item in log_dir_name_list:
log_dir_full_path = optmap['logdir']+log_dir_name_item+'/'
log_file_name_list = get_files(log_dir_full_path, optmap['logpattern'] + one_day[2:])
for log_file_name_item in log_file_name_list:
print log_file_name_item
command = "cat %s%s |awk '/用户登录/' |awk '/vip状态/' >> %s" % (log_dir_full_path, log_file_name_item, temp_vip_active_user_num_file_name)
os.system(command)
else:
print '内网环境'
log_file_name_list = get_files(optmap['logdir'], optmap['logpattern'] + one_day[2:])
for log_file_name_item in log_file_name_list:
command = "cat %s%s |awk '/用户登录/' |awk '/vip状态/' >> %s" % (optmap['logdir'], log_file_name_item, temp_vip_active_user_num_file_name)
os.system(command)
command = "cat %s |wc -l" %temp_vip_active_user_num_file_name
os.system(command)
#一天当中用户可能从月会员降级到周会员,造成不同会员状态的同一帐号统计两次,所以总会员!=年会员+月会员+周会员)
#不同状态的会员用同一计算机登录,所以总mac/ip!=年mac/ip+月mac/ip+周mac/ip
total_account_map = {}
total_mac_map = {}
total_ip_map = {}
before_account_map = {}
before_mac_map = {}
before_ip_map = {}
account_map = {1:{}, 2:{}, 3:{}, 11:{}, 12:{}, 13:{}}
mac_map = {1:{}, 2:{}, 3:{}, 11:{}, 12:{}, 13:{}}
ip_map = {1:{}, 2:{}, 3:{}, 11:{}, 12:{}, 13:{}}
temp_vip_active_user_num_file = open(temp_vip_active_user_num_file_name)
for one_line in temp_vip_active_user_num_file.readlines():
match = re.search("^(\S+) SS\[\d+\] TRACE: 用户登录:imid:(\d+),mac地址:(\d+),ip地址:(\d+),vip状态:(\d+),登录时间:(\d+)(\S+)", one_line)
if match:
if string.atoi(match.group(5)) in (1, 2, 3):
total_account_map[string.atoi(match.group(2))] = string.atoi(match.group(5))
total_mac_map[string.atoi(match.group(3))] = string.atoi(match.group(5))
total_ip_map[string.atoi(match.group(4))] = string.atoi(match.group(5))
elif string.atoi(match.group(5)) in (11, 12, 13):
before_account_map[string.atoi(match.group(2))] = string.atoi(match.group(5))
before_mac_map[string.atoi(match.group(3))] = string.atoi(match.group(5))
before_ip_map[string.atoi(match.group(4))] = string.atoi(match.group(5))
account_map[string.atoi(match.group(5))][string.atoi(match.group(2))] = string.atoi(match.group(3))
mac_map[string.atoi(match.group(5))][string.atoi(match.group(3))] = string.atoi(match.group(2))
ip_map[string.atoi(match.group(5))][string.atoi(match.group(4))] = string.atoi(match.group(2))
temp_vip_active_user_num_file.close()
dword_time = time.mktime(time.strptime(one_day, '%Y%m%d'))
db_conn.query("use %s" %optmap['dbname'])
sql = "delete from VIPACTIVEUSERNUM where active_time='%d'" %dword_time
print sql
db_conn.query(sql)
sql = "insert into VIPACTIVEUSERNUM (active_time) values('%d')" %(dword_time)
print sql
db_conn.query(sql)
sql = "update VIPACTIVEUSERNUM set year_account_num=%d, year_mac_num=%d, year_ip_num=%d, month_account_num=%d, month_mac_num=%d, month_ip_num=%d, week_account_num=%d, week_mac_num=%d, week_ip_num=%d, total_mac_num=%d, total_ip_num=%d, before_account_num=%d, before_mac_num=%d, before_ip_num=%d where active_time='%d'" %(len(account_map[3]), len(mac_map[3]), len(ip_map[3]), len(account_map[2]), len(mac_map[2]), len(ip_map[2]), len(account_map[1]), len(mac_map[1]), len(ip_map[1]), len(total_mac_map), len(total_ip_map), len(before_account_map), len(before_mac_map), len(before_ip_map), dword_time)
print sql
db_conn.query(sql)
db_conn.commit()
db_cursor.close()
db_conn.close() |
|