Vocab
Operations and relationship with the "vocab" of the default time slots.
DOWHour
dataclass
Day of week and hour of day class.
Source code in latent_calendar/vocab.py
vocab: str
property
Get the vocab string for an instance.
__add__(hours)
Add a number of hours.
Source code in latent_calendar/vocab.py
from_vocab(vocab)
classmethod
is_after(other)
HourFormatter
dataclass
Class to format the hour that includes midnight and noon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
midnight
|
str | None
|
string to use for midnight |
'Midnight'
|
noon
|
str | None
|
string to use for noon |
'Noon'
|
format_hour
|
HOUR_FORMATTER
|
HOUR_FORMATTER to map hour int to string |
HOUR_FORMATTERS['12hr']
|
Examples:
Just return the number and add midnight and noon.
hour_formatter = HourFormatter(
midnight="Midnight",
noon="Noon",
format_hour=lambda hour: hour
)
hour_formatter(0) # "Midnight"
hour_formatter(12) # "Noon"
hour_formatter(1) # 1
hour_formatter(13) # 13
hour_formatter(24) # "Midnight"
Source code in latent_calendar/vocab.py
am_pm_of_hour(hour)
Get the am or pm of the hour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hour
|
int
|
hour of the day |
required |
Returns:
Type | Description |
---|---|
str
|
am or pm |
get_day_hour(vocab)
make_human_readable(vocab, hour_formatter=HOUR_FORMATTERS['12_am_pm'])
Create a human readable string of the vocab.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vocab
|
str
|
string vocab. i.e. "00 01" |
required |
hour_formatter
|
HOUR_FORMATTER
|
HOUR_FORMATTER to map hour int to string |
HOUR_FORMATTERS['12_am_pm']
|
Returns:
Type | Description |
---|---|
str
|
human readable string of the vocab |
Source code in latent_calendar/vocab.py
map_to_12_hour(hour)
split_vocab(ser)
Split pandas series of vocab into day of week and hour of day DataFrame.