Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
* parse more match info fields
* update dependencies
* configure autoflake
  • Loading branch information
cahna authored Feb 17, 2023
1 parent db2db67 commit 5f31b47
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 184 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ repos:
files: ^(hitfactorpy/|tests/)
additional_dependencies:
- "pydantic>=1.10.4"
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
- id: autoflake
- repo: local
hooks:
- id: black
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Python tools for parsing and analyzing practical match reports.

## Status

**BETA**: Currently supports USPSA match reports.
Currently supports USPSA match reports.

## CLI Docs

Expand Down
51 changes: 46 additions & 5 deletions hitfactorpy/parsers/match_report/match_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,65 @@
MATCH_REPORT_PREFIX_NAME = f"{MatchReportInfoSectionFields.MATCH_NAME.value}:"
MATCH_REPORT_PREFIX_DATE = f"{MatchReportInfoSectionFields.MATCH_DATE.value}:"
MATCH_REPORT_PREFIX_LEVEL = f"{MatchReportInfoSectionFields.MATCH_LEVEL.value}:"
MATCH_REPORT_PREFIX_REGION = f"{MatchReportInfoSectionFields.REGION.value}:"
MATCH_REPORT_PREFIX_CLUB_NAME = f"{MatchReportInfoSectionFields.CLUB_NAME.value}:"
MATCH_REPORT_PREFIX_CLUB_CODE = f"{MatchReportInfoSectionFields.CLUB_CODE.value}:"
MATCH_REPORT_PREFIX_PS_PRODUCT = f"{MatchReportInfoSectionFields.PS_PRODUCT.value}:"
MATCH_REPORT_PREFIX_PS_VERSION = f"{MatchReportInfoSectionFields.PS_VERSION.value}:"
MATCH_REPORT_PREFIX_PLATFORM = "PLATFORM "


def parse_match_info(info_lines: List[str]) -> ParsedMatchInfo:
def parse_match_info(info_lines: List[str]) -> ParsedMatchInfo: # noqa: C901
name: Optional[str] = None
raw_date: Optional[str] = None
date: Optional[datetime] = None
level: Optional[MatchLevel] = None
region: Optional[str] = None
club_name: Optional[str] = None
club_code: Optional[str] = None
ps_product: Optional[str] = None
ps_version: Optional[str] = None
platform: Optional[str] = None
for line in info_lines:
if line.startswith(MATCH_REPORT_PREFIX_NAME):
name = line.partition(MATCH_REPORT_PREFIX_NAME)[-1]
name = line.partition(MATCH_REPORT_PREFIX_NAME)[-1].strip()
_logger.debug("match name found: %s", name)
elif line.startswith(MATCH_REPORT_PREFIX_DATE):
raw_date = line.partition(MATCH_REPORT_PREFIX_DATE)[-1]
raw_date = line.partition(MATCH_REPORT_PREFIX_DATE)[-1].strip()
_logger.debug("match date found: %s", raw_date)
date = parse_match_date(raw_date)
elif line.startswith(MATCH_REPORT_PREFIX_LEVEL):
level_text = line.partition(MATCH_REPORT_PREFIX_LEVEL)[-1].upper()
level_text = line.partition(MATCH_REPORT_PREFIX_LEVEL)[-1].strip().upper()
_logger.debug("attempting to parse match level: %s", level_text)
level = parse_match_level(level_text)
_logger.debug("parsed match level: %s", level)
return ParsedMatchInfo(name=name, raw_date=raw_date, date=date, match_level=level)
elif line.startswith(MATCH_REPORT_PREFIX_REGION):
region = line.partition(MATCH_REPORT_PREFIX_REGION)[-1].strip()
_logger.debug("region found: %s", region)
elif line.startswith(MATCH_REPORT_PREFIX_CLUB_NAME):
club_name = line.partition(MATCH_REPORT_PREFIX_CLUB_NAME)[-1].strip()
_logger.debug("club name found: %s", club_name)
elif line.startswith(MATCH_REPORT_PREFIX_CLUB_CODE):
club_code = line.partition(MATCH_REPORT_PREFIX_CLUB_CODE)[-1].strip()
_logger.debug("club code found: %s", club_code)
elif line.startswith(MATCH_REPORT_PREFIX_PS_PRODUCT):
ps_product = line.partition(MATCH_REPORT_PREFIX_PS_PRODUCT)[-1].strip()
_logger.debug("ps_product found: %s", ps_product)
elif line.startswith(MATCH_REPORT_PREFIX_PS_VERSION):
ps_version = line.partition(MATCH_REPORT_PREFIX_PS_VERSION)[-1].strip()
_logger.debug("ps_version found: %s", ps_version)
elif line.startswith(MATCH_REPORT_PREFIX_PLATFORM):
platform = line.partition(MATCH_REPORT_PREFIX_PLATFORM)[-1].strip()
_logger.debug("platform found: %s", platform)
return ParsedMatchInfo(
name=name,
raw_date=raw_date,
date=date,
match_level=level,
region=region,
club_name=club_name,
club_code=club_code,
ps_product=ps_product,
ps_version=ps_version,
platform=platform,
)
6 changes: 6 additions & 0 deletions hitfactorpy/parsers/match_report/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class ParsedMatchInfo:
raw_date: Optional[str] = None
date: Optional[datetime] = None
match_level: Optional[MatchLevel] = None
region: Optional[str] = None
ps_product: Optional[str] = None
ps_version: Optional[str] = None
platform: Optional[str] = None
club_name: Optional[str] = None
club_code: Optional[str] = None


@dataclass(frozen=True)
Expand Down
6 changes: 6 additions & 0 deletions hitfactorpy/parsers/match_report/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def parse_match_report(report_text: str) -> ParsedMatchReport:
raw_date=match_info.raw_date,
date=match_info.date,
match_level=match_info.match_level,
platform=match_info.platform,
ps_product=match_info.ps_product,
ps_version=match_info.ps_version,
club_code=match_info.club_code,
club_name=match_info.club_name,
region=match_info.region,
competitors=competitors,
stages=stages,
stage_scores=stage_scores,
Expand Down
6 changes: 6 additions & 0 deletions hitfactorpy/parsers/match_report/strict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def parse_match_report(report_text: str) -> ParsedMatchReport:
raw_date=match_info.raw_date,
date=match_info.date,
match_level=match_info.match_level,
platform=match_info.platform,
ps_product=match_info.ps_product,
ps_version=match_info.ps_version,
club_code=match_info.club_code,
club_name=match_info.club_name,
region=match_info.region,
competitors=competitors,
stages=stages,
stage_scores=stage_scores,
Expand Down
1 change: 0 additions & 1 deletion hitfactorpy/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import decimal
from typing import Protocol

from .decimal_ import D4
from .enums import PowerFactor, Scoring
Expand Down
Loading

0 comments on commit 5f31b47

Please sign in to comment.