requirements: 1. In the Grader class of the grade_view module, complete the method read_source. This method shall minimally: a. Check if the filepath argument exists. Raise a FileNotFoundError with the given file path if it does not exist. Otherwise: i. Read from csv file ii. Return a collection object with the stored data (i.e. first names, last names and scores) from the csv file (NOTE: remember to convert score to a number type)
2. In the Grader class of the grade_view module, complete the method write_results. This method shall minimally: a. Create a new csv file (use the filepath parameter as file name) to store the data in the grade_book dictionary of the course’s GradeBook object. (HINT: access from the Grader object’s course attribute i.e. self.course.grade_book.grade_book) b. The header for the new csv file must be as follows header: [‘G-number’, ‘First_name’, ‘Surname’, ‘Score’, ‘Grade’]
3. In the Grader class of the grade_view module, complete the method initialize_course. This method shall minimally: a. Initialize the instance attribute course, by assigning it to a new Course object using the parameters: crse_num, crs_code and dept_code, b. Invoke the read_source method with the filepath parameter and use the returned collection object to: i. Create a list containing Student objects (See columns 2 and 3 from student_data.csv) ii. Invoke the enroll method of the now initialized course instance attribute to enroll all Student objects previously created. iii. Invoke the update_gradebook method of the course attribute to update scores for all Student objects previously created (See column 4 from student_data.csv)
^^given code
import os
from collections.abc import Iterable
class Grader:
def __init__(self, course_name: str, course_code: str, dept_code: str, infile: str, outfile: str = None):
self.course = None
self.initialize_course(course_name, course_code, dept_code, infile)
if outfile:
self.write_results(outfile)
def initialize_course(self, crs_num, crs_code, dept_code, filepath): # TODO
“”” Initializes course object attribute
Reads data from csv using read_src method
Creates student objects with names read from csv file
Enrolls created student objects using course object’s enroll method
Updates and calculates students grades
Using course object’s update_gradebook method “””
pass
def read_source(self, filepath) -> Iterable: # TODO
“”” Checks if the given filepath exists, Raises a FileNotFoundError if False
Reads student’s first names, surnames and scores from csv file
NOTE: remember to convert score to a number
Returns a collection object with first names, surnames and scores “””
pass
def write_results(self, filepath): # TODO
“”” Writes a csv file to store the data in the GradeBook dictionary
Hint: access from the course attribute i.e. self.course.grade_book.grade_book
CSV file header: [‘G-number’, ‘First_name’, ‘Surname’, ‘Score’, ‘Grade’] “””
pass
if __name__ == ‘__main__’:
try:
inp = os.path.join(os.getcwd(), ‘data’, ‘student_data.csv’)
except FileNotFoundError as e:
print(e)
print(‘As a start verify that your project structure conforms with what is specified for the assignment’)
else:
out = os.path.join(os.getcwd(), ‘data’, ‘graded_data’)
Grader(‘130’, ‘004’, ‘CYSE’, infile=inp, outfile=out)
Last Completed Projects
| topic title | academic level | Writer | delivered |
|---|
