flowmachine.core.hour_slice¶
Class DayOfWeekPeriod¶
DayOfWeekPeriod(weekday: str)
Represents a repeated "day-of-the-week" time period.
Parameters¶
-
weekday
:str
The weekday during which this day period is repeated every week. Should be one of: 'Monday', "Tuesday", "Wednesday", etc. (or an equivalent name if a non-English locale is being used).
Methods¶
filter_timestamp_column_by_day_of_week¶
filter_timestamp_column_by_day_of_week(self, ts_col: sqlalchemy.orm.attributes.InstrumentedAttribute)
Returns a sql expression which filters the timestamp column
Class DayPeriod¶
DayPeriod(weekday=None)
Represents a repeated "daily" time period.
Parameters¶
-
weekday
:None
This argument must be None for
DayPeriod
(it only exists for compatibility with the sister classDayOfWeekPeriod
). An error is raised if a different value is passed.
Methods¶
filter_timestamp_column_by_day_of_week¶
filter_timestamp_column_by_day_of_week(self, ts_col: sqlalchemy.orm.attributes.InstrumentedAttribute) -> sqlalchemy.sql.elements.ColumnElement
Returns an expression equivalent to TRUE (because no additional filtering is needed to limit the day of the week).
Parameters¶
-
ts_col
:sqlalchemy.orm.attributes.InstrumentedAttribute
The timestamp column to filter. Note that this input argument is ignored for the DayPeriod class because it requires no additional filtering to limit the day of the week.
Returns¶
sqlalchemy.sql.elements.ColumnElement
Class HourAndMinutesTimestamp¶
HourAndMinutesTimestamp(hour_str, **kwargs)
Represents an HH:MM period of the day and allows filtering a timestamp column accordingly.
Parameters¶
-
hour_str
:str
A string in the format 'HH:MM'.
Methods¶
filter_timestamp_column¶
filter_timestamp_column(self, ts_col, cmp_op: <built-in function callable>) -> sqlalchemy.sql.elements.ColumnElement
Filter timestamp column by comparing to this hour-of-day using the given comparison operator.
Parameters¶
-
ts_col
:sqlalchemy column
The timestamp column to filter.
-
cmp_op
:callable
Comparison operator to use. For example:
operator.lt
,operator.ge
.
Returns¶
-
sqlalchemy.sql.elements.ColumnElement
Sqlalchemy expression representing the filtered timestamp column. This can be used in WHERE clauses of other sql queries.
Class HourInterval¶
HourInterval(*, start_hour: str, stop_hour: str, freq: str, weekday: str = None)
Represents an interval of hours during the day which is repeated regularly, for example each day, or every Tuesday. The interval is considered to be half-open, i.e. the left endpoint is included and the right endpoint is excluded. For example: 08:30 <= HH:MM < 16:00.
Parameters¶
-
start_hour
:str
Start hour of this hour interval in the format 'HH:MM' (e.g. '08:00'). The start hour can also be
None
, indicating that the hour interval starts at midnight at the beginning of the day. -
stop_hour
:str
Stop hour of this hour interval in the format 'HH:MM' (e.g. '19:30'). The stop hour can also be
None
, indicating that the hour interval extends until midnight. -
freq
:str
Frequency at which the underlying time interval is repeated. This must be either "day" or "week". In the latter case the
weekday
argument must also be provided. -
weekday
:str
, defaultNone
The day of the week for which this hour interval is valid. This argument is only relevant if
freq="week"
and is ignored otherwise.
Methods¶
filter_timestamp_column¶
filter_timestamp_column(self, ts_col) -> sqlalchemy.sql.elements.ColumnElement
Filter timestamp column using this hour interval.
Parameters¶
-
ts_col
:sqlalchemy column
The timestamp column to filter.
Returns¶
-
sqlalchemy.sql.elements.ColumnElement
Sqlalchemy expression representing the filtered timestamp column. This can be used in WHERE clauses of other sql queries.
Class HourSlice¶
HourSlice(*, hour_intervals: List[flowmachine.core.hour_slice.HourInterval])
Represents a collection of multiple non-overlapping hour intervals.
Parameters¶
-
hour_intervals
:typing.List
List of hour interval. These are assumed to be non-overlapping (but note that this is not currently enforced).
Methods¶
get_subsetting_condition¶
get_subsetting_condition(self, ts_col) -> sqlalchemy.sql.elements.ColumnElement
Return sqlalchemy expression which represents subsetting the given timestamp column by hours of the day.
Parameters¶
-
ts_col
:sqlalchemy column
The timestamp column to which to apply the subsetting.
Returns¶
sqlalchemy.sql.elements.ColumnElement
Class MissingHourAndMinutesTimestamp¶
MissingHourAndMinutesTimestamp()
Represents a "missing" HH:MM timestamp. This is used to represent time intervals during the day where the start or end is missing (i.e. extends until midnight)
Methods¶
filter_timestamp_column¶
filter_timestamp_column(self, ts_col, cmp_op: <built-in function callable>) -> sqlalchemy.sql.elements.ColumnElement
Filter timestamp column by comparing to this hour-of-day using the given comparison operator.
Note that for the class MissingHourAndMinutesTimestamp
this always returns TRUE, since a missing timestamp imposes no constraint.
Parameters¶
-
ts_col
:sqlalchemy column
The timestamp column to filter.
-
cmp_op
:callable
Comparison operator to use. For example:
operator.lt
,operator.ge
.
Returns¶
sqlalchemy.sql.elements.ColumnElement
make_hour_interval_period¶
make_hour_interval_period(freq, *, weekday: Optional[str] = None)
Returns an appropriate instance of DayPeriod
or DayOfWeekPeriod
, depending on the value of freq
.
Parameters¶
-
freq
:{"day", "week"}
Indicated whether the interval period should be repeated every day or on a particular day of the week ("week").
-
weekday
:typing.Optional
, defaultNone
The weekday during which this day period is repeated every week. If
freq="day"
then the value ofweekday
must be None. Otherwise it should be one of: 'Monday', "Tuesday", "Wednesday", etc.
Returns¶
DayOfWeekPeriod
,DayPeriod