Monitor game elo wip
This commit is contained in:
parent
4bc56537a9
commit
e4d984afee
|
@ -17,6 +17,7 @@ object Monitor extends LilaController {
|
||||||
private def reporting = env.monitor.reporting
|
private def reporting = env.monitor.reporting
|
||||||
private def usernameMemo = env.user.usernameMemo
|
private def usernameMemo = env.user.usernameMemo
|
||||||
private def userRepo = env.user.userRepo
|
private def userRepo = env.user.userRepo
|
||||||
|
private def gameRepo = env.game.gameRepo
|
||||||
private implicit def timeout = Timeout(500 millis)
|
private implicit def timeout = Timeout(500 millis)
|
||||||
|
|
||||||
def index = Action {
|
def index = Action {
|
||||||
|
@ -31,10 +32,14 @@ object Monitor extends LilaController {
|
||||||
Async {
|
Async {
|
||||||
import core.Futuristic.ioToFuture
|
import core.Futuristic.ioToFuture
|
||||||
(~get("key") match {
|
(~get("key") match {
|
||||||
case "elo" ⇒ userRepo.idsAverageElo(usernameMemo.keys).toFuture
|
case "elo" ⇒
|
||||||
case "moves" ⇒ (reporting ? GetNbMoves).mapTo[Int]
|
userRepo.idsAverageElo(usernameMemo.keys).toFuture zip
|
||||||
|
gameRepo.recentAverageElo(100000).toFuture map {
|
||||||
|
case (users, (rated, casual)) ⇒ List(users, rated, casual) mkString " "
|
||||||
|
}
|
||||||
|
case "moves" ⇒ (reporting ? GetNbMoves).mapTo[Int]
|
||||||
case "players" ⇒ (reporting ? GetNbMembers).mapTo[Int] map { "%d %d".format(_, usernameMemo.preciseCount) }
|
case "players" ⇒ (reporting ? GetNbMembers).mapTo[Int] map { "%d %d".format(_, usernameMemo.preciseCount) }
|
||||||
case _ ⇒ (reporting ? GetStatus).mapTo[String]
|
case _ ⇒ (reporting ? GetStatus).mapTo[String]
|
||||||
}).asPromise map { x ⇒ Ok(x.toString) }
|
}).asPromise map { x ⇒ Ok(x.toString) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.novus.salat._
|
||||||
import com.novus.salat.dao._
|
import com.novus.salat.dao._
|
||||||
import com.mongodb.casbah.{ WriteConcern, MongoCollection }
|
import com.mongodb.casbah.{ WriteConcern, MongoCollection }
|
||||||
import com.mongodb.casbah.query.Imports._
|
import com.mongodb.casbah.query.Imports._
|
||||||
|
import com.mongodb.casbah.map_reduce.MapReduceInlineOutput
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.scala_tools.time.Imports._
|
import org.scala_tools.time.Imports._
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
@ -56,13 +57,13 @@ final class GameRepo(collection: MongoCollection)
|
||||||
update(idSelector(game), _grater asDBObject game.encode)
|
update(idSelector(game), _grater asDBObject game.encode)
|
||||||
}
|
}
|
||||||
|
|
||||||
def save(progress: Progress): IO[Unit] =
|
def save(progress: Progress): IO[Unit] =
|
||||||
GameDiff(progress.origin.encode, progress.game.encode) |> {
|
GameDiff(progress.origin.encode, progress.game.encode) |> {
|
||||||
case (Nil, Nil) ⇒ io()
|
case (Nil, Nil) ⇒ io()
|
||||||
case (sets, unsets) ⇒ {
|
case (sets, unsets) ⇒ {
|
||||||
val fullSets = ("ua" -> new Date) :: sets
|
val fullSets = ("ua" -> new Date) :: sets
|
||||||
val ops = unsets.isEmpty.fold(
|
val ops = unsets.isEmpty.fold(
|
||||||
$set(fullSets: _*),
|
$set(fullSets: _*),
|
||||||
$set(fullSets: _*) ++ $unset(unsets: _*)
|
$set(fullSets: _*) ++ $unset(unsets: _*)
|
||||||
)
|
)
|
||||||
val wc = WriteConcern.None
|
val wc = WriteConcern.None
|
||||||
|
@ -206,6 +207,38 @@ final class GameRepo(collection: MongoCollection)
|
||||||
count(("ca" $gte from $lt to))
|
count(("ca" $gte from $lt to))
|
||||||
}).sequence
|
}).sequence
|
||||||
|
|
||||||
|
def recentAverageElo(minutes: Int): IO[(Int, Int)] = io {
|
||||||
|
val result = collection.mapReduce(
|
||||||
|
mapFunction = """function() {
|
||||||
|
emit(!!this.ra, this.p);
|
||||||
|
}""",
|
||||||
|
reduceFunction = """function(rated, values) {
|
||||||
|
var sum = 0, nb = 0;
|
||||||
|
values.forEach(function(game) {
|
||||||
|
if(typeof game[0] != "undefined") {
|
||||||
|
game.forEach(function(player) {
|
||||||
|
if(player.elo) {
|
||||||
|
sum += player.elo;
|
||||||
|
++nb;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return nb == 0 ? nb : Math.round(sum / nb);
|
||||||
|
}""",
|
||||||
|
output = MapReduceInlineOutput,
|
||||||
|
query = Some {
|
||||||
|
("ca" $gte (DateTime.now - minutes.minutes)) ++ ("p.elo" $exists true)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
(for {
|
||||||
|
ratedRow ← result.hasNext option result.next
|
||||||
|
rated ← ratedRow.getAs[Double]("value")
|
||||||
|
casualRow ← result.hasNext option result.next
|
||||||
|
casual ← casualRow.getAs[Double]("value")
|
||||||
|
} yield rated.toInt -> casual.toInt) | (0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
private def idSelector(game: DbGame): DBObject = idSelector(game.id)
|
private def idSelector(game: DbGame): DBObject = idSelector(game.id)
|
||||||
private def idSelector(id: String): DBObject = DBObject("_id" -> id)
|
private def idSelector(id: String): DBObject = DBObject("_id" -> id)
|
||||||
}
|
}
|
||||||
|
|
1
todo
1
todo
|
@ -53,3 +53,4 @@ block user creation from an IP
|
||||||
mute IP
|
mute IP
|
||||||
time color toward end http://fr.lichess.org/forum/lichess-feedback/suggestion-time-color-towards-end#5
|
time color toward end http://fr.lichess.org/forum/lichess-feedback/suggestion-time-color-towards-end#5
|
||||||
fast join game = creator not redirected properly?
|
fast join game = creator not redirected properly?
|
||||||
|
resign popup on close window
|
||||||
|
|
Loading…
Reference in a new issue