Skip to content

Commit

Permalink
Merge branch 'master' into ui-i18n-functions-always
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored Nov 8, 2024
2 parents 2857dcd + 615e327 commit bd3a356
Show file tree
Hide file tree
Showing 150 changed files with 856 additions and 543 deletions.
6 changes: 6 additions & 0 deletions bin/mongodb/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,9 @@ db.study_chapter_flat.createIndex(
);
db.title_request.createIndex({ userId: 1 });
db.title_request.createIndex({ 'history.0.status.n': 1, 'history.0.at': 1 });

// you may want to run these on the insight database
// if it's a different one
db.insight.createIndex({ mr: 1, p: 1, c: 1 });
db.insight.createIndex({ mr: 1, a: 1 }, { partialFilterExpression: { mr: { $exists: true } } });
db.insight.createIndex({ u: 1, d: -1 });
3 changes: 2 additions & 1 deletion modules/core/src/main/game/misc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ enum Source(val id: Int) derives Eq:
case Arena extends Source(id = 5)
case Position extends Source(id = 6)
case Import extends Source(id = 7)
case ImportLive extends Source(id = 9)
case ImportLive extends Source(id = 9) // wut?
case Simul extends Source(id = 10)
case Pool extends Source(id = 12)
case Swiss extends Source(id = 13)

object Source:
val byId = values.mapBy(_.id)
val byName = values.mapBy(_.name)
val searchable = List(Lobby, Friend, Ai, Position, Arena, Simul, Pool, Swiss)
val expirable = Set(Lobby, Arena, Pool, Swiss)
def apply(id: Int): Option[Source] = byId.get(id)
Expand Down
10 changes: 6 additions & 4 deletions modules/game/src/main/BSONHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object BSONHandlers:

given BSONHandler[GameRule] = valueMapHandler[String, GameRule](GameRule.byKey)(_.toString)

given sourceHandler: BSONHandler[Source] = valueMapHandler[Int, Source](Source.byId)(_.id)

private[game] given crazyhouseDataHandler: BSON[Crazyhouse.Data] with
import Crazyhouse.*
def reads(r: BSON.Reader) =
Expand Down Expand Up @@ -191,7 +193,7 @@ object BSONHandlers:
createdAt = createdAt,
movedAt = r.dateD(F.movedAt, createdAt),
metadata = GameMetadata(
source = r.intO(F.source).flatMap(Source.apply),
source = r.getO[Source](F.source),
pgnImport = r.getO[PgnImport](F.pgnImport),
tournamentId = r.getO[TourId](F.tournamentId),
swissId = r.getO[SwissId](F.swissId),
Expand Down Expand Up @@ -219,9 +221,9 @@ object BSONHandlers:
F.status -> o.status,
F.turns -> o.chess.ply,
F.startedAtTurn -> w.intO(o.chess.startedAtPly.value),
F.clock -> (o.chess.clock.flatMap { c =>
F.clock -> o.chess.clock.flatMap { c =>
clockBSONWrite(o.createdAt, c).toOption
}),
},
F.daysPerTurn -> o.daysPerTurn,
F.moveTimes -> o.binaryMoveTimes,
F.whiteClockHistory -> clockHistory(Color.White, o.clockHistory, o.chess.clock, o.flagged),
Expand All @@ -231,7 +233,7 @@ object BSONHandlers:
F.bookmarks -> w.intO(o.bookmarks),
F.createdAt -> w.date(o.createdAt),
F.movedAt -> w.date(o.movedAt),
F.source -> o.metadata.source.map(_.id),
F.source -> o.metadata.source,
F.pgnImport -> o.metadata.pgnImport,
F.tournamentId -> o.metadata.tournamentId,
F.swissId -> o.metadata.swissId,
Expand Down
4 changes: 4 additions & 0 deletions modules/insight/src/main/BSONHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import lila.db.BSON
import lila.db.dsl.{ *, given }
import lila.rating.BSONHandlers.perfTypeIdHandler
import lila.rating.PerfType
import lila.core.game.Source
import lila.game.BSONHandlers.sourceHandler

object BSONHandlers:

Expand Down Expand Up @@ -102,6 +104,7 @@ object BSONHandlers:
ratingDiff = r.get[IntRatingDiff](ratingDiff),
analysed = r.boolD(analysed),
provisional = r.boolD(provisional),
source = r.getO[Source](source),
date = r.date(date)
)
def writes(w: BSON.Writer, e: InsightEntry) =
Expand All @@ -124,5 +127,6 @@ object BSONHandlers:
ratingDiff -> e.ratingDiff,
analysed -> w.boolO(e.analysed),
provisional -> w.boolO(e.provisional),
source -> e.source,
date -> e.date
)
22 changes: 20 additions & 2 deletions modules/insight/src/main/InsightDimension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import lila.db.dsl.{ *, given }
import lila.insight.BSONHandlers.given
import lila.insight.InsightEntry.BSONFields as F
import lila.rating.BSONHandlers.perfTypeIdHandler
import lila.game.BSONHandlers.sourceHandler
import lila.rating.PerfType
import lila.core.game.Source

enum InsightDimension[A](
val key: String,
Expand Down Expand Up @@ -231,6 +233,15 @@ enum InsightDimension[A](
"Time left on the player clock, accounting for increment. 100% = full clock, 0% = flagging."
)

case GameSource
extends InsightDimension[Source](
"source",
"Game source",
F.source,
InsightPosition.Game,
"How the game was created."
)

object InsightDimension:

def requiresStableRating(d: InsightDimension[?]) = d match
Expand Down Expand Up @@ -260,6 +271,10 @@ object InsightDimension:
case ClockPercentRange => lila.insight.ClockPercentRange.all.toList
case Blur => lila.insight.Blur.values.toIndexedSeq
case TimeVariance => lila.insight.TimeVariance.values.toIndexedSeq
case GameSource =>
Source.values.toIndexedSeq.filter:
case Source.Ai | Source.Import | Source.ImportLive => false
case _ => true

def valueByKey[X](d: InsightDimension[X], key: String): Option[X] = d match
case Period => key.toIntOption.map(lila.insight.Period.apply)
Expand All @@ -284,6 +299,7 @@ object InsightDimension:
case ClockPercentRange => key.toIntOption.flatMap(lila.insight.ClockPercentRange.byPercent.get)
case Blur => lila.insight.Blur(key == "true").some
case TimeVariance => key.toFloatOption.map(lila.insight.TimeVariance.byId)
case GameSource => Source.byName.get(key)

def valueToJson[X](d: InsightDimension[X])(v: X)(using Translate): JsObject =
Json.obj(
Expand All @@ -292,7 +308,7 @@ object InsightDimension:
)

def valueKey[X](d: InsightDimension[X])(v: X): String =
(d match
d.match
case Date => v.toString
case Period => v.days.toString
case Perf => v.key
Expand All @@ -315,7 +331,8 @@ object InsightDimension:
case ClockPercentRange => v.bottom.toInt
case Blur => v.id
case TimeVariance => v.id
).toString
case GameSource => v.name
.toString

def valueJson[X](d: InsightDimension[X])(v: X)(using Translate): JsValue =
d match
Expand All @@ -341,6 +358,7 @@ object InsightDimension:
case ClockPercentRange => JsString(v.name)
case Blur => JsString(v.name)
case TimeVariance => JsString(v.name)
case GameSource => JsString(v.toString)

def filtersOf[X](d: InsightDimension[X], selected: List[X]): Bdoc =

Expand Down
3 changes: 3 additions & 0 deletions modules/insight/src/main/InsightEntry.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lila.insight

import lila.common.SimpleOpening
import lila.core.game.Source

case class InsightEntry(
id: String, // gameId + w/b
Expand All @@ -20,6 +21,7 @@ case class InsightEntry(
ratingDiff: IntRatingDiff,
analysed: Boolean,
provisional: Boolean,
source: Option[Source],
date: Instant
)

Expand Down Expand Up @@ -48,4 +50,5 @@ case object InsightEntry:
val ratingDiff = "rd"
val analysed = "a"
val provisional = "pr"
val source = "so"
val date = "d"
40 changes: 17 additions & 23 deletions modules/insight/src/main/InsightIndexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ final private class InsightIndexer(
)

def all(user: User): Funit =
workQueue {
storage.fetchLast(user.id).flatMap {
_.fold(fromScratch(user)) { e =>
computeFrom(user, e.date.plusSeconds(1))
}
}
}
workQueue:
storage
.fetchLast(user.id)
.flatMap:
_.fold(fromScratch(user)): e =>
computeFrom(user, e.date.plusSeconds(1))

def update(game: Game, userId: UserId, previous: InsightEntry): Funit =
povToEntry(game, userId, previous.provisional).flatMap {
Expand All @@ -39,11 +38,8 @@ final private class InsightIndexer(
}

private def fromScratch(user: User): Funit =
fetchFirstGame(user).flatMap {
_.so { g =>
computeFrom(user, g.createdAt)
}
}
fetchFirstGame(user).flatMapz: g =>
computeFrom(user, g.createdAt)

private def gameQuery(user: User) =
Query.user(user.id) ++
Expand All @@ -58,25 +54,23 @@ final private class InsightIndexer(
private def fetchFirstGame(user: User): Fu[Option[Game]] =
if user.count.rated == 0 then fuccess(none)
else
{
(user.count.rated >= maxGames).so(
(user.count.rated >= maxGames)
.so:
gameRepo.coll
.find(gameQuery(user))
.sort(Query.sortCreated)
.skip(maxGames - 1)
.one[Game](ReadPref.sec)
)
}.orElse(
gameRepo.coll
.find(gameQuery(user))
.sort(Query.sortChronological)
.one[Game](ReadPref.sec)
)
.orElse:
gameRepo.coll
.find(gameQuery(user))
.sort(Query.sortChronological)
.one[Game](ReadPref.sec)

private def computeFrom(user: User, from: Instant): Funit =
storage
.nbByPerf(user.id)
.flatMap { nbs =>
.flatMap: nbs =>
var nbByPerf = nbs
def toEntry(game: Game): Fu[Option[InsightEntry]] =
val nb = nbByPerf.getOrElse(game.perfKey, 0) + 1
Expand All @@ -94,4 +88,4 @@ final private class InsightIndexer(
.grouped(100.atMost(maxGames))
.map(storage.bulkInsert)
.runWith(Sink.ignore)
} void
.void
2 changes: 2 additions & 0 deletions modules/insight/src/main/JsonQuestion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ case class JsonQuestion(
case ClockPercentRange.key => build(ClockPercentRange)
case Blur.key => build(Blur)
case TimeVariance.key => build(TimeVariance)
case GameSource.key => build(GameSource)
case _ => none
}
.filterNot(_.isEmpty)
Expand Down Expand Up @@ -75,6 +76,7 @@ case class JsonQuestion(
case AccuracyPercentRange.key => build(AccuracyPercentRange)
case Blur.key => build(Blur)
case TimeVariance.key => build(TimeVariance)
case GameSource.key => build(GameSource)
case _ => none
yield question

Expand Down
3 changes: 2 additions & 1 deletion modules/insight/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ final class JsonView:
dimWrites.writes(D.Period),
dimWrites.writes(D.Perf),
dimWrites.writes(D.Color),
dimWrites.writes(D.OpponentStrength)
dimWrites.writes(D.OpponentStrength),
dimWrites.writes(D.GameSource)
)
),
Categ(
Expand Down
1 change: 1 addition & 0 deletions modules/insight/src/main/PovToEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ final private class PovToEntry(
ratingDiff = ~pov.player.ratingDiff,
analysed = analysis.isDefined,
provisional = provisional,
source = game.source,
date = game.createdAt
)

Expand Down
2 changes: 1 addition & 1 deletion modules/mod/src/main/ui/ModUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ModUi(helpers: Helpers)(isChatPanic: () => Boolean):
cls := (!allowed).option("disabled"),
title := {
if allowed
then "Definitely erase everything about this user?"
then "Definitely erase everything about this user"
else "This user has some history, only admins can erase"
},
(!allowed).option(disabled)
Expand Down
2 changes: 1 addition & 1 deletion modules/user/src/main/UserApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ final class UserApi(userRepo: UserRepo, perfsRepo: UserPerfsRepo, cacheApi: Cach
userRepo.coll
.aggregateList(max, _.priTemp): framework =>
import framework.*
Match($inIds(ids) ++ userRepo.botWithBioSelect) -> List(
Match($inIds(ids) ++ userRepo.botWithBioSelect ++ userRepo.enabledSelect ++ userRepo.notLame) -> List(
Sort(Descending(BSONFields.roles), Descending(BSONFields.playTimeTotal)),
Limit(max),
PipelineOperator(perfsRepo.aggregate.lookup)
Expand Down
2 changes: 1 addition & 1 deletion translation/dest/activity/fa-IR.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<item quantity="other">تکمیل %1$s بازی مکاتبه‌ای %2$s</item>
</plurals>
<plurals name="followedNbPlayers">
<item quantity="one">%s بازیکن را دنبال کرد</item>
<item quantity="one">شروع به دنبالیدن %s بازیکن کرد</item>
<item quantity="other">شروع به دنبالیدن %s بازیکن کرد</item>
</plurals>
<plurals name="gainedNbFollowers">
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/ca-ES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Diferència puntuació</string>
<string name="gamesThisTournament">Partides en aquest torneig</string>
<string name="score">Puntuació</string>
<string name="perPage">%s per pàgina</string>
<string name="allTeams">Tots els equips</string>
<string name="tournamentFormat">Format del torneig</string>
<string name="tournamentLocation">Ubicació del torneig</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/da-DK.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Rating-forskel</string>
<string name="gamesThisTournament">Partier i denne turnering</string>
<string name="score">Score</string>
<string name="perPage">%s pr. side</string>
<string name="allTeams">Alle hold</string>
<string name="tournamentFormat">Turneringsformat</string>
<string name="tournamentLocation">Turneringssted</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/de-DE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Wertungsdifferenz</string>
<string name="gamesThisTournament">Partien in diesem Turnier</string>
<string name="score">Punktestand</string>
<string name="perPage">%s pro Seite</string>
<string name="allTeams">Alle Teams</string>
<string name="tournamentFormat">Turnierformat</string>
<string name="tournamentLocation">Turnierort</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/en-US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Rating diff</string>
<string name="gamesThisTournament">Games in this tournament</string>
<string name="score">Score</string>
<string name="perPage">%s per page</string>
<string name="allTeams">All teams</string>
<string name="tournamentFormat">Tournament format</string>
<string name="tournamentLocation">Tournament Location</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/es-ES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Diferencia de valoración</string>
<string name="gamesThisTournament">Partidas en este torneo</string>
<string name="score">Resultado</string>
<string name="perPage">%s por página</string>
<string name="allTeams">Todos los equipos</string>
<string name="tournamentFormat">Formato del torneo</string>
<string name="tournamentLocation">Ubicación del torneo</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/fi-FI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<string name="ratingDiff">Vahvuuslukujen erotus</string>
<string name="gamesThisTournament">Pelit tässä turnauksessa</string>
<string name="score">Pisteet</string>
<string name="perPage">%s per sivu</string>
<string name="allTeams">Kaikki joukkueet</string>
<string name="tournamentFormat">Turnauksen laji</string>
<string name="tournamentLocation">Turnauksen sijainti</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/fr-FR.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Différence de cote</string>
<string name="gamesThisTournament">Partie de ce tournoi</string>
<string name="score">Résultat</string>
<string name="perPage">%s par page</string>
<string name="allTeams">Toutes les équipes</string>
<string name="tournamentFormat">Format du tournoi</string>
<string name="tournamentLocation">Lieu du tournoi</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/gl-ES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Diferenza de puntuación</string>
<string name="gamesThisTournament">Partidas neste torneo</string>
<string name="score">Resultado</string>
<string name="perPage">%s por páxina</string>
<string name="allTeams">Todos os equipos</string>
<string name="tournamentFormat">Formato do torneo</string>
<string name="tournamentLocation">Lugar do torneo</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/gsw-CH.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<string name="ratingDiff">Wertigs Differänz</string>
<string name="gamesThisTournament">Schpiel i dem Turnier</string>
<string name="score">Resultat</string>
<string name="perPage">%s pro Site</string>
<string name="allTeams">Alli Teams</string>
<string name="tournamentFormat">Turnier-Format</string>
<string name="tournamentLocation">Turnier-Lokal</string>
Expand Down
1 change: 0 additions & 1 deletion translation/dest/broadcast/he-IL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
<string name="ratingDiff">הפרש הדירוג</string>
<string name="gamesThisTournament">משחקים בטורניר זה</string>
<string name="score">ניקוד</string>
<string name="perPage">%s לכל עמוד</string>
<string name="allTeams">כל הקבוצות</string>
<string name="tournamentFormat">שיטת הטורניר</string>
<string name="tournamentLocation">מיקום הטורניר</string>
Expand Down
Loading

0 comments on commit bd3a356

Please sign in to comment.