From e213abb4ed5b8c6635e4caaf18b1e69229900ee6 Mon Sep 17 00:00:00 2001 From: Made Baruna Date: Sat, 2 Jul 2022 18:20:19 +0700 Subject: [PATCH] Add 50:50 rank --- src/locales/en.json | 1 + src/locales/id.json | 1 + src/routes/wish/_rank.svelte | 109 +++++++++++++++++++++++++++++++- src/routes/wish/_summary.svelte | 8 +++ 4 files changed, 117 insertions(+), 2 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 88c23cf8..66f48222 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -479,6 +479,7 @@ "totalPull": "Total Pull", "luck5": "Luckiness 5★", "luck4": "Luckiness 4★", + "luckWinRateOff": "Luckiness Win 50:50", "medianTotal": "Global Median {median} pulls", "medianLuck": "Global Median {median}%", "moreTotal": "More pulls than {percentage}% of paimon.moe users", diff --git a/src/locales/id.json b/src/locales/id.json index 94648693..3cb7488f 100644 --- a/src/locales/id.json +++ b/src/locales/id.json @@ -479,6 +479,7 @@ "totalPull": "Total Wish", "luck5": "Keberuntungan 5★", "luck4": "Keberuntungan 4★", + "luckWinRateOff": "Keberuntungan Menang 50:50", "medianTotal": "Median Global {median} pull", "medianLuck": "Median Global {median}%", "moreTotal": "Lebih banyak dari {percentage}% pengguna paimon.moe", diff --git a/src/routes/wish/_rank.svelte b/src/routes/wish/_rank.svelte index 7216f0a5..9b569656 100644 --- a/src/routes/wish/_rank.svelte +++ b/src/routes/wish/_rank.svelte @@ -22,12 +22,26 @@ legendary: '...', rare: '...', }; + let percentageWinRateOff = { + legendary: 0, + rare: 0, + }; + let medianWinRateOff = { + legendary: '...', + rare: '...', + }; let loading = { total: true, legendary: true, rare: true, + winRateOff: { + legendary: true, + rare: true, + }, }; + let disableWinRateOff = false; + export async function getData() { loading.total = true; percentage = 0; @@ -73,7 +87,6 @@ } percentage = 100 - (totalLower / total) * 100; - console.log(totalLower, percentage, value); loading.total = false; } @@ -122,16 +135,69 @@ } percentageLuck[rarity] = 100 - (totalLower / total) * 100; - console.log(totalLower, percentage, value); loading[rarity] = false; } + export async function getDataWinRateOff(rarity, percentages) { + loading.winRateOff[rarity] = true; + percentageWinRateOff[rarity] = 0; + medianWinRateOff[rarity] = '...'; + + if (percentages[current] === undefined) return; + if (percentages[current].winRateOff === undefined) { + disableWinRateOff = true; + return; + } + + try { + const url = new URL(`${__paimon.env.API_HOST}/wish/summary/winrateoff`); + const query = new URLSearchParams({ banner: current, rarity }); + url.search = query.toString(); + + const res = await fetch(url, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + data = await res.json(); + + total = 0; + const sorted = []; + for (const item of data) { + total += item[1]; + sorted.push(...new Array(item[1]).fill(item[0])); + } + medianWinRateOff[rarity] = (sorted[Math.round(sorted.length / 2)] * 100).toFixed(2); + + getPercentileWinRateOff(percentages[current].winRateOff[rarity], rarity); + } catch (err) { + console.error(err); + } + } + + function getPercentileWinRateOff(value, rarity) { + let totalLower = 0; + for (const item of data) { + const qty = item[0]; + const amount = item[1]; + totalLower += amount; + + if (qty >= value) break; + } + + percentageWinRateOff[rarity] = 100 - (totalLower / total) * 100; + + loading.winRateOff[rarity] = false; + } + export function getDataLuckAll(percentages) { const sources = percentages === undefined ? wishPercentage : percentages; getDataLuck('legendary', sources); getDataLuck('rare', sources); + + getDataWinRateOff('legendary', sources); } function change(type) { @@ -143,6 +209,7 @@ $: fixedPoint = percentage < 0.1 ? 2 : percentage < 2 ? 1 : 0; $: fixedPointLegendary = percentageLuck.legendary < 0.1 ? 2 : percentageLuck.legendary < 2 ? 1 : 0; $: fixedPointRare = percentageLuck.rare < 0.1 ? 2 : percentageLuck.rare < 2 ? 1 : 0; + $: fixedPointWinRateOff = percentageWinRateOff < 0.1 ? 2 : percentageWinRateOff < 2 ? 1 : 0;
@@ -182,6 +249,44 @@
+ {#if current !== 'standard' && !disableWinRateOff} +
+ +
+

{$t('wish.rank.luckWinRateOff')}

+

+ {#if percentageWinRateOff.legendary < 50} + {$t('wish.rank.moreLuck', { + values: { percentage: (100 - percentageWinRateOff.legendary).toFixed(fixedPointRare) }, + })} + {:else} + {$t('wish.rank.lessLuck', { values: { percentage: percentageWinRateOff.legendary.toFixed(0) } })} + {/if} +

+
+
+ + {loading.winRateOff.legendary + ? $t('wish.rank.top') + : $t(`wish.rank.${percentageWinRateOff.legendary < 50 ? 'top' : 'bottom'}`)} + + + {loading.winRateOff.legendary + ? '...' + : percentageWinRateOff.legendary < 50 + ? percentageWinRateOff.legendary.toFixed(fixedPointWinRateOff) + : (100 - percentageWinRateOff.legendary).toFixed(fixedPointWinRateOff)}% + +
+
+ {/if}