# Class to create test grade data. # This could be a simple script, but I prefer to keep it as a # class to show the coherence of the methods. class CreateGradeData # Create a data set and print it on standard output # # @param nStudents - number of students # @param types - an array of quatruples, where the elements are: # name - the name of the type, # abbreviation - one letter abbreviation, # points - total number of points for this type of grade, # grades - an array of grades to generate where each element has the form: # high - maximum points # low - minimum points # low - the lowest possible percent grade to generate # high - the highest possible percentgrade to generate def CreateGradeData.makeGradeData(nStudents, types) puts types.size types.each {|i| puts i[0] + " " + i[1] + " " + i[2].to_s} studentIds = CreateGradeData.makeStudents(nStudents) types.each {|i| CreateGradeData.makeGrades(i, studentIds)} end # Generate grades of a particular type # @param type - the type of grade to generate as an array # @param sIds - the student IDs def CreateGradeData.makeGrades(type, sIds) a = type[1] # abbreviation g = type[3] # array of generating parameters g.each do |i| sIds.each{|s| CreateGradeData.generateGrade(s, a, i)} end end # Generate one grade # @param sId - student ID # @param a - abbreviation for the assignment type # @param g - generating specification [low, high] def CreateGradeData.generateGrade(sId, a, g) grade = g[0] + rand(g[1]-g[0]+1) puts a + " " + sId.to_s + " " + grade.to_s + " " + g[1].to_s end # Create an array of student IDs. The SIDs will be 5 digits between # 10000 and 99999 def CreateGradeData.makeStudents(nStudents) result = [] (0..(nStudents-1)).each do |i| x = 10000 + rand(89999) while result.include?(x) do x = 10000 + rand(89999) end result[i] = x end return result end end t = [ ["Quizzes", "Q", 10, [[0, 10], [0, 10], [0, 10], [0, 10], [0, 10], [0, 10]]], ["Exams", "E", 25, [[50, 100],[40, 100]]], ["Homework", "H", 25, [[5, 25], [10, 50], [15, 50], [8, 20], [0, 15], [5, 20]]], ["Project", "P", 30, [[40, 75], [5, 25]]], ["Participation", "C", 10, [[0, 10]]] ]; CreateGradeData.makeGradeData(25, t)