Added power ranking report output
This commit is contained in:
102
get_rankings.py
102
get_rankings.py
@@ -2,6 +2,7 @@ from pathlib import Path
|
|||||||
import tbaapiv3client
|
import tbaapiv3client
|
||||||
from tbaapiv3client.rest import ApiException
|
from tbaapiv3client.rest import ApiException
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
from datetime import datetime as dt
|
||||||
|
|
||||||
from csv import DictWriter
|
from csv import DictWriter
|
||||||
|
|
||||||
@@ -93,7 +94,83 @@ def get_event_teams(api_client: tbaapiv3client.ApiClient, season:str) -> dict[di
|
|||||||
|
|
||||||
return event_teams
|
return event_teams
|
||||||
|
|
||||||
def write_rank_csv(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
def write_power_rank(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
||||||
|
# Create annual rank CSV
|
||||||
|
results_list:list[dict] = []
|
||||||
|
|
||||||
|
for team, ranks in rankings.items():
|
||||||
|
result = {
|
||||||
|
'team': team
|
||||||
|
}
|
||||||
|
|
||||||
|
rank_sum = 0
|
||||||
|
point_total_sum = 0
|
||||||
|
point_district_sum = 0
|
||||||
|
point_district_na_sum = 0
|
||||||
|
|
||||||
|
entry_count = 0
|
||||||
|
|
||||||
|
for season in seasons:
|
||||||
|
rank = ''
|
||||||
|
point_total = ''
|
||||||
|
point_district = ''
|
||||||
|
point_district_na = ''
|
||||||
|
|
||||||
|
if season in ranks:
|
||||||
|
rank = ranks[season]['rank']
|
||||||
|
point_total = ranks[season]['point_total']
|
||||||
|
|
||||||
|
point_district = 0
|
||||||
|
|
||||||
|
if ranks[season]['points_event1'] is not None:
|
||||||
|
point_district += ranks[season]['points_event1']
|
||||||
|
|
||||||
|
if ranks[season]['points_event2'] is not None:
|
||||||
|
point_district += ranks[season]['points_event2']
|
||||||
|
|
||||||
|
point_district_na = 0
|
||||||
|
|
||||||
|
if ranks[season]['points_event1_na'] is not None:
|
||||||
|
point_district_na += ranks[season]['points_event1_na']
|
||||||
|
|
||||||
|
if ranks[season]['points_event2_na'] is not None:
|
||||||
|
point_district_na += ranks[season]['points_event2_na']
|
||||||
|
|
||||||
|
rank_sum += rank
|
||||||
|
point_total_sum += point_total
|
||||||
|
point_district_sum += point_district
|
||||||
|
point_district_na_sum += point_district_na
|
||||||
|
|
||||||
|
entry_count += 1
|
||||||
|
|
||||||
|
result[f'{season} Rank'] = rank
|
||||||
|
result[f'{season} Point Total'] = point_total
|
||||||
|
result[f'{season} Points District'] = point_district
|
||||||
|
result[f'{season} Points District No Awards'] = point_district_na
|
||||||
|
|
||||||
|
|
||||||
|
rank_avg = ''
|
||||||
|
point_total_avg = ''
|
||||||
|
point_district_avg = ''
|
||||||
|
point_district_na_avg = ''
|
||||||
|
|
||||||
|
if entry_count > 0:
|
||||||
|
rank_avg = rank_sum / entry_count
|
||||||
|
point_total_avg = point_total_sum / entry_count
|
||||||
|
point_district_avg = point_district_sum / entry_count
|
||||||
|
point_district_na_avg = point_district_na_sum / entry_count
|
||||||
|
|
||||||
|
result[f'Avg Rank'] = rank_avg
|
||||||
|
result[f'Avg Point Total'] = point_total_avg
|
||||||
|
result[f'Avg Points District'] = point_district_avg
|
||||||
|
result[f'Avg Points District No Awards'] = point_district_na_avg
|
||||||
|
|
||||||
|
|
||||||
|
results_list.append(result)
|
||||||
|
|
||||||
|
write_result(path, results_list)
|
||||||
|
|
||||||
|
def write_rank(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
||||||
# Create annual rank CSV
|
# Create annual rank CSV
|
||||||
results_list:list[dict] = []
|
results_list:list[dict] = []
|
||||||
|
|
||||||
@@ -111,9 +188,9 @@ def write_rank_csv(path: str | Path, rankings: list[dict], seasons:list[str]) ->
|
|||||||
|
|
||||||
results_list.append(result)
|
results_list.append(result)
|
||||||
|
|
||||||
write_result_csv(path, results_list)
|
write_result(path, results_list)
|
||||||
|
|
||||||
def write_point_total_csv(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
def write_point_total(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
||||||
# Create annual rank CSV
|
# Create annual rank CSV
|
||||||
results_list:list[dict] = []
|
results_list:list[dict] = []
|
||||||
|
|
||||||
@@ -131,9 +208,9 @@ def write_point_total_csv(path: str | Path, rankings: list[dict], seasons:list[s
|
|||||||
|
|
||||||
results_list.append(result)
|
results_list.append(result)
|
||||||
|
|
||||||
write_result_csv(path, results_list)
|
write_result(path, results_list)
|
||||||
|
|
||||||
def write_points_events_csv(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
def write_points_events(path: str | Path, rankings: list[dict], seasons:list[str]) -> None:
|
||||||
# Create annual rank CSV
|
# Create annual rank CSV
|
||||||
results_list:list[dict] = []
|
results_list:list[dict] = []
|
||||||
|
|
||||||
@@ -157,9 +234,9 @@ def write_points_events_csv(path: str | Path, rankings: list[dict], seasons:list
|
|||||||
|
|
||||||
results_list.append(result)
|
results_list.append(result)
|
||||||
|
|
||||||
write_result_csv(path, results_list)
|
write_result(path, results_list)
|
||||||
|
|
||||||
def write_result_csv(path: str| Path, results_list:list[dict]) -> None:
|
def write_result(path: str| Path, results_list:list[dict]) -> None:
|
||||||
if not isinstance(path, Path):
|
if not isinstance(path, Path):
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
|
|
||||||
@@ -172,6 +249,9 @@ def write_result_csv(path: str| Path, results_list:list[dict]) -> None:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
run_time = dt.now()
|
||||||
|
run_time_str = run_time.strftime('%Y%m%d_%H%M')
|
||||||
|
|
||||||
seasons = ['2022fim', '2023fim', '2024fim']
|
seasons = ['2022fim', '2023fim', '2024fim']
|
||||||
root_dir = Path('results')
|
root_dir = Path('results')
|
||||||
|
|
||||||
@@ -246,7 +326,7 @@ def main():
|
|||||||
|
|
||||||
if len(event_details):
|
if len(event_details):
|
||||||
# Write Event Details
|
# Write Event Details
|
||||||
with open(root_dir / f'{key} details.csv', 'w', newline='') as f:
|
with open(root_dir / f'{run_time_str} - {key} details.csv', 'w', newline='') as f:
|
||||||
writer = DictWriter(f, event_details[0])
|
writer = DictWriter(f, event_details[0])
|
||||||
|
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
@@ -279,15 +359,13 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
# Write Event Summary
|
# Write Event Summary
|
||||||
with open(root_dir / f'event summary.csv', 'w', newline='') as f:
|
with open(root_dir / f'{run_time_str} - event summary.csv', 'w', newline='') as f:
|
||||||
writer = DictWriter(f, event_summary[0].keys())
|
writer = DictWriter(f, event_summary[0].keys())
|
||||||
|
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
writer.writerows(event_summary)
|
writer.writerows(event_summary)
|
||||||
|
|
||||||
#write_rank_csv(root_dir / "season_rankings.csv", rankings, seasons)
|
write_power_rank(root_dir / f"{run_time_str} - season_power_rank.csv", rankings, seasons)
|
||||||
#write_point_total_csv(root_dir / "season_point_total.csv", rankings, seasons)
|
|
||||||
#write_points_events_csv(root_dir / "season_points_events.csv", rankings, seasons)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user