fix study game cite when year is incomplete - closes #3903
This commit is contained in:
parent
99829e30bf
commit
c9c8375f7d
|
@ -1,8 +1,5 @@
|
|||
package lila.study
|
||||
|
||||
import org.joda.time.DateTime
|
||||
import scala.util.Try
|
||||
|
||||
import chess.format.pgn.{ Parser, ParsedPgn, Tag }
|
||||
import lila.common.LightUser
|
||||
import lila.game.{ Game, Namer }
|
||||
|
@ -62,21 +59,17 @@ private final class ExplorerGame(
|
|||
|
||||
private def gameUrl(game: Game) = s"$baseUrl/${game.id}"
|
||||
|
||||
private def gameYear(pgn: Option[ParsedPgn], g: Game): Int =
|
||||
pgn.flatMap(_.tags.anyDate).flatMap { pgnDate =>
|
||||
Try(DateTime.parse(pgnDate, Tag.UTCDate.format)).toOption map (_.getYear)
|
||||
} | g.createdAt.getYear
|
||||
|
||||
private def gameTitle(g: Game): String = {
|
||||
val pgn = g.pgnImport.flatMap(pgnImport => Parser.full(pgnImport.pgn).toOption)
|
||||
val white = pgn.flatMap(_.tags(_.White)) | Namer.playerText(g.whitePlayer)(lightUser)
|
||||
val black = pgn.flatMap(_.tags(_.Black)) | Namer.playerText(g.blackPlayer)(lightUser)
|
||||
val result = chess.Color.showResult(g.winnerColor)
|
||||
val event: String = {
|
||||
val raw = pgn.flatMap(_.tags(_.Event))
|
||||
val year = gameYear(pgn, g).toString
|
||||
raw.find(_ contains year) | raw.fold(year)(e => s"$e, $year")
|
||||
}
|
||||
s"$white - $black, $result, $event"
|
||||
val event: Option[String] =
|
||||
(pgn.flatMap(_.tags(_.Event)), pgn.flatMap(_.tags.year).map(_.toString)) match {
|
||||
case (Some(event), Some(year)) if event.contains(year) => event.some
|
||||
case (Some(event), Some(year)) => s"$event, $year".some
|
||||
case (eventO, yearO) => eventO orElse yearO
|
||||
}
|
||||
s"$white - $black, $result, ${event | "-"}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ object Dependencies {
|
|||
val findbugs = "com.google.code.findbugs" % "jsr305" % "3.0.1"
|
||||
val hasher = "com.roundeights" %% "hasher" % "1.2.0"
|
||||
val jodaTime = "joda-time" % "joda-time" % "2.9.9"
|
||||
val chess = "org.lichess" %% "scalachess" % "8.1"
|
||||
val chess = "org.lichess" %% "scalachess" % "8.2"
|
||||
val maxmind = "com.sanoma.cda" %% "maxmind-geoip2-scala" % "1.2.3-THIB"
|
||||
val prismic = "io.prismic" %% "scala-kit" % "1.2.11-THIB"
|
||||
val java8compat = "org.scala-lang.modules" %% "scala-java8-compat" % "0.8.0"
|
||||
|
|
Loading…
Reference in a new issue