Skip to content

Commit

Permalink
Tidying and linting of refactored classification files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jatkinson1000 committed Aug 24, 2023
1 parent 949147e commit dcc36c3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 108 deletions.
8 changes: 3 additions & 5 deletions archeryutils/classifications/agb_field_classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
Routine Listings
----------------
_make_AGB_field_classification_dict
calculate_AGB_field_classification
AGB_field_classification_scores
_make_agb_field_classification_dict
calculate_agb_field_classification
agb_field_classification_scores
"""
from typing import List, Dict, Any
Expand Down Expand Up @@ -204,8 +204,6 @@ def calculate_agb_field_classification(
ArcheryGB 2023 Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7 (2023)
"""
# TODO: Need routines to sanitise/deal with variety of user inputs

# deal with reduced categories:
if age_group.lower().replace(" ", "") in ("adult", "50+", "under21"):
age_group = "Adult"
Expand Down
37 changes: 17 additions & 20 deletions archeryutils/classifications/agb_indoor_classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Routine Listings
----------------
_make_AGB_old_indoor_classification_dict
calculate_AGB_indoor_classification
AGB_indoor_classification_scores
_make_agb_old_indoor_classification_dict
calculate_agb_indoor_classification
agb_indoor_classification_scores
"""
from typing import List, Dict, Any
import numpy as np
Expand All @@ -15,6 +15,14 @@
import archeryutils.classifications.classification_utils as cls_funcs


ALL_INDOOR_ROUNDS = load_rounds.read_json_to_round_dict(
[
"AGB_indoor.json",
"WA_indoor.json",
]
)


def _make_agb_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
"""
Generate new (2023) AGB indoor classification data.
Expand Down Expand Up @@ -77,10 +85,10 @@ def _make_agb_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
bowstyle["bowstyle"], gender, age["age_group"]
)

class_HC = np.empty(len(agb_classes_in))
class_hc = np.empty(len(agb_classes_in))
for i in range(len(agb_classes_in)):
# Assign handicap for this classification
class_HC[i] = (
class_hc[i] = (
bowstyle["datum_in"]
+ age_steps * bowstyle["ageStep_in"]
+ gender_steps * bowstyle["genderStep_in"]
Expand All @@ -91,7 +99,7 @@ def _make_agb_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
# Consider a method to reduce this (affects other code)
classification_dict[groupname] = {
"classes": agb_classes_in,
"class_HC": class_HC,
"class_HC": class_hc,
"classes_long": agb_classes_in_long,
}

Expand Down Expand Up @@ -139,8 +147,6 @@ def calculate_agb_indoor_classification(
ArcheryGB 2023 Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7 (2023)
"""
# TODO: Need routines to sanitise/deal with variety of user inputs

if bowstyle.lower() in ("traditional", "flatbow", "asiatic"):
bowstyle = "Barebow"

Expand Down Expand Up @@ -207,15 +213,6 @@ def agb_indoor_classification_scores(
ArcheryGB Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7
"""
# TODO: Should this be defined outside the function to reduce I/O or does
# it have no effect?
all_indoor_rounds = load_rounds.read_json_to_round_dict(
[
"AGB_indoor.json",
"WA_indoor.json",
]
)

# deal with reduced categories:
if bowstyle.lower() in ("flatbow", "traditional", "asiatic"):
bowstyle = "Barebow"
Expand All @@ -234,7 +231,7 @@ def agb_indoor_classification_scores(
# Enforce full size face
class_scores = [
hc_eq.score_for_round(
all_indoor_rounds[cls_funcs.strip_spots(roundname)],
ALL_INDOOR_ROUNDS[cls_funcs.strip_spots(roundname)],
group_data["class_HC"][i],
hc_scheme,
hc_params,
Expand All @@ -256,15 +253,15 @@ def agb_indoor_classification_scores(
# above current (floored to handle 0.5) and amending accordingly
for i, (sc, hc) 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)],
ALL_INDOOR_ROUNDS[cls_funcs.strip_spots(roundname)],
np.floor(hc) + 1,
hc_scheme,
hc_params,
round_score_up=True,
)[0]
if next_score == sc:
# If already at max score this classification is impossible
if sc == all_indoor_rounds[roundname].max_score():
if sc == 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
42 changes: 12 additions & 30 deletions archeryutils/classifications/agb_old_indoor_classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
import archeryutils.classifications.classification_utils as cls_funcs


ALL_INDOOR_ROUNDS = load_rounds.read_json_to_round_dict(
[
"AGB_indoor.json",
"WA_indoor.json",
]
)


def _make_agb_old_indoor_classification_dict() -> Dict[str, Dict[str, Any]]:
"""
Generate AGB outdoor classification data.
Expand Down Expand Up @@ -73,7 +81,6 @@ def calculate_agb_old_indoor_classification(
bowstyle: str,
gender: str,
age_group: str,
hc_scheme: str = "AGBold",
) -> str:
"""
Calculate AGB indoor classification from score.
Expand All @@ -93,8 +100,6 @@ def calculate_agb_old_indoor_classification(
archer's gender under AGB outdoor target rules
age_group : str
archer's age group under AGB outdoor target rules
hc_scheme : str
handicap scheme to be used for legacy purposes. Default AGBold
Returns
-------
Expand All @@ -106,17 +111,6 @@ def calculate_agb_old_indoor_classification(
ArcheryGB 2023 Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7 (2023)
"""
# TODO: Need routines to sanitise/deal with variety of user inputs

# TODO: Should this be defined outside the function to reduce I/O or does
# it have no effect?
all_indoor_rounds = load_rounds.read_json_to_round_dict(
[
"AGB_indoor.json",
"WA_indoor.json",
]
)

# deal with reduced categories:
age_group = "Adult"
if bowstyle.lower() not in ("compound"):
Expand All @@ -130,9 +124,9 @@ def calculate_agb_old_indoor_classification(
# Get scores required on this round for each classification
class_scores = [
hc_eq.score_for_round(
all_indoor_rounds[roundname],
ALL_INDOOR_ROUNDS[roundname],
group_data["class_HC"][i],
hc_scheme,
"AGBold",
hc_params,
round_score_up=True,
)[0]
Expand Down Expand Up @@ -165,7 +159,6 @@ def agb_old_indoor_classification_scores(
bowstyle: str,
gender: str,
age_group: str,
hc_scheme: str = "AGBold",
) -> List[int]:
"""
Calculate AGB indoor classification scores for category.
Expand All @@ -183,8 +176,6 @@ def agb_old_indoor_classification_scores(
archer's gender under AGB outdoor target rules
age_group : str
archer's age group under AGB outdoor target rules
hc_scheme : str
handicap scheme to be used for legacy purposes. Default AGBold
Returns
-------
Expand All @@ -196,15 +187,6 @@ def agb_old_indoor_classification_scores(
ArcheryGB Rules of Shooting
ArcheryGB Shooting Administrative Procedures - SAP7
"""
# TODO: Should this be defined outside the function to reduce I/O or does
# it have no effect?
all_indoor_rounds = load_rounds.read_json_to_round_dict(
[
"AGB_indoor.json",
"WA_indoor.json",
]
)

# deal with reduced categories:
age_group = "Adult"
if bowstyle.lower() not in ("compound"):
Expand All @@ -218,9 +200,9 @@ def agb_old_indoor_classification_scores(
# Get scores required on this round for each classification
class_scores = [
hc_eq.score_for_round(
all_indoor_rounds[roundname],
ALL_INDOOR_ROUNDS[roundname],
group_data["class_HC"][i],
hc_scheme,
"AGBold",
hc_params,
round_score_up=True,
)[0]
Expand Down
Loading

0 comments on commit dcc36c3

Please sign in to comment.