Beispiel #1
0
def test_quake3_feed_preprocess(q3_dump):
    feeder = quake3.Q3MatchFeeder()
    matches = []
    for line in q3_dump.splitlines():
        try:
            feeder.feed(line)
        except dataprovider.FeedFull:
            matches.append(feeder.consume())

    for match in matches:
        transformer = quake3.Q3toQL(match['EVENTS'])
        transformer.process()
        result = transformer.result
        preprocessor = dataprovider.MatchPreprocessor()

        preprocessor.process_events(result['events'])

        for ev in preprocessor.events:
            assert not ev['DATA'].get('WARMUP', False)

        assert preprocessor.match_guid
        assert preprocessor.events

        if preprocessor.finished:
            assert preprocessor.duration
 def test_process_events_warmup(self):
     mp = dataprovider.MatchPreprocessor()
     events = [
         {'TYPE': 'MATCH_STARTED', 'DATA': {
             'MATCH_GUID': 'dummy', 'WARMUP': True}},
     ]
     mp.process_events(events)
     assert events[0] not in mp.events
 def test_process_events_finish_only(self):
     mp = dataprovider.MatchPreprocessor()
     events = [
         {'TYPE': 'MATCH_REPORT', 'DATA': {
             'MATCH_GUID': 'dummy', 'ABORTED': False, 'GAME_LENGTH': 900}}
     ]
     mp.process_events(events)
     assert mp.finished
     assert not mp.started
 def test_process_events_start_only(self):
     mp = dataprovider.MatchPreprocessor()
     events = [
         {'TYPE': 'MATCH_STARTED', 'DATA': {'MATCH_GUID': 'dummy'}},
     ]
     mp.process_events(events)
     assert mp.started
     assert not mp.finished
     assert events[0] in mp.events
 def test_process_events_aborted(self, aborted):
     mp = dataprovider.MatchPreprocessor()
     events = [
         {'TYPE': 'MATCH_STARTED', 'DATA': {'MATCH_GUID': 'dummy'}},
         {'TYPE': 'MATCH_REPORT', 'DATA': {
             'MATCH_GUID': 'dummy', 'ABORTED': aborted, 'GAME_LENGTH': 900}}
     ]
     mp.process_events(events)
     assert aborted == mp.aborted
Beispiel #6
0
def api2_admin_rebuild():
    if not auth(flask.request.form['token']):
        return 'Bye'

    data_store().prepare_for_rebuild()

    # TODO Server Domain is not saved
    data_dir = app.config['RAW_DATA_DIR']
    if data_dir:
        for f in listdir(data_dir):
            with open(path.join(data_dir, f)) as fh:
                data = fh.read()
                match = {
                    'EVENTS': data.splitlines()
                }

                server_domain = app.config['SERVER_DOMAIN']
                source_type = 'Q3'
                transformer = quake3.Q3toQL(match['EVENTS'])
                transformer.server_domain = server_domain

                try:
                    transformer.process()

                except Exception as e:
                    # TODO save for investigation if error
                    logger.exception(e)
                    continue

                results = transformer.result

                # PREPROCESS
                preprocessor = dataprovider.MatchPreprocessor()
                preprocessor.process_events(results['events'])

                if not preprocessor.finished:
                    continue

                fmi = dataprovider.FullMatchInfo(
                    events=preprocessor.events,
                    match_guid=preprocessor.match_guid,
                    duration=preprocessor.duration,
                    start_date=results['start_date'],
                    finish_date=results['finish_date'],
                    server_domain=server_domain,
                    source=source_type)

                analyzer = analyze.Analyzer()
                report = analyzer.analyze(fmi)
                data_store().store_analysis_report(report)

        data_store().post_rebuild()
        return 'OK'

    return 'No Data'
Beispiel #7
0
def api2_admin_match_import():
    """
    Import q3 match log previously stored in RAW_DATA_DIR
    The log file should contain single match events, excluding
    match delimiter (-----)
    """
    if not auth(flask.request.form['token']):
        return 'Bye'

    # TODO this code should be rewritten
    if 'file' not in flask.request.files:
        raise Exception("No Files")

    req_file = flask.request.files['file']
    data = req_file.read().decode("utf-8")
    match = {
        'EVENTS': data.splitlines()
    }

    server_domain = app.config['SERVER_DOMAIN']
    source_type = 'Q3'
    transformer = quake3.Q3toQL(match['EVENTS'])
    transformer.server_domain = server_domain

    try:
        transformer.process()

    except Exception as e:
        # TODO save for investigation if error
        logger.exception(e)
        return 'Failed'

    results = transformer.result

    # PREPROCESS
    preprocessor = dataprovider.MatchPreprocessor()
    preprocessor.process_events(results['events'])

    if not preprocessor.finished:
        return 'Match not finished'

    fmi = dataprovider.FullMatchInfo(
        events=preprocessor.events,
        match_guid=preprocessor.match_guid,
        duration=preprocessor.duration,
        start_date=results['start_date'],
        finish_date=results['finish_date'],
        server_domain=server_domain,
        source=source_type)

    analyzer = analyze.Analyzer()
    report = analyzer.analyze(fmi)
    data_store().store_analysis_report(report)
    return 'OK'
Beispiel #8
0
def test_quakelive_feed_preprocess(quakelive_dump):
    feeder = quakelive.QLMatchFeeder()
    matches = []
    for event in quakelive_dump:
        try:
            feeder.feed(event)
        except dataprovider.FeedFull:
            matches.append(feeder.consume())

    for match in matches:
        preprocessor = dataprovider.MatchPreprocessor()
        preprocessor.process_events(match['EVENTS'])

        for ev in preprocessor.events:
            assert not ev['DATA'].get('WARMUP', False)

        assert preprocessor.match_guid
        assert preprocessor.events

        if preprocessor.finished:
            assert preprocessor.duration
Beispiel #9
0
def test_quake3_analyze(q3_dump):
    feeder = quake3.Q3MatchFeeder()
    matches = []
    for line in q3_dump.splitlines():
        try:
            feeder.feed(line)
        except dataprovider.FeedFull:
            matches.append(feeder.consume())

    for match in matches[-1:]:
        transformer = quake3.Q3toQL(match['EVENTS'])
        transformer.process()
        result = transformer.result
        preprocessor = dataprovider.MatchPreprocessor()

        preprocessor.process_events(result['events'])

        if not preprocessor.finished:
            continue

        fmi = dataprovider.FullMatchInfo.from_preprocessor(
            preprocessor, transformer.result['start_date'],
            transformer.result['finish_date'], 'serv-domain', 'Q3')

        analyzer = analyze.Analyzer()
        result = analyzer.analyze(fmi)

        assert result.match_metadata.duration == 900
        assert result.match_metadata.frag_limit == 200
        assert result.match_metadata.map_name == 'nodm9'
        assert result.match_metadata.match_guid
        assert result.match_metadata.server_domain == 'serv-domain'
        assert result.match_metadata.server_name == 'MY Q3'
        assert result.match_metadata.time_limit == 15

        assert result.final_scores['291b0ba5fdf78b268369a9d7'][0] == 0
        assert result.final_scores['6a018beb6405ef59ce1471b0'][0] == 27
        assert result.final_scores['7ee3d47a164c6544ea50fee6'][0] == 37
        assert result.final_scores['88fdc96e8804eaa084d740f8'][0] == 33
        assert result.final_scores['9ac5682eefa9134bbfe3c481'][0] == 42
        assert result.final_scores['a126a35a25eab0623f504183'][0] == 41
        assert result.final_scores['d37928942982cc79e7e0fe12'][0] == 85
        assert result.final_scores['e0fbefd04b9203526e6f22b8'][0] == 45
        assert result.final_scores['q3-world'][0] == 16

        assert len(result.team_switches) == 10
        assert result.team_switches[-1] == (697.3, '291b0ba5fdf78b268369a9d7',
                                            None, 'DISCONNECTED')

        assert result.players[
            '291b0ba5fdf78b268369a9d7'].name == 'Turbo Wpierdol'
        assert result.players['6a018beb6405ef59ce1471b0'].name == 'MACIEK'
        assert result.players['7ee3d47a164c6544ea50fee6'].name == 'n0npax'
        assert result.players['88fdc96e8804eaa084d740f8'].name == 'darkside'
        assert result.players['9ac5682eefa9134bbfe3c481'].name == 'BOLEK'
        assert result.players[
            'a126a35a25eab0623f504183'].name == 'killer clown'
        assert result.players['d37928942982cc79e7e0fe12'].name == 'Bartoszer'
        assert result.players['e0fbefd04b9203526e6f22b8'].name == 'Stefan'

        assert result.kills[-1] == (897.1, 'd37928942982cc79e7e0fe12',
                                    'd37928942982cc79e7e0fe12',
                                    'ROCKET_SPLASH')

        assert result.server_info.server_name == 'MY Q3'
        assert result.server_info.server_domain == 'serv-domain'
        assert result.server_info.server_type == 'Q3'

        assert result.special_scores['GAUNTLET_KILL'][3] == (
            150.4, 'd37928942982cc79e7e0fe12', 'e0fbefd04b9203526e6f22b8', 1)

        assert result.special_scores['KILLING_SPREE'][2] == (
            64.9, 'd37928942982cc79e7e0fe12', '9ac5682eefa9134bbfe3c481', 1)
 def test_is_valid(self, started, finished, aborted, result):
     mp = dataprovider.MatchPreprocessor()
     mp.started = started
     mp.finished = finished
     mp.aborted = aborted
     assert mp.is_valid() is result
Beispiel #11
0
def api2_upload():
    if not auth(flask.request.form['token']):
        return 'Bye'

    # TODO this code should be rewritten
    if 'file' not in flask.request.files:
        raise Exception("No Files")

    req_file = flask.request.files['file']
    data = req_file.read().decode("utf-8")
    server_domain = app.config['SERVER_DOMAIN']
    source_type = 'Q3'
    feeder = quake3.Q3MatchFeeder()
    matches = []

    for line in data.splitlines():
        try:
            feeder.feed(line)
        except quake3.FeedFull:
            matches.append(feeder.consume())
            feeder.feed(line)

    final_results = []
    errors = 0
    for match in matches:
        # TRANSFORM TO QL
        transformer = quake3.Q3toQL(match['EVENTS'])
        transformer.server_domain = server_domain

        try:
            transformer.process()

        except Exception as e:
            # TODO save for investigation if error
            errors += 1
            logger.exception(e)
            continue

        results = transformer.result

        # PREPROCESS
        preprocessor = dataprovider.MatchPreprocessor()
        preprocessor.process_events(results['events'])

        if not preprocessor.finished:
            continue

        if app.config['RAW_DATA_DIR']:
            base = app.config['RAW_DATA_DIR']
            preprocessor.match_guid
            p = path.join(base, "{}.log".format(preprocessor.match_guid))
            with open(p, 'w') as fh:
                for line in match['EVENTS']:
                    fh.write(line)
                    fh.write('\n')

        final_results.append(dataprovider.FullMatchInfo(
            events=preprocessor.events,
            match_guid=preprocessor.match_guid,
            duration=preprocessor.duration,
            start_date=results['start_date'],
            finish_date=results['finish_date'],
            server_domain=server_domain,
            source=source_type))

        fmi = final_results[-1]
        analyzer = analyze.Analyzer()
        report = analyzer.analyze(fmi)
        data_store().store_analysis_report(report)

    return flask.jsonify({
        "ACCEPTED_MATCHES": [
            r.get_summary() for r in final_results],
        "ERRORS": errors
    })
Beispiel #12
0
final_results = []

for match in raw_matches:
    transformer = quake3.Q3toQL(match['EVENTS'])
    transformer.server_domain = SERVER_DOMAIN

    try:
        transformer.process()
    except Exception as e:
        print(e)
        continue

    results = transformer.result

    # PREPROCESS
    preprocessor = dataprovider.MatchPreprocessor()
    preprocessor.process_events(results['events'])

    if not preprocessor.finished:
        continue

    res = dataprovider.FullMatchInfo(
        events=preprocessor.events,
        match_guid=preprocessor.match_guid,
        duration=preprocessor.duration,
        start_date=results['start_date'],
        finish_date=results['finish_date'],
        server_domain=SERVER_DOMAIN,
        source="Q3")

    m = res.as_dict()