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
/
progressgrid.go
87 lines (76 loc) · 1.73 KB
/
progressgrid.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
package handlers
import (
"fmt"
"html/template"
"net/http"
"strconv"
"strings"
"github.com/andrewcharlton/school-dashboard/analysis/group"
"github.com/andrewcharlton/school-dashboard/env"
)
// ProgressGrid produces a page containing a progress grid for a subject
func ProgressGrid(e env.Env) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
path := strings.Split(r.URL.Path, "/")
switch len(path) {
case 3:
selectSubject(e, w, r, "Progress Grid")
case 4:
selectLevel(e, w, r, "Progress Grid")
case 5:
selectClass(e, w, r, "Progress Grid")
case 6:
progressGridPage(e, w, r)
}
}
}
// Performs analysis of the results
func progressGridPage(e env.Env, 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)
path := strings.Split(r.URL.Path, "/")
subjID, err := strconv.Atoi(path[3])
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
subject := e.Subjects[subjID]
class := path[4]
if strings.HasPrefix(path[4], "All") {
class = ""
}
f := getFilter(e, r)
g, err := e.GroupByFilteredClass(path[3], class, f)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
data := struct {
Query template.URL
Year string
Subject string
Level string
SubjID string
Class string
KS2Prior string
Group group.Group
ProgressGrid group.ProgressGrid
}{
template.URL(r.URL.RawQuery),
f.Year,
subject.Subj,
subject.Lvl,
path[3],
path[4],
subject.KS2Prior,
g,
g.ProgressGrid(subject, f.NatYear),
}
err = e.Templates.ExecuteTemplate(w, "progressgrid.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
}