Please make sure to solve all the TO-DO portions in the code on top of any other coding necessary!
Deliberate answers and explanations would be very much appreciated

please answer in python and please fuffill all the requirements that are asked in each file! Thank you Purpose of this Lab: The main objective of this lab is to get you familiar with the libraries discussed in the class (PathLib and the CSV library), and get you comfortable using abstractions and standard coding formats. Introduction to the Lab : A research team was administering a survey of random people to get their favorite team in their favorite sport. The survey was taking down this information in comma separate files (.csv files) and saving these files in a single directory. Each CSV file that is stored by the collectors has 3 columns with these self-identifying column headers: "City", "Team Name", "Sport" Here is an example of a file: Lab Overview: Write a program that will do the following: 1. Example of a survey database.csv file: A 1 City 2 Old Trafford 3 London 4 Liverpool 5 Madrid A B Team Name Chiefs Raptors 4 Washington Nationals 6 Barcelona 7 Madrid 1. Consolidate all the information from the csv files they have provided into a single csv file called "survey_database.csv" 2. A summary of the collected data in a file called "report.txt" 3. An error log of the collected data in a file called "error_log.txt" The following are their detailed requirements for the program: . Survey Database 1 City 2 3 Toronto Kansas City 1. They want the program to be able to search, find and read all the .csv files in the current working directory to create the "survey database.csv file in the current working directory. 2. The CSV should contain the following information (defined in self-identifying column header names): "City", "Team Name", "Sport", "Number of Times Picked" • The rows following that header should contain that information for the top 3 most picked teams in each sport ▪ "picked" in this context is the team appearing once in the CSV files • The ranking of the team is defined by the inverse of the times they were picked and their alphabetic Team Name. In other words, teams that appear more often in the read csv files are at the top. In the event of ties in their count, their names are used to resolve the ties. Example of a report.txt file: 5 Tampa Bay Lightning 6 Toronto Raptors Raptors 7 Toronto IN3 B Team Name Manchester United Arsenal Liverpool Atletico Madrid Barcelona Real Madrid 1. Number of files read: (num good files read} Number of lines read: (num lines read in good files read} с Sport NFL NBA MLB NHL NBA NBA C Sport EPL EPL EPL LALIGA LALIGA LALIGA • Report 1. They want a new report created every time they run the program. The following is the content of the summary report in a "report.txt" file created in the current working directory. The report is simply a text file with the following information: D Number of Times Picked 1 Number of files read: 1 2 Number of lines read: 23 5 4 2 4 4 4
Error log 1. They want a new error log created every time they run the program. This error log simply has the name of the files that contain errors, on their separate line. An error could be missing strings or empty strings. Make file called "error_log.txt" in the current working directory with that information. Example error Jog.txt file: 1 2 3 random csv.csv broken csv.csv Important details: 1. If a file has an error (i.e it is missing one of the 3 fields it should have (City, Team Name or Sport)), it file is considered corrupted and it will not count AT ALL. In other words, if you read 5 rows already then you encounter an empty filed on the sixth, you will discard those 5 rows with the whole file as well. 2. Every line, including the last, in report.txt and error_log.txt ends in a new line character. 3. If there are no error files encountered, simply create the error Jog.txt file with nothing in it. 4. If there are less than 3 teams in a sport, simply output the teams that you do have. 5. Every CSV file you read will have an header, and the survery_database.csv file you create must also have a header. 6. The order of sports in survey database.csv does not matter. Breakdown: 1. main.py: Do not change anything in main.py. Your code must run with the main given to you, and will be run the same way by the autograder. main.py from read import readAllFiles from write import sort Sport, separate Sports, output Sports def main() > None: separated sports separate Sports (readAllFiles()) sorted sports map (sort Sport, separated_sports) output Sports (sorted_sports) if name == "__main__": main () 1. sportclub.py: Contains the class SportClub. Read through the class to understand how it works, and complete the following functions: • _eq_(other): Function to check if the current instance of the class (self) is equal to another object. This can be useful in sortSport(sport). __It__(other): Function to check if the current instance of the class (self) is less than another object. This can also be useful in sortSport(sport).
sportclub.py Elass SportClub: ***A simple class to store and handle information about SportClubs. Attributes: city (str): The city the SportClub is based in. nane (str); The name of the SportClub. sport (str): The sport the club plays. count (int): The amount of time the SportClub has been seen. Todo: complete theeq andit functions of this class definit__(self, city: str, name: str, sport: str, count: int0) -> None: "Make a SportClub. Args: city: The city the SportClub is based in. name: The name of the SportClub. sport: The sport the club plays. count: The amount of time the SportClub has been seen. self.setCity (city) self. setNane (name) self.setSport (sport) self. count count def setName(self, name: str) -> None: ***Set the name of the SportClub. Args: name: Nane of the SportClub. self.nane nane def setCity (self, city: str)-> None: "Set the city the SportClub is based in. Arge: city: The city the SportClub is based in. self.city- city def setSport (self. sport: str) -> Bone: "Set the sport the club plays. Args: sport: The sport the club plays. self. sport sport def getName(self) -> str def "Get the name of the SportClub. Returns: A formatted version of the private attribute nane. return self.nane, title() defelf): getCity the city the SportClub is based in. Returns: A formatted version of the private attribute city. return self.city. title() def getSport (self): Get the sport the club plays. Returns: A formatted version of the private attribute sport. return self.sport.upper () def increment Count (self) -> None: ***Increment the times the SportClub has been seen by 1. self.count+1 def hash (self) -> int: Get the hash of current object. Returns Harh of the object unique identifier (self.getCity(), self.getName(), self.getSport ()) return hash (unique identifier) defstr (self) -> str: Get the string version of current object. Returns: str sunnary of the object return f'Mane: [self.getCity()) [self.getName()). Sport: (self.getSport (1. Count: [self.getCount (1 defeq (self. o: object) -> bool: Check if another object is equal to self. Returns: True if they are equal, False otherwise #TODO: Complete the function, which can be useful for ordering a List of Sportclub objects #hint: object o may not be of type SportClub. #check documentation (https://docs.python.org/3/reference/dat anodel.html#object.__eq_) return False # erase this lt (self, o: object) -> bool: Check it self is less than another object. Returns: True if self is less than o. False otherwise #TODO: Complete the function, which can be useful for ordering a List of Sportclub objects #hint: object o may not be of type SportClub. #check documentation (https://docs.python.org/3/reference/dat anodel.htal object.lt) return True # erase this
1. read.py: Contains two functions you need to complete: o readFile(file): Function to read one .csv file. Returns a list of tuples of three fields (City, Name and Sport). The output should not include raw input formatting like commas, the header, etc. Raises ValueError if it finds that the file it's reading is an error file. o readAllFiles(): Function to read all .csv files in the current working directory. Returns a list of SportClub objects. This function should call the readFile(file), and gather its output into a list of unique SportClub objects. Each of these unique SportClub objects will store the identifying information of the team, and how many times the participants have picked the team. This is the function that will also produce the report.txt and error_log.txt files you read about. from pathlib import Path import csv from sportclub import SportClub from typing import List, Tuple def readFile(file: Path) -> List [Tuple [str, str, str]]: "Read a CSV file and return its content A good CSV file will have the header "City, Team Name, Sport" and appropriate Args: www file: a path to the file to be read Returns: a list of tuples that each contain (city, name, sport) of the SportClub Raises: ValueError: if the reading csv has missing data (empty fields) # TODO: Complete the function return [] # erase this def readAllFiles () -> List [SportClub]: "Read all the csv files in the current working directory to create a list Take all the csv files in the current working directory, calls readFile (file Create a new file called "report.txt" in the current working directory conta Create a new file called "error_log.txt" in the current working directory co Returns: a list of unique SportClub objects with their respective counts 30 30 30 # TODO: Complete the function return [] # erase this
1. write.py: Contains three functions you need to complete: o separateSports(all_clubs): Function to separate a list of all sport clubs by their sport. Takes as input the list of all clubs seen, and returns an iterable of lists of sport clubs. Each of those lists only contain sport clubs that play the same sport. The order of the sports does not matter. o sortSport(sport): Function to sort a list of SportClub objects by their counts and name. Takes a list of SportClub objects of the same sport as an argument. Returns a list of the sorted SportClub objects. ▪ Hint: make use of the standard_It_and_eq_functions you defined earlier by calling standard Python sorting functions. You can read how and sort by multiple keys by reading the documentation provided in the hints of those functions. o outputSports(sorted_sports): Function to create the survey_database.csv file output file and output the top 3 most picked teams of each sport. Takes an iterable of lists of sorted SportClub objects of the as an argument. write.py Enport csv from sportclub inport SportClub from typing import List, Iterable def separateSports (all_clubs: List [SportClub])-> Iterable [List [SportClub]]: "Separate a list of SportClubs into their own sports For example, given the list [SportClub ("LA", "Lakers", "NBA"). SportClub ("Houston", "Rockets" "NBA"), SportClub ("LA", "Angels", "MLB")). return the iterable [[SportClub ("LA", "Lakers", "NBA"), SportClub ("Houston", "Rockets", "NBA")], [SportClub ("LA", "Angels", "LB")]] Args: all clubs: A list of SportClubs that contain SportClubs of 1 or more sports. Returns: An iterable of lists of sportclubs that only contain clubs playing the same sport. #TODO: Complete the function return [[] # erase this def sort Sport (sport: List [SportClub])-> List [SportClub]: "Sort a list of SportClubs by the inverse of their count and their name For example, given the list [SportClub ("Houston", "Rockets", "NBA", 80), SportClub ("LA", "Warriors", "NBA", 130), SportClub ("LA", "Lakers", "NBA", 130)] return the list [SportClub ("LA", "Lakers", "NBA", 130), SportClub ("LA", Warriors", "NBA", 130), SportClub ("Houston Rockets", "NBA", 80)] Args: sport: A list of SportClubs that only contain clubs playing the same sport Returns: A sorted list of the SportClubs #TODO: Complete the function #hint: check documentation for sorting lists # (https://docs. python.org/3/library/functions. html#sorted, https://docs.python.org/3/howto/sorting ... rtinghowto) return # erase this def output Sports (sorted_sports: Iterable [List [SportClub]])-> None: Create the output csv given an iterable of list of sorted clubs Create the csv "survey database.csv" in the current working directory, and output the information: Sport, of teams in Args: sorted sports: an Iterable of different sports, each already sorted correctly # TODO: Complete the function pass # erase this