fix: fallback on mix fail

This commit is contained in:
2025-11-04 16:54:01 +01:00
parent b581655d6c
commit c0cab3fe19
2 changed files with 70 additions and 53 deletions
+1 -1
View File
@@ -66,7 +66,7 @@
<option value="25">(~25%) Some mixes</option>
<option value="50">(~50%) Half mixes</option>
<option value="75">(~75%) A lot of mixes </option>
<option value="100">(100%) Only mixes</option>
<option value="100">(~100%) Only mixes</option>
</select></td>
</tr>
<tr>
+24 -7
View File
@@ -189,7 +189,7 @@ const app = createApp({
}
}
},
// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function, complexity, max-statements
generateData() {
this.table.splice(0, this.table.length);
const duration = parseInt(this.config.duration, 10);
@@ -222,26 +222,30 @@ const app = createApp({
const time = this.getTime(currentTimeMinute);
const minIndexScore = Math.min(...Object.values(indexScores));
const maxIndexScore = Math.max(...Object.values(indexScores));
let retries = 500;
let shouldAddMix = prng() < mixThreshold;
if (
currentTimeMinute + duration >= this.endTimeMinute &&
this.config.endWithAll
) {
this.table.push([time, "🥗 Salad 🥗"]);
} else if (prng() < mixThreshold) {
} else {
if (shouldAddMix) {
const minMixScore = Math.min(...Object.values(mixScores));
const maxMixScore = Math.max(...Object.values(mixScores));
const indexScoreThreshold =
minIndexScore + (maxIndexScore - minIndexScore) * 0.5;
minIndexScore + (maxIndexScore - minIndexScore) * mixThreshold;
const mixScoreThreshold =
minMixScore + (maxMixScore - minMixScore) * 0.25;
let retries = 500;
let index1 = getCandidateIndex();
let index2 = getCandidateIndex();
while (index2 === index1) {
index2 = getCandidateIndex();
}
const key = () =>
`${Math.min(index1, index2)}-${Math.max(index1, index2)}`;
while (
(index1 === index2 ||
lastIndexes.includes(index1) ||
(lastIndexes.includes(index1) ||
lastIndexes.includes(index2) ||
indexScores[index1] > indexScoreThreshold ||
indexScores[index2] > indexScoreThreshold ||
@@ -250,7 +254,15 @@ const app = createApp({
) {
index1 = getCandidateIndex();
index2 = getCandidateIndex();
// eslint-disable-next-line max-depth
while (index2 === index1) {
index2 = getCandidateIndex();
}
}
if (retries === 0) {
shouldAddMix = false;
} else {
// eslint-disable-next-line max-depth
if (prng() >= 0.5) {
this.table.push([
time,
@@ -266,9 +278,13 @@ const app = createApp({
indexScores[index2] += 1;
mixScores[key()] += 1;
lastIndexes = [index1, index2];
} else {
}
}
if (!shouldAddMix) {
const indexScoreThreshold =
minIndexScore + (maxIndexScore - minIndexScore) * 0.25;
let retries = 500;
let index = getCandidateIndex();
while (
(lastIndexes.includes(index) ||
@@ -282,6 +298,7 @@ const app = createApp({
lastIndexes = [index];
}
}
}
},
},
});