mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-04-19 06:00:18 +00:00
impr: add duplicate detect in St3ScoreParser.write_database
This commit is contained in:
parent
b334108f8c
commit
8f30906e1b
25
src/arcaea_offline/external/arcaea/st3.py
vendored
25
src/arcaea_offline/external/arcaea/st3.py
vendored
@ -1,9 +1,15 @@
|
|||||||
|
import logging
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ...models.scores import Score
|
from ...models.scores import Score
|
||||||
from .common import ArcaeaParser
|
from .common import ArcaeaParser
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class St3ScoreParser(ArcaeaParser):
|
class St3ScoreParser(ArcaeaParser):
|
||||||
CLEAR_TYPES_MAP = {0: -1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}
|
CLEAR_TYPES_MAP = {0: -1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}
|
||||||
@ -42,3 +48,22 @@ class St3ScoreParser(ArcaeaParser):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
def write_database(self, session: Session, *, skip_duplicate=True):
|
||||||
|
parsed_scores = self.parse()
|
||||||
|
for parsed_score in parsed_scores:
|
||||||
|
query_score = session.scalar(
|
||||||
|
select(Score).where(
|
||||||
|
(Score.song_id == parsed_score.song_id)
|
||||||
|
& (Score.rating_class == parsed_score.rating_class)
|
||||||
|
& (Score.score == parsed_score.score)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if query_score and skip_duplicate:
|
||||||
|
logger.info(
|
||||||
|
f"{repr(parsed_score)} skipped because "
|
||||||
|
f"potential duplicate item {repr(query_score)} found."
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
session.add(parsed_score)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user