learn wip
parent
57366fb1ee
commit
cc8f0ee214
|
@ -585,6 +585,9 @@ notify {
|
|||
collection.notify = notify
|
||||
actor.name = notify
|
||||
}
|
||||
learn {
|
||||
collection.progress = learn_progress
|
||||
}
|
||||
simulation {
|
||||
enabled = false
|
||||
players = 300
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package lila.learn
|
||||
|
||||
import lila.db.BSON
|
||||
import lila.db.dsl._
|
||||
import reactivemongo.bson._
|
||||
|
||||
object BSONHandlers {
|
||||
|
||||
private implicit val StageHandler = new BSONHandler[BSONString, Stage] {
|
||||
def read(bs: BSONString) = Stage.byId(Stage.Id(bs.value)) err s"No such Stage: ${bs.value}"
|
||||
def write(x: Stage) = BSONString(x.id.value)
|
||||
}
|
||||
|
||||
private implicit val StageProgressScoreHandler = intAnyValHandler[StageProgress.Score](_.value, StageProgress.Score.apply)
|
||||
private implicit val StageProgressTriesHandler = intAnyValHandler[StageProgress.Tries](_.value, StageProgress.Tries.apply)
|
||||
private implicit val StageProgressBSONHandler = Macros.handler[StageProgress]
|
||||
|
||||
private implicit val LearnProgressStagesHandler = BSON.MapDocument.MapHandler[StageProgress]
|
||||
implicit val LearnProgressHandler = Macros.handler[LearnProgress]
|
||||
}
|
|
@ -5,6 +5,11 @@ import com.typesafe.config.Config
|
|||
final class Env(
|
||||
config: Config,
|
||||
db: lila.db.Env) {
|
||||
|
||||
private val CollectionProgress = config getString "collection.progress"
|
||||
|
||||
lazy val api = new LearnApi(
|
||||
coll = db(CollectionProgress))
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package lila.search
|
||||
|
||||
object JSONHandlers {
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package lila.learn
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.user.User
|
||||
|
||||
final class LearnApi(coll: Coll) {
|
||||
|
||||
import BSONHandlers._
|
||||
|
||||
def get(user: User): Fu[LearnProgress] =
|
||||
coll.uno[LearnProgress]($id(user.id)) map { _ | LearnProgress.empty(user.id) }
|
||||
|
||||
def save(p: LearnProgress): Funit =
|
||||
coll.update($id(p.id), p, upsert = true).void
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package lila.learn
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.user.User
|
||||
|
||||
case class LearnProgress(
|
||||
_id: User.ID,
|
||||
stages: Map[String, StageProgress],
|
||||
createdAt: DateTime,
|
||||
updatedAt: DateTime) {
|
||||
|
||||
def id = _id
|
||||
}
|
||||
|
||||
object LearnProgress {
|
||||
|
||||
def empty(userId: User.ID) = LearnProgress(
|
||||
_id = userId,
|
||||
stages = Map.empty,
|
||||
createdAt = DateTime.now,
|
||||
updatedAt = DateTime.now)
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package lila.learn
|
||||
|
||||
sealed abstract class Stage(val id: Stage.Id)
|
||||
|
||||
object Stage {
|
||||
|
||||
case class Id(value: String) extends AnyVal
|
||||
|
||||
case object Intro extends Stage(Id("intro"))
|
||||
|
||||
val all = List(Intro)
|
||||
|
||||
def byId(id: Id) = all.find(_.id == id)
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package lila.learn
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
case class StageProgress(
|
||||
stage: Stage,
|
||||
score: StageProgress.Score,
|
||||
tries: StageProgress.Tries,
|
||||
updatedAt: DateTime)
|
||||
|
||||
object StageProgress {
|
||||
|
||||
case class Score(value: Int) extends AnyVal
|
||||
case class Tries(value: Int) extends AnyVal
|
||||
}
|
|
@ -95,7 +95,6 @@ object Condition {
|
|||
object BSONHandlers {
|
||||
import reactivemongo.bson._
|
||||
import lila.db.BSON
|
||||
import lila.db.BSON.{ Reader, Writer }
|
||||
import lila.db.dsl._
|
||||
private implicit val PerfTypeBSONHandler = new BSONHandler[BSONString, PerfType] {
|
||||
def read(bs: BSONString): PerfType = PerfType(bs.value) err s"No such PerfType: ${bs.value}"
|
||||
|
|
Loading…
Reference in New Issue