package main import ( "github.com/julienschmidt/httprouter" "git.nemunai.re/srs/adlin/libadlin" ) func init() { router.GET("/api/grades/", apiHandler(computeGrades)) } func computeGrades(_ httprouter.Params, _ []byte) (interface{}, error) { 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, } 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 } }