From 12223cb6ecd94a19846b36ab5e91b91838abcce4 Mon Sep 17 00:00:00 2001 From: ts1678 Date: Thu, 16 Oct 2025 19:50:58 -0700 Subject: [PATCH 1/4] theprogram --- main.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..e900b2a --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +import pymongo +import json + +client = pymongo.MongoClient("localhost" , 27017) + +db = client["tim_data"] + +# there's probably a better way to do this +db.team_collection.drop() +db.results_collection.drop() + +col = db["team_collection"] +res = db["results_collection"] + +unique_teams = [] + +with open("example_tim_data.json") as f: + data = json.load(f) + col.insert_many(data) + +for doc in col.find(): + if not doc['team_num'] in unique_teams: + unique_teams.append(doc['team_num']) + +for team in unique_teams: + this_match_count = 0 # these variables will all be incorrect until their final operations are done at the end + most_balls_scored = 0 + least_balls_scored = 0 + average_balls_scored = 0 + percent_climb_success = 0 + for i in col.find({'team_num': team}): + this_match_count += 1 + percent_climb_success += i["climbed"] + if i["num_balls"] > most_balls_scored: + most_balls_scored = i["num_balls"] + if i["num_balls"] < least_balls_scored or least_balls_scored == 0: + least_balls_scored = i["num_balls"] + average_balls_scored += i["num_balls"] + res.insert_one({"team_number": team, + "average_balls_scored": average_balls_scored/this_match_count, + "least_balls_scored": least_balls_scored, + "most_balls_scored": most_balls_scored, + "number_of_matches_played": this_match_count, + "percent_climb_success": percent_climb_success/this_match_count}) \ No newline at end of file From 854a154ed0b75aa9835c269a06bed4d081bc492c Mon Sep 17 00:00:00 2001 From: ts1678 <179778808+ts1678@users.noreply.github.com> Date: Wed, 29 Oct 2025 19:45:43 -0700 Subject: [PATCH 2/4] add yaml --- example_tim_data.yaml | 4 ++++ main.py | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 example_tim_data.yaml diff --git a/example_tim_data.yaml b/example_tim_data.yaml new file mode 100644 index 0000000..378eacf --- /dev/null +++ b/example_tim_data.yaml @@ -0,0 +1,4 @@ +team_num: int +match_num: int +climbed: bool +num_balls: int \ No newline at end of file diff --git a/main.py b/main.py index e900b2a..afcf139 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import pymongo +import yaml import json client = pymongo.MongoClient("localhost" , 27017) @@ -16,6 +17,12 @@ with open("example_tim_data.json") as f: data = json.load(f) + with open("example_tim_data.yaml", "r") as y: + yaml_data = yaml.load(y, yaml.Loader) + for i in data: + for j in i: + if type(i[j]).__name__ != yaml_data[j]: + raise ValueError col.insert_many(data) for doc in col.find(): From a29c2034f640526012ec4f8de619e78e49db3a07 Mon Sep 17 00:00:00 2001 From: ts1678 <179778808+ts1678@users.noreply.github.com> Date: Wed, 29 Oct 2025 19:58:39 -0700 Subject: [PATCH 3/4] Rename some things --- main.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index afcf139..f3d90a9 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,12 @@ import pymongo import yaml import json +from warnings import warn client = pymongo.MongoClient("localhost" , 27017) db = client["tim_data"] -# there's probably a better way to do this db.team_collection.drop() db.results_collection.drop() @@ -15,13 +15,16 @@ unique_teams = [] -with open("example_tim_data.json") as f: - data = json.load(f) - with open("example_tim_data.yaml", "r") as y: - yaml_data = yaml.load(y, yaml.Loader) - for i in data: - for j in i: - if type(i[j]).__name__ != yaml_data[j]: +with open("example_tim_data.json", "r") as tim_data_file: + data = json.load(tim_data_file) + with open("example_tim_data.yaml", "r") as tim_yaml_file: + yaml_data = yaml.load(tim_yaml_file, yaml.Loader) + for tim_element in data: + for key in tim_element: + if key not in yaml_data: + warn("The Key from the TIM data is not in the YAML!") + continue + if type(tim_element[key]).__name__ != yaml_data[key]: raise ValueError col.insert_many(data) From 40ee91bd300c61b3fb6f49fa0b9cb4de1072e1cc Mon Sep 17 00:00:00 2001 From: ts1678 <179778808+ts1678@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:02:21 -0700 Subject: [PATCH 4/4] good enough --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index f3d90a9..e5046f1 100644 --- a/main.py +++ b/main.py @@ -13,8 +13,6 @@ col = db["team_collection"] res = db["results_collection"] -unique_teams = [] - with open("example_tim_data.json", "r") as tim_data_file: data = json.load(tim_data_file) with open("example_tim_data.yaml", "r") as tim_yaml_file: @@ -28,12 +26,14 @@ raise ValueError col.insert_many(data) +unique_teams = [] + for doc in col.find(): if not doc['team_num'] in unique_teams: unique_teams.append(doc['team_num']) for team in unique_teams: - this_match_count = 0 # these variables will all be incorrect until their final operations are done at the end + this_match_count = 0 most_balls_scored = 0 least_balls_scored = 0 average_balls_scored = 0