rename insight models

pull/7982/head
Thibault Duplessis 2021-01-22 09:18:06 +01:00
parent 61ddc65030
commit 9c975aff4a
9 changed files with 35 additions and 35 deletions

View File

@ -17,7 +17,7 @@ final private class AggregationPipeline(store: Storage)(implicit ec: scala.concu
import question.{ dimension, filters, metric }
import lila.insight.{ Dimension => D, Metric => M }
import Entry.{ BSONFields => F }
import InsightEntry.{ BSONFields => F }
import Storage._
val sampleGames = Sample(10_000)

View File

@ -67,9 +67,9 @@ private object BSONHandlers {
implicit val PeriodBSONHandler = intIsoHandler(lila.common.Iso.int[Period](Period.apply, _.days))
implicit def MoveBSONHandler =
new BSON[Move] {
new BSON[InsightMove] {
def reads(r: BSON.Reader) =
Move(
InsightMove(
phase = r.get[Phase]("p"),
tenths = r.get[Int]("t"),
role = r.get[Role]("r"),
@ -82,7 +82,7 @@ private object BSONHandlers {
blur = r.boolD("b"),
timeCv = r.intO("v").map(v => v.toFloat / TimeVariance.intFactor)
)
def writes(w: BSON.Writer, b: Move) =
def writes(w: BSON.Writer, b: InsightMove) =
BSONDocument(
"p" -> b.phase,
"t" -> b.tenths,
@ -99,10 +99,10 @@ private object BSONHandlers {
}
implicit def EntryBSONHandler =
new BSON[Entry] {
import Entry.BSONFields._
new BSON[InsightEntry] {
import InsightEntry.BSONFields._
def reads(r: BSON.Reader) =
Entry(
InsightEntry(
id = r.str(id),
number = r.int(number),
userId = r.str(userId),
@ -113,7 +113,7 @@ private object BSONHandlers {
opponentRating = r.int(opponentRating),
opponentStrength = r.get[RelativeStrength](opponentStrength),
opponentCastling = r.get[Castling](opponentCastling),
moves = r.get[List[Move]](moves),
moves = r.get[List[InsightMove]](moves),
queenTrade = r.get[QueenTrade](queenTrade),
result = r.get[Result](result),
termination = r.get[Termination](termination),
@ -122,7 +122,7 @@ private object BSONHandlers {
provisional = r.boolD(provisional),
date = r.date(date)
)
def writes(w: BSON.Writer, e: Entry) =
def writes(w: BSON.Writer, e: InsightEntry) =
BSONDocument(
id -> e.id,
number -> e.number,

View File

@ -28,7 +28,7 @@ object Dimension {
import BSONHandlers._
import Position._
import Entry.{ BSONFields => F }
import InsightEntry.{ BSONFields => F }
import lila.rating.BSONHandlers.perfTypeIdHandler
case object Period

View File

@ -62,7 +62,7 @@ final class InsightApi(
Pov(g)
.map { pov =>
pov.player.userId ?? { userId =>
storage find Entry.povToId(pov) flatMap {
storage find InsightEntry.povToId(pov) flatMap {
_ ?? { old =>
indexer.update(g, userId, old)
}

View File

@ -7,7 +7,7 @@ import lila.rating.PerfType
import org.joda.time.DateTime
import cats.data.NonEmptyList
case class Entry(
case class InsightEntry(
id: String, // gameId + w/b
number: Int, // auto increment over userId
userId: String,
@ -18,7 +18,7 @@ case class Entry(
opponentRating: Int,
opponentStrength: RelativeStrength,
opponentCastling: Castling,
moves: List[Move],
moves: List[InsightMove],
queenTrade: QueenTrade,
result: Result,
termination: Termination,
@ -31,7 +31,7 @@ case class Entry(
def gameId = id take Game.gameIdSize
}
case object Entry {
case object InsightEntry {
def povToId(pov: Pov) = pov.gameId + pov.color.letter
@ -58,7 +58,7 @@ case object Entry {
}
}
case class Move(
case class InsightMove(
phase: Phase,
tenths: Int,
role: Role,

View File

@ -37,7 +37,7 @@ final private class InsightIndexer(
}
}
def update(game: Game, userId: String, previous: Entry): Funit =
def update(game: Game, userId: String, previous: InsightEntry): Funit =
povToEntry(game, userId, previous.provisional) flatMap {
case Right(e) => storage update e.copy(number = previous.number)
case _ => funit
@ -76,7 +76,7 @@ final private class InsightIndexer(
private def computeFrom(user: User, from: DateTime, fromNumber: Int): Funit =
storage nbByPerf user.id flatMap { nbs =>
var nbByPerf = nbs
def toEntry(game: Game): Fu[Option[Entry]] =
def toEntry(game: Game): Fu[Option[InsightEntry]] =
game.perfType ?? { pt =>
val nb = nbByPerf.getOrElse(pt, 0) + 1
nbByPerf = nbByPerf.updated(pt, nb)

View File

@ -28,7 +28,7 @@ object Metric {
import DataType._
import Position._
import Entry.{ BSONFields => F }
import InsightEntry.{ BSONFields => F }
case object MeanCpl
extends Metric(

View File

@ -27,7 +27,7 @@ final private class PovToEntry(
advices: Map[Ply, Advice]
)
def apply(game: Game, userId: String, provisional: Boolean): Fu[Either[Game, Entry]] =
def apply(game: Game, userId: String, provisional: Boolean): Fu[Either[Game, InsightEntry]] =
enrich(game, userId, provisional) map
(_ flatMap convert toRight game)
@ -84,7 +84,7 @@ final private class PovToEntry(
case _ => chess.Pawn
}
private def makeMoves(from: RichPov): List[Move] = {
private def makeMoves(from: RichPov): List[InsightMove] = {
val cpDiffs = ~from.moveAccuracy toVector
val prevInfos = from.analysis.?? { an =>
Accuracy.prevColorInfos(from.pov, an) pipe { is =>
@ -124,7 +124,7 @@ final private class PovToEntry(
}
case _ => none
}
Move(
InsightMove(
phase = Phase.of(from.division, ply),
tenths = movetime.roundTenths,
role = role,
@ -174,7 +174,7 @@ final private class PovToEntry(
}
}
private def convert(from: RichPov): Option[Entry] = {
private def convert(from: RichPov): Option[InsightEntry] = {
import from._
import pov.game
for {
@ -182,8 +182,8 @@ final private class PovToEntry(
myRating <- pov.player.rating
opRating <- pov.opponent.rating
perfType <- game.perfType
} yield Entry(
id = Entry povToId pov,
} yield InsightEntry(
id = InsightEntry povToId pov,
number = 0, // temporary :-/ the Indexer will set it
userId = myId,
color = pov.color,

View File

@ -11,33 +11,33 @@ final private class Storage(val coll: AsyncColl)(implicit ec: scala.concurrent.E
import Storage._
import BSONHandlers._
import Entry.{ BSONFields => F }
import InsightEntry.{ BSONFields => F }
def fetchFirst(userId: String): Fu[Option[Entry]] =
coll(_.find(selectUserId(userId)).sort(sortChronological).one[Entry])
def fetchFirst(userId: String): Fu[Option[InsightEntry]] =
coll(_.find(selectUserId(userId)).sort(sortChronological).one[InsightEntry])
def fetchLast(userId: String): Fu[Option[Entry]] =
coll(_.find(selectUserId(userId)).sort(sortAntiChronological).one[Entry])
def fetchLast(userId: String): Fu[Option[InsightEntry]] =
coll(_.find(selectUserId(userId)).sort(sortAntiChronological).one[InsightEntry])
def count(userId: String): Fu[Int] =
coll(_.countSel(selectUserId(userId)))
def insert(p: Entry) = coll(_.insert.one(p).void)
def insert(p: InsightEntry) = coll(_.insert.one(p).void)
def bulkInsert(ps: Seq[Entry]) =
def bulkInsert(ps: Seq[InsightEntry]) =
coll {
_.insert.many(
ps.flatMap(BSONHandlers.EntryBSONHandler.writeOpt)
)
}
def update(p: Entry) = coll(_.update.one(selectId(p.id), p, upsert = true).void)
def update(p: InsightEntry) = coll(_.update.one(selectId(p.id), p, upsert = true).void)
def remove(p: Entry) = coll(_.delete.one(selectId(p.id)).void)
def remove(p: InsightEntry) = coll(_.delete.one(selectId(p.id)).void)
def removeAll(userId: String) = coll(_.delete.one(selectUserId(userId)).void)
def find(id: String) = coll(_.one[Entry](selectId(id)))
def find(id: String) = coll(_.one[InsightEntry](selectId(id)))
def ecos(userId: String): Fu[Set[String]] =
coll {
@ -66,7 +66,7 @@ final private class Storage(val coll: AsyncColl)(implicit ec: scala.concurrent.E
private object Storage {
import Entry.{ BSONFields => F }
import InsightEntry.{ BSONFields => F }
def selectId(id: String) = BSONDocument(F.id -> id)
def selectUserId(id: String) = BSONDocument(F.userId -> id)