Example #1
0
def test_room_descriptor():
    rm1s1, = artmd.make_seats("myroom", 1)
    rm2s1, = artmd.make_seats("otherroom", 1)
    v1 = artmd.make_visit(rm1s1, "p1", "02:00", "04:00")  # noqa
    v2 = artmd.make_visit(rm2s1, "p2", "02:00", "04:00")  # noqa
    myroom = arm.Room.objects.get(room="myroom")
    assert myroom.descriptor == "org;dep;bldg;myroom"
Example #2
0
def test_SearchByRoomForm():
    def tr(times: str) -> str:
        return f"{aud.nowstring()} {times}"

    def get_rooms(descr, times) -> tg.Set[arm.Room]:
        f = arf.SearchByRoomForm(
            dict(roomdescriptor=descr, timerange=tr(times)))
        f.full_clean()
        return set(f.cleaned_data['rooms_qs'])

    def get_visits(descr, times) -> tg.Set[arm.Visit]:
        f = arf.SearchByRoomForm(
            dict(roomdescriptor=descr, timerange=tr(times)))
        f.full_clean()
        return set(f.cleaned_data['visits_qs'])

    #----- create data:
    rm1s1, = artmd.make_seats("myroom", 1)
    rm2s1, = artmd.make_seats("otherroom", 1)
    rm1, rm2 = (rm1s1.room, rm2s1.room)
    v11 = artmd.make_visit(rm1s1, "p11", "02:00", "04:00")  # noqa
    v12 = artmd.make_visit(rm1s1, "p12", "03:00", "05:00")  # noqa
    v21 = artmd.make_visit(rm2s1, "p21", "02:00", "04:00")  # noqa
    #----- check rooms_qs:
    assert get_rooms("%myroom", "02:00-04:00") == set((rm1, ))
    assert get_rooms("%org%", "02:00-04:00") == set((rm1, rm2))
    assert get_rooms("---", "02:00-04:00") == set()
    #----- check visits_qs:
    assert get_visits("%myroom", "02:00-04:00") == set((v11, v12))
    assert get_visits("%myroom", "02:00-02:40") == set((v11, ))
    assert get_visits("%myroom", "01:00-02:40") == set((v11, ))
    assert get_visits("%myroom", "02:20-03:01") == set(
        (v11, ))  # too short for v12
    assert get_visits("%org%", "01:00-05:00") == set((v11, v12, v21))
    assert get_visits("---", "01:00-05:00") == set()
Example #3
0
def test_current_unique_visitorsN():
    # test can fail if run very shortly before midnight, just run it again
    def show_them(room):
        them = room.current_unique_visitors_qs()
        print([v.email for v in them])

    rm1s1, rm1s2, rm1s3 = artmd.make_seats("room1", 3)
    rm2s1, = artmd.make_seats("room2", 1)
    room = rm1s1.room
    person1_early = artmd.make_visit(rm1s1, "p1", "02:58", "04:00")  # noqa
    person2_ontime = artmd.make_visit(rm1s2, "p2", "03:00", "04:00")  # noqa
    person3_late = artmd.make_visit(rm1s3, "p3", "03:03", "04:00")  # noqa
    person4_otherroom = artmd.make_visit(rm2s1, "p4", "03:00", "04:00")  # noqa
    person3_changed = artmd.make_visit(rm1s1, "p3", "03:30", "04:00")  # noqa

    # --- now look at different times how many are in rm1:
    def freeze_at(ts: str):
        return freeze_time(aud.make_dt('now', ts))

    with freeze_at("02:50"):
        show_them(room)
        assert room.current_unique_visitorsN() == 0
    with freeze_at("02:59"):
        show_them(room)
        assert room.current_unique_visitorsN() == 1
    with freeze_at("03:01"):
        show_them(room)
        assert room.current_unique_visitorsN() == 2
    with freeze_at("03:06"):
        show_them(room)
        assert room.current_unique_visitorsN() == 3
    with freeze_at("03:33"):
        show_them(room)
        assert room.current_unique_visitorsN() == 3
    with freeze_at("05:00"):
        show_them(room)
        assert room.current_unique_visitorsN() == 0
Example #4
0
def test_get_overlapping_visits():
    # test can fail if run very shortly before midnight, just run it again
    rm1s1, rm1s2 = artmd.make_seats("room1", 2)
    rm2s1, = artmd.make_seats("room2", 1)
    targetvisit = artmd.make_visit(rm1s1, "p1", "03:00", "04:00")
    shorttargetvisit = artmd.make_visit(rm1s1, "p1", "03:00", "03:01")
    # --- the following other visits have _y if they are to be found, _n if not:
    otherroom_n = artmd.make_visit(rm2s1, "p2", "03:00", "04:00")
    before_n = artmd.make_visit(rm1s2, "p3", "02:00", "03:00")
    within_y = artmd.make_visit(rm1s2, "p4", "03:15", "03:45")
    across_y = artmd.make_visit(rm1s2, "p5", "02:00", "05:00")
    after_n = artmd.make_visit(rm1s2, "p3", "04:00", "05:00")
    halfbefore_y = artmd.make_visit(rm1s2, "p6", "02:30", "03:30")
    halfafter_y = artmd.make_visit(rm1s2, "p7", "03:30", "04:30")
    nearlybefore_n = artmd.make_visit(rm1s2, "p8", "02:00", "03:01")
    nearlyafter_n = artmd.make_visit(rm1s2, "p9", "03:59", "05:00")
    # --- now look which ones appear for targetvisit:
    results = set(targetvisit.get_overlapping_visits())
    result_pks = set(el.pk for el in results)
    expected = set(el.pk for el in (targetvisit, within_y, across_y,
                                    halfbefore_y, halfafter_y))
    not_expected = set(el.pk for el in (otherroom_n, before_n, after_n,
                                        nearlybefore_n, nearlyafter_n))
    print("result_pks", result_pks)
    print("expected", expected)
    print("not_expected", not_expected)
    assert result_pks.isdisjoint(not_expected)
    assert result_pks == expected
    # --- now look which ones appear for shorttargetvisit:
    assert shorttargetvisit.get_overlapping_visits().count() == 0
Example #5
0
def test_visitors_by_week_report(freezer):
    #----- first week: create rooms and some visits:
    freezer.move_to("2021-12-03T02:03")
    seat_r1, = artmd.make_seats("room1", 1, "org1", "dep1")
    seat_r2, = artmd.make_seats("room2", 1, "org1", "dep1")
    seat_r2b, = artmd.make_seats("room2", 1, "org2", "dep2")
    artmd.make_visit(seat_r1, "p1")
    artmd.make_visit(seat_r2, "p1")
    artmd.make_visit(seat_r2, "p2")
    artmd.make_visit(seat_r2b, "p1")
    artmd.make_visit(seat_r2b, "p3")
    artmd.make_visit(seat_r2b, "p4")
    artmd.make_visit(seat_r2b, "p5")

    #----- second week: create more visits:
    freezer.move_to("2021-12-10T02:10")
    artmd.make_visit(seat_r2, "p1")
    artmd.make_visit(seat_r2, "p1")  # double registration
    artmd.make_visit(seat_r2, "p2")

    #----- that evening, look at report:
    freezer.move_to("2021-12-10T18:00")
    #-- first week:
    wr = arr.visitors_by_week_report("%")
    assert wr[0].organizationsN == 2
    assert wr[0].departmentsN == 2
    assert wr[0].buildingsN == 2  # all same name
    assert wr[0].roomsN == 3  # only 2 different names
    assert wr[0].visitorsN == 5
    assert wr[0].visitsN == 7
    assert wr[0].visits_per_visitor == 7 / 5

    #-- second week:
    assert wr[0].organizationsN == 2
    assert wr[0].departmentsN == 2
    assert wr[0].buildingsN == 2
    assert wr[0].roomsN == 3  #
    assert wr[0].visitorsN == 5
    assert wr[0].visitsN == 7
    assert wr[0].visits_per_visitor == 7 / 5

    #-- first week, narrowed search:
    wr = arr.visitors_by_week_report("%dep1%")
    assert wr[0].organizationsN == 1
    assert wr[0].departmentsN == 1
    assert wr[0].buildingsN == 1
    assert wr[0].roomsN == 2
    assert wr[0].visitorsN == 2
    assert wr[0].visitsN == 3
    assert wr[0].visits_per_visitor == 3 / 2