Skip to content

Commit

Permalink
upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
outductor committed Jun 27, 2023
1 parent 5cb31d9 commit 40063e2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,7 @@ object VoteMenu extends Menu {
s"$RESET${DARK_GRAY}召喚されたらラッキーだよ!"
)
val topFourRankingLore =
List(
topFourRanking.headOption,
topFourRanking.lift(1),
topFourRanking.lift(2),
topFourRanking.lift(3)
).flatMap(_.flatten).flatMap { rankData =>
topFourRanking.flatMap { rankData =>
List(
s"${GRAY}たくさんくれたニンゲン第${rankData.rank}位!",
s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ trait FairyReadAPI[F[_], G[_], Player] {
/**
* @return 妖精に食べさせたりんごの量の上位`top`件を返す作用
*/
def rankingByMostConsumedApple(top: Int): F[Vector[Option[AppleConsumeAmountRank]]]
def rankingByMostConsumedApple(top: Int): F[Vector[AppleConsumeAmountRank]]

/**
* @return 妖精が食べたりんごの合計数を返す作用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ object System {

override def rankingByMostConsumedApple(
top: Int
): IO[Vector[Option[AppleConsumeAmountRank]]] =
): IO[Vector[AppleConsumeAmountRank]] =
persistence.fetchMostConsumedApplePlayersByFairy(top)

override def totalConsumedApple: IO[AppleAmount] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ trait FairyPersistence[F[_]] {
* @param top 最上位から何番目まで取得するか件数を指定する。0以下であってはならない。
* @return 指定した件数が要素数となり、その並びが消費量の降順になっているような順序つきのコレクションを返す作用。
*/
def fetchMostConsumedApplePlayersByFairy(top: Int): F[Vector[Option[AppleConsumeAmountRank]]]
def fetchMostConsumedApplePlayersByFairy(top: Int): F[Vector[AppleConsumeAmountRank]]

/**
* @return 妖精が今まで食べたりんごの合計数を返す作用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] {
): F[Option[AppleConsumeAmountRank]] =
Sync[F].delay {
DB.readOnly { implicit session =>
sql"""SELECT vote_fairy.uuid AS uuid,name,given_apple_amount,COUNT(*) AS rank
sql"""SELECT vote_fairy.uuid AS uuid, name, given_apple_amount,
| RANK() OVER(ORDER BY given_apple_amount DESC) AS rank
| FROM vote_fairy
| INNER JOIN playerdata
| ON (playerdata.uuid = vote_fairy.uuid)
| ORDER BY rank DESC;"""
| ORDER BY rank"""
.stripMargin
.map(rs =>
rs.string("uuid") -> AppleConsumeAmountRank(
Expand All @@ -183,19 +184,20 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] {

override def fetchMostConsumedApplePlayersByFairy(
top: Int
): F[Vector[Option[AppleConsumeAmountRank]]] =
): F[Vector[AppleConsumeAmountRank]] =
Sync[F].delay {
DB.readOnly { implicit session =>
sql"""SELECT name,given_apple_amount,COUNT(*) AS rank FROM vote_fairy
| INNER JOIN playerdata ON (vote_fairy.uuid = playerdata.uuid)
| ORDER BY rank DESC LIMIT $top;"""
sql"""SELECT name, given_apple_amount, RANK() OVER(ORDER BY given_apple_amount DESC) AS rank FROM vote_fairy
| INNER JOIN playerdata ON (vote_fairy.uuid = playerdata.uuid)
| ORDER BY rank
| LIMIT $top;"""
.stripMargin
.map { rs =>
for {
name <- rs.stringOpt("name")
rank <- rs.intOpt("rank")
givenAppleAmount <- rs.intOpt("given_apple_amount")
} yield AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount))
val name = rs.string("name")
val rank = rs.int("rank")
val givenAppleAmount = rs.int("given_apple_amount")

AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount))
}
.toList()
.apply()
Expand Down

0 comments on commit 40063e2

Please sign in to comment.