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 home(): wmtboc = Races(mysql).get_by_event('WMTBOC') emtboc = Races(mysql).get_by_event('EMTBOC') wmtboc = sorted(wmtboc, key=lambda x: x[1], reverse=True) emtboc = sorted(emtboc, key=lambda x: x[1], reverse=True) wcup = Races(mysql).get_by_event('WCUP') recent = Races(mysql).get_by_year(2021) res = Results(mysql) first_ms = res.first_medal_year(2021) first_me = res.first_medal_year(2021, event='EMTBOC') first = first_ms + first_me for comp in first: tmp = COMPETITORS[comp['competitor_id']] comp['name'] = "{} {}".format(tmp['first'], tmp['last']) comp['team'] = tmp['nationality'] return flask.render_template('index.html', wmtboc=wmtboc, emtboc=emtboc, wcup=wcup, recent=recent, flags=tools.IOC_INDEX, first=first)
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)
def impostor(self, **kwargs): last_insert_id = Results.create( kwargs['impostor'], kwargs['win_flg'], kwargs['impostor02'], kwargs['win_flg02'], kwargs['impostor03'], kwargs['win_flg03'], kwargs['posted_user_name'], kwargs['posted_user_id'], kwargs['posted_server_id']) last_record = Results.last_insert_record(last_insert_id) return helper.format_records( [Results.last_insert_record(last_insert_id)])
def medals_table(event='WMTBOC'): model = Results(mysql) medal_lines = [ model.get_place_count(place, event.upper()) for place in range(1, 4) ] relay_lines = [ model.get_place_count(place, event.upper(), "relay") for place in range(1, 4) ] converted = tools.merge_medal_lines(*medal_lines) converted_relay = tools.merge_medal_lines(*relay_lines) together = tools.merge_medal_dicts(converted, converted_relay) ranking = tools.sort_medal_table(converted) ranking_relay = tools.sort_medal_table(converted_relay) ranking_together = tools.sort_medal_table(together) countries = { COMPETITORS[com_id]["nationality"] for com_id in converted.keys() } rel_countries = { COMPETITORS[com_id]["nationality"] for com_id in converted_relay.keys() } stats = { 'individual': len(converted), 'indiv_countries': len(countries), 'relay': len(converted_relay), 'rel_countries': len(rel_countries) } table_content = { 'all': (together, ranking_together), 'individual': (converted, ranking), 'relay': (converted_relay, ranking_relay) } title = "Medals from {}".format(tools.EVENT_NAMES[event.upper()]) return flask.render_template('medals.html', title=title, stats=stats, table_content=table_content, competitors=COMPETITORS, flags=tools.IOC_INDEX)
def results(self, limit, order_by): records = Results.results(limit, order_by) return [ helper.format_records(arr) for arr in list(helper.split_list(records)) ]
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)
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 count(event='WMTBOC'): wmtboc = Races(mysql).get_by_event(event.upper(), True) per_year = defaultdict(list) for mrace in wmtboc: per_year[mrace[1]].append(mrace[0]) title = event.upper() wmtboc_table = { year: Results(mysql).get_by_events_id(id_list) for year, id_list in per_year.items() } wmtboc_table = { year: (len(flags), flags) for year, flags in wmtboc_table.items() } return flask.render_template('count.html', wmtboc=wmtboc_table, flags=tools.IOC_INDEX, title=title)
def propogate_in_period(self, n, dt): """Checks to see if results exist, otherwise propogates the requested number of times """ from models.results import Results from utils.save_load import save, load key = self.save_key(n, dt) data = load(['propogate_in_period', key]) if data is not None: return data vectors = [(self._spacecraft.position, self._spacecraft.velocity)] position = self._spacecraft.position velocity = self._spacecraft.velocity for i in range(1, n + 1): # Generates the base propogation series and freezes the values vector = self._propogator(vectors[i - 1][0], vectors[i - 1][1], dt) for item in vector: item.flags.writeable = False vectors.append(vector) data = Results(vectors, dt, self._spacecraft._t, self._pname) save(['propogate_in_period', key], data) return data
def get(self): new_result = Results(name='omer', notes=json.dumps({'hi': 3})) db.session.add(new_result) db.session.commit() return 'Ha'
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)
def get(self, text_id): text = DataModel.find_by_text_id(text_id) if text: obj = DataModel(text_id, text.text_description) # class object instance text_desc = obj.text_description # passing text_description(attribute of obj) to text_desc and to operations.py result = operations.words_without_stopwords(text_desc) obj_result = Results(result) obj_result.save_to_db() nouns = operations.total_nouns(text_desc) obj_noun = Results(nouns) obj_noun.save_to_db() adjectives = operations.total_adjectives(text_desc) obj_adjectives = Results(adjectives) obj_adjectives.save_to_db() verbs = operations.total_verbs(text_desc) obj_verbs = Results(verbs) obj_verbs.save_to_db() noun_noun_phrases = operations.noun_noun_phrase(text_desc) obj_noun_noun = Results(noun_noun_phrases) obj_noun_noun.save_to_db() noun_adj_phrases = operations.noun_adj_phrase(text_desc) obj_noun_adj = Results(noun_adj_phrases) obj_noun_adj.save_to_db() adj_noun_phrases = operations.adj_noun_phrase(text_desc) obj_adj_noun = Results(adj_noun_phrases) obj_adj_noun.save_to_db() sentences_with_two_or_more_nouns = operations.sentences_with_two_or_more_nouns(text_desc) obj_sentences_noun = Results(sentences_with_two_or_more_nouns) obj_sentences_noun.save_to_db() sentences_with_two_or_more_adj = operations.sentences_with_two_or_more_adj(text_desc) obj_sentences_adj = Results(sentences_with_two_or_more_adj) obj_sentences_adj.save_to_db() sentences_with_two_or_more_verbs = operations.sentences_with_two_or_more_verbs(text_desc) obj_sentences_verbs = Results(sentences_with_two_or_more_verbs) obj_sentences_verbs.save_to_db() sentences_without_nouns = operations.sentences_without_noun(text_desc) obj_sentences_without_noun = Results(sentences_without_nouns) obj_sentences_without_noun.save_to_db() sentences_without_adjectives = operations.sentences_without_adj(text_desc) obj_sentences_without_adjectives = Results(sentences_without_adjectives) obj_sentences_without_adjectives.save_to_db() sentences_without_verbs = operations.sentences_without_verbs(text_desc) obj_sentences_without_verbs = Results(sentences_without_verbs) obj_sentences_without_verbs.save_to_db() person_names = operations.person_names(text_desc) obj.names = Results(person_names) obj.names.save_to_db() tenses = operations.tense(text_desc) obj_tense = Results(tenses) obj_tense.save_to_db() return {'word_without_stopwords': result, 'nouns': nouns, 'adjectives': adjectives, 'verbs': verbs, 'noun_noun_phrases': noun_noun_phrases, 'noun_adj_phrases': noun_adj_phrases, 'adj_noun_phrases': adj_noun_phrases, 'sentences_with_one_or_more_nouns': str(sentences_with_two_or_more_nouns), 'sentences_with_one_or_more_adj': str(sentences_with_two_or_more_adj), 'sentences_with_one_or_more_verbs': str(sentences_with_two_or_more_verbs), 'sentences_without_nouns': str(sentences_without_nouns), 'sentences_without_adjectives': str(sentences_without_adjectives), 'sentences_without_verbs': str(sentences_without_verbs), 'person_names': person_names, 'sentences_with_different_tenses': tenses} return {"message": "Something is wrong"}