wrestling package

Module contents

This package is for wrestling statisics.

The data containers provided can be used to represent the various aspects of a match including Wrestlers, Events, Scoring Events, and Matches themselves. These containers can all be extended in the future for other styles or rulesets in the future.

The only package requirement is attrs.

Important notes:
Use Mark class when prompted (as validation will utilize the Mark class extended functionality.)

Submodules

wrestling.base module

Module for base classes and globals used throughout the project.

This module contains the Years dictionary, Result enumeration class, the Mark class which is foundational to all other classes in the project, and the CollegeLabel and HSLabel classes inheriting from the Mark class.

class wrestling.base.CollegeLabel(tag: Union[str, int])

Bases: wrestling.base.Mark

Label class for College scoring event labels.

Parameters:point_value – Numeric point value for label, different than tag value.
__attrs_post_init__()

Post init hook function.

This function checks if the label tag is considered a valid label based on college (folkstyle) ruleset. If not it adjusts the ‘isvalid’ and ‘msg’ attributes accordingly.

point_value
points_dict

Dictionary of valid scoring event labels and their point values.

Returns:Dictionary of labels and their corresponding point values.
Return type:Dict
valid_labels

Set of valid scoring event labels based on current college ruleset.

Returns:Scoring events.
Return type:Set
class wrestling.base.HSLabel(tag: Union[str, int])

Bases: wrestling.base.Mark

Label class for High School scoring event labels.

Parameters:point_value – Numeric point value for label, different than tag value.
__attrs_post_init__()

Post init hook function.

This function checks if the label tag is considered a valid label based on high school (folkstyle) ruleset. If not it adjusts the ‘isvalid’ and ‘msg’ attributes accordingly.

point_value
points_dict

Dictionary of valid scoring event labels and their point values.

Returns:Dictionary of labels and their corresponding point values.
Return type:Dict
valid_labels

Set of valid scoring event labels based on current college ruleset.

Returns:Scoring events.
Return type:Set
class wrestling.base.Mark(tag: Union[str, int])

Bases: object

Mark object which acts as a Meta class for str and int inputs.

This class should be used whenever validation on a class field is stonger than simple type validation. Prompts will be provided for established classes.

Parameters:
  • String or Integer value for the Mark. (tag) –
  • isvalid – Whether tag is valid or invalid, default to True.
  • msg – Message for tag, defaults to empty string, should be changed if isvalid
  • False. (is) –
check_tag(attribute, value)

Attrs based validator function for tag attribute.

Raises:TypeError – TypeError if tag value is not int or str type.
isvalid
msg
tag
class wrestling.base.Result

Bases: enum.IntEnum

Enumeration class for match Results.

This class contains information on Results structured as an enumeration. There are additional properties for other metrics that can be identified based on the Result.

Parameters:enum (IntEnum) – IntEnum super class.
Returns:String abbreviated representation of the result. value (int): Numeric representation of the result.
Return type:name (str)
LD = -1
LF = -4
LM = -2
LT = -3
NC = 0
WD = 1
WF = 4
WM = 2
WT = 3
bonus

Identifies whether Result is considered bonus or not.

Returns:True if considered bonus, else False.
Return type:bool
pin

Identifies if Result is a pin variation.

Returns:True if method of result is Fall, else False.
Return type:bool
team_points

Calculates team points earned based on Result.

Returns:Number of team points earned.
Return type:int
text

Expanded text representation of result.

Returns:Full text of result.
Return type:str
win

Win or Loss.

Returns:True if Win, False if Loss.
Return type:bool
wrestling.base.YEARS = {-1: 'Unknown', 0: 'K', 1: '1st', 2: '2nd', 3: '3rd', 4: '4th', 5: '5th', 6: '6th', 7: '7th', 8: '8th', 9: '9th', 10: '10th', 11: '11th', 12: '12th', 13: 'Fr.', 14: 'RS Fr.', 15: 'So.', 16: 'RS So.', 17: 'Jr.', 18: 'RS Jr.', 19: 'Sr.', 20: 'RS Sr.'}

Module level variable containing string variants of acceptable years of eligibility.

Type:dict[int, str]

wrestling.events module

Module for Events.

This module builds the Events class with validation for its fields. When validation is stronger than simple type validation, the Mark class is used in replace of traditional str or int classes to track accuracy.

Example

event = Event(name=’Practice’, kind=Mark(‘Dual Meet’))

class wrestling.events.Event(name, kind: wrestling.base.Mark)

Bases: object

Class for storing event related data.

Parameters:
  • name (str) – Name of the event.
  • kind (str) – Type of event, either ‘Dual Meet’ or ‘Tournament’.
__attrs_post_init__()

Post init function to call Mark input handlers.

kind

Type of event.

Returns:Type of event.
Return type:str
name
to_dict() → Dict[str, str]

Creates a dictionary representation of an Event instance.

Returns:Dictionary with the name and kind of the Event instance.
Return type:Dict
type_input_handler() → None

Function to manage validity of ‘kind’ input attribute via Mark class.

wrestling.events.convert_event_name(name: str) → str

Strips and capitalizes a string.

This function takes a string input and, if the string length is larger than 1, capitalized the string and strips leading/trailing whitespaces.

Parameters:name – Any string of any length.
Returns:Capitalized and stripped string.
Return type:str

wrestling.matches module

Module for Matches.

This module builds the Match base class with validation for its fields. When validation is stronger than simple type validation, the Mark class is used in replace of traditional str or int classes to track accuracy.

Example

>>>match = CollegeMatch(**kwargs)

class wrestling.matches.CollegeMatch(*, id: str, base_url: Optional[str] = None, event: wrestling.events.Event, date: Union[str, datetime.datetime], result: wrestling.base.Result, overtime: Optional[bool] = False, focus: wrestling.wrestlers.Wrestler, opponent: wrestling.wrestlers.Wrestler, weight: wrestling.base.Mark, duration: Optional[int] = 420, time_series: Tuple[wrestling.scoring.CollegeScoring])

Bases: wrestling.matches.Match

Match for college ruleset.

Parameters:
  • duration (Optional[int]) – Length of match, defaults to 420.
  • time_series (Tuple([CollegeScoring])) – sequence of scoring events.
Raises:
  • TypeError – All items in time_series must be CollegeScoring instances.
  • ValueError – time_series must be sorted chronologically.
__attrs_post_init__()

Post init function to call Mark input handlers from super-class.

add_college_ts_points()
check_time_series(attribute, value)

Validates that all time_series are of the correct type and in the correct order.

duration
time_series
class wrestling.matches.HSMatch(*, id: str, base_url: Optional[str] = None, event: wrestling.events.Event, date: Union[str, datetime.datetime], result: wrestling.base.Result, overtime: Optional[bool] = False, focus: wrestling.wrestlers.Wrestler, opponent: wrestling.wrestlers.Wrestler, weight: wrestling.base.Mark, duration: Optional[int] = 360, time_series: Tuple[wrestling.scoring.HSScoring])

Bases: wrestling.matches.Match

Match for college ruleset.

Parameters:
  • duration (Optional[int]) – Length of match, defaults to 360.
  • time_series (Tuple([HSScoring])) – sequence of scoring events.
Raises:
  • TypeError – All items in time_series must be HSScoring instances.
  • ValueError – time_series must be sorted chronologically.
__attrs_post_init__()

Post init function to call Mark input handlers from super-class.

add_hs_ts_points()
check_time_series(attribute, value)

Validates that all time_series are of the correct type and in the correct order.

duration
time_series
class wrestling.matches.Match(*, id: str, base_url: Optional[str] = None, event: wrestling.events.Event, date: Union[str, datetime.datetime], result: wrestling.base.Result, overtime: Optional[bool] = False, focus: wrestling.wrestlers.Wrestler, opponent: wrestling.wrestlers.Wrestler, weight: wrestling.base.Mark)

Bases: object

Match base class.

Parameters:
  • id (str) – Match id.
  • base_url (Optional[Union[str, None]]) – Url to prepend to ‘id’, default to None.
  • event (Event) – Event instance for the event the match occurred at.
  • date (datetime) – Datetime the match occurred at.
  • result (Result) – Result of the match.
  • overtime ([Optional[bool]]) – If the match went into overtime, default to False.
  • focus (Wrestler) – Wrestler instance for the primary wrestler.
  • opponent (Wrestler) – Wrestler instance for the opponent.
  • weight (Mark) – Weight class the match was contested at.
  • isvalid (bool) – Whether the match is valid or has errors.
  • invalid_messages (tuple) – Tuple of (brief) match error messages, can be empty.
  • invalid_count (int) – Count of invalid Marks found in the match.
Raises:

ValueError – Overtime cannot be True if Result method is Tech.

__attrs_post_init__()

Post init function to call Mark input handlers.

base_url
calculate_pts(athlete_filter: str) → int

Calculate total points scored.

Parameters:athlete_filter – ‘f’ or ‘o’ to filter by ‘focus’ or ‘opponent’
Returns:Sum of points scored.
Return type:int
check_overtime(attribute, value)

Checks overtime validity.

check_weight_input()

Function to manage validity of ‘kind’ input attribute via Mark class.

date
event
focus
focus_pts

Number of points the primary wrestler scored.

Returns:Focus points scored
Return type:int
invalid_count
invalid_messages
isvalid
mov

Margin of Victory.

Returns:Difference between focus_points and opponent_points
Return type:int
opp_pts

Number of points the opponent wrestler scored.

Returns:Opponent points scored
Return type:int
opponent
overtime
result
set_validity() → bool

Identifies instance validity status.

This method returns boolean and is used in the attrs post_init hook to set the instance ‘isvalid’ attribute. However, this method also sets the instance ‘invalid_messages’ and ‘invalid_count’ attributes according to the errors it detects when searching the instance.

Any errors detected are input as brief descriptors into the ‘invalid_messages’ attribute of the instance.

The ‘invalid_counts’ is simply a count of how many errors were discovered.

Returns:True if all Marks are valid, else False (if any Marks are invalid).
Return type:bool
td_diff

Takedown differential.

Returns:Difference in primary wrestler takedowns and opponent takedowns
Return type:int
to_dict(ts_only: Optional[bool] = False, results_only: Optional[bool] = False) → Union[Dict[KT, VT], Tuple]

Converts instance to dict representation.

Parameters:
  • ts_only – If you only want the time_series of the instance. Defaults to False.
  • results_only – If you only want the results of the instance. Defaults to False.
Returns:

Dictionary of instance values.

Return type:

Dict[str, Union[str, int]]

video_url

concats base_url and id.

Returns:video_url
Return type:str
Type:Video url
weight

Weight class match contested at.

Returns:Weight.
Return type:str

wrestling.scoring module

Module for Scoring Events.

This module builds the Scoring Events base class with validation for its fields. When validation is stronger than simple type validation, the Mark class is used in replace of traditional str or int classes to track accuracy.

Example

>>>scoring_event = CollegeScoring(
time_stamp=time(hour=0, minute=5, second=15), initiator=’red’, focus_color=’green’, period=2, label=CollegeLabel(‘T2’)

)

class wrestling.scoring.CollegeScoring(*, time_stamp: Union[datetime.time, str], initiator: str, focus_color: str, period: int, label: wrestling.base.CollegeLabel)

Bases: wrestling.scoring.ScoringEvent

College version of a Scoring Event.

Parameters:label (CollegeLabel) – Label for the action.
label

Label of the action that occurred.

class wrestling.scoring.HSScoring(*, time_stamp: Union[datetime.time, str], initiator: str, focus_color: str, period: int, label: wrestling.base.HSLabel)

Bases: wrestling.scoring.ScoringEvent

High School version of a Scoring Event.

Parameters:label (HSLabel) – Label for the action.
label

Label of the action that occurred.

class wrestling.scoring.ScoringEvent(*, time_stamp: Union[datetime.time, str], initiator: str, focus_color: str, period: int)

Bases: object

Scoring Event base class for any scoring action in a match.

Parameters:
  • time_stamp (time) – Time the action occured.
  • initiator (str) – Who initiated the action, red or green.
  • focus_color (str) – Focus of the match.
  • period (int) – Period in which the action occured.
Raises:
  • ValueError – Hour parameter of time_stamp cannot be non-zero.
  • ValueError – ‘focus_color’ and ‘initiator’ must be either ‘red’ or ‘green’
check_time_stamp(attribute, val)

Attrs validator, checks timestamp that hour is not zero.

focus_color
focus_score
formatted_label

String formatted label.

Raises:ValueError – initiator and focus_color must be either red or green.
Returns:Label with focus (f) or opponent (o) prefix.
Return type:str
formatted_time

String formatted time.

Returns:Minute:Second string formatted time_stamp.
Return type:str
initiator
label

Label of the action that occurred.

opp_score
period
time_stamp
to_dict() → Dict[str, Union[int, str, wrestling.base.CollegeLabel, wrestling.base.HSLabel]]

Converts instance to dict.

Returns:Dictionary representation of Scoring Event instance.
Return type:Dict

wrestling.sequence module

Module for determining validity of time_series sequences.

This module checks the time_series attribute of a Match for its conditional validity based on the position. It is used in the Match.time_series validator. Helper functions for checking the next event in a sequence based on a given position are also provided.

wrestling.sequence.COLLEGE_SEQUENCES = {'always': {'fBOT', 'fC', 'fDEFER', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}, 'bottom': {'fBOT', 'fC', 'fDEFER', 'fE1', 'fNEU', 'fP1', 'fP2', 'fR2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oN2', 'oN4', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}, 'neutral': {'fBOT', 'fC', 'fDEFER', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fT2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oT2', 'oTOP', 'oWS'}, 'top': {'fBOT', 'fC', 'fDEFER', 'fN2', 'fN4', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oE1', 'oNEU', 'oP1', 'oP2', 'oR2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}}

Dictionary of valid college next-moves based on position.

wrestling.sequence.HS_SEQUENCES = {'always': {'fBOT', 'fC', 'fDEFER', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}, 'bottom': {'fBOT', 'fC', 'fDEFER', 'fE1', 'fNEU', 'fP1', 'fP2', 'fR2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oN2', 'oN3', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}, 'neutral': {'fBOT', 'fC', 'fDEFER', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fT2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oNEU', 'oP1', 'oP2', 'oRT1', 'oS1', 'oS2', 'oT2', 'oTOP', 'oWS'}, 'top': {'fBOT', 'fC', 'fDEFER', 'fN2', 'fN3', 'fNEU', 'fP1', 'fP2', 'fRT1', 'fS1', 'fS2', 'fTOP', 'fWS', 'oBOT', 'oC', 'oDEFER', 'oE1', 'oNEU', 'oP1', 'oP2', 'oR2', 'oRT1', 'oS1', 'oS2', 'oTOP', 'oWS'}}

Dictionary of valid high school next-moves based on position.

wrestling.sequence.check_bottom(score: Union[wrestling.scoring.CollegeScoring, wrestling.scoring.HSScoring], seq: Set[str])

Checks if next move is valid in bottom position.

Parameters:
  • score – Either CollegeScoring or HSScoring instance.
  • seq (Dict) – HS_SEQUENCES or COLLEGE_SEQUENCES to check the ‘score’ against.
wrestling.sequence.check_neutral(score: Union[wrestling.scoring.CollegeScoring, wrestling.scoring.HSScoring], seq: Set[str])

Checks if next move is valid in neutral position.

Parameters:
  • score – Either CollegeScoring or HSScoring instance.
  • seq (Dict) – HS_SEQUENCES or COLLEGE_SEQUENCES to check the ‘score’ against.
wrestling.sequence.check_top(score: Union[wrestling.scoring.CollegeScoring, wrestling.scoring.HSScoring], seq: Set[str])

Checks if next move is valid in top position.

Parameters:
  • score – Either CollegeScoring or HSScoring instance.
  • seq (Dict) – HS_SEQUENCES or COLLEGE_SEQUENCES to check the ‘score’ against.
wrestling.sequence.isvalid_sequence(level: str, time_series: Tuple[Union[wrestling.scoring.HSScoring, wrestling.scoring.CollegeScoring]]) → bool

Checks if entire sequence is valid.

Parameters:
  • level – ‘high school’ or ‘college’ level for sequence analysis.
  • time_series – Tuple of sorted match time_series events.
Raises:
  • ValueError – Invalid level.
  • ValueError – Not sorted time_series.
  • ValueError – Invalid position.
Returns:

True if sequence is valid, otherwise raises ValueError.

Return type:

bool

wrestling.wrestlers module

Module for creating Wrestler objects.

This module builds the Wrestler class with validation for its fields. When validation is stronger than simple type validation, the Mark class is used in replace of traditional str or int classes to track accuracy.

Example

wrestler = Wrestler(name=’Anthony, Nick’, team=”Eagles”, grade=Mark(‘Sr.’))

class wrestling.wrestlers.Wrestler(*, name, team, grade_int: int = -1)

Bases: object

Wrestler object.

Parameters:
  • name (str) – Name of the wrestler. Ex: Last, First.
  • team (str) – Team the wrestler represents.
  • grade (Union[int, None]) – Grade/eligibility of the wrestler, default to None.
grade_int
grade_str

Eligibility of athlete.

Returns:Grade/Eligbility of athlete.
Return type:str
name
team
to_dict() → Dict[str, str]

Creates a dictionary representation of an Wrestler instance.

Returns:Dictionary with the name, team, and grade of the Wrestler instance.
Return type:Dict
wrestling.wrestlers.convert_to_title(name: str) → str

Makes a string title-ized.

Parameters:name – Any string.
Returns:Capitalized and white-spaced stripped string.
Return type:str