forked from Dniel97/artemis
idac: updated scripts + bugfixes, BACKUP DATABASE!
This commit is contained in:
parent
9ee58cd444
commit
7639c2ef74
@ -1,5 +1,7 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- WARNING: This script is NOT idempotent! MAKE A BACKUP BEFORE RUNNING THIS SCRIPT!
|
||||
|
||||
-- Drop UK idac_user_vs_info_uk
|
||||
ALTER TABLE idac_user_vs_info
|
||||
DROP FOREIGN KEY idac_user_vs_info_ibfk_1,
|
||||
@ -30,19 +32,22 @@ ADD COLUMN select_course_id INT,
|
||||
ADD COLUMN select_course_day INT,
|
||||
ADD COLUMN select_course_random INT,
|
||||
ADD COLUMN matching_success_sec INT,
|
||||
ADD COLUMN boost_flag INT,
|
||||
ADD COLUMN vs_history INT;
|
||||
ADD COLUMN boost_flag INT;
|
||||
|
||||
-- Delete the data from the original table where group_key is NULL
|
||||
DELETE FROM idac_user_vs_info
|
||||
WHERE group_key IS NULL;
|
||||
|
||||
-- Insert data back to the original table from idac_user_vs_course_info
|
||||
INSERT INTO idac_user_vs_info (user, group_key, win_flg, style_car_id, course_id, course_day, players_num, winning, advantage_1, advantage_2, advantage_3, advantage_4, select_course_id, select_course_day, select_course_random, matching_success_sec, boost_flag, vs_history, break_count, break_penalty_flag)
|
||||
SELECT user, CONCAT(FLOOR(RAND()*(99999999999999-10000000000000+1)+10000000000000), 'A69E01A8888'), 0, 0, course_id, 0, 0, vs_cnt, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
FROM idac_user_vs_course_info;
|
||||
|
||||
-- Add back the constraints and indexes to the original table
|
||||
ALTER TABLE idac_user_vs_info
|
||||
ADD CONSTRAINT idac_user_vs_info_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
ADD UNIQUE KEY idac_user_vs_info_uk (user, group_key);
|
||||
|
||||
-- Insert data back to the original table from idac_user_vs_course_info
|
||||
INSERT INTO idac_user_vs_info (user, group_key, win_flg, style_car_id, course_id, course_day, players_num, winning, advantage_1, advantage_2, advantage_3, advantage_4, select_course_id, select_course_day, select_course_random, matching_success_sec, boost_flag, vs_history, break_count, break_penalty_flag)
|
||||
SELECT user, CONCAT(DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), 'A69E01A8888'), 0, 0, course_id, 0, 0, vs_cnt, 0, 0, 0, 0, 0, 0, 0, 0, 0, vs_win, 0, 0
|
||||
FROM idac_user_vs_course_info;
|
||||
|
||||
-- Drop the new table idac_user_vs_course_info
|
||||
DROP TABLE IF EXISTS idac_user_vs_course_info;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- WARNING: This script is NOT idempotent! MAKE A BACKUP BEFORE RUNNING THIS SCRIPT!
|
||||
|
||||
-- Create the new table idac_user_vs_course_info
|
||||
CREATE TABLE idac_user_vs_course_info (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
@ -41,7 +43,6 @@ DROP COLUMN select_course_day,
|
||||
DROP COLUMN select_course_random,
|
||||
DROP COLUMN matching_success_sec,
|
||||
DROP COLUMN boost_flag,
|
||||
DROP COLUMN vs_history,
|
||||
|
||||
ADD COLUMN battle_mode TINYINT UNSIGNED DEFAULT 1 NOT NULL AFTER user,
|
||||
ADD COLUMN invalid INT DEFAULT 0,
|
||||
@ -49,6 +50,19 @@ ADD COLUMN str INT DEFAULT 0,
|
||||
ADD COLUMN str_now INT DEFAULT 0,
|
||||
ADD COLUMN lose_now INT DEFAULT 0;
|
||||
|
||||
-- Create a temporary table to store the records you want to keep
|
||||
CREATE TEMPORARY TABLE temp_table AS
|
||||
SELECT MIN(id) AS min_id
|
||||
FROM idac_user_vs_info
|
||||
GROUP BY battle_mode, user;
|
||||
|
||||
-- Delete records from the original table based on the temporary table
|
||||
DELETE FROM idac_user_vs_info
|
||||
WHERE id NOT IN (SELECT min_id FROM temp_table);
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_table;
|
||||
|
||||
-- Add UK idac_user_vs_info_uk
|
||||
ALTER TABLE idac_user_vs_info
|
||||
ADD CONSTRAINT idac_user_vs_info_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
|
@ -229,6 +229,7 @@ vs_info = Table(
|
||||
Column("str", Integer),
|
||||
Column("str_now", Integer),
|
||||
Column("lose_now", Integer),
|
||||
Column("vs_history", Integer),
|
||||
Column("break_count", Integer),
|
||||
Column("break_penalty_flag", Boolean),
|
||||
UniqueConstraint("user", "battle_mode", name="idac_user_vs_info_uk"),
|
||||
@ -807,9 +808,9 @@ class IDACItemData(BaseData):
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
#This method returns a list of course_info
|
||||
# This method returns a list of course_info
|
||||
def get_vs_course_infos_by_mode(self, aime_id: int, battle_mode: int) -> Optional[List[Row]]:
|
||||
sql = select(vs_course_info).where(vs_info.c.user == aime_id, vs_info.c.battle_mode == battle_mode)
|
||||
sql = select(vs_course_info).where(vs_course_info.c.user == aime_id, vs_course_info.c.battle_mode == battle_mode)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
@ -600,6 +600,7 @@ class IDACSeason2(IDACBase):
|
||||
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["vs_history"] = data.get("vs_history")
|
||||
vs_info["break_count"] += data.get("break_count")
|
||||
vs_info["break_penalty_flag"] = data.get("break_penalty_flag")
|
||||
|
||||
@ -642,21 +643,22 @@ class IDACSeason2(IDACBase):
|
||||
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,
|
||||
"vs_history": data.get("vs_history"),
|
||||
"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)
|
||||
|
||||
@ -672,7 +674,6 @@ class IDACSeason2(IDACBase):
|
||||
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")
|
||||
return vs_info
|
||||
|
||||
@ -804,12 +805,12 @@ class IDACSeason2(IDACBase):
|
||||
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"])
|
||||
vs_courses_infos = self.data.item.get_vs_course_infos_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:
|
||||
if vs_courses_infos is not None:
|
||||
for course in vs_courses_infos:
|
||||
tmp = course._asdict()
|
||||
del tmp["id"]
|
||||
del tmp["user"]
|
||||
@ -830,8 +831,10 @@ class IDACSeason2(IDACBase):
|
||||
"str": vs["str"],
|
||||
"str_now": vs["str_now"],
|
||||
"lose_now": vs["lose_now"],
|
||||
"vs_history": 0,
|
||||
"vs_history": vs["vs_history"],
|
||||
"course_select_priority": 0,
|
||||
"break_count": vs["break_count"],
|
||||
"break_penalty_flag": vs["break_penalty_flag"],
|
||||
"vsinfo_course_data": courses_info,
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user