diff --git a/main.py b/main.py new file mode 100644 index 0000000..48d4e29 --- /dev/null +++ b/main.py @@ -0,0 +1,70 @@ +import pymongo +import json +#client = pymongo.MongoClient("localhost", 27017) +#db = client.scouting_system +#tims = db.tims +with open("example_tim_data.json", "r") as f: + data = json.load(f) +#tims.insert_many(data) +# find data for each team [{num_balls}] +# get num balls scored/climbed for each match +# calc avg +dataforteam = {} #data for each different team +for tim in data: #loop through each team's data + team_number = tim["team_num"] + if team_number not in dataforteam: #check if team hasn't been added to dictionary + dataforteam[team_number] = [] #creates a key/entry of the team number. creates an empty list as the value + dataforteam[team_number].append(tim) #adds the data of the team to the list + else: + dataforteam[team_number].append(tim) #if the team number is already used it adds new data to a new key + + +def summarizer(list_of_tims): + most_scored = 0 + for tim in list_of_tims: #calculate most scored + num_balls = tim["num_balls"] + if num_balls > most_scored: + most_scored = num_balls + + least_scored = 100000 #super high number + for tim in list_of_tims: #calc least scored + num_balls = tim["num_balls"] + if num_balls < least_scored: + least_scored = num_balls + + total_balls = 0 + for tim in list_of_tims: #calc average + num_balls = tim["num_balls"] + total_balls += num_balls + average_scored = total_balls/len(list_of_tims) + + total_climbed = 0 + success_climb = 0 + for tim in list_of_tims: #calc percent climb success + climbed = tim["climbed"] + if climbed == True: + total_climbed += 1 + success_climb += 1 + else: + total_climbed += 1 + percent_climb_success = str(float((success_climb/total_climbed)*100)) + "%" + + return {"most_scored": most_scored, "least_scored": least_scored, "matches_played": len(list_of_tims), "average_scored": average_scored, "percent_climb_success": percent_climb_success} #adds to dictionary + +teams = [ + # { + # #team_num: int + # #Average balls scored (float) + # # Least balls scored (int) + # # Most balls scored (int) + # # Number of matches played (int) + # # Percent climb success (float) + +] + +for team_id, list_of_tims in dataforteam.items(): + team_results = summarizer(list_of_tims) + print(team_id, team_results) + teams.append(team_results) + +print(teams) \ No newline at end of file