Esempio n. 1
0
def api2_map_info():
    if flask.g.user == 'admin':
        data_store().set_map_info(
            flask.request.json['map_name'],
            flask.request.json.get('size', None),
            flask.request.json.get('rate', None),
        )
        return 'OK'
    return 'Bye'
Esempio n. 2
0
def api2_admin_players_merge():
    # TODO PROPER AUTH
    if not auth(flask.request.form['token']):
        return 'Bye'

    source_id = flask.request.form['source_player_id']
    target_id = flask.request.form['target_player_id']
    data_store().merge_players(source_id, target_id)
    return 'OK'
Esempio n. 3
0
def api2_admin_delete():
    if not auth(flask.request.form['token']):
        return 'Bye'

    if not flask.request.form['match_guid']:
        return 'Bye'

    data_store().drop_match_info(flask.request.form['match_guid'])
    return 'OK'
Esempio n. 4
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'
Esempio n. 5
0
def login():
    try:
        username = flask.request.form['username']
        password = flask.request.form['password']
    except KeyError:
        pass
    else:
        if username and password:
            user = data_store().get_user(username)
            if user and pbkdf2_sha256.verify(password, user['password']):
                flask.session['username'] = username

    return flask.redirect('/')
Esempio n. 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'
Esempio n. 7
0
def api2_board_badges():
    return flask.jsonify(data_store().get_badge_sum())
Esempio n. 8
0
def api2_match_badge(match_guid):
    return flask.jsonify(data_store().get_match_badges(match_guid))
Esempio n. 9
0
def api2_match_kill(match_guid):
    return flask.jsonify(data_store().get_match_kills(match_guid))
Esempio n. 10
0
def api2_match_special(match_guid):
    return flask.jsonify(data_store().get_match_special_scores(match_guid))
Esempio n. 11
0
def api2_match_team_lifecycle(match_guid):
    return flask.jsonify(data_store().get_team_lifecycle(match_guid))
Esempio n. 12
0
def api2_maps():
    return flask.jsonify(data_store().get_map_stats())
Esempio n. 13
0
def api2_matches():
    return flask.jsonify(data_store().get_matches(132))
Esempio n. 14
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
    })
Esempio n. 15
0
def api2_board_total():
    return flask.jsonify(data_store().get_total_stats())
Esempio n. 16
0
def api2_board_players():
    return flask.jsonify(data_store().get_players())
Esempio n. 17
0
def api2_match_metadata(match_guid):
    return flask.jsonify(data_store().get_match_metadata(match_guid))
Esempio n. 18
0
def api2_player_badges(player_id):
    return flask.jsonify(data_store().get_player_badges(player_id))
Esempio n. 19
0
def api2_match_players(match_guid):
    return flask.jsonify(data_store().get_match_players(match_guid))