예제 #1
0
def participation_in_event(event='WMTBOC'):

    model = Results(mysql)

    at_last_one_participation = model.get_participation_years(event)

    result = {}

    for competitor_id in at_last_one_participation:
        res = model.get_event_competitor_participation(competitor_id,
                                                       event.upper())
        if res:
            result[competitor_id] = res

    result = sorted(result.items(), key=lambda kv: len(kv[1]), reverse=True)

    title = tools.EVENT_NAMES[event.upper()]
    tname = "{}_NR".format(event.upper())

    return flask.render_template('participations.html',
                                 title=title,
                                 total=getattr(sys.modules[__name__], tname),
                                 table_data=result,
                                 competitors=COMPETITORS,
                                 flags=tools.IOC_INDEX)
예제 #2
0
def competitor(competitor_id):
    model = Results(mysql)
    try:
        current = COMPETITORS[int(competitor_id)]
    except KeyError:
        flask.abort(404)

    data = model.get_competitor_results(competitor_id)
    data.sort(key=operator.itemgetter(2))

    data = [tools.format_competitor_row(row, RACES) for row in data]

    distances = list({row['dist'] for row in data})

    medal_table = tools.prepare_medal_table(model, competitor_id)
    relay_medal_table = tools.prepare_medal_table(model, competitor_id,
                                                  "relay")

    my_wmtboc = model.get_event_competitor_participation(
        competitor_id, 'WMTBOC')
    my_emtboc = model.get_event_competitor_participation(
        competitor_id, 'EMTBOC')

    first_medals = {
        'medal_wmtboc':
        model.get_first_medal(competitor_id, 'WMTBOC'),
        'medal_emtboc':
        model.get_first_medal(competitor_id, 'EMTBOC'),
        'title_wmtboc':
        model.get_first_medal(competitor_id, 'WMTBOC', 1),
        'title_emtboc':
        model.get_first_medal(competitor_id, 'EMTBOC', 1),
        'relay_medal_wmtboc':
        model.get_first_medal(competitor_id, 'WMTBOC', table="relay"),
        'relay_medal_emtboc':
        model.get_first_medal(competitor_id, 'EMTBOC', table="relay"),
        'relay_title_wmtboc':
        model.get_first_medal(competitor_id, 'WMTBOC', 1, table="relay"),
        'relay_title_emtboc':
        model.get_first_medal(competitor_id, 'EMTBOC', 1, table="relay")
    }

    title = "{} {}".format(current['first'], current['last'])

    try:
        birth = current['born'].split('-')[0]
    except AttributeError:
        birth = None

    return flask.render_template('competitor.html',
                                 title=title,
                                 birth=birth,
                                 medal_table=medal_table,
                                 relay_medal_table=relay_medal_table,
                                 wmtboc_total=WMTBOC_NR,
                                 wmtboc_competitor=len(my_wmtboc),
                                 wmtbo_years=", ".join(my_wmtboc),
                                 emtboc_total=EMTBOC_NR,
                                 emtboc_competitor=len(my_emtboc),
                                 emtbo_years=", ".join(my_emtboc),
                                 first_medals=first_medals,
                                 medal_names=MEDAL_NAMES,
                                 races=RACES,
                                 competitor=current,
                                 data=data,
                                 distances=distances,
                                 flags=tools.IOC_INDEX)