コード例 #1
0
ファイル: main.py プロジェクト: Naxesss/Aiess
async def push_events(async_event_generator, current_time, last_time, last_checked_time) -> None:
    """Parses and inserts events generated by the given function over the timeframe.
    Returns whether any events were generated."""
    events = []
    await parse_events(events, async_event_generator, current_time, last_time, last_checked_time)
    insert_db(merge_concurrent(events))

    return bool(events)
コード例 #2
0
def test_merge_concurrent_1_second_off():
    event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 13:00:00"), user=User(1, "someone"))
    event2 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 13:00:01"))

    merged_events = merge_concurrent([event1, event2])
    assert len(merged_events) == 1
    assert merged_events[0].type == event2.type
    assert merged_events[0].user == event1.user
コード例 #3
0
def test_merge_concurrent_different_times():
    event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 11:00:00"), user=User(1, "someone"))
    event2 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 13:00:00"))

    merged_events = merge_concurrent([event1, event2])
    assert len(merged_events) == 2
    assert merged_events[0] == event1
    assert merged_events[1] == event2
コード例 #4
0
def test_merge_concurrent_different_beatmapsets():
    beatmapset1 = Beatmapset(1, "artist", "title", User(1, "someone"), modes=["osu"], genre="g", language="l")
    beatmapset2 = Beatmapset(2, "artist", "title", User(2, "sometwo"), modes=["osu"], genre="g", language="l")
    event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 13:00:00"), beatmapset=beatmapset1, user=User(1, "someone"))
    event2 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 13:00:01"), beatmapset=beatmapset2)

    merged_events = merge_concurrent([event1, event2])
    assert len(merged_events) == 2
    assert merged_events[0] == event1
    assert merged_events[1] == event2
コード例 #5
0
def test_merge_concurrent():
    event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(1, "someone"))
    event2 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 05:00:00"))
    event3 = Event(_type="something else", time=timestamp.from_string("2020-01-01 07:00:00"))

    merged_events = merge_concurrent([event1, event2, event3])
    assert len(merged_events) == 2
    assert merged_events[0].type == event2.type
    assert merged_events[0].user == event1.user
    assert merged_events[1] == event3
コード例 #6
0
def test_merge_concurrent_almost_same_time_nominates():
    nom_event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:01"), user=User(1, "someone"))
    nom_event2 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(2, "sometwo"))
    qual_event1 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 05:00:01"))

    merged_events = merge_concurrent([nom_event1, nom_event2, qual_event1])
    assert len(merged_events) == 2
    assert merged_events[0].type == nom_event1.type
    assert merged_events[0].user == nom_event2.user
    assert merged_events[1].type == qual_event1.type
    assert merged_events[1].user == nom_event1.user
コード例 #7
0
def test_merge_concurrent_duplicates():
    nom_event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(1, "someone"))
    nom_event2 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(1, "someone"))
    nom_event3 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(1, "someone"))
    qual_event1 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 05:00:00"))
    qual_event2 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 05:00:00"))

    merged_events = merge_concurrent([nom_event1, nom_event2, nom_event3, qual_event1, qual_event2])
    assert len(merged_events) == 1
    assert merged_events[0].type == qual_event1.type
    assert merged_events[0].user == nom_event1.user
コード例 #8
0
def test_merge_concurrent_same_time_nominates():
    # Should pick the last event in the list before the qualify as the new qualify event, so the one by sometwo in this case.
    nom_event1 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(1, "someone"))
    nom_event2 = Event(_type="nominate", time=timestamp.from_string("2020-01-01 05:00:00"), user=User(2, "sometwo"))
    qual_event1 = Event(_type="qualify", time=timestamp.from_string("2020-01-01 05:00:00"))

    merged_events = merge_concurrent([nom_event1, nom_event2, qual_event1])
    assert len(merged_events) == 2
    assert merged_events[0].type == nom_event1.type
    assert merged_events[0].user == nom_event1.user
    assert merged_events[1].type == qual_event1.type
    assert merged_events[1].user == nom_event2.user
コード例 #9
0
ファイル: test_reader.py プロジェクト: Naxesss/Aiess
def test_merge_concurrent_different_beatmapsets():
    beatmapset1 = Beatmapset(1, User(1, "someone"), allow_api=False)
    beatmapset2 = Beatmapset(2, User(2, "sometwo"), allow_api=False)
    event1 = Event(_type="nominate",
                   time=timestamp.from_string("2020-01-01 13:00:00"),
                   beatmapset=beatmapset1,
                   user=User(1, "someone"))
    event2 = Event(_type="qualify",
                   time=timestamp.from_string("2020-01-01 13:00:01"),
                   beatmapset=beatmapset2)

    merged_events = merge_concurrent([event1, event2])
    assert len(merged_events) == 2
    assert merged_events[0] == event1
    assert merged_events[1] == event2