IDAC: time trial should display car time now

This commit is contained in:
Dniel97 2023-11-06 18:11:30 +01:00
parent 1224baeade
commit acac2c4670
Signed by untrusted user: Dniel97
GPG Key ID: 6180B3C768FB2E08
3 changed files with 181 additions and 287 deletions

View File

@ -7,10 +7,10 @@ from titles.idac.database import IDACData
class IDACBase: class IDACBase:
def __init__(self, cfg: CoreConfig, game_cfg: IDACConfig) -> None: def __init__(self, core_cfg: CoreConfig, game_cfg: IDACConfig) -> None:
self.core_cfg = cfg self.core_cfg = core_cfg
self.game_config = game_cfg self.game_config = game_cfg
self.game = IDACConstants.GAME_CODE self.game = IDACConstants.GAME_CODE
self.version = IDACConstants.VER_IDAC_SEASON_1 self.version = IDACConstants.VER_IDAC_SEASON_1
self.data = IDACData(cfg) self.data = IDACData(core_cfg)
self.logger = logging.getLogger("idac") self.logger = logging.getLogger("idac")

View File

@ -497,7 +497,7 @@ class IDACItemData(BaseData):
return result.fetchall() return result.fetchall()
def get_time_trial_best_cars_by_course( def get_time_trial_best_cars_by_course(
self, version: int, aime_id: int, course_id: int self, version: int, course_id: int, aime_id: Optional[int] = None
) -> Optional[List[Row]]: ) -> Optional[List[Row]]:
subquery = ( subquery = (
select( select(
@ -508,14 +508,16 @@ class IDACItemData(BaseData):
.where( .where(
and_( and_(
trial.c.version == version, trial.c.version == version,
trial.c.user == aime_id,
trial.c.course_id == course_id, trial.c.course_id == course_id,
) )
) )
.group_by(trial.c.style_car_id)
.subquery()
) )
if aime_id is not None:
subquery = subquery.where(trial.c.user == aime_id)
subquery = subquery.group_by(trial.c.style_car_id).subquery()
sql = select(trial).where( sql = select(trial).where(
and_( and_(
trial.c.version == subquery.c.version, trial.c.version == subquery.c.version,

View File

@ -141,249 +141,83 @@ class IDACSeason2(IDACBase):
"domain_echo2": f"{self.core_cfg.title.hostname}:{self.game_config.server.echo2}", "domain_echo2": f"{self.core_cfg.title.hostname}:{self.game_config.server.echo2}",
"domain_ping": f"{self.core_cfg.title.hostname}", "domain_ping": f"{self.core_cfg.title.hostname}",
"battle_gift_event_master": [], "battle_gift_event_master": [],
"round_event":[ "round_event": [
{ {
"round_event_id":30, "round_event_id": 30,
"round_event_nm":"ARTEMiS Event", "round_event_nm": f"{self.core_cfg.server.name} Event",
"start_dt":int( "start_dt": int(
datetime.strptime("2023-01-01", "%Y-%m-%d").timestamp() datetime.strptime("2023-01-01", "%Y-%m-%d").timestamp()
), ),
"end_dt":int( "end_dt": int(
datetime.strptime("2029-01-01", "%Y-%m-%d").timestamp() datetime.strptime("2029-01-01", "%Y-%m-%d").timestamp()
), ),
"round_start_rank":0, "round_start_rank": 0,
"save_filename":"Round_Event_djg_Or_dpg", "save_filename": "Round_Event_djg_Or_dpg",
"vscount":[ "vscount": [
{ {
"reward_upper_limit":10, "reward_upper_limit": 10,
"reward_lower_limit":10, "reward_lower_limit": 10,
"reward":[ "reward": [{"reward_category": 1, "reward_type": 1}],
{
"reward_category":1,
"reward_type":1
}
]
} }
], ],
"rank":[ "rank": [],
"point": [],
"playable_course_list": [
{"course_id": 4, "course_day": 0},
{"course_id": 4, "course_day": 1},
{"course_id": 6, "course_day": 0},
{"course_id": 6, "course_day": 1},
{"course_id": 8, "course_day": 0},
{"course_id": 8, "course_day": 1},
{"course_id": 10, "course_day": 0},
{"course_id": 10, "course_day": 1},
{"course_id": 12, "course_day": 0},
{"course_id": 12, "course_day": 1},
{"course_id": 14, "course_day": 0},
{"course_id": 14, "course_day": 1},
{"course_id": 16, "course_day": 0},
{"course_id": 16, "course_day": 1},
{"course_id": 18, "course_day": 0},
{"course_id": 18, "course_day": 1},
{"course_id": 20, "course_day": 0},
{"course_id": 20, "course_day": 1},
{"course_id": 22, "course_day": 0},
{"course_id": 22, "course_day": 1},
{"course_id": 24, "course_day": 0},
{"course_id": 24, "course_day": 1},
{"course_id": 26, "course_day": 0},
{"course_id": 26, "course_day": 1},
{"course_id": 36, "course_day": 0},
{"course_id": 36, "course_day": 1},
{"course_id": 38, "course_day": 0},
{"course_id": 38, "course_day": 1},
{"course_id": 40, "course_day": 0},
{"course_id": 40, "course_day": 1},
{"course_id": 42, "course_day": 0},
{"course_id": 42, "course_day": 1},
{"course_id": 44, "course_day": 0},
{"course_id": 44, "course_day": 1},
{"course_id": 46, "course_day": 0},
{"course_id": 46, "course_day": 1},
{"course_id": 48, "course_day": 0},
{"course_id": 48, "course_day": 1},
{"course_id": 50, "course_day": 0},
{"course_id": 50, "course_day": 1},
{"course_id": 52, "course_day": 0},
{"course_id": 52, "course_day": 1},
{"course_id": 54, "course_day": 0},
{"course_id": 54, "course_day": 1},
{"course_id": 56, "course_day": 0},
{"course_id": 56, "course_day": 1},
{"course_id": 58, "course_day": 0},
{"course_id": 58, "course_day": 1},
{"course_id": 68, "course_day": 0},
{"course_id": 68, "course_day": 1},
{"course_id": 70, "course_day": 0},
{"course_id": 70, "course_day": 1},
], ],
"point":[
],
"playable_course_list":[
{
"course_id":4,
"course_day":0
},
{
"course_id":4,
"course_day":1
},
{
"course_id":6,
"course_day":0
},
{
"course_id":6,
"course_day":1
},
{
"course_id":8,
"course_day":0
},
{
"course_id":8,
"course_day":1
},
{
"course_id":10,
"course_day":0
},
{
"course_id":10,
"course_day":1
},
{
"course_id":12,
"course_day":0
},
{
"course_id":12,
"course_day":1
},
{
"course_id":14,
"course_day":0
},
{
"course_id":14,
"course_day":1
},
{
"course_id":16,
"course_day":0
},
{
"course_id":16,
"course_day":1
},
{
"course_id":18,
"course_day":0
},
{
"course_id":18,
"course_day":1
},
{
"course_id":20,
"course_day":0
},
{
"course_id":20,
"course_day":1
},
{
"course_id":22,
"course_day":0
},
{
"course_id":22,
"course_day":1
},
{
"course_id":24,
"course_day":0
},
{
"course_id":24,
"course_day":1
},
{
"course_id":26,
"course_day":0
},
{
"course_id":26,
"course_day":1
},
{
"course_id":36,
"course_day":0
},
{
"course_id":36,
"course_day":1
},
{
"course_id":38,
"course_day":0
},
{
"course_id":38,
"course_day":1
},
{
"course_id":40,
"course_day":0
},
{
"course_id":40,
"course_day":1
},
{
"course_id":42,
"course_day":0
},
{
"course_id":42,
"course_day":1
},
{
"course_id":44,
"course_day":0
},
{
"course_id":44,
"course_day":1
},
{
"course_id":46,
"course_day":0
},
{
"course_id":46,
"course_day":1
},
{
"course_id":48,
"course_day":0
},
{
"course_id":48,
"course_day":1
},
{
"course_id":50,
"course_day":0
},
{
"course_id":50,
"course_day":1
},
{
"course_id":52,
"course_day":0
},
{
"course_id":52,
"course_day":1
},
{
"course_id":54,
"course_day":0
},
{
"course_id":54,
"course_day":1
},
{
"course_id":56,
"course_day":0
},
{
"course_id":56,
"course_day":1
},
{
"course_id":58,
"course_day":0
},
{
"course_id":58,
"course_day":1
},
{
"course_id":68,
"course_day":0
},
{
"course_id":68,
"course_day":1
},
{
"course_id":70,
"course_day":0
},
{
"course_id":70,
"course_day":1
}
]
} }
], ],
"last_round_event": [], "last_round_event": [],
"last_round_event_ranking": [], "last_round_event_ranking": [],
"round_event_exp": [], "round_event_exp": [],
@ -740,12 +574,14 @@ class IDACSeason2(IDACBase):
p = self.data.profile.get_profile(user_id, self.version) p = self.data.profile.get_profile(user_id, self.version)
user_data = p._asdict() user_data = p._asdict()
arcade = self.data.arcade.get_arcade(user_data["store"]) arcade = self.data.arcade.get_arcade(user_data["store"])
del user_data["id"] del user_data["id"]
del user_data["user"] del user_data["user"]
del user_data["version"] del user_data["version"]
user_data["id"] = user_id user_data["id"] = user_id
user_data["store_name"] = self.core_cfg.server.name if arcade is None else arcade["name"] user_data["store_name"] = (
self.core_cfg.server.name if arcade is None else arcade["name"]
)
user_data["last_play_date"] = int(user_data["last_play_date"].timestamp()) user_data["last_play_date"] = int(user_data["last_play_date"].timestamp())
user_data["create_date"] = int(user_data["create_date"].timestamp()) user_data["create_date"] = int(user_data["create_date"].timestamp())
@ -1066,13 +902,13 @@ class IDACSeason2(IDACBase):
for course in courses: for course in courses:
car_list = [] car_list = []
best_cars = self.data.item.get_time_trial_best_cars_by_course( best_cars = self.data.item.get_time_trial_best_cars_by_course(
self.version, user_id, course["course_id"] self.version, course["course_id"], user_id
) )
for car in best_cars: for i, car in enumerate(best_cars):
car_list.append( car_list.append(
{ {
"rank": 1, "rank": i + 1,
# no clue # no clue
"member": user_id, "member": user_id,
"value": car["goal_time"], "value": car["goal_time"],
@ -1099,39 +935,97 @@ class IDACSeason2(IDACBase):
return { return {
"status_code": "0", "status_code": "0",
"course_mybest_data": course_mybest_data, "course_mybest_data": course_mybest_data,
# "course_car_best_data": course_car_best_data,
# "course_best_data": course_best_data,
"location_course_store_best_data": [],
"course_pickup_car_best_data": course_pickup_car_best_data, "course_pickup_car_best_data": course_pickup_car_best_data,
} }
def handle_timetrial_getbestrecordprerace_request(self, data: Dict, headers: Dict): def handle_timetrial_getbestrecordprerace_request(self, data: Dict, headers: Dict):
user_id = headers["session"] user_id = headers["session"]
for car_id in data["car_ids"]: course_id = data["course_id"]
pass for car in data["car_ids"]:
# TODO: get the best record for this car
style_car_id = car["style_car_id"]
course_best_data = [ # Not sure if this is actually correct
{ ranking = self.data.item.get_time_trial_ranking_by_course(
"course_id": 56, self.version, course_id
"rank": 1, )
"member": user_id, course_best_data = []
"value": 118016, for i, rank in enumerate(ranking):
"store": self.core_cfg.server.name, car_user_id = rank["user"]
"car_id": 0,
"style_car_id": 0, # get the username, country and store from the profile
"play_dt": int(datetime.now().timestamp() - 86400), profile = self.data.profile.get_profile(car_user_id, self.version)
"section_time_1": 45205, arcade = self.data.arcade.get_arcade(profile["store"])
"section_time_2": 47779,
"section_time_3": 43480, if arcade is None:
"section_time_4": 41552, arcade = {}
"mission": 1, arcade["name"] = self.core_cfg.server.name
}
] # should never happen
if profile is None:
continue
course_best_data.append(
{
"course_id": course_id,
"rank": i + 1,
"member": car_user_id,
"value": rank["goal_time"],
"store": arcade["name"],
# use car_id from request?
"car_id": 0,
"style_car_id": rank["style_car_id"],
"play_dt": rank["play_dt"].timestamp(),
"section_time_1": rank["section_time_1"],
"section_time_2": rank["section_time_2"],
"section_time_3": rank["section_time_3"],
"section_time_4": rank["section_time_4"],
"mission": rank["mission"],
}
)
best_cars = self.data.item.get_time_trial_best_cars_by_course(
self.version, course_id
)
car_list = []
for i, rank in enumerate(best_cars):
car_user_id = rank["user"]
# get the username, country and store from the profile
profile = self.data.profile.get_profile(car_user_id, self.version)
arcade = self.data.arcade.get_arcade(profile["store"])
if arcade is None:
arcade = {}
arcade["name"] = self.core_cfg.server.name
# should never happen
if profile is None:
continue
car_list.append(
{
"rank": i + 1,
# no clue
"member": car_user_id,
"value": rank["goal_time"],
"store": arcade["name"],
# use car_id from request?
"car_id": 0,
"style_car_id": rank["style_car_id"],
"play_dt": rank["play_dt"].timestamp(),
"section_time_1": rank["section_time_1"],
"section_time_2": rank["section_time_2"],
"section_time_3": rank["section_time_3"],
"section_time_4": rank["section_time_4"],
"mission": rank["mission"],
}
)
return { return {
"status_code": "0", "status_code": "0",
# "course_car_best_data": course_car_best_data, "course_car_best_data": [{"course_id": course_id, "car_list": car_list}],
"course_best_data": course_best_data, "course_best_data": course_best_data,
} }
@ -2357,7 +2251,9 @@ class IDACSeason2(IDACBase):
"win_count_multi": win_count_multi, "win_count_multi": win_count_multi,
} }
def handle_timetrial_getbestrecordprebattle_request(self, data: Dict, headers: Dict): def handle_timetrial_getbestrecordprebattle_request(
self, data: Dict, headers: Dict
):
user_id = headers["session"] user_id = headers["session"]
course_pickup_car_best_data = [] course_pickup_car_best_data = []
@ -2365,13 +2261,13 @@ class IDACSeason2(IDACBase):
for course in courses: for course in courses:
car_list = [] car_list = []
best_cars = self.data.item.get_time_trial_best_cars_by_course( best_cars = self.data.item.get_time_trial_best_cars_by_course(
self.version, user_id, course["course_id"] self.version, course["course_id"], user_id
) )
for car in best_cars: for i, car in enumerate(best_cars):
car_list.append( car_list.append(
{ {
"rank": 1, "rank": i + 1,
# no clue # no clue
"member": user_id, "member": user_id,
"value": car["goal_time"], "value": car["goal_time"],
@ -2397,13 +2293,10 @@ class IDACSeason2(IDACBase):
return { return {
"status_code": "0", "status_code": "0",
# "course_car_best_data": course_car_best_data,
# "course_best_data": course_best_data,
"course_pickup_car_best_data": course_pickup_car_best_data, "course_pickup_car_best_data": course_pickup_car_best_data,
} }
def handle_user_updateonlinebattle_request(self, data: Dict, headers: Dict):
def handle_user_updateonlinebattle_request(self, data: Dict, headers: Dict):
return { return {
"status_code": "0", "status_code": "0",
"bothwin_penalty": 1, "bothwin_penalty": 1,
@ -2415,20 +2308,20 @@ class IDACSeason2(IDACBase):
stock_data: Dict = data.pop("stock_obj") stock_data: Dict = data.pop("stock_obj")
# save stock data in database # save stock data in database
self._save_stock_data(user_id, stock_data) self._save_stock_data(user_id, stock_data)
ticket_data: List = data.pop("ticket_data") ticket_data: List = data.pop("ticket_data")
for ticket in ticket_data: for ticket in ticket_data:
self.data.item.put_ticket(user_id, ticket) self.data.item.put_ticket(user_id, ticket)
reward_dist_data: Dict = data.pop("reward_dist_obj") reward_dist_data: Dict = data.pop("reward_dist_obj")
rank_data: Dict = data.pop("mode_rank_obj") rank_data: Dict = data.pop("mode_rank_obj")
# save rank dist data in database # save rank dist data in database
rank_data.update(reward_dist_data) rank_data.update(reward_dist_data)
self.data.profile.put_profile_rank(user_id, self.version, rank_data) self.data.profile.put_profile_rank(user_id, self.version, rank_data)
driver_debut_data = data.pop("driver_debut_obj") driver_debut_data = data.pop("driver_debut_obj")
# get the use_count and net_vs_use_count of the used car # get the use_count and net_vs_use_count of the used car
style_car_id = data.get("style_car_id") style_car_id = data.get("style_car_id")
car_mileage = data.pop("car_mileage") car_mileage = data.pop("car_mileage")
@ -2441,7 +2334,7 @@ class IDACSeason2(IDACBase):
# save the used car in database # save the used car in database
self.data.item.put_car(user_id, self.version, used_car) self.data.item.put_car(user_id, self.version, used_car)
# get the profile data, update total_play and daily_play, and save it # get the profile data, update total_play and daily_play, and save it
profile = self.data.profile.get_profile(user_id, self.version) profile = self.data.profile.get_profile(user_id, self.version)
total_play = profile["total_play"] + 1 total_play = profile["total_play"] + 1
@ -2463,7 +2356,7 @@ class IDACSeason2(IDACBase):
"avatar_point": data.pop("avatar_point"), "avatar_point": data.pop("avatar_point"),
}, },
) )
self.data.item.put_vs_info(user_id, data) self.data.item.put_vs_info(user_id, data)
vs_info = { vs_info = {
@ -2484,7 +2377,7 @@ class IDACSeason2(IDACBase):
} }
], ],
} }
return { return {
"status_code": "0", "status_code": "0",
"vsinfo_data": vs_info, "vsinfo_data": vs_info,
@ -2501,7 +2394,6 @@ class IDACSeason2(IDACBase):
"maker_use_count": [], "maker_use_count": [],
} }
def handle_user_updatestorebattleresult_request(self, data: Dict, headers: Dict): def handle_user_updatestorebattleresult_request(self, data: Dict, headers: Dict):
user_id = headers["session"] user_id = headers["session"]