1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#   author: Alexander Corey
#   file:   classScores.rb
#   date:   2019-10-29
#   brief:  This program reads a csv text file containing scores
#           and creates an HTML file to display them.
require 'csv'

$htmlOutput = "scores.html"
$flagNamesIds = false 
$htmlOutput = "scores.html"


if ARGV[0] == "-ids" 
  $flagNamesIds = false
elsif ARGV[0] == "-names"
  $flagNamesIds = true
else 
  puts "Invalid command line arg. Please enter -ids or -names.\n"
end


# reading from file
inputFile = ARGV[1]

#grab title
file = File.open(inputFile, "r")
line = file.readline
$classTitle = line.split(",", 2)
file.close
$classTitle[1] = $classTitle[1].split(",").first

#create table
table = CSV.parse(File.read(inputFile), headers: true)
# Parse main columns
$assignStr = table[0][1]
$assignCount = table[0][2].to_i
$testStr = table[1][1]
$testCount = table[1][2].to_i
$assignWeightStr = table[2][1]
$assignWeight = table[2][2].to_i
$testWeightStr = table[3][1]
$testWeight = table[3][2].to_i
$titleRowLen = table.by_row[4].length
$possStr = table[5][1]
$possScores = table[5][2].to_i

$numStudents = table.by_col[0].length
$numStudents.to_i
$numStudents -= 6

# cleaning data
$var3 = 0
$index3 = 0
if ($flagNamesIds == false)
while ($index3 < table.by_col[1].length)
  table[$var3][1] = ""
  $var3   += 1
  $index3 += 1 
end
end


$index = 0
$var = 0

# Build and output html file
file2 = File.open($htmlOutput, "w")
file2.puts "<html><head><style>
table {
  font-family: Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style><h1> #{$classTitle[1]} </h1></head><body>"

#file2.puts "<table><tr><th>#{$assignments[$index]}</th>"
file2.puts "<table><tr>"

while ($index < $titleRowLen)
#while ($index < 8)
file2.puts "<th>#{table[4][$var]}</th>"
$var+= 1
$index += 1
end
file2.puts "</tr><tr>"


$var = 0
$row = 6
$col = 0
$index = 0 #reset index
while ($var < $numStudents)
  while ($index < $titleRowLen)

  file2.puts "<td>#{table[$row][$col]}</td>"
  $col += 1
  $index += 1
  #puts table[$row][$col]
  end
  $var += 1
  $index = 0
  $row += 1 #works
  $col = 0 #reset col
  file2.puts "</tr><tr>"
end
file2.puts "</tr>"

#possible scores
file2.puts "<th>#{table[5][1]}</th>"
file2.puts "<th>  </th>"
$index = 0
$var = 2
while ($index < $titleRowLen - 1)

file2.puts "<th>#{table[5][$var]}</th>"
$var+= 1
$index += 1
end
file2.puts "</tr>"



file2.puts "</table></body></html>"
file2.close