mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 12:59:25 +08:00
add: generate resource report script
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -276,4 +276,6 @@ blcrack/tolua/
|
||||
bin/hook/
|
||||
blcrack/patchelf/build/
|
||||
blcrack/test/
|
||||
blcrack/cracker/pb/
|
||||
blcrack/cracker/pb/
|
||||
|
||||
report/
|
||||
148
res_report.py
Normal file
148
res_report.py
Normal file
@@ -0,0 +1,148 @@
|
||||
import csv
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import glob
|
||||
import os
|
||||
from typing import *
|
||||
|
||||
|
||||
class ResourcesReport:
|
||||
class Record:
|
||||
def __init__(self, time_str, value_str):
|
||||
self.time = datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f")
|
||||
self.value = int(value_str)
|
||||
|
||||
CSV_HEADER = ["Time", "Value"]
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
self.oil_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.gem_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.coin_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.cube_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.pt_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.yellow_coin_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.purple_coin_csv_records: List[ResourcesReport.Record] = list()
|
||||
self.player_exp_csv_records: List[ResourcesReport.Record] = list()
|
||||
|
||||
def process_lines(self, lines):
|
||||
for line in lines:
|
||||
# oil
|
||||
if line.find("[OCR_OIL_LIMIT") != -1:
|
||||
continue
|
||||
if line.find("[OCR_OIL") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.oil_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# gem
|
||||
if line.find("[SHOP_GEMS") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.gem_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# coin
|
||||
if line.find("[OCR_COIN_LIMIT") != -1:
|
||||
continue
|
||||
if line.find("[OCR_COIN") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.coin_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# cube
|
||||
if line.find("[BUILD_CUBE_COUNT") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.cube_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# pt
|
||||
if line.find("[Event_PT_limit]") != -1:
|
||||
continue
|
||||
if line.find("[Event_PT]") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[1]
|
||||
self.pt_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# yellow_coin
|
||||
if line.find("[SHOP_YELLOW_COINS") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.yellow_coin_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# purple_coin
|
||||
if line.find("[SHOP_PURPLE_COINS") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2]
|
||||
self.purple_coin_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
# player_exp
|
||||
if line.find("[OCR_PLAYER_EXP") != -1:
|
||||
line_splited = line.split(" | ")
|
||||
time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2].split("/")[0]
|
||||
self.player_exp_csv_records.append(self.Record(time_str, value_str))
|
||||
|
||||
def sort_records(self):
|
||||
self.oil_csv_records.sort(key=lambda x: x.time)
|
||||
self.gem_csv_records.sort(key=lambda x: x.time)
|
||||
self.coin_csv_records.sort(key=lambda x: x.time)
|
||||
self.cube_csv_records.sort(key=lambda x: x.time)
|
||||
self.pt_csv_records.sort(key=lambda x: x.time)
|
||||
self.yellow_coin_csv_records.sort(key=lambda x: x.time)
|
||||
self.purple_coin_csv_records.sort(key=lambda x: x.time)
|
||||
self.player_exp_csv_records.sort(key=lambda x: x.time)
|
||||
|
||||
def post_process(self):
|
||||
print(f"post process")
|
||||
|
||||
self.sort_records()
|
||||
|
||||
def dump_single(self, f, l):
|
||||
with open(f, mode="w", encoding="utf-8", newline="") as fd:
|
||||
writer = csv.writer(fd)
|
||||
writer.writerow(self.CSV_HEADER)
|
||||
writer.writerows([
|
||||
[i.time.strftime("%Y-%m-%d %H:%M:%S.%f"), str(i.value)]
|
||||
for i in l
|
||||
])
|
||||
|
||||
def dump_to_file(self):
|
||||
config_report_dir = f"./report/{self.config}"
|
||||
if not os.path.exists(config_report_dir):
|
||||
os.makedirs(config_report_dir)
|
||||
|
||||
print(f"gen report to {config_report_dir}")
|
||||
|
||||
self.dump_single(f"{config_report_dir}/oil.csv", self.oil_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/gem.csv", self.gem_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/coin.csv", self.coin_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/cube.csv", self.cube_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/pt.csv", self.pt_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/yellow_coin.csv", self.yellow_coin_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/purple_coin.csv", self.purple_coin_csv_records)
|
||||
self.dump_single(f"{config_report_dir}/player_exp.csv", self.player_exp_csv_records)
|
||||
|
||||
def gen_res_report(self):
|
||||
l = glob.glob(f"./log/*_{self.config}.txt")
|
||||
|
||||
for log in l:
|
||||
print(f"process {log}")
|
||||
|
||||
with open(log, mode="r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
self.process_lines(lines)
|
||||
self.post_process()
|
||||
self.dump_to_file()
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 1:
|
||||
print("Please specify the configuration name !")
|
||||
exit(-1)
|
||||
|
||||
reporter = ResourcesReport(sys.argv[1])
|
||||
reporter.gen_res_report()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user