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)
def great_masters(event='WMTBOC', place=None): model = Results(mysql) at_last_one_participation = model.get_participation_years(event) result = {} for competitor_id, participation_nr in at_last_one_participation: if place: place = place if place <= 3 else 3 res = model.get_last_medal(competitor_id, event.upper(), place) else: res = model.get_last_medal(competitor_id, event.upper(), 1) if res: try: born = int(COMPETITORS[competitor_id]['born'].split('-')[0]) except ValueError: born = 0 except AttributeError: born = 0 if born: age = res[0][1] - born result[competitor_id] = [age, res] result = sorted(result.items(), key=lambda kv: kv[1][0], reverse=True) result = [res for res in result if res[1][0] >= 35] title = "Great masters on {}".format(tools.EVENT_NAMES[event.upper()]) if place: disclaimer = "Competitors who got a {} medal in age 35 and older.".format( tools.EVENT_NAMES[event.upper()]) else: disclaimer = "Competitors who got the {} title in age 35 and older.".format( tools.EVENT_NAMES[event.upper()]) return flask.render_template('youngstars.html', title=title, disclaimer=disclaimer, table_data=result, place=place, medal_names=MEDAL_NAMES, competitors=COMPETITORS, flags=tools.IOC_INDEX)