feat(db): export methods

This commit is contained in:
283375 2023-08-31 22:18:11 +08:00
parent 167f72f9bb
commit 844568db1a
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk
4 changed files with 47 additions and 1 deletions

View File

@ -1,10 +1,11 @@
import logging
from typing import Optional, Type, Union
from typing import List, Optional, Type, Union
from sqlalchemy import Engine, func, inspect, select
from sqlalchemy.orm import DeclarativeBase, InstrumentedAttribute, sessionmaker
from .external.arcsong.arcsong_json import ArcSongJsonBuilder
from .external.exports import ScoreExport, exporters
from .models.config import *
from .models.scores import *
from .models.songs import *
@ -211,7 +212,15 @@ class Database(metaclass=Singleton):
# endregion
# region export
def export_scores(self) -> List[ScoreExport]:
scores = self.get_scores()
return [exporters.score(score) for score in scores]
def generate_arcsong(self):
with self.sessionmaker() as session:
arcsong = ArcSongJsonBuilder(session).generate_arcsong_json()
return arcsong
# endregion

View File

@ -0,0 +1,2 @@
from . import exporters
from .types import ScoreExport

View File

@ -0,0 +1,19 @@
from ...models import Score
from .types import ScoreExport
def score(score: Score) -> ScoreExport:
return {
"id": score.id,
"song_id": score.song_id,
"rating_class": score.rating_class,
"score": score.score,
"pure": score.pure,
"far": score.far,
"lost": score.lost,
"date": score.date,
"max_recall": score.max_recall,
"modifier": score.modifier,
"clear_type": score.clear_type,
"comment": score.comment,
}

View File

@ -0,0 +1,16 @@
from typing import Optional, TypedDict
class ScoreExport(TypedDict):
id: int
song_id: str
rating_class: int
score: int
pure: Optional[int]
far: Optional[int]
lost: Optional[int]
date: Optional[int]
max_recall: Optional[int]
modifier: Optional[int]
clear_type: Optional[int]
comment: Optional[str]