<commit_before>package lila.puzzle

import cats.implicits._
import org.joda.time.DateTime
import scala.concurrent.duration._

import lila.common.paginator.Paginator
import lila.common.config.MaxPerPage
import lila.db.AsyncColl
import lila.db.dsl._
import lila.db.paginator.Adapter
import lila.memo.CacheApi
import lila.user.{ User, UserRepo }

final class PuzzleApi(
    colls: PuzzleColls,
    trustApi: PuzzleTrustApi,
    countApi: PuzzleCountApi
)(implicit ec: scala.concurrent.ExecutionContext, system: akka.actor.ActorSystem, mode: play.api.Mode) {

  import Puzzle.{ BSONFields => F }
  import BsonHandlers._

  object puzzle {

    def find(id: Puzzle.Id): Fu[Option[Puzzle]] =
      colls.puzzle(_.byId[Puzzle](id.value))

    def delete(id: Puzzle.Id): Funit =
      colls.puzzle(_.delete.one($id(id.value))).void

    def of(user: User, page: Int): Fu[Paginator[Puzzle]] =
      colls.puzzle { coll =>
        Paginator(
          adapter = new Adapter[Puzzle](
            collection = coll,
            selector = $doc("users" -> user.id),
            projection = none,
            sort = $sort asc "glicko.r"
          ),<commit_msg>sort puzzles of player by desc rating<commit_after>package lila.puzzle

import cats.implicits._
import org.joda.time.DateTime
import scala.concurrent.duration._

import lila.common.paginator.Paginator
import lila.common.config.MaxPerPage
import lila.db.AsyncColl
import lila.db.dsl._
import lila.db.paginator.Adapter
import lila.memo.CacheApi
import lila.user.{ User, UserRepo }

final class PuzzleApi(
    colls: PuzzleColls,
    trustApi: PuzzleTrustApi,
    countApi: PuzzleCountApi
)(implicit ec: scala.concurrent.ExecutionContext, system: akka.actor.ActorSystem, mode: play.api.Mode) {

  import Puzzle.{ BSONFields => F }
  import BsonHandlers._

  object puzzle {

    def find(id: Puzzle.Id): Fu[Option[Puzzle]] =
      colls.puzzle(_.byId[Puzzle](id.value))

    def delete(id: Puzzle.Id): Funit =
      colls.puzzle(_.delete.one($id(id.value))).void

    def of(user: User, page: Int): Fu[Paginator[Puzzle]] =
      colls.puzzle { coll =>
        Paginator(
          adapter = new Adapter[Puzzle](
            collection = coll,
            selector = $doc("users" -> user.id),
            projection = none,
            sort = $sort desc "glicko.r"
          ),
{'fraction_non_alphanumeric': 0.11977595863851788, 'fraction_numerical': 0.0, 'mean_word_length': 3.124333925399645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4924984', 'n_tokens_mistral': 814, 'n_tokens_neox': 778, 'n_words': 168}