示例#1
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)
示例#2
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)
示例#3
0
def test_filter_by_hour_of_day():
    hd = HourAndMinutesTimestamp(hour_str="09:00")
    expr = hd.filter_timestamp_column(EventsCallsTable.datetime,
                                      cmp_op=greater_or_equal)
    expected = "to_char(events.calls.datetime, 'HH24:MI') >= '09:00'"
    assert expected == get_string_representation(expr)

    hd = HourAndMinutesTimestamp(hour_str="12:40")
    expr = hd.filter_timestamp_column(EventsCallsTable.datetime,
                                      cmp_op=less_than)
    expected = "to_char(events.calls.datetime, 'HH24:MI') < '12:40'"
    assert expected == get_string_representation(expr)

    hd = HourAndMinutesTimestamp(hour_str=None)
    expr = hd.filter_timestamp_column(EventsCallsTable.datetime,
                                      cmp_op=less_than)
    expected = "true"
    assert expected == get_string_representation(expr)
示例#4
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)
示例#5
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)
示例#6
0
def test_multiple_our_slices():
    hs1 = HourInterval(start_hour="08:00", stop_hour="16:30", freq="day")
    hs2 = HourInterval(start_hour="10:00",
                       stop_hour="18:45",
                       freq="week",
                       weekday="Thursday")
    mhs = HourSlice(hour_intervals=[hs1, hs2])

    ts_col = EventsCallsTable.datetime
    expr = mhs.get_subsetting_condition(ts_col)
    expected = ("to_char(events.calls.datetime, 'HH24:MI') >= '08:00' AND "
                "to_char(events.calls.datetime, 'HH24:MI') < '16:30' OR "
                "to_char(events.calls.datetime, 'HH24:MI') >= '10:00' AND "
                "to_char(events.calls.datetime, 'HH24:MI') < '18:45' AND "
                "EXTRACT(isodow FROM events.calls.datetime) = 4")
    assert expected == get_string_representation(expr)