From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Sun, 17 Apr 2022 22:18:53 +0000 (+0900) Subject: Merge branch 'develop' into document X-Git-Url: http://git.osdn.net/view?p=delesterandomselector%2FDelesteRandomSelector.git;a=commitdiff_plain;h=d8f427ee5a252c12f81461f9d0340fa4cebf280f;hp=-c Merge branch 'develop' into document --- d8f427ee5a252c12f81461f9d0340fa4cebf280f diff --combined src/com/ranfa/lib/calc/FanCalc.java index a6a1728,cc4c9a0..563ab1d --- a/src/com/ranfa/lib/calc/FanCalc.java +++ b/src/com/ranfa/lib/calc/FanCalc.java @@@ -1,19 -1,3 +1,19 @@@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.ranfa.lib.calc; import java.math.BigDecimal; @@@ -33,29 -17,21 +33,29 @@@ import com.ranfa.lib.concurrent.Counted * ファン計算用とのライブラリ * ファン数計算とスコア計算を実装 * @author hizum - * + * + * @since 4.0.0 */ public class FanCalc { + // Logger private static final Logger logger = LoggerFactory.getLogger(FanCalc.class); + /** + * 非同期処理用のスレッドプール + */ private static final ExecutorService async = Executors.newCachedThreadPool(new CountedThreadFactory(() -> "DRS", "FanCalcThread", false)); /** * 計算式は * 端数切り上げ(スコア*0.001*ルーム補正値*センター、ゲスト効果補正値*プロデュース方針補正値) * ルーム、センター、ゲスト、プロデュース方針の補正値は百分率。計算時に自動で変換します + * * @param score ライブで獲得したスコアを入力します * @param room ルームアイテムによる補正値を百分率のまま(xxx%)入力します * @param center センター、ゲスト効果による補正値を百分率のまま入力します * @param produce プロデュース方針による補正値を百分率のまま入力します + * @param premium プレミアムパスによる補正値を百分率のまま入力します + * * @return 一人あたりの獲得ファン数。1回のライブで獲得出来るファン数はこの値の5倍です */ public static int fan(int score, int room, int center, int produce, int premium) { @@@ -76,22 -52,9 +76,22 @@@ resCorrected = resCorrected.setScale(0,RoundingMode.UP); BigDecimal resPremiumed = resCorrected.multiply(premiumPercent); resPremiumed = resPremiumed.setScale(0, RoundingMode.UP); - return (resPremiumed.compareTo(BigDecimal.ZERO) == 0) || (resPremiumed == null) ? 0 : Integer.parseInt(resPremiumed.toString()); + return (resPremiumed.compareTo(BigDecimal.ZERO) == 0) ? 0 : Integer.parseInt(resPremiumed.toString()); } + /** + * 計算式は + * 端数切り上げ(スコア*0.001*ルーム補正値*センター、ゲスト効果補正値*プロデュース方針補正値) + * ルーム、センター、ゲスト、プロデュース方針の補正値は百分率。計算時に自動で変換します + * + * @param score スコア + * @param room ルーム補正値 + * @param center センターアイドル補正値 + * @param produce プロデュース方針補正値 + * @param premium プレミアムパス補正値 + * + * @return 一人当たりの獲得ファン数がラップされているCompletableFuture + */ public static CompletableFuture fanAsync(int score, int room, int center, int produce, int premium) { return CompletableFuture.supplyAsync(() -> fan(score, room, center, produce, premium), async); } @@@ -99,31 -62,25 +99,31 @@@ /** * 目標スコアを計算。 * 初期実装の思想は並列処理による再帰計算。 + * * @param fan 目標ファン * @param multiplier LIVEの繰り返し回数 * @param room ルームアイテム補正値(百分率) * @param center センター、ゲスト効果による補正値 * @param produce プロデュース方針にとる補正値 * @param premium プレミアムパスによる補正値 - * @return LIVE一回当たりの目標スコア + * + * @return LIVE一回当たりの目標スコアがラップされているCompletableFuture */ public static CompletableFuture scoreAsync(int fan, int multiplier, int room, int center, int produce, int premium) { return CompletableFuture.supplyAsync(() -> score(fan, multiplier, room, center, produce, premium), async); } /** + * 目標スコアを計算。 + * 初期実装の思想は並列処理による再帰計算。 + * * @param fan 目標ファン * @param multiplier LIVEの繰り返し回数 * @param room ルームアイテム補正値(百分率) * @param center センター、ゲスト効果による補正値 * @param produce プロデュース方針にとる補正値 * @param premium プレミアムパスによる補正値 + * * @return LIVE一回当たりの目標スコア */ private static int score(int fan, int multiplier, int room, int center, int produce, int premium) { diff --combined src/com/ranfa/lib/calc/PRPCalc.java index 339ce46,d895a01..d105dfe --- a/src/com/ranfa/lib/calc/PRPCalc.java +++ b/src/com/ranfa/lib/calc/PRPCalc.java @@@ -1,20 -1,3 +1,20 @@@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.ranfa.lib.calc; import java.io.IOException; @@@ -30,43 -13,16 +30,43 @@@ import org.slf4j.LoggerFactory import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +/** + * PRPの計算ライブラリ。 + * PRPの保管も兼ねています。 + * + * @author Ranfa + * + *@since 4.0.0 + */ public class PRPCalc { + // Logger private final Logger logger = LoggerFactory.getLogger(PRPCalc.class); + /** + * PRPを保管しているファイルパス + */ private static final String PRP_STORAGE_FILE_PATH = "generated/prp.json"; + + /** + * 計算用のBigDecimal値 + */ private static final BigDecimal THAUSAND = BigDecimal.valueOf(1000); + /** + * 合計PRP値を計算するために保管しているPRPのList + */ private List TotalPRPList; + /** + * 合計PRP値 + */ private int TotalPRP; + /** + * コンストラクタ。 + *

+ * 合計PRP値の算出に必要な値を読み出し、Listへ詰め込むまでを行います。 + */ public PRPCalc() { if(Files.notExists(Paths.get(PRP_STORAGE_FILE_PATH))) generateEmptyPRPFile(); @@@ -79,13 -35,6 +79,13 @@@ TotalPRP = calcCurrentTotal(); } + /** + * 内容が空のPRP保管ファイルを生成します。 + *

+ * ファイルを生成するのみで内容の書き込みはしません。 + * + * @return ファイルの生成に成功した場合はtrue、それ以外はfalse + */ public boolean generateEmptyPRPFile() { if(Files.notExists(Paths.get("generated"))) try { @@@ -98,10 -47,6 +98,10 @@@ return true; } + /** + * {@link #TotalPRPList} を参照して現在時点の合計を算出します。 + * @return 現在時点の合計PRP + */ public int calcCurrentTotal() { int res = 0; for(int val : TotalPRPList) @@@ -109,24 -54,12 +109,23 @@@ return res; } + /** + * {@link #TotalPRP} を返します + * @return {@link #TotalPRP}の値 + */ public int getTotalPRP() { return TotalPRP; } + /** + * 入力されたスコアからPRPを計算します。 + *

+ * PRPは「端数切捨て(スコア×0.001)」になります + * @param score 計算するスコア + * @return 入力から計算したPRP値 + */ public static int calcPRPFromScore(int score) { BigDecimal scoreDecimal = BigDecimal.valueOf(score); - scoreDecimal.divide(THAUSAND, RoundingMode.DOWN); - return scoreDecimal.intValueExact(); + return scoreDecimal.divide(THAUSAND, RoundingMode.DOWN).intValueExact(); } }