From 2a48f2a2ce00eabb0f4cfcf18af57d0074518c40 Mon Sep 17 00:00:00 2001 From: mokurin000 <1348292515a@gmail.com> Date: Mon, 4 Aug 2025 13:44:51 +0800 Subject: [PATCH] fix: handle missing music --- pyproject.toml | 1 + utils/flat_user_detail.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8d9f3ad..df5000d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.12" dependencies = [ + "loguru>=0.7.3", "orjson>=3.11.1", "polars>=1.32.0", "pyecharts>=2.0.8", diff --git a/utils/flat_user_detail.py b/utils/flat_user_detail.py index 2c1fa80..b2e6377 100644 --- a/utils/flat_user_detail.py +++ b/utils/flat_user_detail.py @@ -7,6 +7,7 @@ import polars as pl import orjson as json import pyecharts.options as opts from pyecharts.charts import Scatter +from loguru import logger from helpers import query_music_db, find_level, dx_rating @@ -17,15 +18,17 @@ def calculate_dxrating(music: dict): level_id = music["level"] ach = music["achievement"] music_info = query_music_db(music_id) + if not music_info: + logger.error(f"music: {music_id} not found") + return music | {"dxRating": 0} level = find_level(music_info, level_id) try: return music | {"dxRating": dx_rating(Decimal(level.pop()["difficulty"]), ach)} except IndexError as _: - print(f"unknown level: {music_id} - {level_id}", file=stderr) + logger.warning(f"unknown level: {music_id} - {level_id}", file=stderr) return music | {"dxRating": 0} - data = json.loads(stdin.buffer.read()) user_id = data["userId"] music_list: list[dict[str, dict]] = data["userMusicList"]