forked from Hay1tsme/artemis
idac: last round ranking impl
This commit is contained in:
parent
bfbd827dd2
commit
55e7b3770a
|
@ -31,4 +31,5 @@ battle_event:
|
|||
|
||||
round_event:
|
||||
enable: True
|
||||
enabled_round: "S2R2"
|
||||
enabled_round: "S2R2"
|
||||
last_round: "S2R1"
|
|
@ -169,6 +169,16 @@ class IDACRoundConfig:
|
|||
default="S1R1",
|
||||
)
|
||||
|
||||
@property
|
||||
def last_round(self) -> str:
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config,
|
||||
"idac",
|
||||
"round_event",
|
||||
"last_round",
|
||||
default="S1R1",
|
||||
)
|
||||
|
||||
|
||||
class IDACConfig(dict):
|
||||
def __init__(self) -> None:
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
{
|
||||
"round_event_id": 9,
|
||||
"round_event_nm": "シーズン2 特別ラウンド",
|
||||
"start_dt": 1647468000,
|
||||
"end_dt": 1648062000,
|
||||
"round_start_rank": 0,
|
||||
"save_filename": "",
|
||||
"vscount": [
|
||||
{
|
||||
"reward_upper_limit": 30,
|
||||
"reward_lower_limit": 30,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 21,
|
||||
"reward_type": 379
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"reward_upper_limit": 10,
|
||||
"reward_lower_limit": 10,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 21,
|
||||
"reward_type": 367
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"rank": [
|
||||
{
|
||||
"reward_upper_limit": 1,
|
||||
"reward_lower_limit": 1,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 24,
|
||||
"reward_type": 4328
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"reward_upper_limit": 2,
|
||||
"reward_lower_limit": 10,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 24,
|
||||
"reward_type": 4329
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"reward_upper_limit": 11,
|
||||
"reward_lower_limit": 50,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 24,
|
||||
"reward_type": 4330
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"reward_upper_limit": 51,
|
||||
"reward_lower_limit": 100,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 24,
|
||||
"reward_type": 4331
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"reward_upper_limit": 101,
|
||||
"reward_lower_limit": 1000,
|
||||
"reward": [
|
||||
{
|
||||
"reward_category": 24,
|
||||
"reward_type": 4332
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"point": [
|
||||
|
||||
],
|
||||
"playable_course_list": [
|
||||
{
|
||||
"course_id": 0,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 0,
|
||||
"course_day": 1
|
||||
},
|
||||
{
|
||||
"course_id": 2,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 2,
|
||||
"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": 4,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 4,
|
||||
"course_day": 1
|
||||
},
|
||||
{
|
||||
"course_id": 6,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 6,
|
||||
"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": 8,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 8,
|
||||
"course_day": 1
|
||||
},
|
||||
{
|
||||
"course_id": 10,
|
||||
"course_day": 0
|
||||
},
|
||||
{
|
||||
"course_id": 10,
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
|
@ -47,14 +47,14 @@ class IDACOnlineRounds(BaseData):
|
|||
)
|
||||
|
||||
sql = (
|
||||
select([func.find_in_set(func.concat(round_info.c.user, '|', round_info.c.point), subquery.label('rank'))])
|
||||
.select_from(round_info)
|
||||
.where(
|
||||
and_(
|
||||
round_info.c.user == aime_id,
|
||||
round_info.c.round_id == round_event_id
|
||||
)
|
||||
select([func.find_in_set(func.concat(round_info.c.user, '|', round_info.c.point), subquery.label('rank'))])
|
||||
.select_from(round_info)
|
||||
.where(
|
||||
and_(
|
||||
round_info.c.user == aime_id,
|
||||
round_info.c.round_id == round_event_id
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
result = await self.execute(sql)
|
||||
|
@ -77,6 +77,27 @@ class IDACOnlineRounds(BaseData):
|
|||
return None
|
||||
return result.fetchone()
|
||||
|
||||
# get top 5 of a specified round event
|
||||
async def get_round_top_five(self, round_event_id: int) -> Optional[Row]:
|
||||
subquery = (
|
||||
select([func.group_concat(func.concat(round_info.c.user, '|', round_info.c.point),order_by=[round_info.c.point.desc(), round_info.c.play_dt])])
|
||||
.select_from(round_info)
|
||||
.where(round_info.c.round_id == round_event_id)
|
||||
.as_scalar()
|
||||
)
|
||||
|
||||
sql = (
|
||||
select([func.find_in_set(func.concat(round_info.c.user, '|', round_info.c.point), subquery.label('rank'))], round_info.c.user)
|
||||
.select_from(round_info)
|
||||
.where(round_info.c.round_id == round_event_id)
|
||||
.limit(5)
|
||||
)
|
||||
|
||||
result = await self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
# save players info to a specified round event
|
||||
async def put_round_event(
|
||||
self, aime_id: int, round_id: int, round_data: Dict
|
||||
|
|
|
@ -86,7 +86,11 @@ class IDACSeason2(IDACBase):
|
|||
async def _load_round_event(self):
|
||||
self.round_event_id = 0
|
||||
self.round_event = []
|
||||
self.last_round_event_id = 0
|
||||
self.last_round_event = []
|
||||
self.last_round_event_ranking = []
|
||||
if self.game_config.round_event.enable:
|
||||
# Load current round event
|
||||
round = self.game_config.round_event.enabled_round
|
||||
if round is not None:
|
||||
if not os.path.exists(f"./titles/idac/data/rounds/season{self.version+1}/{round}.json"):
|
||||
|
@ -101,6 +105,94 @@ class IDACSeason2(IDACBase):
|
|||
self.round_event.append(self._fix_dates(tmp))
|
||||
self.logger.debug(f"Loaded round id for database: {self.round_event_id}...")
|
||||
|
||||
# Load last round event
|
||||
round = self.game_config.round_event.last_round
|
||||
if round is not None:
|
||||
if not os.path.exists(f"./titles/idac/data/rounds/season{self.version+1}/{round}.json"):
|
||||
self.logger.warning(f"Round info {round} is enabled but json file does not exist!")
|
||||
else:
|
||||
with open(
|
||||
f"./titles/idac/data/rounds/season{self.version+1}/{round}.json", encoding="UTF-8"
|
||||
) as f:
|
||||
self.logger.debug(f"Loading round info {round}...")
|
||||
tmp = json.load(f)
|
||||
self.last_round_event_id = await self.data.rounds._try_load_round_event(tmp["last_round_event_id"], tmp)
|
||||
#self.last_round_event.append(self._fix_dates(tmp))
|
||||
self.logger.debug(f"Loaded round id for database: {self.last_round_event_id}...")
|
||||
|
||||
# Load top five of last round event
|
||||
|
||||
# class LastRoundEventRanking(BaseModel):
|
||||
# round_rank: int
|
||||
# round_point: int
|
||||
# round_play_count: int
|
||||
|
||||
ranking = await self.data.rounds.get_round_top_five(self.last_round_event_id)
|
||||
if ranking is not None:
|
||||
rank_profile = {
|
||||
"round_rank": 0,
|
||||
"round_point": 0,
|
||||
"round_play_count": 0,
|
||||
"username": "DUMMY",
|
||||
"country": 9,
|
||||
"store": self.core_cfg.server.name,
|
||||
"online_battle_rank": 0,
|
||||
"mytitle_id": 0,
|
||||
"mytitle_effect_id": 0,
|
||||
"car_data": [],
|
||||
"user_avatar": []
|
||||
}
|
||||
for user in ranking:
|
||||
# get the user's profile
|
||||
p = await self.data.profile.get_profile(user["user"], self.version)
|
||||
user_data = p._asdict()
|
||||
arcade = await self.data.arcade.get_arcade(user_data["store"])
|
||||
user_data["store_name"] = (
|
||||
self.core_cfg.server.name if arcade is None else arcade["name"]
|
||||
)
|
||||
rank_profile["username"] = user_data["username"]
|
||||
rank_profile["country"] = user_data["country"]
|
||||
rank_profile["store"] = user_data["store_name"]
|
||||
rank_profile["mytitle_id"] = user_data["mytitle_id"]
|
||||
rank_profile["mytitle_effect_id"] = user_data["mytitle_effect_id"]
|
||||
|
||||
# get the user's avatar
|
||||
a = await self.data.profile.get_profile_avatar(user["user"])
|
||||
avatar_data = a._asdict()
|
||||
del avatar_data["id"]
|
||||
del avatar_data["user"]
|
||||
rank_profile["user_avatar"] = avatar_data
|
||||
|
||||
# get the user's rank
|
||||
r = await self.data.profile.get_profile_rank(user_id, self.version)
|
||||
rank_data = r._asdict()
|
||||
del rank_data["id"]
|
||||
del rank_data["user"]
|
||||
del rank_data["version"]
|
||||
rank_profile["online_battle_rank"] = rank_data["online_battle_rank"]
|
||||
|
||||
# get the user's car
|
||||
cars = await self.data.item.get_cars(self.version, user_id, only_pickup=True)
|
||||
fulltune_count = 0
|
||||
total_car_parts_count = 0
|
||||
car_data = []
|
||||
for car in cars:
|
||||
tmp = car._asdict()
|
||||
del tmp["id"]
|
||||
del tmp["user"]
|
||||
del tmp["version"]
|
||||
car_data.append(tmp)
|
||||
rank_profile["car_data"] = car_data
|
||||
|
||||
# get round info
|
||||
ri = await self.data.rounds.get_round_info_by_id(user["user"], self.last_round_event_id)
|
||||
if ri is not None:
|
||||
ri = ri._asdict()
|
||||
rank_profile["round_rank"] = user["find_in_set_1"]
|
||||
rank_profile["round_point"] = ri["point"]
|
||||
rank_profile["round_play_count"] = ri["count"]
|
||||
|
||||
self.last_round_event_ranking.append(rank_profile)
|
||||
|
||||
async def handle_alive_get_request(self, data: Dict, headers: Dict):
|
||||
return {
|
||||
|
@ -194,8 +286,8 @@ class IDACSeason2(IDACBase):
|
|||
),
|
||||
# online battle round event
|
||||
"round_event": self.round_event,
|
||||
"last_round_event": [],
|
||||
"last_round_event_ranking": [],
|
||||
"last_round_event": self.last_round_event,
|
||||
"last_round_event_ranking": self.last_round_event_ranking,
|
||||
"round_event_exp": [],
|
||||
"stamp_info": self.stamp_info,
|
||||
# 0 = use default data, 1+ = server version of timereleasedata response
|
||||
|
|
Loading…
Reference in New Issue