Esempio n. 1
0
def search():
    logging.debug(f"Session: {session}")
    # I feel like there should be a better way to do this
    if request.method == 'POST':
        result = SearchForm(request.form)

        session['search'] = result.search.data
        session['order_by'] = result.order_by.data
        session['game'] = result.game.data

        return redirect(url_for('blueprint.search'))
    else:
        if 'search' not in session:
            return index()
        search_query = session['search']
        order_by = session['order_by']
        game = session['game']

    searchForm = SearchForm(request.form, search=search_query, game=game)

    page = request.args.get('page', 1, type=int)

    if game == 'Any':
        game = '%'

    pagination = queries.basic_search(game, search_query,
                                      order_by).paginate(page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=supported_games)
Esempio n. 2
0
def search():
    logging.debug(f"Session: {session}")
    # I feel like there should be a better way to do this
    if request.method == 'POST':
        result = SearchForm(request.form)

        session['search'] = result.search.data
        session['order_by'] = result.order_by.data
        session['game'] = result.game.data

        return redirect(url_for('blueprint.search'))
    else:
        if 'search' not in session:
            return index()
        search_query = session['search']
        order_by = session['order_by']
        game = session['game']

    searchForm = SearchForm(request.form, search=search_query, game=game)

    page = request.args.get('page', 1, type=int)

    if order_by == 'date_replay':
        order = Replays.date_replay.desc()
    elif order_by == 'date_added':
        order = Replays.date_added.desc()
    elif order_by == 'length':
        order = Replays.length.desc()
    else:
        raise LookupError

    if game == 'Any':
        game = '%'

    replay_query = Replays.query.filter(Replays.created == True).filter(
        Replays.failed == False).filter(Replays.game.ilike(f'{game}')).filter(
            Replays.id.in_(
                Descriptions.query.with_entities(Descriptions.id).filter(
                    Descriptions.description.ilike(f'%{search_query}%')))
        ).filter(Replays.video_processed == True).order_by(order)

    logging.debug(replay_query)
    pagination = replay_query.paginate(page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=config['supported_games'])
Esempio n. 3
0
def submitResult():
    logging.debug(f"Session: {session}")
    # I feel like there should be a better way to do this
    if request.method == 'POST':
        result = SubmitForm(request.form)

        challenge_id = result.challenge_url.data
        session['challenge_url'] = result.challenge_url.data

        from fcreplay.getreplay import Getreplay
        replay_result = Getreplay().get_replay(challenge_id,
                                               player_requested=True)

        session['replay_result'] = replay_result
        logging.info(
            f"Submit replay: {challenge_id} status is: {replay_result}")

        # Add replay and get status here
        return redirect(url_for('blueprint.submitResult'))
    else:
        searchForm = SearchForm()
        if 'replay_result' not in session:
            return index()
        result = session['replay_result']
        return render_template('submitResult.j2.html',
                               form=searchForm,
                               result=result,
                               submt_active=True)
Esempio n. 4
0
def submit():
    searchForm = SearchForm()
    submitForm = SubmitForm()
    return render_template('submit.j2.html',
                           form=searchForm,
                           submitForm=submitForm,
                           submit_active=True)
Esempio n. 5
0
def videopage(challenge_id):
    searchForm = SearchForm()

    replay = queries.single_replay(challenge_id)

    char_detect = queries.character_detect(challenge_id)

    characters = []
    for c in char_detect:
        characters.append({
            'p1_char':
            c.p1_char,
            'p2_char':
            c.p2_char,
            'vid_time':
            c.vid_time,
            'seek_time':
            sum(
                int(x) * 60**i
                for i, x in enumerate(reversed(c.vid_time.split(":"))))
        })

    seek = request.args.get('seek', default=0, type=float)

    logging.debug(
        f"Video page, replay: {replay}, characters: {characters}, seek: {seek}"
    )
    return render_template('video.j2.html',
                           replay=replay,
                           characters=characters,
                           seek=seek,
                           form=searchForm,
                           games=supported_games)
Esempio n. 6
0
def advancedSearch():
    searchForm = SearchForm()
    advancedSearchForm = AdvancedSearchForm()

    all_characters_sql = db.session.execute(
        'select p1_char as char,game from character_detect union select p2_char as char,game from character_detect'
    )
    all_characters_dict = {}

    for row in all_characters_sql:
        if row.game not in all_characters_dict:
            all_characters_dict[row.game] = []
        all_characters_dict[row.game].append(row.char)

    players_list = queries.playerlist()
    players_list = sorted(players_list)

    advancedSearchForm.p1_name.choices = players_list
    advancedSearchForm.p2_name.choices = players_list

    return render_template('advancedSearch.j2.html',
                           advancedsearch_active=True,
                           form=searchForm,
                           advancedSearchForm=advancedSearchForm,
                           character_dict=all_characters_dict,
                           players_list=players_list)
Esempio n. 7
0
def about():
    searchForm = SearchForm()

    sortedGames = sorted(supported_games.items(),
                         key=lambda item: item[1]['game_name'])
    supportedGames = {}
    for game in sortedGames:
        supportedGames[game[0]] = {
            'game_name': supported_games[game[0]]['game_name'],
        }
        supportedGames[game[0]]['count'] = db.session.execute(
            f"select count(id) from replays where created = true and game = '{game[0]}'"
        ).first()[0]

    numberOfReplays = db.session.execute(
        'select count(id) from replays where created = true').first()[0]

    toProcess = db.session.execute(
        'select count(id) from replays where created = false and failed = false'
    ).first()[0]

    return render_template('about.j2.html',
                           about_active=True,
                           form=searchForm,
                           supportedGames=supportedGames,
                           numberOfReplays=numberOfReplays,
                           toProcess=toProcess)
Esempio n. 8
0
def advancedSearch():
    searchForm = SearchForm()
    advancedSearchForm = AdvancedSearchForm()
    return render_template('advancedSearch.j2.html',
                           advancedsearch_active=True,
                           form=searchForm,
                           advancedSearchForm=advancedSearchForm)
Esempio n. 9
0
def index():
    searchForm = SearchForm()
    page = request.args.get('page', 1, type=int)
    pagination = queries.all_replays().paginate(page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=supported_games)
Esempio n. 10
0
def player_name():
    searchForm = SearchForm()
    player_name = session['player_name']
    page = request.args.get('page', 1, type=int)
    pagination = queries.player_search(player_name).paginate(page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=supported_games)
Esempio n. 11
0
def advancedSearchResult():
    logging.debug(f"Session: {session}")
    # I feel like there should be a better way to do this
    if request.method == 'POST':
        result = AdvancedSearchForm(request.form)

        session['search'] = result.search.data
        session['p1_name'] = result.p1_name.data
        session['p2_name'] = result.p2_name.data
        session['char1'] = result.char1.data
        session['char2'] = result.char2.data
        session['p1_rank'] = result.p1_rank.data
        session['p2_rank'] = result.p1_rank.data
        session['order_by'] = result.order_by.data
        session['game'] = result.game.data

        return redirect(url_for('blueprint.advancedSearchResult'))
    else:
        if 'search' not in session:
            return index()
        search_query = session['search']
        p1_name = session['p1_name']
        p2_name = session['p2_name']
        char1 = session['char1']
        char2 = session['char2']
        p1_rank = session['p1_rank']
        p2_rank = session['p2_rank']
        order_by = session['order_by']
        game = session['game']

    searchForm = SearchForm()

    page = request.args.get('page', 1, type=int)

    pagination = queries.advanced_search(game_id=game,
                                         p1_rank=p1_rank,
                                         p2_rank=p2_rank,
                                         search_query=search_query,
                                         order_by=order_by,
                                         char1=char1,
                                         char2=char2,
                                         p1_name=p1_name,
                                         p2_name=p2_name).paginate(page,
                                                                   per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=supported_games)
Esempio n. 12
0
def index():
    searchForm = SearchForm()
    page = request.args.get('page', 1, type=int)
    pagination = Replays.query.filter(Replays.created == 'yes').filter(
        Replays.failed == 'no').filter(
            Replays.video_processed == True).order_by(
                Replays.date_added.desc()).paginate(page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=config['supported_games'])
Esempio n. 13
0
def about():
    searchForm = SearchForm()

    sortedGames = sorted(config['supported_games'])
    supportedGames = {}
    for game in sortedGames:
        supportedGames[game] = config['supported_games'][game]
        supportedGames[game]['count'] = db.session.execute(
            f"select count(id) from replays where created = true and game = '{game}'"
        ).first()[0]

    numberOfReplays = db.session.execute(
        'select count(id) from replays where created = true').first()[0]

    toProcess = db.session.execute(
        'select count(id) from replays where created = false and failed = false'
    ).first()[0]

    return render_template('about.j2.html',
                           about_active=True,
                           form=searchForm,
                           supportedGames=supportedGames,
                           numberOfReplays=numberOfReplays,
                           toProcess=toProcess)
Esempio n. 14
0
def advancedSearchResult():
    logging.debug(f"Session: {session}")
    # I feel like there should be a better way to do this
    if request.method == 'POST':
        result = AdvancedSearchForm(request.form)

        session['search'] = result.search.data
        session['char1'] = result.char1.data
        session['char2'] = result.char2.data
        session['p1_rank'] = result.p1_rank.data
        session['p2_rank'] = result.p1_rank.data
        session['order_by'] = result.order_by.data
        session['game'] = result.game.data

        return redirect(url_for('blueprint.advancedSearchResult'))
    else:
        if 'search' not in session:
            return index()
        search_query = session['search']
        char1 = session['char1']
        char2 = session['char2']
        p1_rank = session['p1_rank']
        p2_rank = session['p2_rank']
        order_by = session['order_by']
        game = session['game']

    searchForm = SearchForm()

    page = request.args.get('page', 1, type=int)

    if order_by == 'date_replay':
        order = Replays.date_replay.desc()
    elif order_by == 'date_added':
        order = Replays.date_added.desc()
    elif order_by == 'length':
        order = Replays.length.desc()
    else:
        raise LookupError

    if char1 == 'Any':
        char1 = '%'
    if char2 == 'Any':
        char2 = '%'

    if game == 'Any':
        game = '%'

    if p1_rank == 'any':
        p1_rank = '%'
    if p2_rank == 'any':
        p2_rank = '%'

    replay_query = [
        Replays.created == True, Replays.failed == False,
        Replays.game.ilike(f'{game}'),
        Replays.p1_rank.ilike(f'{p1_rank}'),
        Replays.p2_rank.ilike(f'{p2_rank}'),
        Replays.id.in_(
            Descriptions.query.with_entities(Descriptions.id).filter(
                Descriptions.description.ilike(f'%{search_query}%'))),
        Replays.video_processed == True
    ]

    with open(
            pkg_resources.resource_filename(
                'fcreplay', 'data/character_detect.json')) as json_data_file:
        character_dict = json.load(json_data_file)

    if game in character_dict:
        replay_query.append(
            Replays.id.in_(
                Character_detect.query.with_entities(
                    Character_detect.challenge_id).filter(
                        Character_detect.p1_char.ilike(f'{char1}')
                        & Character_detect.p2_char.ilike(f'{char2}')).
                union(
                    Character_detect.query.with_entities(
                        Character_detect.challenge_id).filter(
                            Character_detect.p1_char.ilike(f'{char2}')
                            & Character_detect.p2_char.ilike(f'{char1}')))))

    logging.debug(Replays.query.filter(*replay_query))
    pagination = Replays.query.filter(*replay_query).order_by(order).paginate(
        page, per_page=9)
    replays = pagination.items

    return render_template('start.j2.html',
                           pagination=pagination,
                           replays=replays,
                           form=searchForm,
                           games=config['supported_games'])