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
/
attendance.go
106 lines (88 loc) · 2.21 KB
/
attendance.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
package handlers
import (
"fmt"
"html/template"
"net/http"
"github.com/andrewcharlton/school-dashboard/analysis/group"
"github.com/andrewcharlton/school-dashboard/env"
)
// AttendanceGroups produces a page with attendance summaries for the
// various student groups.
func AttendanceGroups(e env.Env) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if redir := checkRedirect(e, w, r, 0); redir {
return
}
header(e, w, r, 0)
defer footer(e, w, r)
f := getFilter(e, r)
g, err := e.GroupByFilter(f)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
type YearGroup struct {
Name string
Query template.URL
Groups []subGroup
Matrix subGroupMatrix
}
// Ignore error - will appear as blank string anyway
week, _ := e.CurrentWeek()
data := struct {
Week string
Query template.URL
YearGroups []YearGroup
}{
week,
template.URL(r.URL.RawQuery),
[]YearGroup{{"All Years", template.URL(""), subGroups(g), groupMatrix(g)}},
}
for year := 7; year < 15; year++ {
y := g.SubGroup(group.Year(year))
if len(y.Students) == 0 {
continue
}
yeargroup := YearGroup{fmt.Sprintf("Year %v", year),
template.URL(fmt.Sprintf("&year=%v", year)),
subGroups(y),
groupMatrix(y)}
data.YearGroups = append(data.YearGroups, yeargroup)
}
err = e.Templates.ExecuteTemplate(w, "attendancegroups.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
// AttendanceExplorer provides a page for exploring the attendance figures
// in more detail, and examine individual students.
func AttendanceExplorer(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
}
week, _ := e.CurrentWeek()
data := struct {
Query template.URL
Week string
Group group.Group
}{
template.URL(r.URL.RawQuery),
week,
g,
}
err = e.Templates.ExecuteTemplate(w, "attendance.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}