Example #1
0
def test_daily_hour_slice():
    hs = HourInterval(start_hour="00:00", stop_hour="06:30", freq="day")
    assert hs.start_hour == "00:00"
    assert hs.stop_hour == "06:30"
    assert hs.period.freq == "day"

    expr = hs.filter_timestamp_column(EventsCallsTable.datetime)
    expected = "to_char(events.calls.datetime, 'HH24:MI') >= '00:00' AND to_char(events.calls.datetime, 'HH24:MI') < '06:30'"
    assert expected == get_string_representation(expr)
Example #2
0
def test_daily_hour_slice_without_stop_hour():
    hs = HourInterval(start_hour="07:20", stop_hour=None, freq="day")
    assert hs.start_hour == "07:20"
    assert hs.stop_hour.is_missing
    assert hs.period.freq == "day"

    expr = hs.filter_timestamp_column(EventsCallsTable.datetime)
    expected = "to_char(events.calls.datetime, 'HH24:MI') >= '07:20'"
    assert expected == get_string_representation(expr)
Example #3
0
def test_weekly_hour_slice_without_stop_value():
    hs = HourInterval(start_hour="10:00",
                      stop_hour=None,
                      freq="week",
                      weekday="Saturday")
    assert hs.start_hour == "10:00"
    assert hs.stop_hour.is_missing
    assert hs.period.freq == "week"
    assert hs.period.weekday == "Saturday"

    ts_col = EventsCallsTable.datetime
    expr = hs.filter_timestamp_column(ts_col)
    expected = ("to_char(events.calls.datetime, 'HH24:MI') >= '10:00' AND "
                "EXTRACT(isodow FROM events.calls.datetime) = 6")
    assert expected == get_string_representation(expr)
Example #4
0
def test_weekly_hour_slice():
    hs = HourInterval(start_hour="04:00",
                      stop_hour="07:45",
                      freq="week",
                      weekday="tuesday")
    assert hs.start_hour == "04:00"
    assert hs.stop_hour == "07:45"
    assert hs.period.freq == "week"
    assert hs.period.weekday == "Tuesday"

    ts_col = EventsCallsTable.datetime
    expr = hs.filter_timestamp_column(ts_col)
    expected = ("to_char(events.calls.datetime, 'HH24:MI') >= '04:00' AND "
                "to_char(events.calls.datetime, 'HH24:MI') < '07:45' AND "
                "EXTRACT(isodow FROM events.calls.datetime) = 2")
    assert expected == get_string_representation(expr)