project04

py

School

Purdue University *

*We aren’t endorsed by this school

Course

177

Subject

Computer Science

Date

Dec 6, 2023

Type

py

Pages

5

Uploaded by SuperTree11868

Report
# CS 177 - project04.py # Jeremiah Budd assign = 'Assignmentinfo.txt' student = 'Studentinfo.txt' submission = 'SubmissionRecord.txt' def date_months(date): #get the month out of a date with slashes dash = 0 # number of slashes that have occured month = "" # the string for year for i in date: # going through all parts of the given if i == "/": # if i is a / dash += 1 # count of / goes up by 1 elif dash == 0: # if the number of / is counted as 2 elready month += i # year is year + a number return int(month) def date_days(date): dash = 0 # number of slashes that have occured days = "" # the string for year for i in date: # going through all parts of the given if i == "/": # if i is a / dash += 1 # count of / goes up by 1 elif dash == 1: # if the number of / is counted as 2 elready days += i # year is year + a number return int(float((days))) def date_years(date): # have to input str or dies dash = 0 # number of slashes that have occured year = "" # the string for year for i in date: # going through all parts of the given if i == "/": # if i is a / dash += 1 # count of / goes up by 1 elif dash == 2: # if the number of / is counted as 2 elready year += i # year is year + a number return int(year) def is_before(date1, date2): month1 = date_months(date1) day1 = date_days(date1) year1 = date_years(date1) month2 = date_months(date2) day2 = date_days(date2) year2 = date_years(date2) if year1 > year2: return False elif year1 == year2 and month1 > month2: return False elif year1 == year2 and month1 == month2 and day1 > day2: return False elif year1 == year2 and month1 == month2 and day1 == day2: return True else: return True def readStudentInfo(filename): data = open(filename, "r").readlines() list_dicts = [] for line in data:
line = line.strip().replace(' ', '') line_str = line.split(",") fun_dict = dict() fun_dict.update({'ID':line_str[0]}) fun_dict.update({'Name':line_str[1]}) fun_dict.update({'Age':line_str[2]}) list_dicts += [fun_dict] return list_dicts def readSubmissionRecord(filename): data = open(filename, "r").readlines() list_dicts = [] for line in data: line = line.strip().replace(' ', '') line_str = line.split(",") fun_dict = dict() fun_dict.update({'ID':line_str[0]}) fun_dict.update({'Name':line_str[1]}) fun_dict.update({'Score':int(line_str[2])}) fun_dict.update({"Date":line_str[3]}) list_dicts += [fun_dict] return list_dicts def readAssignmentInfo(filename): data = open(filename, "r").readlines() list_dicts = [] for line in data: line = line.strip().replace(' ', '') line_str = line.split(",") fun_dict = dict() fun_dict.update({'Name':line_str[0]}) fun_dict.update({'Weight':float(line_str[1])}) fun_dict.update({'Deadline':line_str[2]}) list_dicts += [fun_dict] return list_dicts stud = readStudentInfo(student) subss = readSubmissionRecord(submission) ass = readAssignmentInfo(assign) def biggest_ID(submissions): big_ID = 0 for sub in submissions: if int(sub.get("ID")) > big_ID: big_ID = int(sub.get("ID")) return big_ID def countX(lst, x): count = 0 for ele in lst: if (ele == x): count = count + 1 return count def assign_num(submissions): n = 1 big_n = biggest_ID(submissions) final_list = [] while n <= big_n:
listy = [] for sub in submissions: if int(sub.get("ID")) == n: name = sub.get("Name") listy += [name] new_num = countX(listy, name) sub.update({'num':new_num}) final_list += [sub] n += 1 return final_list def no_more_than_10(submission_w_num): final_list = [] for sub in submission_w_num: if sub.get("num") <= 10: sub.pop("num") final_list += [sub] return final_list def before_deadline(submissions, assignments): final_list = [] for subs in submissions: curr_ass = subs.get("Name") for assign in assignments: if curr_ass == assign.get("Name"): deadline = assign.get("Deadline") submit = subs.get("Date") before = is_before(submit, deadline) if before: final_list += [subs] return final_list def getScore(students, submissions, assigns): list_dicts = [] list_dicts2 = [] submissionss = before_deadline(submissions, assigns) submission = assign_num(submissionss) submissio = no_more_than_10(submission) for single in students: for assign in assigns: name = assign.get('Name') nam_dic = {name:''} nam_dic = {key: 0 for key in nam_dic} single.update({name:''}) list_dicts += [single] for single in list_dicts: for subs in submissio: if subs.get('ID') == single.get('ID'): curr_ass = subs.get("Name") curr_score = single.get(curr_ass) score = subs.get("Score") if curr_score == '': curr_score = 0 if score > curr_score: single.update({curr_ass: score}) for key in single: if single.get(key) == '': single.update({key:0}) list_dicts2 += [single]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
return list_dicts2 score = getScore(stud, subss, ass) def computeFinalGrades(student_scores, assigns): list_dicts = [] list_dicts2 = [] for score in student_scores: score.update({"Final Grade":''}) list_dicts2 += [score] for score in list_dicts2: for key in score: if key != "ID" and key != "Name" and key != "Age": for assign in assigns: curr_ass = key ass = assign.get("Name") weight = assign.get("Weight") grade = score.get(curr_ass) if curr_ass == ass: new_grade = float(grade * weight) if score.get("Final Grade") == '': old_grade = 0 else: old_grade = float(score.get("Final Grade")) new_score = old_grade + new_grade score.update({"Final Grade":new_score}) list_dicts += [score] return list_dicts full = computeFinalGrades(score, ass) def computeAverage(student_full, assigns): just_grade = [] for score in student_full: score.pop("ID") score.pop("Name") score.pop("Age") just_grade += [score] n = len(just_grade) added = dict() for score in just_grade: for key in score: added.update({key:0}) for score in just_grade: for key in score: add_score = score.get(key) old_score = added.get(key) added.update({key:add_score + old_score}) for key in added: average = added.get(key) / n added.update({key:average}) return added def main(): StudentInfo = readStudentInfo("Studentinfo.txt") print(StudentInfo) SubmissionRecord = readSubmissionRecord("SubmissionRecord.txt") print(SubmissionRecord) AssignmentInfo = readAssignmentInfo("Assignmentinfo.txt")
print(AssignmentInfo) Scores = getScore(StudentInfo, SubmissionRecord, AssignmentInfo) print(Scores) FinalGrades = computeFinalGrades(Scores, AssignmentInfo) print(FinalGrades) Average = computeAverage(FinalGrades, AssignmentInfo) print(Average) if __name__ == "__main__": main() StudentInfo = readStudentInfo("Studentinfo.txt") SubmissionRecord = readSubmissionRecord("SubmissionRecord.txt") AssignmentInfo = readAssignmentInfo("Assignmentinfo.txt") Scores = getScore(StudentInfo, SubmissionRecord, AssignmentInfo) FinalGrades = computeFinalGrades(Scores, AssignmentInfo) Average = computeAverage(FinalGrades, AssignmentInfo) """ Created on Wed Nov 8 21:37:22 2023 @author: Jeremiah Budd """