compute nb games per day, make it a cli command
This commit is contained in:
parent
650a6597a0
commit
dad41b72ee
|
@ -183,6 +183,12 @@ class GameRepo(collection: MongoCollection)
|
|||
find("_id" $in ids).toList.map(_.decode).flatten sortBy (_.id)
|
||||
}
|
||||
|
||||
def nbPerDay(days: Int): IO[List[Int]] = ((days to 1 by -1).toList map { day ⇒
|
||||
val from = DateTime.now.withTimeAtStartOfDay - day.days
|
||||
val to = from + 1.day
|
||||
count(("createdAt" $gte from $lt to))
|
||||
}).sequence
|
||||
|
||||
private def idSelector(game: DbGame): DBObject = idSelector(game.id)
|
||||
private def idSelector(id: String): DBObject = DBObject("_id" -> id)
|
||||
}
|
||||
|
|
|
@ -5,4 +5,8 @@ import scalaz.effects._
|
|||
|
||||
case class Games(env: CoreEnv) {
|
||||
|
||||
def perDay(days: Int): IO[Unit] = for {
|
||||
nbs ← env.game.gameRepo.nbPerDay(days)
|
||||
_ ← putStrLn(nbs mkString " ")
|
||||
} yield ()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import scalaz.effects._
|
|||
import play.api.{ Mode, Application, Play }
|
||||
import java.io.File
|
||||
|
||||
import lila.parseIntOption
|
||||
import lila.core.{ Global, CoreEnv }
|
||||
|
||||
object Main {
|
||||
|
@ -18,18 +19,20 @@ object Main {
|
|||
def infos = Infos(env)
|
||||
|
||||
args.toList match {
|
||||
case "average-elo" :: Nil ⇒ infos.averageElo
|
||||
case "i18n-js-dump" :: Nil ⇒ i18n.jsDump
|
||||
case "i18n-fix" :: Nil ⇒ i18n.fileFix
|
||||
case "i18n-fetch" :: from :: Nil ⇒ i18n fetch from
|
||||
case "user-enable" :: username :: Nil ⇒ users enable username
|
||||
case "user-disable" :: username :: Nil ⇒ users disable username
|
||||
case "user-passwd" :: username :: pwd :: Nil ⇒ users.passwd(username, pwd)
|
||||
case "forum-denormalize" :: Nil ⇒ forum.denormalize
|
||||
case "forum-typecheck" :: Nil ⇒ forum.typecheck
|
||||
case "game-cleanup-next" :: Nil ⇒ titivate.cleanupNext
|
||||
case "game-cleanup-unplayed" :: Nil ⇒ titivate.cleanupUnplayed
|
||||
case "game-finish" :: Nil ⇒ titivate.finishByClock
|
||||
case "average-elo" :: Nil ⇒ infos.averageElo
|
||||
case "i18n-js-dump" :: Nil ⇒ i18n.jsDump
|
||||
case "i18n-fix" :: Nil ⇒ i18n.fileFix
|
||||
case "i18n-fetch" :: from :: Nil ⇒ i18n fetch from
|
||||
case "user-enable" :: uid :: Nil ⇒ users enable uid
|
||||
case "user-disable" :: uid :: Nil ⇒ users disable uid
|
||||
case "user-passwd" :: uid :: pwd :: Nil ⇒ users.passwd(uid, pwd)
|
||||
case "forum-denormalize" :: Nil ⇒ forum.denormalize
|
||||
case "forum-typecheck" :: Nil ⇒ forum.typecheck
|
||||
case "game-cleanup-next" :: Nil ⇒ titivate.cleanupNext
|
||||
case "game-cleanup-unplayed" :: Nil ⇒ titivate.cleanupUnplayed
|
||||
case "game-finish" :: Nil ⇒ titivate.finishByClock
|
||||
case "game-per-day" :: Nil ⇒ games.perDay(30)
|
||||
case "game-per-day" :: days :: Nil ⇒ games.perDay(parseIntOption(days) err "days: Int")
|
||||
case _ ⇒
|
||||
putStrLn("Unknown command: " + args.mkString(" "))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue