implement new vs_info saving method

This commit is contained in:
UncleJim 2024-01-06 14:01:14 +00:00
parent 39031757f4
commit a42993aca7

View File

@ -592,49 +592,79 @@ class IDACSeason2(IDACBase):
vs_info = self.data.item.get_vs_infos_by_mode(user_id, battle_mode) vs_info = self.data.item.get_vs_infos_by_mode(user_id, battle_mode)
if vs_info is not None: if vs_info is not None:
vs_info["vs_cnt"] += 1 vs_info = vs_info._asdict()
vs_info["vs_win"] = vs_info["vs_win"] + data.get("win_flg")
vs_info["invalid"] = vs_info["invalid"] + data.get("result") 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_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["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["lose_now"] += 1 if data.get("win_flg") == 0 else 0
vs_info["break_count"] += data.get("break_count") vs_info["break_count"] += data.get("break_count")
vs_info["break_penalty_flag"] = data.get("break_penalty_flag") 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 course_not_exists = True
for course in vs_info["vsinfo_course_data"]:
if course["course_id"] == data.get("course_id"): if vs_courses_info is not None:
course["vs_cnt"] += 1 for course in vs_courses_info:
course["vs_win"] += data.get("win_flg") course = course._asdict()
course_not_exists = False 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: if course_not_exists:
course = {} course = {}
course["course_id"] = data.get("course_id") course["course_id"] = data.get("course_id")
course["vs_cnt"] = 1 course["vs_cnt"] = 1
course["vs_win"] = data.get("win_flg") 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) vs_info["vsinfo_course_data"].append(course)
self.data.item.put_vs_course_info(user_id, battle_mode, course)
else: else:
vs_info = { vs_info = {
"battle_mode": battle_mode, "battle_mode": battle_mode,
"vs_cnt": 1, #"vs_cnt": 1,
"vs_win": data.get("win_flg"), #"vs_win": data.get("win_flg"),
"invalid": data.get("result"), "invalid": data.get("result"),
"str": data.get("win_flg"), "str": data.get("win_flg"),
"str_now": data.get("win_flg"), "str_now": data.get("win_flg"),
"lose_now": 1 if data.get("win_flg") == 0 else 0, "lose_now": 1 if data.get("win_flg") == 0 else 0,
"break_count": data.get("break_count"), "break_count": data.get("break_count"),
"break_penalty_flag": data.get("break_penalty_flag"), "break_penalty_flag": data.get("break_penalty_flag"),
"vsinfo_course_data": [ #"vsinfo_course_data": [
{ # {
"course_id": data.get("course_id"), # "course_id": data.get("course_id"),
"vs_cnt": 1, # "vs_cnt": 1,
"vs_win": data.get("win_flg") # "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["vs_history"] = data.get("vs_history")
vs_info["course_select_priority"] = data.get("course_select_priority") vs_info["course_select_priority"] = data.get("course_select_priority")
@ -765,21 +795,41 @@ class IDACSeason2(IDACBase):
# get the users vs info data # get the users vs info data
vs_info_data = [] vs_info_data = []
vs_info = self.data.item.get_vs_infos(user_id) vs_info = self.data.item.get_vs_infos(user_id)
for vs in vs_info: if vs_info is not None:
vs_info_data.append( for vs in vs_info:
{ vs = vs._asdict()
"battle_mode": vs_info["battle_mode"], vs_courses_info = self.data.item.get_vs_course_info_by_mode(user_id, vs["battle_mode"])
"vs_cnt": vs_info["vs_cnt"], total_vs_win = 0
"vs_win": vs_info["vs_win"], total_vs_cnt = 0
"invalid": vs_info["invalid"], courses_info = []
"str": vs_info["str"], if vs_courses_info is not None:
"str_now": vs_info["str_now"], for course in vs_courses_info:
"lose_now": vs_info["lose_now"], tmp = course._asdict()
"vs_history": 0, del tmp["id"]
"course_select_priority": 0, del tmp["user"]
"vsinfo_course_data": vs_info["vsinfo_course_data"], 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 # get the user's car
cars = self.data.item.get_cars(self.version, user_id, only_pickup=True) cars = self.data.item.get_cars(self.version, user_id, only_pickup=True)