def main(): w = funcs.open_out_file(week_end, "ranking") w.write("Ranking Overview; Week %i-%i:\n\n" % (week_start, week_end)) all_ranks = {} for week in range(week_start, week_end + 1): teams, swaps, aces, wildcards, anime, a_scores, t_scores = funcs.load_all_data( week) # get all previous ranks for team, (_, _, rank) in t_scores.items(): all_ranks.setdefault(team, []).append(rank) # get length of longest username max_name = max([len(team) for team in all_ranks]) w.write("%s" % blank(max_name, 1)) for week in range(week_start, week_end + 1): if week < 10: w.write("%sweek %i " % (blank((p_num + p_num), 3), week)) else: w.write("%sweek %i " % (blank((p_num + p_num), 4), week)) w.write("\n") for team, ranks in sorted(all_ranks.items(), key=lambda x: x[0].lower()): ranking = format_ranking([0] + ranks) w.write("%s%s%s\n" % (team, blank(max_name, len(team) - 2), ranking)) if w: w.close()
def banner_data(): """ Creates input for banner scripts. """ weekly_output_file = open("bannerdata/week%i.txt" % WEEK, "w") _, _, _, _, _, _, t_scores = funcs.load_all_data(WEEK) for team, scores in sorted(t_scores.items(), key=lambda x: x[1][2]): weekly_output_file.write("%s = %i\n" % (team, scores[2])) weekly_output_file.close()
def team_stats(prep=False): """ Creates a statistic of the titles distribution for the team overview thread. This function can also be used during the game to obtain the distribution of the current week. @param prep during the real game (False) or before the game (True) """ if not prep: teams, _, _, _, anime, _, _ = funcs.load_all_data(WEEK) stats_file = open("lists/team_stats_%.2d.txt" % WEEK, "w") else: teams = pickle.load(open("lists/teams.obj")) stats_file = open("lists/team_stats.txt", "w") stats_file.write("[u]Team Stats:[/u]\n") stats_file.write( "The list is ordered on how many times people chose a certain anime ") stats_file.write( "in their team. The number in the brackets is the amount of people ") stats_file.write("who have the anime in their active team.\n\n") anime = re.findall(r'(\d+)\s(.+)', open("lists/anime_list.txt").read()) stats = {a_title.strip(): [0, 0] for a_id, a_title in anime} for series in teams.values(): for _, a_title in series: stats[a_title][0] += 1 for _, a_title in series[:TEAM_LEN]: stats[a_title][1] += 1 s_name = sorted(stats.items(), key=lambda x: x[0].lower()) s_act = sorted(s_name, key=lambda x: x[1][1], reverse=True) s_all = sorted(s_act, key=lambda x: x[1][0], reverse=True) for n, (a_title, _) in enumerate(s_all): stats_file.write( "%i - %s: %i (%i)\n" % ((n + 1), a_title, stats[a_title][0], stats[a_title][1])) stats_file.close()
def team_dist(prep=False): """ Creates a statistic of the team distribution (how many people and who chose the same team) This function can also be used during the game to obtain the team distribution of the current week. @param prep during the real game (False) or before the game (True) """ if not prep: teams, _, _, _, _, _, _ = funcs.load_all_data(WEEK) team_dist_file = open("lists/team_dist_%.2d.txt" % WEEK, "w") else: teams = pickle.load(open("lists/teams.obj")) team_dist_file = open("lists/team_dist.txt", "w") split_teams = {} nonsplit_teams = {} active_teams = {} for team, series in teams.items(): s_team = tuple( sorted(series[:TEAM_LEN], key=lambda x: x[1]) + sorted(series[TEAM_LEN:], key=lambda x: x[1])) n_team = tuple(sorted(series, key=lambda x: x[1])) a_team = tuple(sorted(series[:TEAM_LEN], key=lambda x: x[1])) # add team name to inverse dictionary (key: sorted list of series) if s_team not in split_teams: split_teams[s_team] = [] split_teams[s_team].append(team) if n_team not in nonsplit_teams: nonsplit_teams[n_team] = [] nonsplit_teams[n_team].append(team) if a_team not in active_teams: active_teams[a_team] = [] active_teams[a_team].append(team) same_series_diff_team_dist = 0 n_list_non = [] for series, team_list in nonsplit_teams.items(): if len(team_list) != 1: n_list_non.append((len(team_list), team_list)) else: same_series_diff_team_dist += 1 same_series_and_team_dist = 0 n_list_split = [] for series, team_list in split_teams.items(): if len(team_list) != 1: n_list_split.append((len(team_list), team_list)) else: same_series_and_team_dist += 1 teams_with_same_active_team = 0 n_list_act = [] for series, team_list in active_teams.items(): if len(team_list) != 1: n_list_act.append((len(team_list), team_list)) else: teams_with_same_active_team += 1 team_dist_file.write( "[u]Same 7 series and same active team/bench distribution[/u]\n") team_dist_file.write("Number of unique teams: %i\n\n" % same_series_and_team_dist) team_dist_file.write("Same team chosen by:\n") team_dist_file.write("[list]") for entry in sorted(n_list_split, key=lambda x: x[0], reverse=True): team_dist_file.write("[*]%s\n" % (", ".join(sorted(entry[1], key=str.lower)))) team_dist_file.write("[/list]\n") team_dist_file.write( "[u]Same 7 series but different active team/bench distribution[/u]\n") team_dist_file.write("Number of unique teams: %i\n\n" % same_series_diff_team_dist) team_dist_file.write("Same team chosen by:\n") team_dist_file.write("[list]") for entry in sorted(n_list_non, key=lambda x: x[0], reverse=True): team_dist_file.write("[*]%s\n" % (", ".join(sorted(entry[1], key=str.lower)))) team_dist_file.write("[/list]\n") team_dist_file.write( "[u]Same active team (but can have different benched series)[/u]\n") team_dist_file.write("Number of unique active teams: %i\n\n" % teams_with_same_active_team) team_dist_file.write("Same team chosen by:\n") team_dist_file.write("[list]") for entry in sorted(n_list_act, key=lambda x: x[0], reverse=True): team_dist_file.write("[*]%s\n" % (", ".join(sorted(entry[1], key=str.lower)))) team_dist_file.write("[/list]") team_dist_file.close()
def main(): teams, swaps, aces, wildcards, anime, a_scores, t_scores = funcs.load_all_data( week) xteams, xswaps, xaces, xwildcards, xanime, xa_scores, xt_scores = funcs.load_all_data( week - 1) w = funcs.open_out_file(week, "details") # check for name changes name_changes = funcs.map_users() inv_name_changes = { new[-1]: [initial] + new[:-1] for initial, new in name_changes.items() } # get all nuke receivers (only if this is the first time of wildcard) ### useless?? not used in rest of the code apparently nukes = [(t, wc[13:]) for t, wc in wildcards.items() if "nuke-up" in wc and xwildcards[t] == ""] nukes.extend([(t, wc[15:]) for t, wc in wildcards.items() if "nuke-down" in wc and xwildcards[t] == ""]) # get all nuke senders (only if this is the first time the wildcard is used) nuke_senders = { t: (wc[5:12], wc[13:]) for t, wc in wildcards.items() if "nuke-up" in wc and xwildcards[t] == "" } nuke_senders.update({ t: (wc[5:14], wc[15:]) for t, wc in wildcards.items() if "nuke-down" in wc and xwildcards[t] == "" }) # get all nuke receivers (only if this is the first time the wildcard is used) nuke_recs = {} for sender, (nuke, rec) in nuke_senders.items(): nuke_recs.setdefault(rec, []).append((nuke, sender)) # ------------------------------------------------------------------------- # STATUS # ------------------------------------------------------------------------- for team in sorted(teams, key=str.lower): old_names = funcs.get_old_names(team, inv_name_changes) #w.write("%s\n| %s%s |\n%s\n" % (("-"*(len(team+old_names)+4)), team, old_names, ("-"*(len(team+old_names)+4)))) tmp_str = "Team: %s%s" % (team, old_names) #w.write("%s\n%s\n\n" % (tmp_str, ("-"*len(tmp_str)))) w.write("%s\n\n" % (tmp_str)) tmp_str = "Status before week %i:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) w.write("Rank: %i\n" % xt_scores[team][2]) w.write("All points: %i\n" % xt_scores[team][0]) if team != 'Squirrel500' and team != 'starlightshine': w.write("Active team: %s\n" % ", ".join(sorted([t[1] for t in xteams[team][:-2]]))) w.write("Bench: %s\n" % ", ".join(sorted([t[1] for t in xteams[team][-2:]]))) w.write("Swaps left: %i\n\n" % xswaps[team][0]) # ------------------------------------------------------------------------- # SWAPS # ------------------------------------------------------------------------- w.write("Swaps:\n") if xteams[team][-1][1] != teams[team][-1][1]: w.write("out: %s\nin: %s\n\n" % (teams[team][-1][1], xteams[team][-1][1])) elif xteams[team][-2][1] != teams[team][-2][1]: w.write("out: %s\nin: %s\n\n" % (teams[team][-2][1], xteams[team][-2][1])) else: w.write("None\n\n") # ------------------------------------------------------------------------- # UNIQUE TEAM SCORE # ------------------------------------------------------------------------- w.write("Unique Team Score:\n") if t_scores[team][3] != week: w.write("None\n\n") upoints = 0 else: w.write("%i\n\n" % 4000) upoints = 4000 # ------------------------------------------------------------------------- # ACES # ------------------------------------------------------------------------- w.write("Ace:\n") a_points = 0 old_aces = xaces[team] new_aces = aces[team] print "%s \n" % team print xaces[team] print "\n" print aces[team] print "\n" if len(old_aces) == len(new_aces): w.write("None\n\n") else: ace = new_aces[-1] team_anime = [ a[0] for a in teams[team][:-2] if (anime[a[0]][3][0] + anime[a[0]][3][1]) <= ace_cutoff ] ace_points = [a_scores[a_id][1] for a_id in team_anime] if ace not in team_anime or ace_points[team_anime.index( ace)] != max(ace_points): w.write("%s: %i\n" % (anime[new_aces[-1]][0], -3000)) a_points = -3000 elif ace_points[team_anime.index(ace)] == max(ace_points): w.write("%s: %i\n" % (anime[new_aces[-1]][0], 3000)) a_points = 3000 w.write("\n") #w.write("=> %i\n\n" % a_points) # ------------------------------------------------------------------------- # WILDCARDS # ------------------------------------------------------------------------- w.write("Wildcards:\n") w_points = 0 if week < start_wildcards: w.write("Not yet available\n\n") else: if (wildcards[team] == "" or xwildcards[team] != "") and team not in nuke_recs: w.write("None\n") if wildcards[team] != "" and xwildcards[team] == "": wildcard = wildcards[team][5:] if wildcard == "booster": w.write("%s: %i\n" % (wildcard.capitalize(), 3000)) w_points += 3000 elif wildcard == "extra-swap": w.write("%s: %i\n" % (wildcard.capitalize(), -1500)) w_points -= 1500 else: w.write("%s sent to %s: %i\n" % (nuke_senders[team][0].capitalize(), nuke_senders[team][1], -1500)) w_points -= 1500 if team in nuke_recs: for nuke, sender in sorted(nuke_recs[team], key=lambda x: x[1].lower()): w.write("%s received from %s: %i\n" % (nuke.capitalize(), sender, -6750)) w_points -= 6750 w.write("\n") #w.write("=> %i\n\n" % w_points) # ------------------------------------------------------------------------- # WEEKLY POINTS: WATCHING/COMPLETED # ------------------------------------------------------------------------- tmp_str = "Week %i watching points:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) weekly_points = 0 if team != 'starlightshine': for a_id, a_title in sorted(teams[team][:-2], key=lambda x: x[1]): watching, completed, _, _, _ = anime[a_id][3] w.write("%s\n" % anime[a_id][0]) w.write("- Watching: %i\n" % watching) weekly_points += watching if completed > 0: w.write("- Completed: %i\n" % completed) weekly_points += completed if anime[a_id][2] <= double_watching: w.write("- Watching x2: %i\n" % watching) weekly_points += watching if completed > 0 and anime[a_id][2] <= double_watching: w.write("- Completed x2: %i\n" % completed) weekly_points += completed w.write("=> %i\n\n" % weekly_points) # ------------------------------------------------------------------------- # FORUM POSTS # ------------------------------------------------------------------------- tmp_str = "Week %i discussion post points:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) forum_points = 0 if week % 2 == 1: w.write("Discussion posts ARE NOT counted this week\n\n") else: if team != 'starlightshine': for a_id, a_title in sorted(teams[team][:-2], key=lambda x: x[1]): w.write("%s (%i): %i \n" % (anime[a_id][0], anime[a_id][1][1], anime[a_id][1][1] * 25)) forum_points += anime[a_id][1][1] * 25 w.write("=> %i\n\n" % forum_points) # ------------------------------------------------------------------------- # SPECIAL WEEK POINTS # ------------------------------------------------------------------------- addpoints = 0 if week in week_scores or week in week_dropped or week in week_favorites: tmp_str = "Week %i additional points:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) if team != 'starlightshine': for a_id, a_title in sorted(teams[team][:-2], key=lambda x: x[1]): scorepoints = 0 w.write("%s\n" % anime[a_id][0]) _, _, dropped, score, favs = anime[a_id][3] if week in week_scores: w.write("- Score (%.2f): %i\n" % (score, int(round(score * week_scores[week])))) scorepoints += int(round(score * week_scores[week])) if week in week_dropped: w.write("- Dropped (%i): %i\n" % (dropped, dropped * (-1) * week_dropped[week])) scorepoints += dropped * (-1) * week_dropped[week] if week in week_favorites: w.write("- Favorites (%i): %i\n" % (favs, favs * week_favorites[week])) scorepoints += favs * week_favorites[week] addpoints += scorepoints w.write("=> %i\n\n" % addpoints) # ------------------------------------------------------------------------- # SIMULCAST POINTS # ------------------------------------------------------------------------- if week in fansub_week: tmp_str = "Week %i simulcast points:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) fansub_points = 0 if team != 'starlightshine': for a_id, a_title in sorted(teams[team][:-2], key=lambda x: x[1]): w.write("%s: %i \n" % (anime[a_id][0], anime[a_id][5][1])) fansub_points += anime[a_id][5][1] w.write("=> %i\n\n" % fansub_points) addpoints += fansub_points # ------------------------------------------------------------------------- # LICENSE POINTS # ------------------------------------------------------------------------- if week == license_week: tmp_str = "Week %i license points:" % license_week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) license_points = 0 for a_id, a_title in sorted(teams[team][:-2], key=lambda x: x[1]): if anime[a_id][6] == 1: w.write("%s: %i \n" % (anime[a_id][0], 10000)) license_points += anime[a_id][6] * 10000 w.write("=> %i\n\n" % license_points) addpoints += license_points # ------------------------------------------------------------------------- # SUM UP POINTS # ------------------------------------------------------------------------- addxpoints = addpoints + upoints w.write("\nwildcards ace watching posts additional\n") if get_sign(w_points) == "+": sign = "" else: sign = "-" w.write("%s%s%i" % (sign, blank(len("wildcards"), (len(str(abs(w_points))) + len(sign))), abs(w_points))) w.write(" %s%s %i" % (get_sign(a_points), blank(len(" ace"), len(str( abs(a_points)))), abs(a_points))) w.write( " +%s %i" % (blank(len("watching"), len(str(weekly_points))), weekly_points)) w.write(" +%s %i" % (blank(len("posts"), len(str(forum_points))), forum_points)) w.write(" %s%s %i" % (get_sign(addxpoints), blank(len("additional"), len(str( abs(addxpoints)))), abs(addxpoints))) w.write("\n\n\n") # ------------------------------------------------------------------------- # STATUS # ------------------------------------------------------------------------- tmp_str = "Status after week %i:" % week w.write("%s\n%s\n" % (tmp_str, ("-" * len(tmp_str)))) w.write("Rank: %i\n" % t_scores[team][2]) w.write("New points: %i\n" % t_scores[team][1]) w.write("All points: %i\n" % t_scores[team][0]) if team != 'Squirrel500' and team != 'starlightshine': w.write("Active team: %s\n" % ", ".join(sorted([t[1] for t in teams[team][:-2]]))) if team != 'Squirrel500' and team != 'starlightshine': w.write("Bench: %s\n" % ", ".join(sorted([t[1] for t in teams[team][-2:]]))) w.write("Swaps left: %i\n" % swaps[team][0]) next_swap = swaps[team][1] if next_swap == 0: w.write("Next swap available: in week %i\n" % (week + 1)) else: w.write("Next swap available: in week %i\n" % (week + next_swap)) #w.write("\n%s\n\n" % ("-"*104)) w.write("\n%s\n\n" % ("#" * 60)) if w: w.close()
def main(): teams, swaps, aces, wildcards, anime, a_scores, t_scores = funcs.load_all_data(week) xteams, xswaps, xaces, xwildcards, xanime, xa_scores, xt_scores = funcs.load_all_data(week-1) w = funcs.open_out_file(week, "results") # check for name changes name_changes = funcs.map_users() inv_name_changes = {new[-1]: [initial]+new[:-1] for initial, new in name_changes.items()} # ------------------------------------------------------------------------- # POINTS CRITERIA # ------------------------------------------------------------------------- w.write("Big thanks to ___ for helping out this week.\n\n") # TODO: generate this dynamically w.write("You can find more details and an overview of all the results in the club's [url=https://myanimelist.net/forum/?topicid=1744449]official FAL Spring 2017 thread[/url].\n\n") w.write("[b][u]Points Criteria[/u][/b]\n") w.write("Please see the [url=https://myanimelist.net/forum/?topicid=1742552]Rules thread[/url].\n\n") # ------------------------------------------------------------------------- # DISCUSSION POST NOTICE # ------------------------------------------------------------------------- w.write("[b]%s[/b]\n" % ("-"*deln)) if week % 2 == 0: w.write("[b]Discussion posts ARE counted this week[/b]\n") else: w.write("[b]Discussion posts ARE NOT counted this week[/b]\n") w.write("[b]%s[/b]\n\n" % ("-"*deln)) # ------------------------------------------------------------------------- # ANIME POINTS # ------------------------------------------------------------------------- w.write("[u]Week %i Anime Points:[/u][spoiler]\n" % week) for a_id, info in sorted(anime.items(), key=lambda x:x[1][0].lower()): title, (all_posts, posts), count, details, (all_threads, threads), (fansubs, f_score), l_score = info watching, completed, dropped, score, favorites = details w.write("[u]%s[/u]\n" % title) # discussion posts points if week % 2 == 0: w.write("Episode discussion posts (%i): %i\n" % (posts, posts*25)) # weekly points w.write("Users watching: %i\n" % watching) if completed > 0: w.write("Users completed: %i\n" % completed) if count <= double_watching: w.write("In %i or fewer active teams: watching points x2\n" % double_watching) if completed > 0 and count <= double_watching: w.write("In %i or fewer active teams: completed points x2\n" % double_watching) # additional points if week in week_scores: w.write("Score (%.2f): %i\n" % (score, int(round(score * week_scores[week])))) if week in week_dropped: w.write("Users dropped (%i): %i\n" % (dropped, dropped*(-1)*week_dropped[week])) if week in week_favorites: w.write("Favorites (%i): %i\n" % (favorites, favorites*week_favorites[week])) # simulcast points if week in fansub_week: w.write("Simulcast points: %i\n" % f_score) # license points if week == license_week: w.write("License points: %i\n" % (l_score * 10000)) w.write("Total points: %i\n" % a_scores[a_id][1]) if title != sorted(anime.values(),key=lambda x:x[0].lower())[-1][0]: w.write("\n") w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # POINTS RANKINGS # ------------------------------------------------------------------------- w.write("[u]Total Weekly Points Rankings:[/u][spoiler]\n") for a_id, scores in sorted(a_scores.items(), key=lambda x:x[1][1], reverse=True): w.write("%s - %i\n" % (anime[a_id][0].replace("_"," "), scores[1])) w.write("[/spoiler]\n\n") w.write("[u]Total Overall Points Rankings:[/u][spoiler]\n") for a_id, scores in sorted(a_scores.items(), key=lambda x:x[1][0], reverse=True): w.write("%s - %i\n" % (anime[a_id][0].replace("_"," "), scores[0])) w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # HIGHEST UNIQUE SCORE # ------------------------------------------------------------------------- w.write("[u]Highest Unique Team Score:[/u][spoiler]\n") w.write("%s\n" % sorted(t_scores.items(), key=lambda x:x[1][3], reverse=True)[0][0]) w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # ACE USERS # ------------------------------------------------------------------------- w.write("[u]Ace users:[/u]\n[spoiler]\n") used_aces = 0 for team, ace_list in sorted(aces.items(), key=lambda x:x[0].lower()): old_names = funcs.get_old_names(team, inv_name_changes) old_aces = xaces[team] new_aces = aces[team] print "results" print " %s" % team print aces[team] print "\n" if len(old_aces) == len(new_aces): continue used_aces += 1 ace = new_aces[-1] team_anime = [a[0] for a in teams[team][:-bench_len] if (anime[a[0]][3][0]+anime[a[0]][3][1]) <= ace_cutoff] ace_points = [a_scores[a_id][1] for a_id in team_anime] if ace not in team_anime or ace_points[team_anime.index(ace)] != max(ace_points): w.write("%s - [color=red]%s[/color]\n" % (team, anime[new_aces[-1]][0].replace("_"," "))) elif ace_points[team_anime.index(ace)] == max(ace_points): w.write("%s - [color=green]%s[/color]\n" % (team, anime[new_aces[-1]][0].replace("_"," "))) if used_aces == 0: w.write("None\n") w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # WILDCARD USAGE # ------------------------------------------------------------------------- if week >= start_wildcards: wc_booster = [] wc_nuke_rec = [] wc_nuke_recoil_rec = [] wc_extra_swap = [] for team, wildcard in sorted(wildcards.items(), key=lambda x:x[0].lower()): old_names = funcs.get_old_names(team, inv_name_changes) if xwildcards[team] != "": continue if wildcard[5:] == "booster": wc_booster.append(team) if "nuke-up" in wildcard: wc_nuke_rec.append(wildcard[13:]) wc_nuke_recoil_rec.append(team) if "nuke-down" in wildcard: wc_nuke_rec.append(wildcard[15:]) wc_nuke_recoil_rec.append(team) if wildcard[5:] == "extra-swap": wc_extra_swap.append(team) w.write("[u]Wildcard usage:[/u]\n[spoiler]\n") w.write("[u]Booster users (+3000 points):[/u]\n") if len(wc_booster) == 0: w.write("None\n") for team in wc_booster: w.write("%s%s\n" % (team, old_names)) w.write("\n[u]Nuke receivers (-6750 points):[/u]\n") if len(wc_nuke_rec) == 0: w.write("None\n") for team in wc_nuke_rec: w.write("%s%s\n" % (team, old_names)) w.write("\n[u]Nuke recoil receivers (-1500 points):[/u]\n") if len(wc_nuke_recoil_rec) == 0: w.write("None\n") for team in wc_nuke_recoil_rec: w.write("%s%s\n" % (team, old_names)) w.write("\n[u]Extra swap users (-1500 points):[/u]\n") if len(wc_extra_swap) == 0: w.write("None\n") for team in wc_extra_swap: w.write("%s%s\n" % (team, old_names)) w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # TEAM RANKINGS # ------------------------------------------------------------------------- w.write("[u]Team Rankings:[/u]\n[spoiler]\n") ranked_teams = {} _, _, _, _, _, _, xt_scores = funcs.load_all_data(week-1) for team, info in sorted(t_scores.items(), key=lambda x:x[1][2]): ranked_teams.setdefault(info[2], []).append(team) for rank, team_list in sorted(ranked_teams.items()): for team in sorted(team_list, key=str.lower): old_names = funcs.get_old_names(team, inv_name_changes) w.write("[b]%i[/b] %s %s%s - %i\n" % (rank, ranking_diff(xt_scores[team][2],rank),\ team, old_names, t_scores[team][0])) w.write("[/spoiler]\n\n") # ------------------------------------------------------------------------- # ERROR LOG # ------------------------------------------------------------------------- w.write("[u]Errors:[/u]\n[spoiler]\n") e = open("results/week_%.2i_errors.txt" % week).readlines() if not e: w.write("None\n") errors = {} for line in e: team, error = line.split(" - ") errors.setdefault(team, []).append(error.strip()) for team, error_list in sorted(errors.items()): for error in error_list: w.write("%s - %s\n" % (team, error)) w.write("[/spoiler]\n\n") if w: w.close()
def main(retrieve=True): """ Main function of the scorer. """ mapping = funcs.map_anime() httpconn = httplib.HTTPSConnection("myanimelist.net") e = funcs.open_out_file(week, "errors") # inizialize all data structures in week 1 if week == 1: init_data() # load all data structures from the week before, including name changes teams, swaps, aces, wildcards, anime, a_scores, t_scores = funcs.load_all_data( week - 1) # set current team scores to 0 for team in t_scores: t_scores[team][1] = 0 #for pre-run points deductions ''' for team in teams: for borked_anime in teams[team][:5]: b_title = borked_anime[1] if b_title == 'Anima Yell!': print b_title t_scores[team][1] -= 1562 if b_title == 'Hinomaruzumou': print b_title t_scores[team][1] -= 7518 if b_title == 'Kaze ga Tsuyoku Fuiteiru': print b_title t_scores[team][1] -= 12387 if b_title == 'Release the Spyce': print b_title t_scores[team][1] -= 4253 if b_title == 'RErideD: Tokigoe no Derrida': print b_title t_scores[team][1] -= 6854 if b_title == 'SSSS.Gridman': print b_title t_scores[team][1] -= 7316 if b_title == 'Uchi no Maid ga Uzasugiru!': print b_title t_scores[team][1] -= 9740 if b_title == 'Ulysses: Jehanne Darc to Renkin no Kishi': print b_title t_scores[team][1] -= 3343 print t_scores ''' # extract bench titles bench = { team_name: [a_titles.pop() for i in range(bench_len)][::-1] for team_name, a_titles in teams.items() } # extended slices http://docs.python.org/release/2.3.5/whatsnew/section-slices.html # start using wildcards in week X wildcards, t_scores, swaps = use_wildcards(wildcards, t_scores, swaps, e) # make swaps #teams, swaps, _, _, _, _, _ = funcs.load_all_data(week) #bench = {team_name: [a_titles.pop() for i in range(bench_len)][::-1] for team_name, a_titles in teams.items()} teams, bench, swaps = make_swaps(teams, bench, swaps, anime, mapping, httpconn, e) # count the number of teams for every anime (active team only, not bench) flat_list = [item for sublist in teams.values() for item in sublist] for a_id in anime: anime[a_id][2] = sum([1 for x in flat_list if x[0] == a_id]) # calculate scores for every anime entry if retrieve: for a_id, a_info in anime.items(): score, new_posts, detailed_info, new_threads = get_score( a_id, a_info, week, httpconn) anime[a_id][1][0] += new_posts # add new posts to all posts anime[a_id][1][1] = new_posts # set current posts anime[a_id][3] = detailed_info # set detailed info anime[a_id][4][0] += new_threads # add new posts to all posts anime[a_id][4][1] = new_threads # set current posts a_scores[a_id][1] = score # set current score # use existing scores for the given week (if you need to fix errors like missing aces) else: _, _, _, _, anime, a_scores, _ = funcs.load_all_data(week) #change totals; subtract current current scores if not retrieve: for a_id in a_scores: a_scores[a_id][0] -= a_scores[a_id][1] # follow the format of the below code to make changes to discussion posts when retrieve == False ''' anime['33985'][1][0] -= 87 anime['33985'][1][1] -= 87 a_scores['33985'][1] -= 87*25 anime['33041'][1][0] -= 38 anime['33041'][1][1] -= 38 a_scores['33041'][1] -= 38*25 anime['33572'][1][0] -= 3 anime['33572'][1][1] -= 3 a_scores['33572'][1] -= 3*25 anime['33299'][1][0] -= 5 anime['33299'][1][1] -= 5 a_scores['33299'][1] -= 5*25 anime['33003'][1][0] -= 138 anime['33003'][1][1] -= 138 a_scores['33003'][1] -= 138*25 anime['33051'][1][0] -= 40 anime['33051'][1][1] -= 40 a_scores['33051'][1] -= 40*25 anime['31631'][1][0] -= 17 anime['31631'][1][1] -= 17 a_scores['31631'][1] -= 17*25 anime['32603'][1][0] -= 37 anime['32603'][1][1] -= 37 a_scores['32603'][1] -= 37*25 anime['32038'][1][0] -= 5 anime['32038'][1][1] -= 5 a_scores['32038'][1] -= 5*25 anime['33433'][1][0] -= 192 anime['33433'][1][1] -= 192 a_scores['33433'][1] -= 192*25 anime['32881'][1][0] -= 39 anime['32881'][1][1] -= 39 a_scores['32881'][1] -= 39*25 anime['33023'][1][0] -= 21 anime['33023'][1][1] -= 21 a_scores['33023'][1] -= 21*25 anime['31178'][1][0] -= 27 anime['31178'][1][1] -= 27 a_scores['31178'][1] -= 27*25 anime['33589'][1][0] -= 31 anime['33589'][1][1] -= 31 a_scores['33589'][1] -= 31*25 anime['33094'][1][0] -= 104 anime['33094'][1][1] -= 104 a_scores['33094'][1] -= 104*25 ''' # simulcasts if week in fansub_week: print "fetching simuls" old_scores = {a_id: a_info[5][1] for (a_id, a_info) in anime.items() } # store old information for not retrieve case anime = get_fansubs(anime, mapping, retrieve) for a_id, a_info in anime.items(): if not retrieve: a_scores[a_id][1] -= old_scores[a_id] a_scores[a_id][1] += a_info[5][1] # licenses if week == license_week: anime = get_licenses(anime, mapping) for a_id, a_info in anime.items(): a_scores[a_id][1] += a_info[6] * 10000 # assign anime scores to users for team in teams: print team for a_id in [a[0] for a in teams[team]]: print a_id t_scores[team][1] += a_scores[a_id][1] # process aces aces, teams, t_scores = determine_aces(aces, teams, t_scores, a_scores, anime, mapping, e) # apply highest unique score last = 0 sorted_highest = sorted(t_scores.items(), key=lambda x: x[1][1], reverse=True) for x in sorted_highest[:5]: print x for i, (team, (_, points, _, received)) in enumerate(sorted_highest): print i, team, points, sorted_highest[i + 1][1][1] if points == last: continue # several teams have the same weekly score if points == sorted_highest[i + 1][1][1]: last = points continue # team has already received unique bonus if received > 0: last = points continue # apply bonus to the team t_scores[team][1] += 4000 t_scores[team][3] = week break # add new scores to all scores #old_a_scores = {a_id: scores[1] for (a_id, scores) in a_scores.items()} # store old information for not retrieve case for a_id in a_scores: a_scores[a_id][0] += a_scores[a_id][1] #if not retrieve: #a_scores[a_id][0] -= old_a_scores[a_id] for team in teams: t_scores[team][0] += t_scores[team][1] # add bench titles back to team for team in teams: teams[team].extend(bench[team]) # get new ranking and add it to t_scores ranking = get_ranking(t_scores) for team, rank in ranking.items(): t_scores[team][2] = rank # save all data structures for the current week #print aces funcs.save_all_data(week, teams, swaps, aces, wildcards, anime, a_scores, t_scores, retrieve) if e: e.close()
def main(): ### add old_names in results.py ACES ### and what's this? is it necessary to do it here / in funcs.py??????? ### no name changes in performance/ranking ###### but check if current name is there # check for name changes name_changes = funcs.map_users() inv_name_changes = { new[-1]: [initial] + new[:-1] for initial, new in name_changes.items() } w = funcs.open_out_file(week, "performances") w.write("Weekly Performances; Week %i:\n\n" % week) teams, swaps, aces, wildcards, anime, a_scores, t_scores = funcs.load_all_data( week) # get team scores WITHOUT aces and wildcards and for active anime only clean_t_scores = {team: 0 for team in teams} for team in teams: for a_id in [a[0] for a in teams[team][:5]]: clean_t_scores[team] += a_scores[a_id][1] toprank_week = sorted(clean_t_scores.items(), key=lambda x: x[1], reverse=True)[0][0] toprank_rank = sorted(t_scores.items(), key=lambda x: x[1][0], reverse=True)[0][0] w.write("points this week (points less than #1 this week)") w.write(" [points less than #1 in team ranking]\n\n") w_scores = {} for team, week_points in sorted(clean_t_scores.items(), key=lambda x: x[1], reverse=True): diff_week = week_points - clean_t_scores[toprank_week] diff_rank = week_points - clean_t_scores[toprank_rank] w_scores[team] = [ week_points, get_sign(diff_week), get_sign(diff_rank) ] ranking = get_ranking(w_scores) ranked_teams = {} # {rank: [list of teams]} for team, rank in sorted(ranking.items(), key=lambda x: x[1]): ranked_teams.setdefault(rank, []).append(team) # get length of longest username max_name = max([len(team) for team in teams.keys()]) # get length of highest score max_score = max([len(str(score)) for score in clean_t_scores.values()]) for rank, team_list in sorted(ranked_teams.items()): for team in sorted(team_list, key=str.lower): w.write("%s%i " % (blank(3, len(str(rank))), rank)) w.write("%s%s" % (team, blank(max_name, len(team)))) w.write( "%s%i" % (blank(max_score, len(str(w_scores[team][0])) - 1), w_scores[team][0])) w.write( "%s(%s)" % (blank(max_score, len(str(w_scores[team][1])) - 3), w_scores[team][1])) w.write( "%s[%s]" % (blank(max_score, len(str(w_scores[team][2])) - 3), w_scores[team][2])) w.write("\n") if w: w.close()