mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-04-21 15:00:18 +00:00
feat(db): export methods
This commit is contained in:
parent
167f72f9bb
commit
844568db1a
@ -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
|
||||
|
2
src/arcaea_offline/external/exports/__init__.py
vendored
Normal file
2
src/arcaea_offline/external/exports/__init__.py
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
from . import exporters
|
||||
from .types import ScoreExport
|
19
src/arcaea_offline/external/exports/exporters.py
vendored
Normal file
19
src/arcaea_offline/external/exports/exporters.py
vendored
Normal 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,
|
||||
}
|
16
src/arcaea_offline/external/exports/types.py
vendored
Normal file
16
src/arcaea_offline/external/exports/types.py
vendored
Normal 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]
|
Loading…
x
Reference in New Issue
Block a user