Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #44

Merged
merged 27 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
20880f4
Disable too many arguments in pylint for target and rounds.
jatkinson1000 Aug 19, 2023
0332268
Refactor handicap equations to simplify parameters dataclass.
jatkinson1000 Aug 19, 2023
2de415c
Revert HC_DATA variables to lowercase
jatkinson1000 Aug 20, 2023
1385083
linting of handicaps wip
jatkinson1000 Aug 20, 2023
e10ce47
Merge branch 'main' into linting for refactored classifications.
jatkinson1000 Aug 27, 2023
33077f6
Simple linting of files in archeryutils/
jatkinson1000 Aug 31, 2023
3f53416
Refactor outdoor classifications to abstract distance assignments.
jatkinson1000 Aug 31, 2023
1ce33cc
Bug fix reading json in indoor, mypy typo fix in field_tests.
jatkinson1000 Aug 31, 2023
16403fa
Classifications refactor to address U16 Lady Longbow Bug.
jatkinson1000 Aug 31, 2023
7515065
Clean linting errors in load_rounds.py
jatkinson1000 Sep 2, 2023
dfcc7e2
Linting refactor of handicap code.
jatkinson1000 Sep 2, 2023
79213b7
Bump to python 3.9+.
jatkinson1000 Sep 2, 2023
1d343f7
Fix IFAA min score error and add min_score tests.
jatkinson1000 Sep 2, 2023
bdf7fed
Add tests for non-indoor and -outdoor bowstyles.
jatkinson1000 Sep 2, 2023
3cfb1a3
Apply black to satisy older version.
jatkinson1000 Sep 2, 2023
dc14ff3
linting and refactoring of handicap files.
jatkinson1000 Sep 2, 2023
876ca22
Enforce pydocstyle.
jatkinson1000 Sep 2, 2023
09ba3a6
Disable duplicate code warning for classifications and tests due to s…
jatkinson1000 Sep 2, 2023
dda7c20
Bugfix for clearing gaps in AA tables.
jatkinson1000 Sep 2, 2023
a16328b
Add tests for abstracted handicap functions and table functions.
jatkinson1000 Sep 2, 2023
52a81b6
Use mocker to test opening HcParams json file.
jatkinson1000 Sep 2, 2023
75dd008
bug fix in pyproject.toml add pytest-mock in correct dep set.
jatkinson1000 Sep 2, 2023
1ef757a
Update handicap mocking to satisfy mypy and ignore pylint.
jatkinson1000 Sep 2, 2023
0449549
Add pytest and mock to linting requirements.
jatkinson1000 Sep 2, 2023
52642c1
Update coverage to use pytest-mock.
jatkinson1000 Sep 2, 2023
e7833ac
Refactor and improve handicap printing routines to generate better ou…
jatkinson1000 Sep 3, 2023
9b51ff5
Add handicap table tests and refactor into separate file.
jatkinson1000 Sep 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install pytest coverage
- run: pip install pytest pytest-mock coverage
pip install .

# annotate each step with `if: always` to run all regardless
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
include:
- os: ubuntu-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.8"
- os: ubuntu-latest
python-version: "3.7"
# - os: ubuntu-latest
# python-version: "3.8"
# - os: ubuntu-latest
# python-version: "3.7"

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# archeryutils

![GitHub](https://img.shields.io/github/license/jatkinson1000/archeryutils)
[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jatkinson1000/archeryutils/testing.yaml)
[![codecov](https://codecov.io/gh/jatkinson1000/archeryutils/branch/main/graph/badge.svg?token=AZU7G6H8T0)](https://codecov.io/gh/jatkinson1000/archeryutils)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand Down
2 changes: 1 addition & 1 deletion archeryutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Package providing code for various archery utilities."""
from archeryutils import load_rounds, rounds, targets
from archeryutils.handicaps import handicap_equations, handicap_functions
import archeryutils.classifications as classifications
from archeryutils import classifications

__all__ = [
"rounds",
Expand Down
7 changes: 7 additions & 0 deletions archeryutils/classifications/agb_field_classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
agb_field_classification_scores

"""
# Due to structure of similar classification schemes they may trigger duplicate code.
# => disable for classification files and tests
# pylint: disable=duplicate-code

import re
from typing import List, Dict, Any
import numpy as np
Expand Down Expand Up @@ -288,6 +292,9 @@ def agb_field_classification_scores(
ArcheryGB Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7
"""
# Unused roundname argument to keep consistency with other classification functions
# pylint: disable=unused-argument

# deal with reduced categories:
if age_group.lower().replace(" ", "") in ("adult", "50+", "under21"):
age_group = "Adult"
Expand Down
60 changes: 31 additions & 29 deletions archeryutils/classifications/agb_indoor_classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
calculate_agb_indoor_classification
agb_indoor_classification_scores
"""
# Due to structure of similar classification schemes they may trigger duplicate code.
# => disable for classification files and tests
# pylint: disable=duplicate-code

from typing import List, Dict, Any
import numpy as np

Expand Down Expand Up @@ -59,7 +63,7 @@ def _make_agb_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
# Read in gender info as list of dicts
agb_genders = cls_funcs.read_genders_json()
# Read in classification names as dict
agb_classes_info_in = cls_funcs.read_classes_in_json()
agb_classes_info_in = cls_funcs.read_classes_json("agb_indoor")
agb_classes_in = agb_classes_info_in["classes"]
agb_classes_in_long = agb_classes_info_in["classes_long"]

Expand All @@ -69,40 +73,36 @@ def _make_agb_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
# loop over genders
classification_dict = {}
for bowstyle in agb_bowstyles:
for age in agb_ages:
for gender in agb_genders:
# Get age steps from Adult
age_steps = age["step"]

# Get number of gender steps required
# Perform fiddle in age steps where genders diverge at U15/U16
if gender.lower() == "female" and age["step"] <= 3:
gender_steps = 1
else:
gender_steps = 0

for gender in agb_genders:
for age in agb_ages:
groupname = cls_funcs.get_groupname(
bowstyle["bowstyle"], gender, age["age_group"]
)

class_hc = np.empty(len(agb_classes_in))
classification_dict[groupname] = {
"classes": agb_classes_in,
"classes_long": agb_classes_in_long,
}

# set step from datum based on age and gender steps required
delta_hc_age_gender = cls_funcs.get_age_gender_step(
gender,
age["step"],
bowstyle["ageStep_in"],
bowstyle["genderStep_in"],
)

classification_dict[groupname]["class_HC"] = np.empty(
len(agb_classes_in)
)
for i in range(len(agb_classes_in)):
# Assign handicap for this classification
class_hc[i] = (
classification_dict[groupname]["class_HC"][i] = (
bowstyle["datum_in"]
+ age_steps * bowstyle["ageStep_in"]
+ gender_steps * bowstyle["genderStep_in"]
+ delta_hc_age_gender
+ (i - 1) * bowstyle["classStep_in"]
)

# TODO: class names and long are duplicated many times here
# Consider a method to reduce this (affects other code)
classification_dict[groupname] = {
"classes": agb_classes_in,
"class_HC": class_hc,
"classes_long": agb_classes_in_long,
}

return classification_dict


Expand Down Expand Up @@ -254,17 +254,19 @@ def agb_indoor_classification_scores(

# Handle possibility of gaps in the tables or max scores by checking 1 HC point
# above current (floored to handle 0.5) and amending accordingly
for i, (sc, hc) in enumerate(zip(int_class_scores, group_data["class_HC"])):
for i, (score, handicap) in enumerate(
zip(int_class_scores, group_data["class_HC"])
):
next_score = hc_eq.score_for_round(
ALL_INDOOR_ROUNDS[cls_funcs.strip_spots(roundname)],
np.floor(hc) + 1,
np.floor(handicap) + 1,
hc_scheme,
hc_params,
round_score_up=True,
)[0]
if next_score == sc:
if next_score == score:
# If already at max score this classification is impossible
if sc == ALL_INDOOR_ROUNDS[roundname].max_score():
if score == ALL_INDOOR_ROUNDS[roundname].max_score():
int_class_scores[i] = -9999
# If gap in table increase to next score
# (we assume here that no two classifications are only 1 point apart...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
calculate_AGB_old_indoor_classification
AGB_old_indoor_classification_scores
"""
# Due to structure of similar classification schemes they may trigger duplicate code.
# => disable for classification files and tests
# pylint: disable=duplicate-code

from typing import List, Dict, Any
import numpy as np

Expand Down
Loading