-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgrades.go
More file actions
139 lines (120 loc) Β· 4.21 KB
/
Copy pathgrades.go
File metadata and controls
139 lines (120 loc) Β· 4.21 KB
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
135
136
137
138
139
package main
import (
// "encoding/json"
// "io/ioutil"
// "net/http"
// "github.com/spf13/viper"
// "log"
// "strconv"
// "time"
// "reflect"
// "time"
// "bytes"
"fmt"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
// ui "github.com/GideonWolfe/termui/v3"
// "github.com/GideonWolfe/termui/v3/widgets"
)
func createGradeTable(assignments *[]Assignment) *widgets.Table {
gradeTable := widgets.NewTable()
var tableData [][]string
header := []string{"Name", "Score", "%"}
i := 1
for _, assn := range *assignments {
if !assn.Submission.SubmittedAt.IsZero() {
if assn.Submission.Score > 0{
var assignmentData []string
assignmentData = append(assignmentData, assn.Name)
percentScored := float64(assn.Submission.Score/assn.PointsPossible)*100
scoreString := fmt.Sprint(assn.Submission.EnteredScore)+"/"+fmt.Sprint(assn.PointsPossible)
assignmentData = append(assignmentData, scoreString)
assignmentData = append(assignmentData, fmt.Sprintf("%.f%%", percentScored))
tableData = append(tableData, assignmentData)
if percentScored > 90 {
gradeTable.RowStyles[i-1] = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
} else if percentScored > 80 {
gradeTable.RowStyles[i-1] = ui.NewStyle(ui.ColorBlue, ui.ColorClear, ui.ModifierBold)
} else if percentScored > 70 {
gradeTable.RowStyles[i-1] = ui.NewStyle(ui.ColorYellow, ui.ColorClear, ui.ModifierBold)
} else if percentScored <= 60 {
// log.Panic(assn.Name)
gradeTable.RowStyles[i-1] = ui.NewStyle(ui.ColorRed, ui.ColorClear, ui.ModifierBold)
}
i++
}
}
}
tableData = append(tableData, header)
// reverse the list
for i, j := 0, len(tableData)-1; i < j; i, j = i+1, j-1 {
tableData[i], tableData[j] = tableData[j], tableData[i]
gradeTable.RowStyles[i], gradeTable.RowStyles[j] = gradeTable.RowStyles[j], gradeTable.RowStyles[i]
}
gradeTable.Title = "Scores:"
gradeTable.Rows = tableData
gradeTable.TextStyle = ui.NewStyle(ui.ColorWhite)
gradeTable.RowSeparator = true
gradeTable.FillRow = true
gradeTable.RowStyles[0] = ui.NewStyle(ui.ColorWhite, ui.ColorBlack, ui.ModifierBold)
return gradeTable
}
func createAGBreakdown(assignments *[]Assignment, assignmentGroups *[]AssignmentGroup) *widgets.Plot {
backup := widgets.NewPlot()
backup.Title = "Not enough data"
backup.Data = make([][]float64, 1)
backup.Data =[][]float64{{1, 2, 3, 4, 5}}
backup.AxesColor = ui.ColorWhite
backup.LineColors[0] = ui.ColorGreen
var placeholder []float64
placeholder = append(placeholder, 5.0)
p0 := widgets.NewPlot()
p0.Title = "Score by Assignment Group"
p0.LineColors[0] = ui.ColorCyan
p0.HorizontalScale = 6
var dataLabels []int
// create a dictionary of assignment groups and their IDs
count := 0
aGDict := make(map[int]string)
for _, ag := range *assignmentGroups {
if len(ag.Assignments) > 0 {
count++
aGDict[ag.ID] = ag.Name
}
}
p0.Data = make([][]float64, count)
assignmentDict := make(map[int][]float64)
for _, assn := range *assignments {
if !assn.Submission.SubmittedAt.IsZero() {
if assn.Submission.Score > 0 && assn.PointsPossible != 0{
percentScored := float64(assn.Submission.Score/assn.PointsPossible)*100
assignmentDict[assn.AssignmentGroupID] = append(assignmentDict[assn.AssignmentGroupID], percentScored)
}
}
}
i := 0
for group, data := range assignmentDict {
dataLabels = append(dataLabels, group)
p0.Data = append(p0.Data, data)
i++
}
// log.Panic(p0.Data, assignmentDict)
if len(p0.Data) <= 1 {
return backup
}
return p0
}
func createGradeGrid(course Course, assignments *[]Assignment, assignmentGroups *[]AssignmentGroup) *ui.Grid {
// var assignments *[]Assignment = fetchAssignments(course.ID)
gradeGrid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
gradeGrid.SetRect(0, 0, termWidth, termHeight)
gradeGrid.Title = "Course Grade Grid"
gradeGrid.Set(
ui.NewRow(1.0,
ui.NewRow(2.0/3, createGradeTable(assignments)),
ui.NewRow(1.0/3, createAGBreakdown(assignments, assignmentGroups)),
),
)
return gradeGrid
}