Improve chance simulator forecasts and tracking UI
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
1d278ff551
commit
6e64cfacd5
10 changed files with 534 additions and 101 deletions
|
|
@ -8,14 +8,45 @@ export const RNG_SIMULATOR_LIMITS = {
|
|||
multiplierMax: 1000000,
|
||||
simulationDrawsMin: 1,
|
||||
simulationDrawsMax: 1000000,
|
||||
realDrawsMax: 1000000000,
|
||||
occurrenceRateMin: 0,
|
||||
occurrenceRateMax: 1000000000
|
||||
};
|
||||
|
||||
export const RNG_SIMULATOR_OCCURRENCE_UNITS = ["perHour", "perDay", "perMonth"];
|
||||
export const RNG_SIMULATOR_OCCURRENCE_UNITS = ["perHour", "perDay"];
|
||||
export const RNG_SIMULATOR_HOURLY_DURATION_PRESETS = [
|
||||
{ id: "1h", label: "1h", hours: 1 },
|
||||
{ id: "5h", label: "5h", hours: 5 },
|
||||
{ id: "10h", label: "10h", hours: 10 },
|
||||
{ id: "1j", label: "1j", hours: 24 }
|
||||
];
|
||||
export const RNG_SIMULATOR_DAILY_DURATION_PRESETS = [
|
||||
{ id: "1j", label: "1j", hours: 24 },
|
||||
{ id: "3j", label: "3j", hours: 72 },
|
||||
{ id: "7j", label: "7j", hours: 168 },
|
||||
{ id: "15j", label: "15j", hours: 360 }
|
||||
];
|
||||
export const RNG_SIMULATOR_MONTHLY_DURATION_PRESETS = [
|
||||
{ id: "1j", label: "1j", hours: 24 },
|
||||
{ id: "3j", label: "3j", hours: 72 },
|
||||
{ id: "7j", label: "7j", hours: 168 },
|
||||
{ id: "30j", label: "30j", hours: 720 }
|
||||
];
|
||||
export const RNG_SIMULATOR_YEARLY_DURATION_PRESETS = [
|
||||
{ id: "30j", label: "30j", hours: 720 },
|
||||
{ id: "90j", label: "90j", hours: 2160 },
|
||||
{ id: "1a", label: "1 an", hours: 8760 },
|
||||
{ id: "5a", label: "5 ans", hours: 43800 }
|
||||
];
|
||||
export const RNG_SIMULATOR_LONG_DURATION_PRESETS = [
|
||||
{ id: "1a", label: "1 an", hours: 8760 },
|
||||
{ id: "5a", label: "5 ans", hours: 43800 },
|
||||
{ id: "10a", label: "10 ans", hours: 87600 },
|
||||
{ id: "25a", label: "25 ans", hours: 219000 }
|
||||
];
|
||||
|
||||
export function clampInteger(value, min, max, fallback = min) {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
const parsed = Number.parseInt(String(value ?? "").replace(/[\s\u00a0]/g, ""), 10);
|
||||
if (!Number.isFinite(parsed)) return fallback;
|
||||
return Math.min(max, Math.max(min, parsed));
|
||||
}
|
||||
|
|
@ -76,6 +107,11 @@ export function getEffectiveRate(rate, multiplier = 0) {
|
|||
export function calculateAtLeastOneProbability(rate, draws, multiplier = 0) {
|
||||
const probability = getEffectiveRate(rate, multiplier) / 100;
|
||||
const cleanDraws = clampInteger(draws, 0, Number.MAX_SAFE_INTEGER, 0);
|
||||
return calculateProbabilityForDrawCount(probability, cleanDraws);
|
||||
}
|
||||
|
||||
function calculateProbabilityForDrawCount(probability, draws) {
|
||||
const cleanDraws = clampDecimal(draws, 0, Number.MAX_SAFE_INTEGER, 0);
|
||||
if (probability <= 0 || cleanDraws <= 0) return 0;
|
||||
if (probability >= 1) return 1;
|
||||
return -Math.expm1(cleanDraws * Math.log1p(-probability));
|
||||
|
|
@ -91,19 +127,32 @@ export function calculateDrawsForChance(rate, targetChance, multiplier = 0) {
|
|||
}
|
||||
|
||||
export function normalizeOccurrenceUnit(value) {
|
||||
if (value === "perMonth") return "perDay";
|
||||
return RNG_SIMULATOR_OCCURRENCE_UNITS.includes(value) ? value : "perHour";
|
||||
}
|
||||
|
||||
export function normalizeOccurrenceSettings(value, unit) {
|
||||
const cleanValue = clampDecimal(value, RNG_SIMULATOR_LIMITS.occurrenceRateMin, RNG_SIMULATOR_LIMITS.occurrenceRateMax, 0);
|
||||
if (unit === "perMonth") {
|
||||
return {
|
||||
occurrenceValue: cleanValue / 30,
|
||||
occurrenceUnit: "perDay"
|
||||
};
|
||||
}
|
||||
return {
|
||||
occurrenceValue: cleanValue,
|
||||
occurrenceUnit: normalizeOccurrenceUnit(unit)
|
||||
};
|
||||
}
|
||||
|
||||
export function calculateRngSummary({ rate, multiplier = 0, simulationDraws, occurrenceValue = 0, occurrenceUnit = "perHour" }) {
|
||||
const effectiveRate = getEffectiveRate(rate, multiplier);
|
||||
const probability = effectiveRate / 100;
|
||||
const averageDraws = probability > 0 ? 1 / probability : 0;
|
||||
const cleanOccurrenceValue = clampDecimal(occurrenceValue, RNG_SIMULATOR_LIMITS.occurrenceRateMin, RNG_SIMULATOR_LIMITS.occurrenceRateMax, 0);
|
||||
const cleanOccurrenceUnit = normalizeOccurrenceUnit(occurrenceUnit);
|
||||
const { occurrenceValue: cleanOccurrenceValue, occurrenceUnit: cleanOccurrenceUnit } = normalizeOccurrenceSettings(occurrenceValue, occurrenceUnit);
|
||||
let averageHours = 0;
|
||||
if (cleanOccurrenceValue > 0 && cleanOccurrenceUnit === "perHour") averageHours = averageDraws / cleanOccurrenceValue;
|
||||
else if (cleanOccurrenceValue > 0 && cleanOccurrenceUnit === "perDay") averageHours = (averageDraws / cleanOccurrenceValue) * 24;
|
||||
else if (cleanOccurrenceValue > 0 && cleanOccurrenceUnit === "perMonth") averageHours = (averageDraws / cleanOccurrenceValue) * 24 * 30;
|
||||
|
||||
return {
|
||||
probability,
|
||||
|
|
@ -112,9 +161,9 @@ export function calculateRngSummary({ rate, multiplier = 0, simulationDraws, occ
|
|||
chanceForSimulationDraws: calculateAtLeastOneProbability(rate, simulationDraws, multiplier),
|
||||
timeByFrequency: {
|
||||
hour: averageHours,
|
||||
day: averageHours > 0 ? averageHours / 24 : 0,
|
||||
month: averageHours > 0 ? averageHours / 24 / 30 : 0
|
||||
day: averageHours > 0 ? averageHours / 24 : 0
|
||||
},
|
||||
durationChances: calculateDurationChances(rate, multiplier, cleanOccurrenceValue, cleanOccurrenceUnit),
|
||||
drawsForChance: {
|
||||
50: calculateDrawsForChance(rate, 0.5, multiplier),
|
||||
90: calculateDrawsForChance(rate, 0.9, multiplier),
|
||||
|
|
@ -124,6 +173,79 @@ export function calculateRngSummary({ rate, multiplier = 0, simulationDraws, occ
|
|||
};
|
||||
}
|
||||
|
||||
export function calculateDurationChances(rate, multiplier = 0, occurrenceValue = 0, occurrenceUnit = "perHour") {
|
||||
const { occurrenceValue: cleanOccurrenceValue, occurrenceUnit: cleanOccurrenceUnit } = normalizeOccurrenceSettings(occurrenceValue, occurrenceUnit);
|
||||
const drawsPerHour = cleanOccurrenceUnit === "perDay" ? cleanOccurrenceValue / 24 : cleanOccurrenceValue;
|
||||
const averageHours = drawsPerHour > 0 ? (1 / (getEffectiveRate(rate, multiplier) / 100)) / drawsPerHour : 0;
|
||||
const presets = getDurationPresetsForAverageHours(averageHours, cleanOccurrenceUnit);
|
||||
return presets.map((preset) => ({
|
||||
...preset,
|
||||
draws: drawsPerHour > 0 ? drawsPerHour * preset.hours : 0,
|
||||
chance: drawsPerHour > 0 ? calculateProbabilityForDrawCount(getEffectiveRate(rate, multiplier) / 100, drawsPerHour * preset.hours) : 0
|
||||
}));
|
||||
}
|
||||
|
||||
export function getDurationPresetsForAverageHours(averageHours, occurrenceUnit = "perHour") {
|
||||
if (!Number.isFinite(averageHours) || averageHours <= 0) {
|
||||
return occurrenceUnit === "perDay" ? RNG_SIMULATOR_DAILY_DURATION_PRESETS : RNG_SIMULATOR_HOURLY_DURATION_PRESETS;
|
||||
}
|
||||
if (occurrenceUnit === "perDay" && averageHours <= 24 * 365) return RNG_SIMULATOR_MONTHLY_DURATION_PRESETS;
|
||||
if (averageHours <= 24 * 7) return RNG_SIMULATOR_HOURLY_DURATION_PRESETS;
|
||||
if (averageHours <= 24 * 365) return RNG_SIMULATOR_MONTHLY_DURATION_PRESETS;
|
||||
if (averageHours <= 24 * 365 * 10) return RNG_SIMULATOR_YEARLY_DURATION_PRESETS;
|
||||
return RNG_SIMULATOR_LONG_DURATION_PRESETS;
|
||||
}
|
||||
|
||||
export function getAveragePositionStatus(averageRatio) {
|
||||
const ratio = Number.isFinite(averageRatio) && averageRatio >= 0 ? averageRatio : 0;
|
||||
if (ratio < 0.25) return { id: "start", tone: "positive" };
|
||||
if (ratio < 0.5) return { id: "farBelow", tone: "positive" };
|
||||
if (ratio < 0.9) return { id: "below", tone: "positive" };
|
||||
if (ratio < 1.1) return { id: "average", tone: "" };
|
||||
if (ratio < 1.5) return { id: "slightlyAbove", tone: "negative" };
|
||||
if (ratio < 3) return { id: "high", tone: "negative" };
|
||||
return { id: "catastrophic", tone: "negative" };
|
||||
}
|
||||
|
||||
export function calculateRngRealDrawsSummary({ rate, multiplier = 0, realDraws = 0, averageDraws = 0, drawsForChance = {}, costPerDraw = "" }) {
|
||||
const cleanRealDraws = clampInteger(realDraws, 0, RNG_SIMULATOR_LIMITS.realDrawsMax, 0);
|
||||
const cumulativeChance = calculateAtLeastOneProbability(rate, cleanRealDraws, multiplier);
|
||||
const noSuccessChance = 1 - cumulativeChance;
|
||||
const cleanAverageDraws = Number.isFinite(averageDraws) && averageDraws > 0 ? averageDraws : 0;
|
||||
const averageRatio = cleanAverageDraws > 0 ? cleanRealDraws / cleanAverageDraws : 0;
|
||||
const averagePosition = getAveragePositionStatus(averageRatio);
|
||||
const drawsUntilAverage = cleanAverageDraws > cleanRealDraws ? Math.ceil(cleanAverageDraws - cleanRealDraws) : 0;
|
||||
const cleanCost = Number(normalizeCostString(costPerDraw));
|
||||
const hasCost = Number.isFinite(cleanCost) && cleanCost > 0;
|
||||
const averageSuccessCost = hasCost && cleanAverageDraws > 0 ? cleanAverageDraws * cleanCost : 0;
|
||||
const spentCost = hasCost ? cleanRealDraws * cleanCost : 0;
|
||||
const targets = {};
|
||||
Object.entries(drawsForChance || {}).forEach(([target, draws]) => {
|
||||
const remainingDraws = Number.isFinite(draws) ? Math.max(0, draws - cleanRealDraws) : Number.POSITIVE_INFINITY;
|
||||
targets[target] = {
|
||||
draws,
|
||||
remainingDraws,
|
||||
progress: Number.isFinite(draws) && draws > 0 ? Math.min(1, cleanRealDraws / draws) : 0,
|
||||
remainingCost: hasCost && Number.isFinite(remainingDraws) ? remainingDraws * cleanCost : 0
|
||||
};
|
||||
});
|
||||
return {
|
||||
realDraws: cleanRealDraws,
|
||||
hasCost,
|
||||
cumulativeChance,
|
||||
noSuccessChance,
|
||||
averageRatio,
|
||||
averagePosition,
|
||||
drawsUntilAverage,
|
||||
averageExceeded: cleanAverageDraws > 0 && cleanRealDraws >= cleanAverageDraws,
|
||||
spentCost,
|
||||
averageSuccessCost,
|
||||
averageCostDelta: hasCost && cleanAverageDraws > 0 ? spentCost - averageSuccessCost : 0,
|
||||
costUntilAverage: hasCost && drawsUntilAverage > 0 ? drawsUntilAverage * cleanCost : 0,
|
||||
targets
|
||||
};
|
||||
}
|
||||
|
||||
export function calculateRngCostSummary({ costPerDraw, averageDraws, drawsForChance, simulationDraws, simulationSuccesses, firstSuccessDraw = 0 }) {
|
||||
const cleanCost = Number(normalizeCostString(costPerDraw));
|
||||
if (!Number.isFinite(cleanCost) || cleanCost <= 0) return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue