Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
progress report generator
require 'csv'
require 'pry'
require 'erb'
class Student
attr_reader :id, :name, :section
attr_accessor :group1,
:group2,
:absences,
:diagnostic,
:packet1,
:test1_individual,
:test1_group,
:teamwork1,
:teamwork1_comments,
:packet2,
:test2_individual,
:test2_group,
:teamwork2,
:teamwork2_comments
def initialize id, name, section
@id, @name, @section = id, name, section
@teamwork1_comments = []
@teamwork2_comments = []
end
def absence_count
return 0 unless absences
absences.length
end
def absence_grade
[0,50-absence_count].max
end
def points_earned
absence_grade +
diagnostic +
packet1 +
test1_individual +
test1_group +
teamwork1 +
packet2 +
test2_individual +
test2_group +
teamwork2
end
def final_weight
1000 - points_earned
end
def points_needed_on_final_for grade_symbol
grade_points = {
a: 900,
b: 800,
c: 700,
d: 650
}
grade_points[grade_symbol] - points_earned
end
def percentage_needed_on_final_for grade_symbol
(points_needed_on_final_for(grade_symbol).to_f / final_weight * 100).round(1)
end
def total1
packet1 + teamwork1 + test1_individual + test1_group
end
def total2
packet2 + teamwork2 + test2_individual + test2_group
end
end
students = []
CSV.foreach("students.csv") do |row|
if row[0] && row[0].downcase!='email'
students << Student.new(row[0], row[1], row[2])
end
end
CSV.foreach("groups1.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
student.group1 = row[2].to_i
end
end
CSV.foreach("groups2.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
student.group2 = row[2].to_i
end
end
CSV.foreach("diagnostic.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
student.diagnostic = row[3].to_i
end
end
CSV.foreach("absences.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
student.absences = row[4..-1].compact
end
end
CSV.foreach("tests.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
binding.pry unless student
student.test1_individual = row[3].to_i
student.test1_group = row[4].to_i
student.test2_individual = row[5].to_i
student.test2_group = row[6].to_i
end
end
CSV.foreach("teamwork.csv") do |row|
if row[0] && row[0].downcase!='email'
student = students.select{|s| s.id == row[0]}.first
student.teamwork1 = row[3].to_i
student.teamwork1_comments << row[4] if row[4]
student.teamwork2 = row[5].to_i
student.teamwork2_comments << row[6] if row[6]
elsif row[2][0..4].downcase == 'group'
group = row[2].split(' ')[1].to_i
group_members = students.select{|s| s.group1 == group}
group_members.each do |member|
member.teamwork1_comments << row[3] if row[3]
member.teamwork2_comments << row[5] if row[5]
end
end
end
CSV.foreach("packets.csv") do |row|
if row[0] && row[0].downcase!='group'
group_members = students.select{|s| s.group1 == row[0].to_i}
group_members.each do |member|
member.packet1 = row[1].to_i
member.packet2 = row[2].to_i
end
end
end
template_filename = 'output.tex.erb'
template_file = File.read template_filename
template_erb = ERB.new template_file
File.write 'output.tex', template_erb.result(binding)
%x{pdflatex output.tex}
\documentclass[11pt]{article}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{fancyvrb}
\usepackage{multicol}
\usepackage{fancyhdr}
\begin{document}
<% students.each do |student| %>
\centerline{Midsemester Progress Report - Mr. Clontz - MATH 2630-<%=student.section%> - Spring 2015}
\textbf{Name:}
<%= student.name %>
\textbf{Group:}
<%= student.group1 %>
\textbf{Absences:}
<%= student.absence_count %>
<% student.absences.each do |absence| %><%= absence %>, <% end %>
\textbf{Attendance Grade:}
<%= student.absence_grade %>/50
\textbf{Diagnostic Exam Grade:}
<%= student.diagnostic %>/50
\textbf{Packet/Test 1 Grades:} <%= student.total1 %>/100
\begin{itemize}
\item Packet: <%= student.packet1 %>/20
\item Test (I): <%= student.test1_individual %>/30
\item Test (G): <%= student.test1_group %>/30
\item Teamwork: <%= student.teamwork1 %>/20
\end{itemize}
<% student.teamwork1_comments.each do |comment| %>
Comment: <%=comment%>
<% end %>
\textbf{Packet/Test 2 Grades:} <%= student.total2 %>/100
\begin{itemize}
\item Packet: <%= student.packet2 %>/20
\item Test (I): <%= student.test2_individual %>/30
\item Test (G): <%= student.test2_group %>/30
\item Teamwork: <%= student.teamwork2 %>/20
\end{itemize}
<% student.teamwork2_comments.each do |comment| %>
Comment: <%=comment%>
<% end %>
\textbf{Current Grade:} <%= student.points_earned %>/300
\textbf{Current Weight of Final:} <%= student.final_weight %>/1000
\begin{itemize}
\item Needed on Final for an A: <%= student.percentage_needed_on_final_for(:a) %>\%
\item Needed on Final for an B: <%= student.percentage_needed_on_final_for(:b) %>\%
\item Needed on Final for an C: <%= student.percentage_needed_on_final_for(:c) %>\%
\item Needed on Final for an D: <%= student.percentage_needed_on_final_for(:d) %>\%
\end{itemize}
\textbf{New Group for 2nd half of Semester:}
<%= student.group2 %>
\newpage
<% end %>
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment