Skip to content

Commit

Permalink
feat: use jsonl to store race data
Browse files Browse the repository at this point in the history
sub-task of #107
  • Loading branch information
NateScarlet committed Jul 14, 2021
1 parent fc991d9 commit 72aadee
Show file tree
Hide file tree
Showing 7 changed files with 643 additions and 23,211 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"astype",
"cygames",
"dmmgameplayer",
"jsonl",
"LANCZOS",
"nargs",
"ndarray",
Expand Down
5 changes: 4 additions & 1 deletion auto_derby/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@


import argparse
from auto_derby import plugin
import logging
import logging.handlers
import os
import time
import warnings
import webbrowser

import win32con
import win32gui

from auto_derby import plugin

from . import clients, config, jobs, templates, version

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -113,6 +115,7 @@ def main():
continue
logging.getLogger(i).setLevel(logging.DEBUG)

warnings.filterwarnings("once", module="auto_derby(\\..*)?")
try:
main()
except SystemExit:
Expand Down
2 changes: 1 addition & 1 deletion auto_derby/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class config:
CHECK_UPDATE = os.getenv("AUTO_DERBY_CHECK_UPDATE", "").lower() == "true"

single_mode_race_data_path = os.getenv(
"AUTO_DERBY_SINGLE_MODE_RACE_DATA_PATH", "single_mode_races.json"
"AUTO_DERBY_SINGLE_MODE_RACE_DATA_PATH", "single_mode_races.jsonl"
)
ocr_data_path = os.getenv("AUTO_DERBY_OCR_LABEL_PATH", "ocr_labels.json")
ocr_image_path = os.getenv("AUTO_DERBY_OCR_IMAGE_PATH", "")
Expand Down
28 changes: 23 additions & 5 deletions auto_derby/single_mode/race.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import math
import os
import warnings
from typing import Any, Dict, Iterator, Set, Text, Tuple, Type

import cast_unknown as cast
Expand All @@ -26,11 +27,28 @@ class g:
race_class: Type[Race]


def reload() -> None:
def _iter_races():
with open(g.data_path, "r", encoding="utf-8") as f:
for line in f:
yield Race.new().from_dict(json.loads(line))


def _load_legacy_json():
warnings.warn(
"json race data support will be removed at next major version, use jsonl instead",
DeprecationWarning,
)
with open(g.data_path, "r", encoding="utf-8") as f:
g.races = tuple(Race.new().from_dict(i) for i in json.load(f))


def reload() -> None:
if g.data_path.endswith(".json"):
_load_legacy_json()
return
g.races = tuple(_iter_races())


def _running_style_single_score(
ctx: Context,
race1: Race,
Expand Down Expand Up @@ -423,15 +441,15 @@ def __init__(self):

def to_dict(self) -> Dict[Text, Any]:
return {
"name": self.name,
"stadium": self.stadium,
"name": self.name,
"grade": self.grade,
"ground": self.ground,
"distance": self.distance,
"permission": self.permission,
"month": self.month,
"half": self.half,
"grade": self.grade,
"entryCount": self.entry_count,
"distance": self.distance,
"ground": self.ground,
"track": self.track,
"turn": self.turn,
"targetStatuses": self.target_statuses,
Expand Down
11 changes: 6 additions & 5 deletions scripts/extract_single_mode_races.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,21 @@ def _read_master_mdb(path: Text) -> Iterator[Race]:


def main():

parser = argparse.ArgumentParser()
parser.add_argument(
"path",
nargs="?",
default=os.getenv("LocalAppData", "")
+ "Low/cygames/umamusume/master/master.mdb",
default=os.path.expandvars(
"${LocalAppData}Low/cygames/umamusume/master/master.mdb"
),
)
args = parser.parse_args()
path: Text = args.path

data = [i.to_dict() for i in _read_master_mdb(path)]
with pathlib.Path(g.data_path).open("w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
for race in _read_master_mdb(path):
json.dump(race.to_dict(), f, ensure_ascii=False)
f.write("\n")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 72aadee

Please sign in to comment.