Last active
August 18, 2019 04:11
-
-
Save dsetzer/9d93b2dc1551fae726c0951057f9f65c to your computer and use it in GitHub Desktop.
bustabit streak logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = { | |
target: { value: 2, type: 'multiplier', label: 'Target Payout' }, | |
streak: { value: 4, type: 'multiplier', label: 'Min Length' } | |
}; | |
const history = engine.getState().history; | |
const busts = [], streaks = []; | |
let currentStart = null, currentStreak = 0; | |
for (let i = 0; i < history.length; i++) { | |
let item = [history[i].gameId, null, history[i].bust]; | |
updateStreaks(item); | |
busts.push(item); | |
} | |
engine.on('GAME_ENDED', () => { | |
const lastGame = engine.history.first(); | |
let item = [lastGame.gameId, lastGame.lastGameTick, lastGame.bust]; | |
updateStreaks(item); | |
busts.push(item); | |
}); | |
function updateStreaks(item) { | |
if (item[2] >= config.target.value) { | |
if (currentStreak < 1) currentStart = Date.now(); | |
currentStreak++; | |
} else { | |
if (currentStreak >= config.streak.value) { | |
streaks.push({ startTime: currentStart, endTime: Date.now(), length: currentStreak }); | |
outputStats(streaks); | |
} | |
currentStreak = 0; | |
} | |
} | |
function outputStats(streaks) { | |
if (!streaks) return; | |
log(`Streak Record for ${config.target.value}x (min length ${config.streak.value} games)`); | |
for (let streak of streaks) { | |
log(`${(new Date(streak.startTime)).toLocaleDateString()} | <-[${(new Date(streak.startTime)).toLocaleTimeString()}] - [${(new Date(streak.endTime)).toLocaleTimeString()}]-> | Length : ${ streak.length} games`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment