This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/token-validator/grades.go

83 lines
1.7 KiB
Go
Raw Normal View History

package main
import (
"github.com/julienschmidt/httprouter"
2020-03-27 13:57:14 +00:00
2021-10-31 15:43:43 +00:00
"git.nemunai.re/srs/adlin/libadlin"
)
func init() {
router.GET("/api/grades/", apiHandler(computeGrades))
}
func computeGrades(_ httprouter.Params, _ []byte) (interface{}, error) {
2020-03-27 13:57:14 +00:00
if stds, err := adlin.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,
"TP3": 0,
}
2020-03-27 13:57:14 +00:00
if states, err := std.GetStatesByChallenge(); err != nil {
return nil, err
} else {
for _, st := range states {
if st.Challenge >= 200 {
switch st.Challenge {
case 200:
res[std.Login]["TP3"] += 5
case 201:
res[std.Login]["TP3"] += 5
case 202:
res[std.Login]["TP3"] += 6
case 203:
res[std.Login]["TP3"] += 4
}
} else if st.Challenge >= 100 {
switch st.Challenge {
case 100:
res[std.Login]["TP2"] += 4
case 101:
res[std.Login]["TP2"] += 6
case 102:
res[std.Login]["TP2"] += 6
case 103:
res[std.Login]["TP2"] += 4
}
} else {
switch st.Challenge {
case 1:
res[std.Login]["TP1"] += 3
case 2:
res[std.Login]["TP1"] += 3
case 3:
res[std.Login]["TP1"] += 4
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
case 8:
res[std.Login]["TP1"] += 1
case 9:
res[std.Login]["TP1"] += 1
case 10:
res[std.Login]["TP1"] += 1
}
}
}
}
}
return res, nil
}
}