Exemplo n.º 1
0
def test_compute_hourly_count_active_0_minutes():
    t1 = Timestamp(2017, 4, 12, 10, 0, 0)
    t2 = Timestamp(2017, 4, 12, 10, 30, 0)
    model = Model(
        StubDataStore(session_events=[(t1, INACTIVE)], desk_events=[]))
    result = model.compute_hourly_count(t1, t2)
    assert result.counts.sum() == 0
Exemplo n.º 2
0
def test_get_active_time_active_20_minutes_with_changed_desk_state():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    t3 = Timestamp(2018, 1, 1, 0, 20, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[(t2, UP)]))
    assert model.get_active_time(Timestamp.min, t3) == Timedelta(minutes=10)
Exemplo n.º 3
0
def test_get_session_spans_empty():
    t1 = Timestamp.min
    t2 = Timestamp.max
    model = Model(StubDataStore.empty())

    result = model.get_session_spans(t1, t2)

    expected = make_spans([(t1, t2, INACTIVE)])
    assert_frame_equal(result, expected)
Exemplo n.º 4
0
def test_get_session_spans_one_active_span():
    t1 = Timestamp(2018, 1, 1)
    t2 = Timestamp(2018, 1, 2)
    t3 = Timestamp(2018, 1, 3)
    model = Model(StubDataStore(session_events=[(t2, ACTIVE)], desk_events=[]))

    result = model.get_session_spans(t1, t3)

    expected = make_spans([(t1, t2, INACTIVE), (t2, t3, ACTIVE)])
    assert_frame_equal(result, expected)
Exemplo n.º 5
0
def test_get_desk_spans_one_up_span():
    t1 = Timestamp(2018, 1, 1)
    t2 = Timestamp(2018, 1, 2)
    t3 = Timestamp(2018, 1, 3)
    model = Model(StubDataStore(session_events=[], desk_events=[(t2, UP)]))

    result = model.get_desk_spans(t1, t3)

    expected = make_spans([(t1, t2, DOWN), (t2, t3, UP)])
    assert_frame_equal(result, expected)
Exemplo n.º 6
0
def test_compute_hourly_count_active_30_minutes():
    t1 = Timestamp(2017, 4, 12, 10, 0, 0)
    t2 = Timestamp(2017, 4, 12, 10, 30, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE), (t2, INACTIVE)],
                      desk_events=[]))
    result = model.compute_hourly_count(t1, t2)
    specific_hour = result[(result.weekday == 'Wednesday')
                           & (result.hour == 10)]
    assert specific_hour.counts.iloc[0] == 1
Exemplo n.º 7
0
def client(mocker, loop, aiohttp_client):
    time_service = mocker.patch('autodesk.application.timeservice.TimeService',
                                autospec=True)
    time_service.min = Timestamp.min
    time_service.now.return_value = Timestamp(2019, 4, 25, 12, 0)

    model = Model(
        StubDataStore(session_events=SESSION_EVENTS, desk_events=DESK_EVENTS))

    button_pin = NoopPin(4)
    timer = mocker.patch('autodesk.timer.Timer', autospec=True)
    desk_controller = DeskController(0, NoopPin(0), NoopPin(1), NoopPin(3))
    light_controller = LightController(NoopPin(2))
    operation = Operation()
    limits = (Timedelta(minutes=30), Timedelta(minutes=30))
    scheduler = Scheduler(limits)
    session_service = SessionService(model, light_controller, time_service)
    desk_service = DeskService(operation, model, desk_controller, time_service)
    service = AutoDeskService(operation, scheduler, timer, time_service,
                              session_service, desk_service)

    factory = mocker.patch(
        'autodesk.application.autodeskservicefactory.AutoDeskServiceFactory',
        autospec=True)
    factory.create.return_value = service

    return loop.run_until_complete(
        aiohttp_client(api.setup_app(button_pin, factory)))
Exemplo n.º 8
0
 def create(self, loop):
     operation = Operation()
     timer = Timer(loop)
     model = Model(SqliteDataStore(self.database_path))
     scheduler = Scheduler(self.limits)
     desk_controller = DeskController(
         self.delay, self.pin_factory.create_output(self.motor_pins[0]),
         self.pin_factory.create_output(self.motor_pins[1]),
         self.pin_factory.create_output(self.light_pins[0]))
     light_controller = LightController(
         self.pin_factory.create_output(self.light_pins[1]))
     timer_service = TimeService()
     session_service = SessionService(model, light_controller,
                                      timer_service)
     desk_service = DeskService(operation, model, desk_controller,
                                timer_service)
     return AutoDeskService(operation, scheduler, timer, timer_service,
                            session_service, desk_service)
Exemplo n.º 9
0
from autodesk.model import Model
from autodesk.plots import plot_weekday_hourly_count
from autodesk.sqlitedatastore import SqliteDataStore
from pandas import Timestamp
import sys

model = Model(SqliteDataStore(sys.argv[1]))
figure = plot_weekday_hourly_count(
    model.compute_hourly_count(Timestamp.min, Timestamp.now()))
figure.savefig(sys.argv[2], format='png')
Exemplo n.º 10
0
def test_get_active_time_just_after_desk_change():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    model = Model(
        StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[(t2, UP)]))
    assert model.get_active_time(Timestamp.min, t2) == Timedelta(0)
Exemplo n.º 11
0
def test_get_active_time_active_for_10_minutes():
    t1 = Timestamp(2018, 1, 1, 0, 0, 0)
    t2 = Timestamp(2018, 1, 1, 0, 10, 0)
    model = Model(StubDataStore(session_events=[(t1, ACTIVE)], desk_events=[]))
    assert model.get_active_time(Timestamp.min, t2) == Timedelta(minutes=10)
Exemplo n.º 12
0
def test_get_active_time_active_zero():
    t = Timestamp(2018, 1, 1)
    model = Model(StubDataStore(session_events=[(t, ACTIVE)], desk_events=[]))
    assert model.get_active_time(Timestamp.min, t) == Timedelta(0)
Exemplo n.º 13
0
def test_get_active_time_empty():
    model = Model(StubDataStore.empty())
    assert model.get_active_time(Timestamp.min, Timestamp.max) == Timedelta(0)
Exemplo n.º 14
0
def test_get_desk_state_empty():
    model = Model(StubDataStore.empty())
    assert model.get_desk_state() == DOWN
Exemplo n.º 15
0
def test_get_session_state_empty():
    model = Model(StubDataStore.empty())
    assert model.get_session_state() == INACTIVE
Exemplo n.º 16
0
def inmemory_model():
    model = Model(SqliteDataStore(':memory:'))
    yield model
    model.close()