python分析日志_python 分析游戏日志

本文介绍了使用Python分析游戏日志的过程,以解决玩家签到未收到奖励的问题。通过解析 depositcheckin.log 和 depositlose.log 文件,匹配正则表达式获取关键信息,统计玩家的签到和漏签情况,找出错误的漏签日期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

日志

国庆前上线了签到送奖励类新功能,收假后收到反馈有几个玩家为实际签到了却没有收到奖励,遂对游戏记录进行分析。使用的是 python ,大致记录下。

由日至文件分析筛选出两种类型的日志

其一是 签到记录,玩家实际签到的信息,需要的信息有,日期,玩家id,文件 depositcheckin.log

[2018-09-30 23:52:55.82 INF *agent*] @server/agent/camps/deposit.lua:140::[pid:1001dbd,uid:Aaa294159] deposit checkin {open_ts=1538321892,last=1538322775,lose={},with_today=true,status=1,days=1,has_mail=true}

[2018-09-30 23:52:59.17 INF *agent*] @server/agent/camps/deposit.lua:140::[pid:1001dc5,uid:Aaa294624] deposit checkin {open_ts=1538321950,last=1538322779,lose={},with_today=true,status=1,days=1,has_mail=true}

其二是查询记录,包括玩家漏签的信息,需要的信息有,玩家id,漏签日期 lose 后的数组既是,文件 depositlose.log

[2018-10-03 01:07:45.95 INF *agent*] @server/agent/main.lua:336::[pid:1004d8c,uid:Naa126591] client response: query_deposit, ret:{open_ts=1538293842,lose={"2018-10-02"},with_today=false,status=1,days=364}

[2018-10-03 01:08:23.31 INF *agent*] @server/agent/main.lua:336::[pid:1004d8c,uid:Naa126591] client response: query_deposit, ret:{open_ts=1538293842,lose={"2018-10-02"},with_today=false,status=1,days=364}

分析代码

打开文件读取每行日志

正则表达式匹配出需要的信息

统计每个玩家漏签,签到,并对比得到出错的漏签日期

代码还是很暴力哈

import re

lose,checkin = {},{}

def scan_lose():

f = open("./depositlose.log","r")

for l in f.readlines():

m = re.match(".*uid:([A-Z]+[a-z]+[0-9]+)]",l)

if not m :continue

uid = m.group(1)

if uid not in lose:

lose[uid] = []

m = re.match(".*lose={(.*)}.*}",l)

if not m :continue

ret = m.group(1)

for date in ret.split(","):

if not date or date=='""':continue

if date[1:-1] not in lose[uid]:

lose[uid].append(date[1:-1])

f.close()

def scan_checkin():

f = open("./depositcheckin.log","r")

for l in f.readlines():

m = re.match(".*uid:([A-Z]+[a-z]+[0-9]+)]",l)

if not m :continue

uid = m.group(1)

if uid not in checkin:

checkin[uid] = []

date = l[1:11]

if date not in checkin[uid]:

checkin[uid].append(date)

f.close()

def analyse():

for uid,it in lose.items():

if not it : continue

fake = []

ck = checkin.get(uid,[])

for date in it:

if date in ck and date not in fake:

fake.append(date)

if not fake:continue

print(uid,fake,len(fake))

def main():

scan_lose()

scan_checkin()

analyse()

main()

后续

虽然有反馈的玩家仅有几个,统计出来有 70 多个出错的玩家,罪过罪过!! 各个玩家漏掉的天数 1 2 3 4 天不等,旧有的补发奖励的借口,只能单次给一个人发送,遂改为可发送多人,以便使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值