def race(race_id): model = Results(mysql) try: race = RACES[int(race_id)] except KeyError: flask.abort(404) data = model.get_race_results(race_id) title = "{} {} {}".format(race['event'], race['year'], DISTANCE_NAMES[race['distance']]) if race['distance'] == 'relay': women_list = model.get_relay_results(race_id, 'W') men_list = model.get_relay_results(race_id, 'M') women = tools.prepare_relay_output(women_list) men = tools.prepare_relay_output(men_list) country = set(men.keys()).union(set(women.keys())) return flask.render_template('relay.html', title=title, women=women, men=men, stats={ 'men': len(men.keys()), 'women': len(women.keys()), 'country': len(country) }, competitors=COMPETITORS, flags=tools.IOC_INDEX, race=race) elif race['distance'] in ('sprint-relay', 'mix-relay'): result_list = model.get_relay_results(race_id, 'X') results = tools.prepare_relay_output(result_list) return flask.render_template('mix_relay.html', title=title, results=results, stats={'teams': len(results.keys())}, competitors=COMPETITORS, flags=tools.IOC_INDEX, race=race) else: women = [row for row in data if COMPETITORS[row[0]]["gender"] == 'F'] men = [row for row in data if COMPETITORS[row[0]]["gender"] == 'M'] country = {COMPETITORS[row[0]]["nationality"] for row in data} return flask.render_template('race.html', title=title, women=women, men=men, stats={ 'men': len(men), 'women': len(women), 'country': len(country) }, competitors=COMPETITORS, flags=tools.IOC_INDEX, race=race)
def nation(code, year): code = code.upper() sel_competitors = { cid: comp for cid, comp in COMPETITORS.items() if comp['nationality'] == code } id_comp = {val['competitor_id'] for val in sel_competitors.values()} races_year = Races(mysql).get_by_year(year) model = Results(mysql) all_results = [model.get_race_results(myrace[0]) for myrace in races_year] filtered_results = [[row for row in result if row[0] in id_comp] for result in all_results] filtered_results = [result for result in filtered_results if result] if filtered_results: title = "Team {} results for {}".format(code, year) return flask.render_template('races_team.html', title=title, results=filtered_results, competitors=sel_competitors, race_info=RACES, years=tools.years(), team=code) else: title = "No results for team {} in {}".format(code, year) return flask.render_template('races_team_nores.html', title=title)