token-validator: add a new route to get computed grades
This commit is contained in:
parent
ffcccce709
commit
7682cae26c
2 changed files with 87 additions and 2 deletions
62
token-validator/grades.go
Normal file
62
token-validator/grades.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
router.GET("/api/grades/", apiHandler(computeGrades))
|
||||
}
|
||||
|
||||
func computeGrades(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
if stds, err := getStudents(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
res := map[string]map[string]float32{}
|
||||
|
||||
for _, std := range stds {
|
||||
res[std.Login] = map[string]float32{
|
||||
"TP1": 0,
|
||||
"TP2": 0,
|
||||
}
|
||||
|
||||
if states, err := std.getStatesByChallenge(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, st := range states {
|
||||
if st.Challenge >= 100 {
|
||||
switch st.Challenge {
|
||||
case 100:
|
||||
res[std.Login]["TP2"] += 5
|
||||
case 101:
|
||||
res[std.Login]["TP2"] += 5
|
||||
case 102:
|
||||
res[std.Login]["TP2"] += 5
|
||||
case 103:
|
||||
res[std.Login]["TP2"] += 5
|
||||
}
|
||||
} else {
|
||||
switch st.Challenge {
|
||||
case 1:
|
||||
res[std.Login]["TP1"] += 4
|
||||
case 2:
|
||||
res[std.Login]["TP1"] += 4
|
||||
case 3:
|
||||
res[std.Login]["TP1"] += 5
|
||||
case 4:
|
||||
res[std.Login]["TP1"] += 2
|
||||
case 5:
|
||||
res[std.Login]["TP1"] += 2
|
||||
case 6:
|
||||
res[std.Login]["TP1"] += 1
|
||||
case 7:
|
||||
res[std.Login]["TP1"] += 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
Reference in a new issue