Skip to content

Commit

Permalink
Merge pull request #21 from Jylpah/dev
Browse files Browse the repository at this point in the history
version 1.1.1
  • Loading branch information
Jylpah authored Jan 1, 2024
2 parents f1a70e7 + dd080ba commit d25f33d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package-macos-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
mypy src
- name: Test with pytest
run: |
pytest --cov .
pytest --cov=src tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
mypy src
- name: Test with pytest
run: |
pytest --cov .
pytest --cov=src tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blitz-models"
version = "1.1.0"
version = "1.1.1"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Pydantic models for Wargaming's World of Tanks Blitz game "
readme = "README.md"
Expand Down Expand Up @@ -66,6 +66,7 @@ mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
include = ["pyproject.toml", "src/**/*.py", "tests/**/*.py"]
indent-width = 4
extend-include = ["*.ipynb"]
extend-exclude = [".venv", ".vscode" ]
fixable = ["ALL"]


Expand Down
6 changes: 2 additions & 4 deletions src/blitzmodels/account.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any, Optional, Self, TypeVar, Dict
from typing import Any, Optional, Self, Dict
import logging
from bson.int64 import Int64
from pydantic import (
field_validator,
model_validator,
ConfigDict,
BaseModel,
Field,
)

Expand All @@ -28,8 +27,7 @@
debug = logger.debug


B = TypeVar("B", bound="BaseModel")

# B = TypeVar("B", bound="BaseModel")

###########################################
#
Expand Down
19 changes: 10 additions & 9 deletions src/blitzmodels/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
from pydantic import field_validator, ConfigDict, Field, field_serializer
import logging

logger = logging.getLogger()
error = logger.error
message = logger.warning
verbose = logger.info
debug = logger.debug

from pydantic_exportables import ( # noqa: E402
from pydantic_exportables import (
CSVExportable,
TXTExportable,
JSONExportable,
Importable,
Idx,
BackendIndexType,
BackendIndex,
IndexSortOrder,
DESCENDING,
ASCENDING,
)


logger = logging.getLogger()
error = logger.error
message = logger.warning
verbose = logger.info
debug = logger.debug

###########################################
#
# Release()
Expand Down Expand Up @@ -67,7 +68,7 @@ def indexes(self) -> dict[str, Idx]:
return {"release": self.index}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
indexes: list[list[BackendIndex]] = list()
indexes.append([("name", ASCENDING), ("launch_date", DESCENDING)])
return indexes
Expand Down
17 changes: 15 additions & 2 deletions src/blitzmodels/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TXTExportable,
JSONExportable,
Idx,
BackendIndexType,
IndexSortOrder,
BackendIndex,
ASCENDING,
TEXT,
Expand Down Expand Up @@ -152,7 +152,7 @@ def indexes(self) -> dict[str, Idx]:
return {"tank_id": self.index}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
indexes: list[list[BackendIndex]] = list()
indexes.append([("tier", ASCENDING), ("type", ASCENDING)])
indexes.append([("tier", ASCENDING), ("nation", ASCENDING)])
Expand Down Expand Up @@ -180,3 +180,16 @@ def txt_row(self, format: str = "") -> str:
return f"({self.tank_id}) {self.name} tier {self.tier} {self.type} {self.nation}"
else:
return f"({self.tank_id}) {self.name}"

# def update(self, new: "Tank") -> bool:
# """update Tank with a new info"""
# if self.tank_id != new.tank_id:
# error(f"tank_ids do not match: {self.tank_id} != {new.tank_id}")
# return False
# updated: bool = False
# for name, info in new.model_fields.items():
# new_value: Any = getattr(new, name)
# if new_value != info.get_default():
# self._set_skip_validation(name, new_value)
# updated = True
# return updated
45 changes: 29 additions & 16 deletions src/blitzmodels/wg_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from typing import Any, Optional, ClassVar, TypeVar, Sequence, Tuple, Self, Type, Dict
from typing import (
Any,
Optional,
ClassVar,
TypeVar,
Sequence,
Tuple,
Self,
Type,
Dict,
Annotated,
)
from types import TracebackType
import logging
from sys import path
import pyarrow # type: ignore
from bson.objectid import ObjectId
from bson import ObjectId
from pydantic import (
field_validator,
model_validator,
Expand All @@ -12,6 +23,7 @@
field_serializer,
Field,
)

from aiohttp import ClientTimeout
from urllib.parse import quote
from collections import defaultdict
Expand All @@ -21,9 +33,10 @@
from configparser import ConfigParser
from pydantic_exportables import (
JSONExportable,
PyObjectId,
TypeExcludeDict,
Idx,
BackendIndexType,
IndexSortOrder,
BackendIndex,
DESCENDING,
ASCENDING,
Expand Down Expand Up @@ -150,7 +163,7 @@ def unset(cls, v: int | bool | None) -> None:

class TankStat(JSONExportable):
# fmt: off
id: ObjectId = Field(default=_NULL_OBJECT_ID, alias="_id")
id: Annotated[PyObjectId, Field(default=_NULL_OBJECT_ID, alias="_id")]
region: Region | None = Field(default=None, alias="r")
all: WGTankStatAll = Field(..., alias="s")
last_battle_time: int = Field(..., alias="lb")
Expand Down Expand Up @@ -228,7 +241,7 @@ def indexes(self) -> dict[str, Idx]:
}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
indexes: list[list[BackendIndex]] = list()
indexes.append(
[
Expand Down Expand Up @@ -391,7 +404,7 @@ class PlayerAchievements(JSONExportable):

class PlayerAchievementsMaxSeries(JSONExportable):
# fmt: off
id : ObjectId | None = Field(default=None, alias="_id")
id : Annotated[PyObjectId, Field(default=_NULL_OBJECT_ID, alias="_id")]
jointVictory: int = Field(default=0, alias="jv")
account_id : int = Field(default=0, alias="a")
region : Region | None = Field(default=None, alias="r")
Expand Down Expand Up @@ -426,18 +439,18 @@ class PlayerAchievementsMaxSeries(JSONExportable):
)

@field_serializer("id", when_used="json")
def serialize_ObjectId(self, obj_id: ObjectId | None, _info) -> str | None:
if obj_id is None:
return None
def serialize_ObjectId(self, obj_id: ObjectId, _info) -> str:
return str(obj_id)

@property
def index(self) -> Idx:
"""return backend index"""
if self.id is None:
return self.mk_index(self.account_id, self.region, self.added)
else:
return self.id
if self.id == _NULL_OBJECT_ID:
self._set_skip_validation(
"id",
self.mk_index(self.account_id, self.region, self.added),
)
return self.id

@property
def indexes(self) -> dict[str, Idx]:
Expand All @@ -449,7 +462,7 @@ def indexes(self) -> dict[str, Idx]:
}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
indexes: list[list[BackendIndex]] = list()
indexes.append(
[("region", ASCENDING), ("account_id", ASCENDING), ("added", DESCENDING)]
Expand Down Expand Up @@ -761,8 +774,8 @@ def indexes(self) -> dict[str, Idx]:
return {"code": self.index}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
indexes: list[list[tuple[str, BackendIndexType]]] = list()
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
indexes: list[list[tuple[str, IndexSortOrder]]] = list()
indexes.append([("code", TEXT)])
return indexes

Expand Down
6 changes: 3 additions & 3 deletions src/blitzmodels/wotinspector/wi_apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
DESCENDING,
ASCENDING,
Idx,
BackendIndexType,
IndexSortOrder,
)
from pydantic_exportables.utils import get_model

Expand Down Expand Up @@ -291,9 +291,9 @@ def indexes(self) -> dict[str, Idx]:
return {"id": self.index}

@classmethod
def backend_indexes(cls) -> list[list[tuple[str, BackendIndexType]]]:
def backend_indexes(cls) -> list[list[tuple[str, IndexSortOrder]]]:
"""return backend search indexes"""
indexes: list[list[tuple[str, BackendIndexType]]] = list()
indexes: list[list[tuple[str, IndexSortOrder]]] = list()
indexes.append(
[
("summary.protagonist", ASCENDING),
Expand Down

0 comments on commit d25f33d

Please sign in to comment.