Created
December 2, 2013 22:38
-
-
Save sdanko11/7760369 to your computer and use it in GitHub Desktop.
Teacher Grades
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AssignmentGrade | |
| def initialize(grade_data) | |
| @student_grades = grade_data | |
| end | |
| def gets_an_asignment_grade(assignment_number) | |
| @student_grades.student_grades.each do |person| | |
| if assignment_number == 1 | |
| puts person[:name] | |
| puts person[:grade][0] | |
| elsif assignment_number == 2 | |
| puts person[:name] | |
| puts person[:grade][1] | |
| elsif assignment_number == 3 | |
| puts person[:name] | |
| puts person[:grade][2] | |
| elsif assignment_number == 4 | |
| puts person[:name] | |
| puts person[:grade][3] | |
| elsif assignment_number == 5 | |
| puts person[:name] | |
| puts person[:grade][4] | |
| else | |
| puts 'No assingment' | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FinalGrade | |
| attr_reader :final_grades_formatted | |
| def initialize(students_with_averages) | |
| @each_student_averages = students_with_averages | |
| @final_grades_formatted = [] | |
| end | |
| def print_student_letter_grades | |
| @each_student_averages.students_with_final_average.each do |person| | |
| puts '======================' | |
| puts person.keys | |
| person.values.each do |grade| | |
| if grade >= 90 | |
| puts "Grade: A" | |
| puts "Final Average: #{person.values.join}" | |
| puts '======================' | |
| elsif grade >= 80 && grade < 90 | |
| puts "Grade: B" | |
| puts "Final Average: #{person.values.join}" | |
| puts '======================' | |
| elsif grade >= 70 && grade < 80 | |
| puts 'Grade: C' | |
| puts "Final Average: #{person.values.join}" | |
| puts '======================' | |
| elsif grade >= 60 && grade < 70 | |
| puts 'Grade: D' | |
| puts "Final Average: #{person.values.join}" | |
| puts '======================' | |
| else puts 'Grade: F' | |
| puts "Final Average: #{person.values.join}" | |
| puts '======================' | |
| end | |
| end | |
| end | |
| end | |
| def format_grades_for_test_file | |
| @each_student_averages.students_with_final_average.each do |person| | |
| grades = {} | |
| person.values.each do |grade| | |
| if grade >= 90 | |
| name = person.keys[0].join(' ').split | |
| grades = {first_name: name[0], last_name: name[1], final_average: person.values, final_grade: 'A'} | |
| @final_grades_formatted << grades | |
| elsif grade >= 80 && grade < 90 | |
| name = person.keys[0].join(' ').split | |
| grades = {first_name: name[0], last_name: name[1], final_average: person.values, final_grade: 'B'} | |
| @final_grades_formatted << grades | |
| elsif grade >= 70 && grade < 80 | |
| name = person.keys[0].join(' ').split | |
| grades = {first_name: name[0], last_name: name[1], final_average: person.values, final_grade: 'C'} | |
| @final_grades_formatted << grades | |
| elsif grade >= 60 && grade < 70 | |
| name = person.keys[0].join(' ').split | |
| grades = {first_name: name[0], last_name: name[1], final_average: person.values, final_grade: 'D'} | |
| @final_grades_formatted << grades | |
| else name = person.keys[0].join(' ').split | |
| grades = {first_name: name[0], last_name: name[1], final_average: person.values, final_grade: 'F'} | |
| @final_grades_formatted << grades | |
| end | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| require_relative 'student_grades_class' | |
| require_relative 'grade_summary_class' | |
| require_relative 'grade_reader_class' | |
| require_relative 'write_to_file_class' | |
| require_relative 'final_grade_class' | |
| class GradeReader | |
| attr_accessor :student_grades | |
| def initialize | |
| @student_grades = [] | |
| end | |
| def load_data(file_name) | |
| raise "#{file_name} does not exist" unless File.exists? file_name | |
| CSV.foreach(file_name, headers: true) do |row| | |
| students ={} | |
| row['person'] | |
| row['grades'] | |
| students = {name: row['person'], grade: row['grades'].split(' ')} | |
| @student_grades << students | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GradeSummary | |
| attr_accessor :student_grades | |
| def initialize(student_grades) | |
| @each_student_grades =[] | |
| @all_grades = [] | |
| @students_and_scores = student_grades | |
| end | |
| def sum(grades) | |
| grades.inject(0) {|sum, number| sum += number} | |
| end | |
| def count_grades(grades) | |
| grades.count | |
| end | |
| def class_averages | |
| @students_and_scores.student_grades.each do |name| | |
| @each_student_grades.concat(name[:grade]) | |
| end | |
| @all_grades = @each_student_grades.flatten | |
| @all_grades.map! do |number| | |
| number.to_i | |
| end | |
| sum_of_all_grades = sum(@all_grades) | |
| total_grades = count_grades(@all_grades) | |
| class_average = (sum_of_all_grades/total_grades) | |
| variences = [] | |
| @all_grades.each do |number| | |
| varience = (number - class_average)*(number - class_average) | |
| variences << varience | |
| end | |
| total_of_variences = sum(variences) | |
| standard_deviation = (total_of_variences/total_grades) | |
| puts '===========================' | |
| puts "Class Min: #{@all_grades.min}" | |
| puts "Class Max: #{@all_grades.max}" | |
| puts "Average Class Score: #{class_average}" | |
| puts "Standard Deviation: #{standard_deviation}" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Last Name | First Name | Final Average | Final Grade | |
|---|---|---|---|---|
| Smith | Johnny | [78] | C | |
| Strong | Sally | [94] | A | |
| Fallon | Jimmy | [80] | B | |
| Bostworth | Chris | [86] | B | |
| Boyd | Brian | [64] | D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative 'grade_reader_class' | |
| require_relative 'student_grades_class' | |
| require_relative 'assignment_grade_class' | |
| require_relative 'grade_summary_class' | |
| require_relative 'final_grade_class' | |
| require_relative 'write_to_file_class' | |
| require 'csv' | |
| puts "Hi welcome to your grade book?" | |
| puts "To load your grades in type your file name" | |
| file_name = gets.chomp | |
| file = GradeReader.new | |
| raise "#{file_name} does not exist" unless File.exists? file_name | |
| file.load_data(file_name) | |
| puts "What would you like to do?" | |
| puts "To view course analytics type 'course analytics'" | |
| puts "To view student averages type 'view student averages'" | |
| puts "To out put your grades to a file for report cards type 'report cards'" | |
| command = gets.chomp | |
| while true | |
| if command == 'course analytics' | |
| grades = GradeSummary.new(file) | |
| grades.class_averages | |
| puts "What do you want to do? Type 'done' to exit" | |
| command = gets.chomp | |
| end | |
| if command == "view student averages" | |
| grades = StudentGrades.new(file) | |
| grades.get_students_final_average | |
| final_grades = FinalGrade.new(grades) | |
| final_grades.print_student_letter_grades | |
| puts "What do you want to do? Type 'done' to exit" | |
| command = gets.chomp | |
| end | |
| if command == 'report cards' | |
| grades = StudentGrades.new(file) | |
| grades.get_students_final_average | |
| final_grades = FinalGrade.new(grades) | |
| final_grades.format_grades_for_test_file | |
| report_card = WriteToFile.new(final_grades) | |
| report_card.write_to_file | |
| puts '========================' | |
| puts "Export Succesful" | |
| puts '========================' | |
| puts "What do you want to do? Type 'done' to exit" | |
| command = gets.chomp | |
| end | |
| break if command == 'done' | |
| if ['course analytics', "view student averages", 'report cards', 'done'].any? {|string| command.downcase != string } | |
| puts "Invalid Command try again, type 'done' to exit" | |
| command = gets.chomp | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class StudentGrades | |
| attr_reader :students_with_final_average | |
| def initialize(student_data) | |
| @students_with_final_average = [] | |
| @students_and_scores = student_data | |
| end | |
| def print_student_names_with_test_scores | |
| @students_and_scores.student_grades.each do |name| | |
| puts "Name: #{name[:name]}" | |
| puts "Grades: #{name[:grade].join(',')}" | |
| end | |
| end | |
| def get_students_final_average | |
| student_grades = [] | |
| @students_and_scores.student_grades.each do |name| | |
| all_student_grades = {name[:name] => name[:grade]} | |
| student_grades << all_student_grades | |
| end | |
| student_grades.each do |person| | |
| person.values.each do |grade| | |
| grade.map! do |number| | |
| number.to_i | |
| end | |
| end | |
| end | |
| student_grades.each do |person| | |
| person.values.each do |grades| | |
| sum_of_grades = grades.inject() {|sum, grade| sum += grade} | |
| grade_count = grades.count | |
| @@averages = sum_of_grades/grade_count | |
| end | |
| student_with_average = {person.keys => @@averages} | |
| @students_with_final_average << student_with_average | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| person | grades | |
|---|---|---|
| Johnny Smith | 100 80 75 78 60 | |
| Sally Strong | 100 100 90 95 85 | |
| Jimmy Fallon | 95 97 85 40 85 | |
| Chris Bostworth | 98 86 85 82 80 | |
| Brian Boyd | 50 60 65 70 75 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| class WriteToFile | |
| def initialize(formated_grades) | |
| @formated_grades = formated_grades | |
| end | |
| def write_to_file | |
| CSV.open("final_grades.csv", "wb") do |csv| | |
| csv << ["Last Name", "First Name", "Final Average", "Final Grade"] | |
| @formated_grades.final_grades_formatted.each do |person| | |
| csv << [person[:last_name], person[:first_name], person[:final_average], person[:final_grade]] | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment