From a42993aca746bdee83f0ca192e0db8a6495f6590 Mon Sep 17 00:00:00 2001 From: UncleJim Date: Sat, 6 Jan 2024 14:01:14 +0000 Subject: [PATCH] implement new vs_info saving method --- titles/idac/season2.py | 118 +++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 34 deletions(-) diff --git a/titles/idac/season2.py b/titles/idac/season2.py index 4f780e5..6f4e402 100644 --- a/titles/idac/season2.py +++ b/titles/idac/season2.py @@ -592,49 +592,79 @@ class IDACSeason2(IDACBase): vs_info = self.data.item.get_vs_infos_by_mode(user_id, battle_mode) if vs_info is not None: - vs_info["vs_cnt"] += 1 - vs_info["vs_win"] = vs_info["vs_win"] + data.get("win_flg") + vs_info = vs_info._asdict() vs_info["invalid"] = vs_info["invalid"] + data.get("result") vs_info["str_now"] = vs_info["str_now"] + data.get("win_flg") if data.get("win_flg") == 1 else 0 vs_info["str"] = vs_info["str"] if vs_info["str"] > vs_info["str_now"] else vs_info["str_now"] vs_info["lose_now"] += 1 if data.get("win_flg") == 0 else 0 vs_info["break_count"] += data.get("break_count") vs_info["break_penalty_flag"] = data.get("break_penalty_flag") - + + self.data.item.put_vs_info(user_id, battle_mode, vs_info) + + vs_info["vs_cnt"] = 0 + vs_info["vs_win"] = 0 + vs_info["vsinfo_course_data"] = [] + + vs_courses_info = self.data.item.get_vs_course_info_by_mode(user_id, battle_mode) course_not_exists = True - for course in vs_info["vsinfo_course_data"]: - if course["course_id"] == data.get("course_id"): - course["vs_cnt"] += 1 - course["vs_win"] += data.get("win_flg") - course_not_exists = False - + + if vs_courses_info is not None: + for course in vs_courses_info: + course = course._asdict() + if course["course_id"] == data.get("course_id"): + course["vs_cnt"] += 1 + course["vs_win"] += data.get("win_flg") + vs_info["vs_cnt"] += course["vs_cnt"] + vs_info["vs_win"] += course["vs_win"] + self.data.item.put_vs_course_info(user_id, battle_mode, course) + course_not_exists = False + else: + vs_info["vs_cnt"] += course["vs_cnt"] + vs_info["vs_win"] += course["vs_win"] + vs_info["vsinfo_course_data"].append(course) + if course_not_exists: course = {} course["course_id"] = data.get("course_id") course["vs_cnt"] = 1 course["vs_win"] = data.get("win_flg") + vs_info["vs_cnt"] += course["vs_cnt"] + vs_info["vs_win"] += course["vs_win"] vs_info["vsinfo_course_data"].append(course) + self.data.item.put_vs_course_info(user_id, battle_mode, course) else: vs_info = { "battle_mode": battle_mode, - "vs_cnt": 1, - "vs_win": data.get("win_flg"), + #"vs_cnt": 1, + #"vs_win": data.get("win_flg"), "invalid": data.get("result"), "str": data.get("win_flg"), "str_now": data.get("win_flg"), "lose_now": 1 if data.get("win_flg") == 0 else 0, "break_count": data.get("break_count"), "break_penalty_flag": data.get("break_penalty_flag"), - "vsinfo_course_data": [ - { - "course_id": data.get("course_id"), - "vs_cnt": 1, - "vs_win": data.get("win_flg") - } - ], + #"vsinfo_course_data": [ + # { + # "course_id": data.get("course_id"), + # "vs_cnt": 1, + # "vs_win": data.get("win_flg") + # } + #], } + self.data.item.put_vs_info(user_id, battle_mode, vs_info) - self.data.item.put_vs_info(user_id, battle_mode, vs_info) + course_info = { + "course_id": data.get("course_id"), + "vs_cnt": 1, + "vs_win": data.get("win_flg") + } + self.data.item.put_vs_course_info(user_id, battle_mode, course_info) + + vs_info["vs_cnt"] = 1 + vs_info["vs_win"] = data.get("win_flg") + vs_info["vsinfo_course_data"] = [] + vs_info["vsinfo_course_data"].append(course_info) vs_info["vs_history"] = data.get("vs_history") vs_info["course_select_priority"] = data.get("course_select_priority") @@ -765,21 +795,41 @@ class IDACSeason2(IDACBase): # get the users vs info data vs_info_data = [] vs_info = self.data.item.get_vs_infos(user_id) - for vs in vs_info: - vs_info_data.append( - { - "battle_mode": vs_info["battle_mode"], - "vs_cnt": vs_info["vs_cnt"], - "vs_win": vs_info["vs_win"], - "invalid": vs_info["invalid"], - "str": vs_info["str"], - "str_now": vs_info["str_now"], - "lose_now": vs_info["lose_now"], - "vs_history": 0, - "course_select_priority": 0, - "vsinfo_course_data": vs_info["vsinfo_course_data"], - } - ) + if vs_info is not None: + for vs in vs_info: + vs = vs._asdict() + vs_courses_info = self.data.item.get_vs_course_info_by_mode(user_id, vs["battle_mode"]) + total_vs_win = 0 + total_vs_cnt = 0 + courses_info = [] + if vs_courses_info is not None: + for course in vs_courses_info: + tmp = course._asdict() + del tmp["id"] + del tmp["user"] + del tmp["battle_mode"] + + total_vs_win += tmp["vs_win"] + total_vs_cnt += tmp["vs_cnt"] + + courses_info.append(tmp) + + + vs_info_data.append( + { + "battle_mode": vs["battle_mode"], + "vs_cnt": total_vs_cnt, + "vs_win": total_vs_win, + "invalid": vs["invalid"], + "str": vs["str"], + "str_now": vs["str_now"], + "lose_now": vs["lose_now"], + "vs_history": 0, + "course_select_priority": 0, + "vsinfo_course_data": courses_info, + } + ) + # get the user's car cars = self.data.item.get_cars(self.version, user_id, only_pickup=True)