PYTHON: read.py 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 content. Args: 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 def readAllFiles() -> List[SportClub]:    """Read all the csv files in the current working directory to create a list of SportClubs that contain unique SportClubs with their corresponding counts. Take all the csv files in the current working directory, calls readFile(file) on each of them, and accumulates the data gathered into a list of SportClubs.Create a new file called "report.txt" in the current working directory containing the number of good files and good lines read. Create a new file called "error_log.txt" in the current working directory containing the name of the error/bad files read.Returns: a list of unique SportClub objects with their respective counts    """    # TODO: Complete the function sportclub.py class SportClub:    """A simple class to store and handle information about SportClubs.    Attributes:        city (str): The city the SportClub is based in.        name (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 the __eq__ and __lt__ functions of this class    """    def __init__(self,  city: str = "", name: str = "", sport: str= "", count: int = 0) -> None:        self.setCity(city)        self.setName(name)        self.setSport(sport)        self.count = count    def setName(self, name: str) -> None:        self.name = name    def setCity(self, city: str) -> None:        self.city = city    def setSport(self, sport: str) -> None:        self.sport = sport    def getName(self) -> str:        return self.name.title()    def getCity(self):        return self.city.title()    def getSport(self):        return self.sport.upper()    def getCount(self):        return self.count    def incrementCount(self) -> None:        self.count += 1    def __hash__(self) -> int:        unique_identifier = (self.getCity(), self.getName(), self.getSport())        return hash(unique_identifier)    def __str__(self) -> str:        return f"Name: {self.getCity()} {self.getName()}, Sport: {self.getSport()}, Count: {self.getCount()}"    def __eq__(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.    def __lt__(self, o: object) -> bool:        """Check if self is less than another object.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

PYTHON:

read.py

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 content. Args: 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

def readAllFiles() -> List[SportClub]:
   """Read all the csv files in the current working directory to create a list of SportClubs that contain unique SportClubs with their corresponding counts. Take all the csv files in the current working directory, calls readFile(file) on each of them, and accumulates the data gathered into a list of SportClubs.Create a new file called "report.txt" in the current working directory containing the number of good files and good lines read. Create a new file called "error_log.txt" in the current working directory containing the name of the error/bad files read.Returns: a list of unique SportClub objects with their respective counts
   """
   # TODO: Complete the function
sportclub.py

class SportClub:
   """A simple class to store and handle information about SportClubs.

   Attributes:
       city (str): The city the SportClub is based in.
       name (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 the __eq__ and __lt__ functions of this class
   """
   def __init__(self,  city: str = "", name: str = "", sport: str= "", count: int = 0) -> None:
       self.setCity(city)
       self.setName(name)
       self.setSport(sport)
       self.count = count

   def setName(self, name: str) -> None:
       self.name = name

   def setCity(self, city: str) -> None:
       self.city = city

   def setSport(self, sport: str) -> None:
       self.sport = sport

   def getName(self) -> str:
       return self.name.title()

   def getCity(self):
       return self.city.title()

   def getSport(self):
       return self.sport.upper()

   def getCount(self):
       return self.count

   def incrementCount(self) -> None:
       self.count += 1

   def __hash__(self) -> int:
       unique_identifier = (self.getCity(), self.getName(), self.getSport())
       return hash(unique_identifier)

   def __str__(self) -> str:
       return f"Name: {self.getCity()} {self.getName()}, Sport: {self.getSport()}, Count: {self.getCount()}"

   def __eq__(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.

   def __lt__(self, o: object) -> bool:
       """Check if 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.

write.py

import csv
from sportclub import 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", "MLB")]] 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


def sortSport(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 
  
   def outputSports(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: "City,Team Name,Sport,Number of Times Picked" for the top 3 teams in each sport. Args: sorted_sports: an Iterable of different sports, each already sorted correctly
   """
   # TODO: Complete the function

i need help with this program that I'm working on.....
I need to create a program that will do the following:
1. Consolidate all the information from the csv files they have provided into a single csv file called "survey database.csv"
2. Report a summary of the collected data in a file called "report.txt"
3. Report 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
I 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 3. If there are no error files encountered, simply create the error_log.txt file with nothing in it.
in the current working directory.
• 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.
Report
I 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:
• Number of files read: (num good files read}
▪ Number of lines read: (num lines read in good files read}
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.
• Error log
1. A new error log needs to be 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. Create a file called "error_log.txt" in the current working directory with
that information.
You will get 4 files (main.py, read.py, write.py and sportclub.py). The instructions here are also present in the files themselves:
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.
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.
2. sportclub.py: Contains the class SportClub. Read through the class to understand how it works, and complete the following functions:
o__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).
o __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).
3. 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.
4. 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 to
do this 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.
Transcribed Image Text:i need help with this program that I'm working on..... I need to create a program that will do the following: 1. Consolidate all the information from the csv files they have provided into a single csv file called "survey database.csv" 2. Report a summary of the collected data in a file called "report.txt" 3. Report 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 I 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 3. If there are no error files encountered, simply create the error_log.txt file with nothing in it. in the current working directory. • 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. Report I 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: • Number of files read: (num good files read} ▪ Number of lines read: (num lines read in good files read} 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. • Error log 1. A new error log needs to be 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. Create a file called "error_log.txt" in the current working directory with that information. You will get 4 files (main.py, read.py, write.py and sportclub.py). The instructions here are also present in the files themselves: 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. 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. 2. sportclub.py: Contains the class SportClub. Read through the class to understand how it works, and complete the following functions: o__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). o __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). 3. 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. 4. 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 to do this 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.
1 from read import readAllFiles
from write import sortSport, separateSports, outputSports
HN M
2
3
4 def main() -> None:
5
6
7
8
9
10
11
if
separated_sports separateSports (readAllFiles())
map(sortSport, separated_sports)
outputSports (sorted_sports)
sorted_sports
name
main()
||
=
___main__":
Transcribed Image Text:1 from read import readAllFiles from write import sortSport, separateSports, outputSports HN M 2 3 4 def main() -> None: 5 6 7 8 9 10 11 if separated_sports separateSports (readAllFiles()) map(sortSport, separated_sports) outputSports (sorted_sports) sorted_sports name main() || = ___main__":
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY