supercontest.util.timing
Time, date, timezone, conversion - all timing related utilities.
Functions
Converts an integer to its English day-of-the-week equivalent. |
|
Converts an English day-of-the-week string to its integer equivalent. |
|
I have timezone explicitly set True in sqlalchemy, |
|
Properly formats the strings for datetime in the database into python datetime objects, including tzinfo. |
|
Takes a datetime (like the |
|
All the timestamps in postgres are stored as UTC. |
|
Calculates the number of hours since a certain time. |
|
Checks if you are in a window around a kickoff time (set by lines), before or after, to force the score fetch. |
|
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.queryandpsqlqueries 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.datetimecol 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(). Rememberdatetimereturns the object of the current UTC timestamp, but we want it fully aware withtzinfo, so we pass topytz.- 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
datetimecols (just vals) of thegamestable.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.