tier times working now

This commit is contained in:
Joachim 2018-09-13 21:31:55 +02:00
parent 9fdb66e92b
commit 738977800d

View File

@ -30,26 +30,40 @@ class RouteDefiner(router: Router, vertx: Vertx, postgreSQLClient: AsyncSQLClien
* Get the tier-overview times. * Get the tier-overview times.
*/ */
router.get("/championship/:idchampionship/tier/:tier/times").handler { rc -> router.get("/championship/:idchampionship/tier/:tier/times").handler { rc ->
val query = "with rankedtimes as (with penalisedtimes as (select idrace,\n" + val query2 = """with racetimes as (select idrace, sum(laptime)+ interval '1 second' *
" laptime + interval '1 second' *\n" + coalesce((select sum(penaltyseconds) from comment where idrace = valid_laptimes.idrace),0) penalisedtime
" (select coalesce(sum(penaltyseconds), 0)\n" + from valid_laptimes inner join race using (idrace) where publishresults group by idrace),
" from comment\n" + selectedtimes as (select *, ROW_NUMBER() OVER (PARTITION BY idteam, idchampionship, tier, poule
" where idrace = valid_laptimes.idrace)as penalisedlaptime\n" + ORDER BY penalisedtime) rownr from racetimes inner join race using (idrace) where penalisedtime is not null order by idteam, rownr),
" from valid_laptimes),\n" + finaltimes as (
" summedtimes as (select idrace, idteam, poule, sum(penalisedlaptime) laptimesum\n" + select idchampionship, tier, poule, idteam, avg(penalisedtime) result
" from penalisedtimes\n" + from selectedtimes
" inner join race using (idrace)\n" + where rownr < 3
" where tier = ?\n" + group by idchampionship, tier, poule, idteam
" and race.idchampionship = ?\n" + having count(*) = 2
" and publishresults\n" + )
" group by idrace, idteam, poule\n" + select idteam, name, poule, extract(epoch from result) result from finaltimes inner join team using (idteam) where tier = ? and finaltimes.idchampionship = ? order by 4
" having count(*) > 1)\n" + """
" select *, ROW_NUMBER() OVER (PARTITION BY idteam\n" + // val query = "with rankedtimes as (with penalisedtimes as (select idrace,\n" +
" ORDER BY laptimesum) rownr\n" + // " laptime + interval '1 second' *\n" +
" from summedtimes)\n" + // " (select coalesce(sum(penaltyseconds), 0)\n" +
"select idteam, team.name, poule, extract(epoch from avg(laptimesum)) result from rankedtimes inner join team using (idteam) where rownr < 3 " + // " from comment\n" +
"group by idteam, poule, team.name order by 4" // " where idrace = valid_laptimes.idrace)as penalisedlaptime\n" +
rc.end(postgreSQLClient.rxQueryWithParams(query, JsonArray( // " 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(query2, JsonArray(
rc.pathParam("tier").toInt(), rc.pathParam("tier").toInt(),
rc.pathParam("idchampionship").toInt() rc.pathParam("idchampionship").toInt()
)).map { it.rows }) )).map { it.rows })