supercontest.util.timing

Time, date, timezone, conversion - all timing related utilities.

Functions

convert_day_int_to_str

Converts an integer to its English day-of-the-week equivalent.

convert_day_str_to_int

Converts an English day-of-the-week string to its integer equivalent.

convert_utc_to_pt

I have timezone explicitly set True in sqlalchemy, db.session.query and psql queries both return UTC datetimes.

convert_westgate_datetime_to_utc

Properly formats the strings for datetime in the database into python datetime objects, including tzinfo.

get_dow

Takes a datetime (like the game.datetime col from the db) and returns the day of the week.

get_utc_now

All the timestamps in postgres are stored as UTC.

hours_since

Calculates the number of hours since a certain time.

is_around_kickoff

Checks if you are in a window around a kickoff time (set by lines), before or after, to force the score fetch.

is_today

Checks if today is in a list of acceptable days.

supercontest.util.timing.convert_day_int_to_str(day_int: int) str

Converts an integer to its English day-of-the-week equivalent.

Parameters:

day_int – 0, 1, …, 6

Returns:

Monday, Tuesday, … , Sunday

supercontest.util.timing.convert_day_str_to_int(day_str: str) int

Converts an English day-of-the-week string to its integer equivalent.

Parameters:

day_str – Monday, Tuesday, … , Sunday

Returns:

0, 1, …, 6

supercontest.util.timing.convert_utc_to_pt(datetime_obj: datetime) datetime

I have timezone explicitly set True in sqlalchemy, db.session.query and psql queries both return UTC datetimes. This function converts them to pacific time.

Parameters:

datetime_obj – A datetime object aware in the utc timezone.

Returns:

A datetime object aware in the pacific timezone.

supercontest.util.timing.convert_westgate_datetime_to_utc(date_str: str) datetime

Properly formats the strings for datetime in the database into python datetime objects, including tzinfo.

Westgate returns a date string like this: "THURSDAY, NOVEMBER 9, 2017 5:25 PM". It is in the pacific timezone.

Parameters:

date_str – The westgate datetime string (pacific).

Returns:

The python standard datetime object (in UTC) for that westgate string.

supercontest.util.timing.get_dow(datetime_obj: datetime) str

Takes a datetime (like the game.datetime col from the db) and returns the day of the week. Specifically ignores year, week, etc - this just categorizes along weekday. Times are cast to PT. This is obviously for statistical analysis (bucketing).

Parameters:

datetime_obj – A datetime object.

Returns:

Eg "Sun".

supercontest.util.timing.get_utc_now() datetime

All the timestamps in postgres are stored as UTC. Therefore, to make proper comparison, you must always use utcnow(). Remember datetime returns the object of the current UTC timestamp, but we want it fully aware with tzinfo, so we pass to pytz.

Returns:

The datetime obj for NOW, aware in the UTC timezone.

supercontest.util.timing.hours_since(start: datetime) float

Calculates the number of hours since a certain time.

Parameters:

start – Datetime, aware in UTC timezone.

Returns:

Number of hours since the start time.

supercontest.util.timing.is_around_kickoff(datetimes: list[datetime], within: int = 30) bool

Checks if you are in a window around a kickoff time (set by lines), before or after, to force the score fetch.

Parameters:
  • datetimes – The datetime cols (just vals) of the games table.

  • within – Number of minutes (before AND after) around kickoff to check within.

Returns:

True if around kickoff (fetch scores), False if not around kickoff (don’t fetch).

supercontest.util.timing.is_today(allowable_days: tuple[str, ...]) bool

Checks if today is in a list of acceptable days.

Parameters:

allowable_days – Eg ['Monday', 'Thursday', ... ]

Returns:

If today is in the provided list of days.