Hi! Thank you very much for this extension, Iām using it in several server apiās.
I have a small issue and I canāt figure out what exactly the cause is.
Iām using a server connect api to calculate results with code in RunJS, Iām requesting the results by sending data to perform the calculations on trough the API Action component in App Connect.
The issue is that 50% of the time RunJS returns no results. I checked the request of all empty results, and they all had the necessary data sent and there were no errors.
What could be happening in the cases where there is no result? Something related to RunJS, my code, the network or server connect?
let multipleWins = false;
let sectorArr = participants;
let prizes = prizesArr;
let winners = [];
function getWinnerChances() {
let totalChances = 0;
for (let w = 0; w < winners.length; w++) {
totalChances = totalChances + winners[w].chance;
}
return totalChances;
}
function startGame() {
for (let prize = 0; prize < prizes.length; prize += 1) {
let winningSector = randomSector();
prizes[prize].winner = sectorArr[winningSector - 1].id;
winners.push({
winner: sectorArr[winningSector - 1].id,
prize: prizes[prize].id,
chance: sectorArr[winningSector - 1].chance,
coins: prizes[prize].coins,
});
if (multipleWins == false) {
sectorArr[winningSector - 1].chance = 0;
sectorArr[winningSector - 1].radians = 0;
}
}
}
function randomSector() {
let chancesArr = sectorArr;
if (multipleWins == false) {
for (i = 0; i < chancesArr.length; i++) {
if (chancesArr[i].chance > 0) {
chancesArr[i].chance =
chancesArr[i].chance +
getWinnerChances() / (sectorArr.length - winners.length);
}
}
}
const cumulativeSum = (
(sum) => (value) =>
(sum += value)
)(0);
let newList = chancesArr.map((currElement, index) => {
let max = sectorArr[index].chance;
currElement = max;
return currElement;
});
let cumulativeList = newList.map(cumulativeSum);
let listMinMax = cumulativeList.map((currElement, index) => {
let max = currElement;
let min = 0;
if (index == 0) {
min = 0;
} else {
min = cumulativeList[index - 1];
}
currElement = { min, max };
return currElement;
});
let cSector = Math.random();
let chosenSector;
for (let i = 0; i < listMinMax.length; i++) {
if (listMinMax[i].min < cSector && listMinMax[i].max > cSector) {
chosenSector = i + 1;
break;
} else {
continue;
}
}
return chosenSector;
}
startGame();
return winners;