fix: fallback on mix fail
This commit is contained in:
+1
-1
@@ -66,7 +66,7 @@
|
|||||||
<option value="25">(~25%) Some mixes</option>
|
<option value="25">(~25%) Some mixes</option>
|
||||||
<option value="50">(~50%) Half mixes</option>
|
<option value="50">(~50%) Half mixes</option>
|
||||||
<option value="75">(~75%) A lot of 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>
|
</select></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -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() {
|
generateData() {
|
||||||
this.table.splice(0, this.table.length);
|
this.table.splice(0, this.table.length);
|
||||||
const duration = parseInt(this.config.duration, 10);
|
const duration = parseInt(this.config.duration, 10);
|
||||||
@@ -222,64 +222,81 @@ const app = createApp({
|
|||||||
const time = this.getTime(currentTimeMinute);
|
const time = this.getTime(currentTimeMinute);
|
||||||
const minIndexScore = Math.min(...Object.values(indexScores));
|
const minIndexScore = Math.min(...Object.values(indexScores));
|
||||||
const maxIndexScore = Math.max(...Object.values(indexScores));
|
const maxIndexScore = Math.max(...Object.values(indexScores));
|
||||||
let retries = 500;
|
let shouldAddMix = prng() < mixThreshold;
|
||||||
if (
|
if (
|
||||||
currentTimeMinute + duration >= this.endTimeMinute &&
|
currentTimeMinute + duration >= this.endTimeMinute &&
|
||||||
this.config.endWithAll
|
this.config.endWithAll
|
||||||
) {
|
) {
|
||||||
this.table.push([time, "🥗 Salad 🥗"]);
|
this.table.push([time, "🥗 Salad 🥗"]);
|
||||||
} else if (prng() < mixThreshold) {
|
|
||||||
const minMixScore = Math.min(...Object.values(mixScores));
|
|
||||||
const maxMixScore = Math.max(...Object.values(mixScores));
|
|
||||||
const indexScoreThreshold =
|
|
||||||
minIndexScore + (maxIndexScore - minIndexScore) * 0.5;
|
|
||||||
const mixScoreThreshold =
|
|
||||||
minMixScore + (maxMixScore - minMixScore) * 0.25;
|
|
||||||
let index1 = getCandidateIndex();
|
|
||||||
let index2 = getCandidateIndex();
|
|
||||||
const key = () =>
|
|
||||||
`${Math.min(index1, index2)}-${Math.max(index1, index2)}`;
|
|
||||||
while (
|
|
||||||
(index1 === index2 ||
|
|
||||||
lastIndexes.includes(index1) ||
|
|
||||||
lastIndexes.includes(index2) ||
|
|
||||||
indexScores[index1] > indexScoreThreshold ||
|
|
||||||
indexScores[index2] > indexScoreThreshold ||
|
|
||||||
mixScores[key()] > mixScoreThreshold) &&
|
|
||||||
(retries -= 1) > 0
|
|
||||||
) {
|
|
||||||
index1 = getCandidateIndex();
|
|
||||||
index2 = getCandidateIndex();
|
|
||||||
}
|
|
||||||
if (prng() >= 0.5) {
|
|
||||||
this.table.push([
|
|
||||||
time,
|
|
||||||
`${this.candidates[index1]} & ${this.candidates[index2]}`,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
this.table.push([
|
|
||||||
time,
|
|
||||||
`${this.candidates[index2]} & ${this.candidates[index1]}`,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
indexScores[index1] += 1;
|
|
||||||
indexScores[index2] += 1;
|
|
||||||
mixScores[key()] += 1;
|
|
||||||
lastIndexes = [index1, index2];
|
|
||||||
} else {
|
} else {
|
||||||
const indexScoreThreshold =
|
if (shouldAddMix) {
|
||||||
minIndexScore + (maxIndexScore - minIndexScore) * 0.25;
|
const minMixScore = Math.min(...Object.values(mixScores));
|
||||||
let index = getCandidateIndex();
|
const maxMixScore = Math.max(...Object.values(mixScores));
|
||||||
while (
|
const indexScoreThreshold =
|
||||||
(lastIndexes.includes(index) ||
|
minIndexScore + (maxIndexScore - minIndexScore) * mixThreshold;
|
||||||
indexScores[index] > indexScoreThreshold) &&
|
const mixScoreThreshold =
|
||||||
(retries -= 1) > 0
|
minMixScore + (maxMixScore - minMixScore) * 0.25;
|
||||||
) {
|
let retries = 500;
|
||||||
index = getCandidateIndex();
|
let index1 = getCandidateIndex();
|
||||||
|
let index2 = getCandidateIndex();
|
||||||
|
while (index2 === index1) {
|
||||||
|
index2 = getCandidateIndex();
|
||||||
|
}
|
||||||
|
const key = () =>
|
||||||
|
`${Math.min(index1, index2)}-${Math.max(index1, index2)}`;
|
||||||
|
while (
|
||||||
|
(lastIndexes.includes(index1) ||
|
||||||
|
lastIndexes.includes(index2) ||
|
||||||
|
indexScores[index1] > indexScoreThreshold ||
|
||||||
|
indexScores[index2] > indexScoreThreshold ||
|
||||||
|
mixScores[key()] > mixScoreThreshold) &&
|
||||||
|
(retries -= 1) > 0
|
||||||
|
) {
|
||||||
|
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,
|
||||||
|
`${this.candidates[index1]} & ${this.candidates[index2]}`,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
this.table.push([
|
||||||
|
time,
|
||||||
|
`${this.candidates[index2]} & ${this.candidates[index1]}`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
indexScores[index1] += 1;
|
||||||
|
indexScores[index2] += 1;
|
||||||
|
mixScores[key()] += 1;
|
||||||
|
lastIndexes = [index1, index2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldAddMix) {
|
||||||
|
const indexScoreThreshold =
|
||||||
|
minIndexScore + (maxIndexScore - minIndexScore) * 0.25;
|
||||||
|
let retries = 500;
|
||||||
|
let index = getCandidateIndex();
|
||||||
|
while (
|
||||||
|
(lastIndexes.includes(index) ||
|
||||||
|
indexScores[index] > indexScoreThreshold) &&
|
||||||
|
(retries -= 1) > 0
|
||||||
|
) {
|
||||||
|
index = getCandidateIndex();
|
||||||
|
}
|
||||||
|
this.table.push([time, this.candidates[index]]);
|
||||||
|
indexScores[index] += 1;
|
||||||
|
lastIndexes = [index];
|
||||||
}
|
}
|
||||||
this.table.push([time, this.candidates[index]]);
|
|
||||||
indexScores[index] += 1;
|
|
||||||
lastIndexes = [index];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user