can now output tier times

This commit is contained in:
Joachim 2018-09-08 21:54:33 +02:00
parent dba491bf1b
commit 9fdb66e92b

View File

@ -26,6 +26,35 @@ class RouteDefiner(router: Router, vertx: Vertx, postgreSQLClient: AsyncSQLClien
})
}
/**
* Get the tier-overview times.
*/
router.get("/championship/:idchampionship/tier/:tier/times").handler { rc ->
val query = "with rankedtimes as (with penalisedtimes as (select idrace,\n" +
" laptime + interval '1 second' *\n" +
" (select coalesce(sum(penaltyseconds), 0)\n" +
" from comment\n" +
" where idrace = valid_laptimes.idrace)as penalisedlaptime\n" +
" from valid_laptimes),\n" +
" summedtimes as (select idrace, idteam, poule, sum(penalisedlaptime) laptimesum\n" +
" from penalisedtimes\n" +
" inner join race using (idrace)\n" +
" where tier = ?\n" +
" and race.idchampionship = ?\n" +
" and publishresults\n" +
" group by idrace, idteam, poule\n" +
" having count(*) > 1)\n" +
" select *, ROW_NUMBER() OVER (PARTITION BY idteam\n" +
" ORDER BY laptimesum) rownr\n" +
" from summedtimes)\n" +
"select idteam, team.name, poule, extract(epoch from avg(laptimesum)) result from rankedtimes inner join team using (idteam) where rownr < 3 " +
"group by idteam, poule, team.name order by 4"
rc.end(postgreSQLClient.rxQueryWithParams(query, JsonArray(
rc.pathParam("tier").toInt(),
rc.pathParam("idchampionship").toInt()
)).map { it.rows })
}
router.get("/championship/:idchampionship/tier/:tier/poules").handler { rc ->
rc.end(postgreSQLClient.rxQueryWithParams("select distinct(poule) from poule where idchampionship = ? and tier = ? order by poule",
JsonArray(
@ -63,7 +92,7 @@ class RouteDefiner(router: Router, vertx: Vertx, postgreSQLClient: AsyncSQLClien
* Get all times in a poule
*/
router.get("/championship/:idchampionship/tier/:tier/poule/:poule/times").handler { rc ->
rc.end(postgreSQLClient.rxQueryWithParams("select idteam, idrace, array_agg(extract(milliseconds from laptime)) laptimesms,\n" +
rc.end(postgreSQLClient.rxQueryWithParams("select idteam, idrace, array_agg(extract(epoch from laptime)*1000) laptimesms,\n" +
" (select sum(penaltyseconds) from comment where comment.idrace = race.idrace) penaltysum\n" +
"from poule\n" +
" inner join team_poule using (poule, tier, idchampionship)\n" +