This repository has been archived by the owner on Jul 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress8.go
134 lines (113 loc) · 2.67 KB
/
progress8.go
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
package handlers
import (
"fmt"
"html/template"
"net/http"
"sort"
"strconv"
"github.com/andrewcharlton/school-dashboard/analysis/group"
"github.com/andrewcharlton/school-dashboard/analysis/student"
"github.com/andrewcharlton/school-dashboard/env"
)
type point struct {
X float64
Y float64
Name string
P8 student.Progress8Score
}
type points []point
func (p points) Len() int { return len(p) }
func (p points) Less(i, j int) bool { return p[i].X < p[j].X }
func (p points) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Progress8 returns a handler to produce the Progress 8 page.
func Progress8(e env.Env) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if redir := checkRedirect(e, w, r, 2); redir {
return
}
header(e, w, r, 2)
defer footer(e, w, r)
f := getFilter(e, r)
g, err := e.GroupByFilter(f)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
nat, exists := e.Attainment8[f.NatYear]
if !exists {
fmt.Fprintf(w, "Error: %v", err)
}
natLine := points{}
for ks2, att8 := range nat {
n, err := strconv.ParseFloat(ks2, 64)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
natLine = append(natLine, point{X: n, Y: att8.Overall})
}
sort.Sort(natLine)
pupilData := [4]points{}
for _, s := range g.Students {
p8 := s.Basket().Overall()
var key int
switch {
case s.PP && s.Gender == 1:
key = 0
case s.Gender == 1:
key = 1
case s.PP && s.Gender == 0:
key = 2
case s.Gender == 0:
key = 3
}
pupilData[key] = append(pupilData[key], point{X: s.KS2.APS / 6,
Y: p8.Attainment,
Name: s.Name(),
P8: p8})
}
data := struct {
Query template.URL
Group group.Group
NatLine points
PupilData [4]points
}{
template.URL(r.URL.RawQuery),
g,
natLine,
pupilData,
}
err = e.Templates.ExecuteTemplate(w, "progress8.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
// Progress8Groups calculates the progress 8 scores for each group of students
func Progress8Groups(e env.Env) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if redir := checkRedirect(e, w, r, 1); redir {
return
}
header(e, w, r, 1)
defer footer(e, w, r)
f := getFilter(e, r)
g, err := e.GroupByFilter(f)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
data := struct {
Query template.URL
Groups []subGroup
Matrix subGroupMatrix
}{
template.URL(r.URL.RawQuery),
subGroups(g),
groupMatrix(g),
}
err = e.Templates.ExecuteTemplate(w, "progress8groups.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}