From 082821799a3dea71afef64f83e22fb1c91fc6999 Mon Sep 17 00:00:00 2001 From: rito528 Date: Tue, 28 Feb 2023 22:26:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20fetchMostConsumedApplePlayersBy?= =?UTF-8?q?Fairy=E9=96=A2=E6=95=B0=E3=81=A7for=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E4=B8=AD=E8=BA=AB=E3=82=92=E5=B1=95=E9=96=8B=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/JdbcFairyPersistence.scala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala index feb5a66bbe..bf4d3461c0 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala @@ -190,14 +190,19 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] { | INNER JOIN playerdata ON (vote_fairy.uuid = playerdata.uuid) | ORDER BY rank DESC LIMIT $top;""" .stripMargin - .map(rs => (rs.stringOpt("name"), rs.intOpt("rank"), rs.intOpt("given_apple_amount"))) + .map { rs => + (rs.stringOpt("name"), rs.intOpt("rank"), rs.intOpt("given_apple_amount")) + } .toList() .apply() - .map(data => - if (data._1.nonEmpty) - Some(AppleConsumeAmountRank(data._1.get, data._2.get, AppleAmount(data._3.get))) - else None - ) + .map { + case (name, rank, givenAppleAmount) => + for { + name <- name + rank <- rank + givenAppleAmount <- givenAppleAmount + } yield AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount)) + } .toVector } } From 985747a813960d06b16c661843dfc756acae60c4 Mon Sep 17 00:00:00 2001 From: rito528 Date: Tue, 28 Feb 2023 22:30:41 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20map=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E4=B8=80=E3=81=A4=E3=81=AB=E3=81=BE=E3=81=A8=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/JdbcFairyPersistence.scala | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala index bf4d3461c0..4c2f411c95 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala @@ -191,18 +191,14 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] { | ORDER BY rank DESC LIMIT $top;""" .stripMargin .map { rs => - (rs.stringOpt("name"), rs.intOpt("rank"), rs.intOpt("given_apple_amount")) + for { + name <- rs.stringOpt("name") + rank <- rs.intOpt("rank") + givenAppleAmount <- rs.intOpt("given_apple_amount") + } yield AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount)) } .toList() .apply() - .map { - case (name, rank, givenAppleAmount) => - for { - name <- name - rank <- rank - givenAppleAmount <- givenAppleAmount - } yield AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount)) - } .toVector } } From d6b2b28c0f833f3a4f1e848b87fc513f9b9e56db Mon Sep 17 00:00:00 2001 From: rito528 Date: Tue, 28 Feb 2023 22:42:50 +0900 Subject: [PATCH 3/5] =?UTF-8?q?docs:=20fetchMOstConsumedApplePlayersByFair?= =?UTF-8?q?y=E9=96=A2=E6=95=B0=E3=81=AE=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AB=E6=8C=87=E5=AE=9A=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=88=86=E3=81=A0=E3=81=91=E8=A6=81=E7=B4=A0=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8B=E3=81=93=E3=81=A8=E3=82=92=E4=BF=9D=E8=A8=BC?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84=E6=96=87=E8=A8=80=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vote/subsystems/fairy/domain/FairyPersistence.scala | 1 + .../subsystems/fairy/infrastructure/JdbcFairyPersistence.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala index 99ae4c43bd..9331e34689 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala @@ -86,6 +86,7 @@ trait FairyPersistence[F[_]] { /** * 妖精に食べさせたりんごの量が多いプレイヤーを上位とし、そのランキングの上から指定した件数を返す + * ただし、要素数が`top`件あることは保証しない。 * * @param top 最上位から何番目まで取得するか件数を指定する。0以下であってはならない。 * @return 指定した件数が要素数となり、その並びが消費量の降順になっているような順序つきのコレクションを返す作用。 diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala index 4c2f411c95..1e86fc4584 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala @@ -186,7 +186,7 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] { ): F[Vector[Option[AppleConsumeAmountRank]]] = Sync[F].delay { DB.readOnly { implicit session => - sql"""SELECT name,given_apple_amount,COUNT(*) AS rank FROM vote_fairy + 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;""" .stripMargin From 7a0b7c76921c3fd3326eef3c064d451dce6000a9 Mon Sep 17 00:00:00 2001 From: rito528 Date: Tue, 28 Feb 2023 22:55:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20topFourRankingLore=E3=81=A7Option.ge?= =?UTF-8?q?t=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unchama/seichiassist/menus/VoteMenu.scala | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala index 1d0132aa17..cd74e0eaa5 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala @@ -382,14 +382,11 @@ object VoteMenu extends Menu { topFourRanking.lift(1), topFourRanking.lift(2), topFourRanking.lift(3) - ).flatMap { rankDataOpt => - if (rankDataOpt.nonEmpty) { - val rankData = rankDataOpt.get.get - List( - s"${GRAY}たくさんくれたニンゲン第${rankData.rank}位!", - s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}個" - ) - } else Nil + ).flatMap(_.flatten).flatMap { rankData => + List( + s"${GRAY}たくさんくれたニンゲン第${rankData.rank}位!", + s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}個" + ) } val statistics = List( s"${AQUA}ぜーんぶで${allEatenAppleAmount.amount}個もらえた!", From 75d130b4743ad4205ef873664225a341596286a1 Mon Sep 17 00:00:00 2001 From: rito528 Date: Tue, 28 Feb 2023 22:59:49 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20statistics=E3=82=92=E6=B1=82?= =?UTF-8?q?=E3=82=81=E3=82=8B=E9=9A=9B=E3=81=AB.get=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unchama/seichiassist/menus/VoteMenu.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala index cd74e0eaa5..829b904c78 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala @@ -388,13 +388,15 @@ object VoteMenu extends Menu { s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}個" ) } - val statistics = List( - s"${AQUA}ぜーんぶで${allEatenAppleAmount.amount}個もらえた!", - "", - s"$GREEN↓呼び出したニンゲンの情報↓", - s"${GREEN}今までに${myRank.get.consumed.amount}個もらった", - s"${GREEN}ニンゲンの中では${myRank.get.rank}番目にたくさんくれる!" - ) + val statistics = myRank.map { rank => + List( + s"${AQUA}ぜーんぶで${allEatenAppleAmount.amount}個もらえた!", + "", + s"$GREEN↓呼び出したニンゲンの情報↓", + s"${GREEN}今までに${rank.consumed.amount}個もらった", + s"${GREEN}ニンゲンの中では${rank.rank}番目にたくさんくれる!" + ) + }.orEmpty Button( new IconItemStackBuilder(Material.GOLDEN_APPLE)