diff --git a/libfic/stats.go b/libfic/stats.go index 194834c9..17be41f9 100644 --- a/libfic/stats.go +++ b/libfic/stats.go @@ -13,11 +13,18 @@ var FirstBlood = 0.12 var SubmissionCostBase = 0.5 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 { - 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