-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19aa928
commit a024281
Showing
10 changed files
with
107 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@rules_python//python:defs.bzl", "py_library", "py_test") | ||
|
||
filegroup( | ||
name = "fixtures", | ||
srcs = glob(["fixtures/*"]), | ||
visibility = ["//ark_nova_stats:__subpackages__"], | ||
) | ||
|
||
py_library( | ||
name = "game_log", | ||
srcs = ["game_log.py"], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
py_test( | ||
name = "game_log_test", | ||
srcs = ["game_log_test.py"], | ||
data = [":fixtures"], | ||
deps = [ | ||
":game_log", | ||
"@py_deps//pytest", | ||
"@rules_python//python/runfiles", | ||
], | ||
) |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class GameLogEntryData: | ||
uid: str | ||
type: str | ||
log: str | ||
args: dict | ||
lock_uuid: Optional[str] = None | ||
synchro: Optional[int] = None | ||
h: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class GameLogEntry: | ||
channel: str | ||
table_id: str | ||
packet_id: str | ||
packet_type: str | ||
move_id: str | ||
time: str | ||
data: list[GameLogEntryData] | ||
|
||
def __post_init__(self): | ||
self.data = [GameLogEntryData(**x) for x in self.data] # type: ignore | ||
|
||
|
||
@dataclass | ||
class GameLogPlayer: | ||
id: int | ||
color: str | ||
name: str | ||
avatar: str | ||
|
||
|
||
@dataclass | ||
class GameLogData: | ||
logs: list[GameLogEntry] | ||
players: list[GameLogPlayer] | ||
|
||
def __post_init__(self): | ||
self.players = [GameLogPlayer(**x) for x in self.players] # type: ignore | ||
self.logs = [GameLogEntry(**x) for x in self.logs] # type: ignore | ||
|
||
|
||
@dataclass | ||
class GameLog: | ||
status: int | ||
data: GameLogData | ||
|
||
def __post_init__(self): | ||
self.data = GameLogData(**self.data) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
import sys | ||
|
||
import pytest | ||
from python.runfiles import Runfiles | ||
|
||
from ark_nova_stats.bga_log_parser.game_log import GameLog | ||
|
||
|
||
class TestGameLog: | ||
def test_parses_sample_game(self): | ||
r = Runfiles.Create() | ||
sample_game_fixture = r.Rlocation( | ||
"_main/ark_nova_stats/bga_log_parser/fixtures/sample_game.log.json" | ||
) | ||
with open(sample_game_fixture, "r") as sample_game_logfile: | ||
game_log = json.loads(sample_game_logfile.read().strip()) | ||
|
||
x = GameLog(**game_log) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main([__file__] + sys.argv[1:])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters