Skip to content

Commit

Permalink
Add submit_crescendo function and related checks
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBottone committed Jan 6, 2024
1 parent 7666f1f commit 2315f96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ dmypy.json
migrations/

.vscode/
.DS_Store
24 changes: 24 additions & 0 deletions highscores/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def submit_over_under(score_obj: Score) -> Union[str, None]:
return submit_score(score_obj, over_under_clean_code_check)


def submit_crescendo(score_obj: Score) -> Union[str, None]:
return submit_score(score_obj, crescendo_clean_code_check)


def decode_time_data(in_string: str) -> str:
out_bytes = ""

Expand Down Expand Up @@ -268,6 +272,10 @@ def over_under_clean_code_check(score_obj: Score) -> Union[str, None]:
return clean_code_check(score_obj, check_over_under_game_settings, check_score)


def crescendo_clean_code_check(score_obj: Score) -> Union[str, None]:
return clean_code_check(score_obj, check_crescendo_game_settings, check_score)


def extract_clean_code_info(score_obj: Score) -> tuple[str, list[str], str, str, str, str, str]:
""" Extracts the relevant information from the clean code.
:param score_obj: Score object to extract from
Expand Down Expand Up @@ -444,6 +452,20 @@ def check_over_under_game_settings(game_options: list, restart_option: str, game
return None # No error


def check_crescendo_game_settings(game_options: list, restart_option: str, game_index: str) -> Union[str, None]:
""" Checks if the Crescendo game settings are valid.
:return: None if the settings are valid, or a response with an error message if they are not.
"""
if (game_index != '15'):
return 'Wrong game! This form is for Crescendo.'
if (game_options[2] != '1'):
return 'You must set setting 3 to "1" for high score submissions.'
if (game_options[3] != '4'):
return 'You must set setting 4 to "4" for high score submissions.'

return None # No error


def check_robot_type(score_obj: Score, robot_model: str) -> Union[str, None]:
""" Checks if the robot model is valid.
:return: None if the robot model is valid, or a response with an error message if it is not.
Expand Down Expand Up @@ -608,6 +630,7 @@ def check_time_data(score_obj: Score) -> Union[str, None]:
"su": submit_spin_up,
"cs": submit_centerstage,
"ou": submit_over_under,
"cr": submit_crescendo,
}

game_to_submit_func = {
Expand All @@ -620,4 +643,5 @@ def check_time_data(score_obj: Score) -> Union[str, None]:
"Spin Up": submit_spin_up,
"CENTERSTAGE": submit_centerstage,
"Over Under": submit_over_under,
"Crescendo": submit_crescendo,
}

0 comments on commit 2315f96

Please sign in to comment.