2019-09-16 13:36:19 +00:00
|
|
|
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"
|
2019-09-16 13:36:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2019-09-16 13:36:19 +00:00
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
res := map[string]map[string]float32{}
|
|
|
|
|
|
|
|
for _, std := range stds {
|
|
|
|
res[std.Login] = map[string]float32{
|
|
|
|
"TP1": 0,
|
|
|
|
"TP2": 0,
|
2021-02-04 08:40:32 +00:00
|
|
|
"TP3": 0,
|
2019-09-16 13:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 13:57:14 +00:00
|
|
|
if states, err := std.GetStatesByChallenge(); err != nil {
|
2019-09-16 13:36:19 +00:00
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
for _, st := range states {
|
2021-02-04 08:40:32 +00:00
|
|
|
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 {
|
2019-09-16 13:36:19 +00:00
|
|
|
switch st.Challenge {
|
|
|
|
case 100:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP2"] += 4
|
2019-09-16 13:36:19 +00:00
|
|
|
case 101:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP2"] += 6
|
2019-09-16 13:36:19 +00:00
|
|
|
case 102:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP2"] += 6
|
2019-09-16 13:36:19 +00:00
|
|
|
case 103:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP2"] += 4
|
2019-09-16 13:36:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch st.Challenge {
|
|
|
|
case 1:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP1"] += 3
|
2019-09-16 13:36:19 +00:00
|
|
|
case 2:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP1"] += 3
|
2019-09-16 13:36:19 +00:00
|
|
|
case 3:
|
2021-02-04 08:40:32 +00:00
|
|
|
res[std.Login]["TP1"] += 4
|
2019-09-16 13:36:19 +00:00
|
|
|
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
|
2021-02-04 08:40:32 +00:00
|
|
|
case 8:
|
|
|
|
res[std.Login]["TP1"] += 1
|
|
|
|
case 9:
|
|
|
|
res[std.Login]["TP1"] += 1
|
|
|
|
case 10:
|
|
|
|
res[std.Login]["TP1"] += 1
|
2019-09-16 13:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|