import json import os import xlwt def calculate_multiplier(max_score): if max_score >= 990000: return 4 elif max_score >= 980000: return 3.75 elif max_score >= 970000: return 3.5 elif max_score >= 960000: return 3.25 elif max_score >= 950000: return 3 elif max_score >= 940000: return 2.75 elif max_score >= 920000: return 2.5 elif max_score >= 900000: return 2 elif max_score >= 850000: return 1.5 elif max_score >= 800000: return 1 elif max_score >= 700000: return 0.8 elif max_score >= 600000: return 0.7 elif max_score >= 500000: return 0.6 elif max_score >= 400000: return 0.5 elif max_score >= 300000: return 0.4 elif max_score >= 200000: return 0.3 elif max_score >= 100000: return 0.2 elif max_score >= 1: return 0.1 else: return 0 def grade_to_name(grade): grade_names = { 1: "NORMAL", 2: "HARD", 3: "EXPERT", 4: "INFERNO" } return grade_names.get(grade, "Unknown Grade") def get_music_name(levels_dict, music_id): music_entry = levels_dict.get(music_id, {}) return music_entry.get("name", "Unknown") def json_template(music, diff, rate, max, level, music_id): template = { 'id': music_id, 'music': music, 'difficulty': diff, 'rate': level, 'max_score': max, 'level': rate } return template def output_json_template(b50, alt15, total): template = { 'b50_total': total, 'b50': b50, 'alt15': alt15 } return template def output_xls(b50, alt15, t): xls = xlwt.Workbook(encoding='utf-8') work_sheet = xls.add_sheet('Sheet1') work_sheet.col(1).width = 256*30 work_sheet.write(0, 0, "Best50") work_sheet.write(0, 1, "注意:该表格仅计算单曲rate最高50首,并采用了新14定数表作为统计资料") work_sheet.write(2, 0, "ID") work_sheet.write(2, 1, '歌曲') work_sheet.write(2, 2, '难度') work_sheet.write(2, 3, '单曲rate') work_sheet.write(2, 4, '最高分数') work_sheet.write(2, 5, '定数') work_sheet.write(1, 4, 'Rate:') count = 3 style_ex = xlwt.XFStyle() pattern = xlwt.Pattern() pattern.pattern = xlwt.Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 10 style_ex.pattern = pattern style_inf = xlwt.XFStyle() pattern1 = xlwt.Pattern() pattern1.pattern = xlwt.Pattern.SOLID_PATTERN pattern1.pattern_fore_colour = 20 style_inf.pattern = pattern1 for i in b50: work_sheet.write(count, 0, i['id']) work_sheet.write(count, 1, i['music']) if i['difficulty'] == 'EXPERT': work_sheet.write(count, 2, i['difficulty'], style=style_ex) elif i['difficulty'] == 'INFERNO': work_sheet.write(count, 2, i['difficulty'], style=style_inf) work_sheet.write(count, 3, i['rate']) work_sheet.write(count, 4, i['max_score']) work_sheet.write(count, 5, i['level']) count = count + 1 work_sheet.write(count, 0, '候补未鸟加歌曲') for i in alt15: if i['max_score'] < 990000: count = count + 1 work_sheet.write(count, 0, i['id']) work_sheet.write(count, 1, i['music']) if i['difficulty'] == 'EXPERT': work_sheet.write(count, 2, i['difficulty'], style=style_ex) elif i['difficulty'] == 'INFERNO': work_sheet.write(count, 2, i['difficulty'], style=style_inf) work_sheet.write(count, 3, i['rate']) work_sheet.write(count, 4, i['max_score']) work_sheet.write(count, 5, i['level']) work_sheet.write(1, 5, xlwt.Formula('SUM(D4:D53)'), style=xlwt.easyxf('font: bold on; pattern: pattern solid, fore_colour ice_blue')) xls.save('output.xls') # print("//////////////////////////////////////////////////////////////////////") # print("华卡音舞 Ver.3 3.50.00") # print("全曲 Rate + Best 50 计算器") # print("版本号 V0.05(2)") # print("由WOAOL项目组制作") # print("WACCA NEVER END") # print("请注意,该版本计算器不区分B15和B35,仅计算全曲的Best50成绩,并使用V4的14定数表") # print("该版本计算器为子版本,正常计算国服B50请不要用此计算器及其配套Table_output.json") # print("//////////////////////////////////////////////////////////////////////") if not os.path.isfile('Table_output_V4.json'): print("") print("错误:找不到Table_output_V4.json。") print("请将Rate_SDJE.py、Table_output_V4.json、playLog.json这三个文件放在同一目录下。") print("") exit() if not os.path.isfile('playlog_b50.json'): print("") print("错误:找不到playlog_b50.json.json。") print("请将Rate_SDJE.py、Table_output_V4.json、playlog_b50.json这三个文件放在同一目录下。") print("") exit() with open('playlog_b50.json', 'r', encoding='utf-8') as file: play_logs = json.load(file) with open('Table_output_V4.json', 'r', encoding='utf-8') as file: table_output = json.load(file) levels_dict = {} for entry in table_output: music_id = entry["music_id"] levels_dict[music_id] = { "name": entry["music_name"], "levels": { 1: entry["level_nm"], 2: entry["level_hd"], 3: entry["level_ex"], 4: entry["level_in"] }, "start_time": entry["start_time"], "start_inf": entry["start_inf"] } best_50 = [] music_rates = {} for log in play_logs: music_id = log['music_id'] music_grade = log['music_grade'] max_score = log['max_score'] music_name = get_music_name(levels_dict, music_id) level_data = levels_dict.get(music_id, {}).get("levels", {}) level = level_data.get(music_grade) if level is None: continue multiplier = calculate_multiplier(max_score) rate = multiplier * level grade_name = grade_to_name(music_grade) start_time = levels_dict[music_id]["start_time"] start_inf = levels_dict[music_id]["start_inf"] if music_name not in music_rates: music_rates[music_name] = [] music_rates[music_name].append((grade_name, rate, max_score, music_id, music_grade)) best_50.append((music_name, grade_name, rate, max_score, level, music_id)) # for music_name, grades_rates in music_rates.items(): # print(f"\n{music_name}") # for grade_name, rate, max_score, music_id, music_grade in grades_rates: # if rate > 0: # level = levels_dict[music_id]["levels"][music_grade] # print(f" 难度: {grade_name} 定数: {level:.1f} 分数: {max_score} Rate: {rate:.3f}") best_50_sorted = sorted(best_50, key=lambda x: x[2], reverse=True)[0:50] best_50_alternate = sorted(best_50, key=lambda x: x[2], reverse=True)[50:150] best_50_total = sum(rate for _, _, rate, _, _, _ in best_50_sorted) best_50_first_rate = best_50_sorted[0][2] best_50_last_rate = best_50_sorted[49][2] b50_json = [] alt15_json = [] for music_name, grade_name, rate, max_score, level, music_id in best_50_sorted: # print(f"{music_name}\n 难度: {grade_name} 定数: {level:.1f} 分数: {max_score} Rate: {rate:.3f}\n") lv = f'{level:.1f}' lv = float(lv) rt = f'{rate:.3f}' rt = float(rt) b50_json.append(json_template(music_name, grade_name, lv, max_score, rt, music_id)) for music_name, grade_name, rate, max_score, level, music_id in best_50_alternate: # print(f"{music_name}\n 难度: {grade_name} 定数: {level:.1f} 分数: {max_score} Rate: {rate:.3f}\n") lv = f'{level:.1f}' lv = float(lv) rt = f'{rate:.3f}' rt = float(rt) alt15_json.append(json_template(music_name, grade_name, lv, max_score, rt, music_id)) total = f'{best_50_total:.3f}' total = float(total) data = output_json_template(b50_json, alt15_json, total) output_xls(b50_json, alt15_json, total) with open('b50_result.json', 'w+', encoding='utf-8') as json_file: json.dump(data, json_file, ensure_ascii=False, indent=2) print('Done') # print(f"\nBest 35 单曲最高: {best_50_first_rate:.3f}") # print(f"\nBest 35 单曲最低: {best_50_last_rate:.3f}") # # print(f"\nBest 50 合计: {best_50_total:.3f}")