fic: improve ranking query lisibility
This commit is contained in:
parent
74550f8907
commit
2c5144aac0
@ -13,11 +13,18 @@ var FirstBlood = 0.12
|
|||||||
var SubmissionCostBase = 0.5
|
var SubmissionCostBase = 0.5
|
||||||
|
|
||||||
func exoptsQuery(whereExo string) string {
|
func exoptsQuery(whereExo string) string {
|
||||||
return "SELECT S.id_team, S.time, E.gain AS points, coeff FROM (SELECT id_team, id_exercice, MIN(time) AS time, " + fmt.Sprintf("%f", FirstBlood) + " AS coeff FROM exercice_solved GROUP BY id_exercice UNION SELECT id_team, id_exercice, time, coefficient AS coeff FROM exercice_solved) S INNER JOIN exercices E ON S.id_exercice = E.id_exercice " + whereExo + " UNION ALL SELECT id_team, MAX(time) AS time, (FLOOR(COUNT(*)/10 - 1) * (FLOOR(COUNT(*)/10)))/0.2 + (FLOOR(COUNT(*)/10) * (COUNT(*)%10)) AS points, " + fmt.Sprintf("%f", SubmissionCostBase * -1) + " AS coeff FROM exercice_tries S " + whereExo + " GROUP BY id_exercice, id_team"
|
return `SELECT S.id_team, S.time, E.gain AS points, coeff FROM (
|
||||||
|
SELECT id_team, id_exercice, MIN(time) AS time, ` + fmt.Sprintf("%f", FirstBlood) + ` AS coeff FROM exercice_solved GROUP BY id_exercice UNION
|
||||||
|
SELECT id_team, id_exercice, time, coefficient AS coeff FROM exercice_solved
|
||||||
|
) S INNER JOIN exercices E ON S.id_exercice = E.id_exercice ` + whereExo + ` UNION ALL
|
||||||
|
SELECT id_team, MAX(time) AS time, (FLOOR(COUNT(*)/10 - 1) * (FLOOR(COUNT(*)/10)))/0.2 + (FLOOR(COUNT(*)/10) * (COUNT(*)%10)) AS points, ` + fmt.Sprintf("%f", SubmissionCostBase * -1) + ` AS coeff FROM exercice_tries S ` + whereExo + ` GROUP BY id_exercice, id_team`
|
||||||
}
|
}
|
||||||
|
|
||||||
func rankQuery(whereTeam string) string {
|
func rankQuery(whereTeam string) string {
|
||||||
return "SELECT A.id_team, SUM(A.points * A.coeff) AS score, MAX(A.time) AS time FROM (" + exoptsQuery("") + " UNION ALL SELECT D.id_team, D.time, H.cost AS points, -1.0 AS coeff FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint HAVING points != 0) A " + whereTeam + " GROUP BY A.id_team ORDER BY score DESC, time ASC"
|
return `SELECT A.id_team, SUM(A.points * A.coeff) AS score, MAX(A.time) AS time FROM (
|
||||||
|
` + exoptsQuery("") + ` UNION ALL
|
||||||
|
SELECT D.id_team, D.time, H.cost AS points, -1.0 AS coeff FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint HAVING points != 0
|
||||||
|
) A ` + whereTeam + ` GROUP BY A.id_team ORDER BY score DESC, time ASC`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Points
|
// Points
|
||||||
|
Loading…
Reference in New Issue
Block a user