Merge pull request #2 from danilotitato/develop

Implement a skewed bell random for the added time in Random Hour
This commit is contained in:
Lea
2023-03-11 22:32:22 +01:00
committed by GitHub
5 changed files with 44 additions and 28 deletions
+6 -5
View File
@@ -69,8 +69,9 @@ var factor_donations = 1.5
// General Twitch, Streamlabs And StreamElements Config for Random Hour // General Twitch, Streamlabs And StreamElements Config for Random Hour
var range_t1 = [0.5, 2] // [min, max, skew]
var range_t2 = [1.0, 3] var range_t1 = [0.1, 3, 1]
var range_t3 = [2.0, 5] var range_t2 = [0.1, 3, 2]
var range_bits = [0.5, 2] var range_t3 = [0.1, 3, 3]
var range_donations = [0.5, 2] var range_bits = [0.1, 3, 1]
var range_donations = [0.1, 3, 1]
+5 -5
View File
@@ -35,11 +35,11 @@ if (streamelements_token !== "") {
function onEvent(data) { function onEvent(data) {
logObject("StreamElements", data); logObject("StreamElements", data);
if (!countdownEnded) { if (!countdownEnded) {
let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomBellSkew(...range_t1): 1);
let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomBellSkew(...range_t2): 1);
let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomBellSkew(...range_t3): 1);
let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomBellSkew(...range_bits): 1);
let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomInRangeNoRounding(...range_donations): 1); let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomBellSkew(...range_donations): 1);
if ((data['listener'] === "subscriber-latest") && subEnable) { if ((data['listener'] === "subscriber-latest") && subEnable) {
if (data['event']['gifted'] || data['event']['bulkGifted']) { if (data['event']['gifted'] || data['event']['bulkGifted']) {
+5 -5
View File
@@ -7,11 +7,11 @@ if (streamlabs_token !== "") {
socket.on("event", (event) => { socket.on("event", (event) => {
logObject("Streamlabs", event); logObject("Streamlabs", event);
let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomBellSkew(...range_t1): 1);
let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomBellSkew(...range_t2): 1);
let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomBellSkew(...range_t3): 1);
let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomBellSkew(...range_bits): 1);
let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomInRangeNoRounding(...range_donations): 1); let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomBellSkew(...range_donations): 1);
if (event.type == "subscription" && !event.message[0].gifter) { if (event.type == "subscription" && !event.message[0].gifter) {
if (!countdownEnded && subEnable) { if (!countdownEnded && subEnable) {
+10 -10
View File
@@ -12,9 +12,9 @@ if (twitch_channel_name !== "") {
client.on('subscription', (channel, username, methods, message, userstate) => { client.on('subscription', (channel, username, methods, message, userstate) => {
if (!countdownEnded && subEnable) { if (!countdownEnded && subEnable) {
let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomBellSkew(...range_t1): 1);
let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomBellSkew(...range_t2): 1);
let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomBellSkew(...range_t3): 1);
switch (methods['plan']) { switch (methods['plan']) {
case "Prime": case "Prime":
@@ -42,9 +42,9 @@ if (twitch_channel_name !== "") {
client.on('resub', (channel, username, months, message, userstate, methods) => { client.on('resub', (channel, username, months, message, userstate, methods) => {
if (!countdownEnded && subEnable) { if (!countdownEnded && subEnable) {
let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomBellSkew(...range_t1): 1);
let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomBellSkew(...range_t2): 1);
let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomBellSkew(...range_t3): 1);
switch (methods['plan']) { switch (methods['plan']) {
case "Prime": case "Prime":
@@ -72,9 +72,9 @@ if (twitch_channel_name !== "") {
client.on('subgift', (channel, username, months, recipient, methods, userstate) => { client.on('subgift', (channel, username, months, recipient, methods, userstate) => {
if (!countdownEnded && subEnable) { if (!countdownEnded && subEnable) {
let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomBellSkew(...range_t1): 1);
let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomBellSkew(...range_t2): 1);
let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomBellSkew(...range_t3): 1);
switch (methods['plan']) { switch (methods['plan']) {
case "Prime": case "Prime":
@@ -102,7 +102,7 @@ if (twitch_channel_name !== "") {
client.on('cheer', (channel, userstate, message) => { client.on('cheer', (channel, userstate, message) => {
if (!countdownEnded && bitEnable) { if (!countdownEnded && bitEnable) {
let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomBellSkew(...range_bits): 1);
if (userstate.bits >= min_amount_of_bits) { if (userstate.bits >= min_amount_of_bits) {
let times = Math.floor(userstate.bits/min_amount_of_bits); let times = Math.floor(userstate.bits/min_amount_of_bits);
+18 -3
View File
@@ -6,9 +6,24 @@ const randomInRange = (min, max) => {
return Math.floor(Math.random() * (max - min)) + min; return Math.floor(Math.random() * (max - min)) + min;
}; };
const randomInRangeNoRounding = (min, max) => { const randomBellSkew = (min, max, skew) => {
return Math.random() * (max - min) + min; let u = 0, v = 0;
}; while(u === 0) u = Math.random() //Converting [0,1) to (0,1)
while(v === 0) v = Math.random()
let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v )
num = num / 10.0 + 0.5 // Translate to 0 -> 1
if (num > 1 || num < 0)
num = randomBellSkew(min, max, skew) // resample between 0 and 1 if out of range
else{
num = Math.pow(num, skew) // Skew
num *= max - min // Stretch to fill range
num += min // offset to min
}
return num
}
const logMessage = (module, message) => { const logMessage = (module, message) => {
console.log(`[${module}]: ${message}`); console.log(`[${module}]: ${message}`);