Skip to content

Commit

Permalink
update run output, prevent line ending conversions for docker-entrypo…
Browse files Browse the repository at this point in the history
…int.sh, update settings names for lists, and update docs]
  • Loading branch information
uberfastman committed Dec 2, 2023
1 parent 3a22bcf commit 2366459
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.txt text
*.sh text eol=lf
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ For those of you who wish for the report to include a custom subset of the avail
The report can also have some of its visual formatting set. The following formatting options are available:

FONT=helvetica
SUPPORTED_FONTS=helvetica,times,symbola,opensansemoji,sketchcollege,leaguegothic
SUPPORTED_FONTS_LIST=helvetica,times,symbola,opensansemoji,sketchcollege,leaguegothic
FONT_SIZE=12
IMAGE_QUALITY=75
MAX_DATA_CHARS=24

The values seen in the `SUPPORTED_FONTS` environment variable are the currently supported fonts for the app.
The values seen in the `SUPPORTED_FONTS_LIST` environment variable are the currently supported fonts for the app.

The player headshots retrieved for individual team pages can come in varying resolutions, and when they are extremely high resolution, they can inflate the size of the report PDF. In order to allow the user to reduce the size of the final report PDF if desired, the following option is available:

Expand All @@ -564,29 +564,29 @@ Once the initial images have been retrieved and quality has been adjusted, the r

In addition to turning on/off the features of the report PDF itself, there are additional setting, which are as follows:

| Option | Description |
|-----------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------|
| `PLATFORM` | Fantasy football platform for which you are generating a report. |
| `SUPPORTED_PLATFORMS` | Comma-delimited list of currently supported fantasy football platforms. |
| `LEAGUE_ID` | The league id of the fantasy football for which you are running the report. |
| `DATA_DIR_LOCAL_PATH` | Directory where saved data is stored. |
| `OUTPUT_DIR_LOCAL_PATH` | Directory where generated reports are created. |
| `WEEK_FOR_REPORT` | Selected NFL season week for which to generate a report. |
| `NUM_PLAYOFF_SIMULATIONS` | Number of Monte Carlo simulations to run for playoff predictions. The more sims, the longer the report will take to generate. |
| `NUM_REGULAR_SEASON_WEEKS` | Number of regular season weeks in selected league. |
| `NUM_PLAYOFF_SLOTS` | Number of playoff slots in selected league. |
| `NUM_PLAYOFF_SLOTS_PER_DIVISION` | Numbers of teams per division that qualify for the playoffs. |
| `COACHING_EFFICIENCY_DISQUALIFIED_TEAMS` | Teams manually DQed from coaching efficiency rankings (if any). |
| `GOOGLE_DRIVE_UPLOAD_BOOL` | Turn on (`True`) or off (`False`) the Google Drive upload functionality. |
| `GOOGLE_DRIVE_AUTH_TOKEN_LOCAL_PATH` | Google OAuth refresh token. |
| `GOOGLE_DRIVE_FOLDER_PATH` | Online folder in Google Drive where reports are uploaded. |
| `GOOGLE_DRIVE_REUPLOAD_FILE_LOCAL_PATH` | File path of selected report that you wish to re-upload to Google Drive by running `upload_to_google_drive.py` as a standalone script. |
| `SLACK_POST_BOOL` | Turn on (`True`) or off (`False`) the Slack upload functionality. |
| `SLACK_AUTH_TOKEN_LOCAL_PATH` | Slack authentication token. |
| `SLACK_POST_OR_FILE` | Choose whether you post a link to the generated report on Slack (set to `post`), or upload the report PDF itself to Slack (set to `file`). |
| `SLACK_CHANNEL` | Selected Slack channel where reports are uploaded. |
| `SLACK_CHANNEL_NOTIFY_BOOL` | Turn on (`True`) or off (`False`) using the `@here` slack tag to notify chosen Slack channel of a posted report file. |
| `SLACK_REPOST_FILE_LOCAL_PATH` | File path of selected report that you wish to repost to Slack. |
| Option | Description |
|----------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `PLATFORM` | Fantasy football platform for which you are generating a report. |
| `SUPPORTED_PLATFORMS_LIST` | Comma-delimited list (with no spaces between items) of currently supported fantasy football platforms. |
| `LEAGUE_ID` | The league id of the fantasy football for which you are running the report. |
| `DATA_DIR_LOCAL_PATH` | Directory where saved data is stored. |
| `OUTPUT_DIR_LOCAL_PATH` | Directory where generated reports are created. |
| `WEEK_FOR_REPORT` | Selected NFL season week for which to generate a report. |
| `NUM_PLAYOFF_SIMULATIONS` | Number of Monte Carlo simulations to run for playoff predictions. The more sims, the longer the report will take to generate. |
| `NUM_REGULAR_SEASON_WEEKS` | Number of regular season weeks in selected league. |
| `NUM_PLAYOFF_SLOTS` | Number of playoff slots in selected league. |
| `NUM_PLAYOFF_SLOTS_PER_DIVISION` | Numbers of teams per division that qualify for the playoffs. |
| `COACHING_EFFICIENCY_DISQUALIFIED_TEAMS_LIST` | Comma-delimited list (with no spaces between items and surrounded by quotes) of teams manually disqualified from coaching efficiency rankings (if any). |
| `GOOGLE_DRIVE_UPLOAD_BOOL` | Turn on (`True`) or off (`False`) the Google Drive upload functionality. |
| `GOOGLE_DRIVE_AUTH_TOKEN_LOCAL_PATH` | Google OAuth refresh token. |
| `GOOGLE_DRIVE_FOLDER_PATH` | Online folder in Google Drive where reports are uploaded. |
| `GOOGLE_DRIVE_REUPLOAD_FILE_LOCAL_PATH` | File path of selected report that you wish to re-upload to Google Drive by running `upload_to_google_drive.py` as a standalone script. |
| `SLACK_POST_BOOL` | Turn on (`True`) or off (`False`) the Slack upload functionality. |
| `SLACK_AUTH_TOKEN_LOCAL_PATH` | Slack authentication token. |
| `SLACK_POST_OR_FILE` | Choose whether you post a link to the generated report on Slack (set to `post`), or upload the report PDF itself to Slack (set to `file`). |
| `SLACK_CHANNEL` | Selected Slack channel where reports are uploaded. |
| `SLACK_CHANNEL_NOTIFY_BOOL` | Turn on (`True`) or off (`False`) using the `@here` slack tag to notify chosen Slack channel of a posted report file. |
| `SLACK_REPOST_FILE_LOCAL_PATH` | File path of selected report that you wish to repost to Slack. |

---

Expand Down
28 changes: 18 additions & 10 deletions report/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, league: BaseLeague, season_weekly_teams_results, week_counter
# option to disqualify team(s) manually entered in the .env file for current week of coaching efficiency
self.coaching_efficiency_dqs = {}
if week_counter == week_for_report:
for team in settings.coaching_efficiency_disqualified_teams:
for team in settings.coaching_efficiency_disqualified_teams_list:
self.coaching_efficiency_dqs[team] = -2
for team_result in self.teams_results.values():
if team == team_result.name:
Expand Down Expand Up @@ -298,26 +298,34 @@ def __init__(self, league: BaseLeague, season_weekly_teams_results, week_counter
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ LOGGER OUTPUT ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

weekly_metrics_output_string = (
weekly_metrics_info = (
f"\n~~~~~ WEEK {week_counter} METRICS INFO ~~~~~\n"
f" SCORE tie(s): {self.ties_for_scores}\n"
f"COACHING EFFICIENCY tie(s): {self.ties_for_coaching_efficiency}\n"
)

# add line for coaching efficiency disqualifications if applicable
ce_dq_str = None
if self.num_coaching_efficiency_dqs > 0:
ce_dq_str = ""
ce_dqs = []
for team_name, ineligible_players_count in self.coaching_efficiency_dqs.items():
if ineligible_players_count == -1:
ce_dq_str += f"{team_name} (incomplete active squad), "
ce_dqs.append(f"{team_name} (incomplete active squad)")
elif ineligible_players_count == -2:
ce_dq_str += f"{team_name} (manually disqualified), "
ce_dqs.append(f"{team_name} (manually disqualified)")
else:
ce_dq_str += (
ce_dqs.append(
f"{team_name} (ineligible bench players: "
f"{ineligible_players_count}/{league.roster_position_counts.get('BN')}), "
f"{ineligible_players_count}/{league.roster_position_counts.get('BN')})"
) # exclude IR
weekly_metrics_output_string += f" COACHING EFFICIENCY DQs: {ce_dq_str[:-2]}\n"

# output weekly metrics info
logger.info(weekly_metrics_output_string)
ce_dq_str = ', '.join(ce_dqs)
weekly_metrics_info += f" COACHING EFFICIENCY DQs: {ce_dq_str}\n"

# log weekly metrics info
logger.debug(weekly_metrics_info)
logger.info(
f"Week {week_counter} data processed"
f"{f' with the following coaching efficiency DQs: {ce_dq_str})' if ce_dq_str else ''}"
f"."
)
6 changes: 3 additions & 3 deletions report/pdf/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def __init__(self, season: int, league: BaseLeague, playoff_prob_sims: int,
# set text styles
self.font_size = settings.report_settings.font_size
font_key = settings.report_settings.font
supported_fonts = settings.report_settings.supported_fonts
if font_key not in supported_fonts:
supported_fonts_list = settings.report_settings.supported_fonts_list
if font_key not in supported_fonts_list:
logger.warning(
f"The {font_key} font is not supported at this time. Report formatting has defaulted to Helvetica. "
f"Please try again with one of the following supported font keys: {supported_fonts}"
f"Please try again with one of the following supported font keys: {supported_fonts_list}"
)
font_dict = {
"helvetica": 1,
Expand Down
2 changes: 1 addition & 1 deletion utilities/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_current_nfl_week(offline: bool) -> int:
def league_data_factory(base_dir: Path, data_dir: Path, platform: str,
game_id: Union[str, int], league_id: str, season: int, start_week: int, week_for_report: int,
save_data: bool, offline: bool) -> BaseLeague:
if platform in settings.supported_platforms:
if platform in settings.supported_platforms_list:
if platform == "yahoo":
yahoo_league = YahooLeagueData(
base_dir,
Expand Down
23 changes: 12 additions & 11 deletions utilities/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def prepare_field_value(self, field_name: str, field: FieldInfo, value: Any, val
return int(value)
except (ValueError, TypeError):
return value
if field_name in ["supported_platforms", "supported_fonts", "coaching_efficiency_disqualified_teams"]:
if field_name.endswith("_list"):
return value.split(",") if value else []
if field_name.endswith("_bool"):
return str(value).lower() == "true"
Expand Down Expand Up @@ -160,10 +160,10 @@ class ReportSettings(CustomSettings):
title=__qualname__,
description="set font for report (defaults to Helvetica)"
)
supported_fonts: List[str] = Field(
supported_fonts_list: List[str] = Field(
["helvetica", "times", "symbola", "opensansemoji", "sketchcollege", "leaguegothic"],
title=__qualname__,
description="supported fonts (comma-delimited list with no spaces)"
description="supported fonts (comma-delimited list with no spaces between items)"
)
font_size: int = Field(
12,
Expand Down Expand Up @@ -257,11 +257,11 @@ class AppSettings(CustomSettings):
title=__qualname__,
description="fantasy football platform for which you are running the report"
)
supported_platforms: List[str] = Field(
supported_platforms_list: List[str] = Field(
["yahoo", "espn", "sleeper", "fleaflicker", "cbs"],
validate_default=False,
title=__qualname__,
description="supported fantasy football platforms"
description="supported fantasy football platforms (comma-delimited list with no spaces between items)"
)
league_id: Optional[str] = Field(
None,
Expand Down Expand Up @@ -301,12 +301,13 @@ class AppSettings(CustomSettings):
title=__qualname__,
description="SLEEPER/FLEAFLICKER: default if number of regular season weeks cannot be scraped/retrieved"
)
coaching_efficiency_disqualified_teams: List[str] = Field(
coaching_efficiency_disqualified_teams_list: List[str] = Field(
[],
title=__qualname__,
description=(
"multiple teams can be manually disqualified from coaching efficiency eligibility (comma-delimited list "
"with no spaces), for example: COACHING_EFFICIENCY_DISQUALIFIED_TEAMS=Team One,Team Two"
"with no spaces between items and surrounded by quotes), for example: "
"COACHING_EFFICIENCY_DISQUALIFIED_TEAMS_LIST=\"Team One,Team Two\""
)
)

Expand Down Expand Up @@ -374,15 +375,15 @@ def create_env_file_from_settings(env_fields: Set[Tuple[str, str, str]], env_fil
app_settings.convert_to_default_values()

if not platform:
supported_platforms = app_settings.supported_platforms
supported_platforms_list = app_settings.supported_platforms_list
platform = input(
f"{Fore.GREEN}For which fantasy football platform are you generating a report? "
f"({'/'.join(supported_platforms)}) -> {Style.RESET_ALL}"
f"({'/'.join(supported_platforms_list)}) -> {Style.RESET_ALL}"
).lower()
if platform not in supported_platforms:
if platform not in supported_platforms_list:
logger.warning(
f"Please only select one of the following platforms: "
f"{', or '.join([', '.join(supported_platforms[:-1]), supported_platforms[-1]])}"
f"{', or '.join([', '.join(supported_platforms_list[:-1]), supported_platforms_list[-1]])}"
)
sleep(0.25)
create_env_file_from_settings(env_fields, env_file_path)
Expand Down

0 comments on commit 2366459

Please sign in to comment.