Deduplicate rating list functions
This commit is contained in:
parent
5c48edc86b
commit
ecebd5d774
|
@ -924,26 +924,16 @@ class ChuniBase:
|
||||||
if "userRecentPlayerList" in upsert: # TODO: Seen in Air, maybe implement sometime
|
if "userRecentPlayerList" in upsert: # TODO: Seen in Air, maybe implement sometime
|
||||||
for rp in upsert["userRecentPlayerList"]:
|
for rp in upsert["userRecentPlayerList"]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if "userRatingBaseList" in upsert:
|
for rating_type in {"userRatingBaseList", "userRatingBaseHotList", "userRatingBaseNextList"}:
|
||||||
await self.data.profile.put_profile_rating_best(
|
if rating_type not in upsert:
|
||||||
|
continue
|
||||||
|
|
||||||
|
await self.data.profile.put_profile_rating(
|
||||||
user_id,
|
user_id,
|
||||||
self.version,
|
self.version,
|
||||||
upsert["userRatingBaseList"]
|
rating_type,
|
||||||
)
|
upsert[rating_type],
|
||||||
|
|
||||||
if "userRatingBaseHotList" in upsert:
|
|
||||||
await self.data.profile.put_profile_rating_hot(
|
|
||||||
user_id,
|
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseHotList"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "userRatingBaseNextList" in upsert:
|
|
||||||
await self.data.profile.put_profile_rating_next(
|
|
||||||
user_id,
|
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseNextList"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"returnCode": "1"}
|
return {"returnCode": "1"}
|
||||||
|
|
|
@ -734,7 +734,13 @@ class ChuniProfileData(BaseData):
|
||||||
"total_play_count": total_play_count
|
"total_play_count": total_play_count
|
||||||
}
|
}
|
||||||
|
|
||||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
async def put_profile_rating(
|
||||||
|
self,
|
||||||
|
aime_id: int,
|
||||||
|
version: int,
|
||||||
|
rating_type: str,
|
||||||
|
rating_data: List[Dict],
|
||||||
|
):
|
||||||
inserted_values = [
|
inserted_values = [
|
||||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||||
for (i, x) in enumerate(rating_data)
|
for (i, x) in enumerate(rating_data)
|
||||||
|
@ -746,33 +752,8 @@ class ChuniProfileData(BaseData):
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
self.logger.warn(
|
self.logger.warn(
|
||||||
f"put_profile_rating_{rating_type}: Could not insert rating entries, aime_id: {aime_id}",
|
f"put_profile_rating: Could not insert {rating_type}, aime_id: {aime_id}",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"best",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_best_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"hot",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_hot_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"next",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_next_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
|
@ -1067,47 +1067,23 @@ class OngekiBase:
|
||||||
if "userKopList" in upsert:
|
if "userKopList" in upsert:
|
||||||
for x in upsert["userKopList"]:
|
for x in upsert["userKopList"]:
|
||||||
await self.data.profile.put_kop(user_id, x)
|
await self.data.profile.put_kop(user_id, x)
|
||||||
|
|
||||||
if "userRatingBaseBestList" in upsert:
|
for rating_type in {
|
||||||
await self.data.profile.put_profile_rating_best(
|
"userRatingBaseBestList",
|
||||||
user_id,
|
"userRatingBaseBestNewList",
|
||||||
self.version,
|
"userRatingBaseHotList",
|
||||||
upsert["userRatingBaseBestList"]
|
"userRatingBaseNextList",
|
||||||
)
|
"userRatingBaseNextNewList",
|
||||||
|
"userRatingBaseHotNextList",
|
||||||
if "userRatingBaseBestNewList" in upsert:
|
}:
|
||||||
await self.data.profile.put_profile_rating_best_new(
|
if rating_type not in upsert:
|
||||||
user_id,
|
continue
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseBestNewList"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "userRatingBaseHotList" in upsert:
|
|
||||||
await self.data.profile.put_profile_rating_hot(
|
|
||||||
user_id,
|
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseHotList"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "userRatingBaseNextList" in upsert:
|
await self.data.profile.put_profile_rating(
|
||||||
await self.data.profile.put_profile_rating_next(
|
|
||||||
user_id,
|
user_id,
|
||||||
self.version,
|
self.version,
|
||||||
upsert["userRatingBaseNextList"]
|
rating_type,
|
||||||
)
|
upsert[rating_type],
|
||||||
|
|
||||||
if "userRatingBaseNextNewList" in upsert:
|
|
||||||
await self.data.profile.put_profile_rating_next_new(
|
|
||||||
user_id,
|
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseNextNewList"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "userRatingBaseHotNextList" in upsert:
|
|
||||||
await self.data.profile.put_profile_rating_next_hot(
|
|
||||||
user_id,
|
|
||||||
self.version,
|
|
||||||
upsert["userRatingBaseHotNextList"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"returnCode": 1, "apiName": "upsertUserAll"}
|
return {"returnCode": 1, "apiName": "upsertUserAll"}
|
||||||
|
|
|
@ -528,6 +528,7 @@ class OngekiProfileData(BaseData):
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
async def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]:
|
async def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]:
|
||||||
sql = delete(rival).where(rival.c.user==aime_id, rival.c.rivalUserId==rival_id)
|
sql = delete(rival).where(rival.c.user==aime_id, rival.c.rivalUserId==rival_id)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
|
@ -536,7 +537,13 @@ class OngekiProfileData(BaseData):
|
||||||
else:
|
else:
|
||||||
return result.rowcount
|
return result.rowcount
|
||||||
|
|
||||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
async def put_profile_rating(
|
||||||
|
self,
|
||||||
|
aime_id: int,
|
||||||
|
version: int,
|
||||||
|
rating_type: str,
|
||||||
|
rating_data: List[Dict],
|
||||||
|
):
|
||||||
inserted_values = [
|
inserted_values = [
|
||||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||||
for (i, x) in enumerate(rating_data)
|
for (i, x) in enumerate(rating_data)
|
||||||
|
@ -553,51 +560,3 @@ class OngekiProfileData(BaseData):
|
||||||
return
|
return
|
||||||
|
|
||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"best",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_best_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_best_new(self, aime_id: int, version: int, rating_best_new_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"best_new",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_best_new_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"hot",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_hot_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"next",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_next_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_next_new(self, aime_id: int, version: int, rating_next_new_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"next_new",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_next_new_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def put_profile_rating_next_hot(self, aime_id: int, version: int, rating_next_hot_data: List[Dict]):
|
|
||||||
return await self._put_profile_rating(
|
|
||||||
"next_hot",
|
|
||||||
aime_id,
|
|
||||||
version,
|
|
||||||
rating_next_hot_data,
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue