本文整理汇总了Golang中github.com/andrewcharlton/school-dashboard/env.Env.GroupByFilter方法的典型用法代码示例。如果您正苦于以下问题:Golang Env.GroupByFilter方法的具体用法?Golang Env.GroupByFilter怎么用?Golang Env.GroupByFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/andrewcharlton/school-dashboard/env.Env
的用法示例。
在下文中一共展示了Env.GroupByFilter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AttendanceExplorer
// 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)
}
}
}
示例2: AttainmentGroups
// AttainmentGroups produces a page with a summary of the
// attainment of each subgroup
func AttainmentGroups(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
}{
template.URL(r.URL.RawQuery),
subGroups(g),
}
err = e.Templates.ExecuteTemplate(w, "attainmentgroups.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
示例3: EnglishAndMaths
// EnglishAndMaths produces a summary page with the number/percentage
// of students achieving passes in English and/or Maths.
func EnglishAndMaths(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
}
groups := []group.Group{{}, {}, {}, {}}
for _, s := range g.Students {
eng := s.EBaccArea("E").Achieved
maths := s.EBaccArea("M").Achieved
switch {
case eng && maths:
groups[2].Students = append(groups[2].Students, s)
case eng:
groups[0].Students = append(groups[0].Students, s)
case maths:
groups[1].Students = append(groups[1].Students, s)
default:
groups[3].Students = append(groups[3].Students, s)
}
}
pcts := []float64{}
for _, grp := range groups {
pcts = append(pcts, float64(len(grp.Students))/float64(len(g.Students)))
}
data := struct {
Query template.URL
Names []string
Groups []group.Group
Pcts []float64
}{
template.URL(r.URL.RawQuery),
[]string{"English Only", "Mathematics Only", "English & Maths", "Neither"},
groups,
pcts,
}
err = e.Templates.ExecuteTemplate(w, "em.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
示例4: AttendanceGroups
// 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)
}
}
}
示例5: KS3Groups
// KS3Groups produces a group breakdown page for
func KS3Groups(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
}
ks3Subjects := subject.List{}
for _, s := range e.Subjects {
if s.Lvl == "KS3" {
ks3Subjects = append(ks3Subjects, *s)
}
}
sort.Sort(ks3Subjects)
data := struct {
Query template.URL
Year string
Subjects subject.List
Groups []subGroup
Matrix subGroupMatrix
}{
template.URL(r.URL.RawQuery),
f.Year,
ks3Subjects,
subGroups(g),
groupMatrix(g),
}
err = e.Templates.ExecuteTemplate(w, "ks3groups.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
示例6: KS3Summary
// KS3Summary produces a page with the student
func KS3Summary(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
}
ks3Subjects := subject.List{}
var lvl subject.Level
for _, s := range e.Subjects {
if s.Lvl == "KS3" {
lvl = s.Level
ks3Subjects = append(ks3Subjects, *s)
}
}
sort.Sort(ks3Subjects)
data := struct {
Query template.URL
Subjects subject.List
KS3 subject.Level
Group group.Group
}{
template.URL(r.URL.RawQuery),
ks3Subjects,
lvl,
g,
}
err = e.Templates.ExecuteTemplate(w, "ks3summary.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
}
}
示例7: Progress8
// 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)
}
}
}