diff --git a/res_report.py b/res_report.py index f8fa1b10b..f722d943a 100644 --- a/res_report.py +++ b/res_report.py @@ -60,82 +60,95 @@ class ResourcesReport: 'action_point' :self.action_point_csv_records, } - def process_lines(self, lines): - lines = iter(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)) + def process_file(self, file): + print(f"Line process - {file} - {os.stat(file).st_size} Bytes") - # 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)) - - # action_points - if line.find(" | INFO | Action points:") != -1: - line_splited = line.split(" | ") - time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2] - value_str = value_str.split("(")[1].split(")")[0] - self.action_point_csv_records.append(self.Record(time_str, value_str)) - - if line.find("Choose urgent commission") != -1: - line = next(lines,"EoL") - if "gem" in line: - if "Duration: 2:00:00" in line: - self.total_gem_expected_value += 5.5 - if "Duration: 4:00:00" in line: - self.total_gem_expected_value += 12 - if "Duration: 8:00:00" in line: - self.total_gem_expected_value += 22.5 + with open(file, mode="r", encoding="utf-8") as f: + lines = f.readlines() + for i in range(len(lines)): + line = lines[i] + try: + # 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], str(self.total_gem_expected_value) - self.gem_expected_csv_records.append(self.Record(time_str, value_str)) + 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)) + + # action_points + if line.find(" | INFO | Action points:") != -1: + line_splited = line.split(" | ") + time_str, value_str = line_splited[0], line_splited[2].rstrip().split(" ")[2] + value_str = value_str.split("(")[1].split(")")[0] + self.action_point_csv_records.append(self.Record(time_str, value_str)) + + if line.find("Choose urgent commission") != -1: + next_line = lines[i + 1] + if "gem" in next_line: + if "Duration: 2:00:00" in next_line: + self.total_gem_expected_value += 5.5 + if "Duration: 4:00:00" in next_line: + self.total_gem_expected_value += 12 + if "Duration: 8:00:00" in next_line: + self.total_gem_expected_value += 22.5 + line_splited = next_line.split(" | ") + time_str, value_str = line_splited[0], str(self.total_gem_expected_value) + self.gem_expected_csv_records.append(self.Record(time_str, value_str)) + except Exception as e: + throw_err = self.config.get("error", False) + if throw_err: + raise e + else: + err_line = line.replace("\n", "") + print(f"ERROR - line {i + 1}, content: {err_line}") + def sort_records(self): for name,records in self.records_dict.items(): @@ -392,11 +405,8 @@ class ResourcesReport: l = glob.glob(f"./log/*_{self.config['config']}.txt") for log in l: - print(f"Line process - {log} - {os.stat(log).st_size} Bytes") + self.process_file(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() @@ -435,6 +445,10 @@ def main(): conf["resample_rate"] = arg _ += 1 continue + if arg == "--error": + conf["error"] = True + _ += 1 + continue if conf['config'] == "": conf["config"] = arg _ += 1