lila/app/views/irwin.scala

146 lines
4.8 KiB
Scala
Raw Normal View History

2019-04-17 13:16:57 -06:00
package views.html
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import controllers.routes
object irwin {
2020-05-05 22:11:15 -06:00
private def percentClass(percent: Int) =
percent match {
case p if p < 30 => "green"
case p if p < 60 => "yellow"
case p if p < 80 => "orange"
case _ => "red"
}
2019-04-17 13:16:57 -06:00
2019-12-13 07:30:20 -07:00
def dashboard(dashboard: lila.irwin.IrwinDashboard)(implicit ctx: Context) =
views.html.base.layout(
title = "Irwin dashboard",
moreCss = cssTag("mod.misc")
) {
2019-04-17 13:16:57 -06:00
main(cls := "page-menu")(
mod.menu("irwin"),
div(cls := "irwin page-menu__content box")(
div(cls := "box__top")(
h1(
"Irwin status: ",
if (dashboard.seenRecently) span(cls := "up")("Operational")
2019-12-13 07:30:20 -07:00
else
span(cls := "down")(
dashboard.lastSeenAt.map { seenAt =>
frag("Last seen ", momentFromNow(seenAt))
} getOrElse {
frag("Unknown")
}
)
2019-04-17 13:16:57 -06:00
),
div(cls := "box__top__actions")(
2019-12-13 07:30:20 -07:00
a(
2020-11-02 00:32:22 -07:00
href := "https://monitor.lichess.ovh/d/a5qOnu9Wz/mod-yield",
2019-12-13 07:30:20 -07:00
cls := "button button-empty"
)("Monitoring")
2019-04-17 13:16:57 -06:00
)
),
table(cls := "slist slist-pad")(
thead(
tr(
th("Recent report"),
th("Completed"),
th("Owner"),
th("Activation")
)
),
tbody(
dashboard.recent.map { rep =>
tr(cls := "report")(
td(userIdLink(rep.suspectId.value.some, params = "?mod")),
td(cls := "little completed")(momentFromNow(rep.date)),
td(rep.owner),
td(cls := s"little activation ${percentClass(rep.activation)}")(
2019-12-13 07:30:20 -07:00
strong(rep.activation, "%"),
" over ",
rep.games.size,
" games"
2019-04-17 13:16:57 -06:00
)
)
}
)
)
)
)
}
2019-04-22 03:42:25 -06:00
def report(report: lila.irwin.IrwinReport.WithPovs)(implicit ctx: Context): Frag =
div(cls := "mz-section mz-section--irwin", dataRel := "irwin")(
2019-04-17 13:16:57 -06:00
header(
a(cls := "title", href := routes.Irwin.dashboard)(
2020-09-04 04:08:24 -06:00
img(src := assetUrl("images/icons/brain.blue.svg")),
2019-12-13 07:30:20 -07:00
" Irwin AI",
br,
"Hunter"
2019-04-17 13:16:57 -06:00
),
div(cls := "infos")(
2020-05-30 21:39:48 -06:00
p("Updated ", momentFromNowServer(report.report.date))
2019-04-17 13:16:57 -06:00
),
div(cls := "assess text")(
strong(cls := percentClass(report.report.activation))(report.report.activation, "%"),
" Overall assessment"
)
),
table(cls := "slist")(
tbody(
report.withPovs.sortBy(-_.report.activation).map {
case lila.irwin.IrwinReport.GameReport.WithPov(gameReport, pov) =>
tr(cls := "text")(
td(cls := "moves")(
a(href := routes.Round.watcher(pov.gameId, pov.color.name))(
gameReport.moves.map { move =>
span(
cls := percentClass(move.activation),
st.title := move.toString,
style := s"height:${move.activation}%"
)
}
)
),
td(
a(href := routes.Round.watcher(pov.gameId, pov.color.name))(
2019-12-13 07:30:20 -07:00
playerLink(
pov.opponent,
withRating = true,
withDiff = true,
withOnline = false,
link = false
),
2019-04-17 13:16:57 -06:00
br,
pov.game.isTournament ?? frag(iconTag(""), " "),
2019-12-13 07:30:20 -07:00
pov.game.perfType.map { pt =>
iconTag(pt.iconChar)
},
2019-04-17 13:16:57 -06:00
shortClockName(pov.game.clock.map(_.config)),
2019-05-14 02:22:46 -06:00
" ",
2020-05-30 21:39:48 -06:00
momentFromNowServer(pov.game.createdAt)
2019-04-17 13:16:57 -06:00
)
),
td(
strong(cls := percentClass(gameReport.activation))(gameReport.activation, "%"),
2019-12-13 07:30:20 -07:00
" ",
em("assessment")
2019-04-17 13:16:57 -06:00
),
td {
val blurs = pov.game.playerBlurPercent(pov.color)
frag(strong(cls := percentClass(blurs))(blurs, "%"), " ", em("blurs"))
}
2019-12-13 07:30:20 -07:00
// td(
// pov.player.holdAlert.exists(_.suspicious) option strong(cls := percentClass(50))("Bot?")
// )
2019-04-17 13:16:57 -06:00
)
}
)
)
)
}