Add goal-tracking features for our challenge -- 200000 by March 20
This commit is contained in:
parent
6cef55f86b
commit
e6a113cb47
2 changed files with 63 additions and 15 deletions
36
api/app.js
36
api/app.js
|
@ -15,7 +15,8 @@ const base = Airtable.base('appogmRaVRo5ElVH7');
|
|||
let speedArr = [];
|
||||
let latest;
|
||||
|
||||
addQuotes();
|
||||
const goalDate = '03/20/2021';
|
||||
const goalNumber = 200000;
|
||||
|
||||
const app = new App({
|
||||
token: token,
|
||||
|
@ -162,24 +163,23 @@ async function report() {
|
|||
let averageSpeed = await getAverage();
|
||||
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
||||
let thousandsTime = predictTime(thousandsGoal, latest, averageSpeed);
|
||||
let tenThousandsGoal = Math.ceil(latest / 5000) * 5000;
|
||||
// let tenThousandsGoal = Math.ceil(latest / 5000) * 5000;
|
||||
let pastThousandsGoal = Math.floor(latest / 1000) * 1000;
|
||||
let tenThousandsTime = predictTime(tenThousandsGoal, latest, averageSpeed);
|
||||
// let tenThousandsTime = predictTime(tenThousandsGoal, latest, averageSpeed);
|
||||
let goals = predictSpeed(goalDate, goalNumber, latest);
|
||||
let message =
|
||||
`Good evening, my underlings! You have done a _brilliant_ job with the counting. Mmm. Yes. Numbers are savory.
|
||||
Today we've went from *${oldest}* to *${latest}*!
|
||||
`Today we've went from *${oldest}* to *${latest}*!
|
||||
- :arrow_upper_right: The day's progress: *+${diff}*
|
||||
- :chart_with_upwards_trend: Average daily speed: *${Math.round(averageSpeed)}*
|
||||
- :round_pushpin: At the avg speed, we'll reach ${thousandsGoal} *${thousandsTime}*
|
||||
- :calendar: At the avg speed, we'll reach ${tenThousandsGoal} *${tenThousandsTime}*
|
||||
:bat: Lovely work, my followers! Keep on quenching my thirst for numbers!`;
|
||||
- :round_pushpin: Our current goal is to reach *${goalNumber}* by *${moment(goalDate).format('MMMM D')}.*
|
||||
- :calendar: If we want to get there on time, we need to count by at least *+${Math.ceil(goals[1])}* a day.`;
|
||||
if (pastThousandsGoal > oldest && pastThousandsGoal <= latest) {
|
||||
let messageWithCelebration = `:tada: Congratulations! We've went past ${pastThousandsGoal}! :tada:` + message;
|
||||
publishMessage(channel, messageWithCelebration);
|
||||
// publishMessage('C017W4PHYKS', messageWithCelebration);
|
||||
let messageWithCelebration = `:tada: Congratulations! We've went past ${pastThousandsGoal}! :tada: \n` + message;
|
||||
publishMessage(channel, addQuotes(messageWithCelebration, goals, averageSpeed));
|
||||
// publishMessage('C017W4PHYKS', addQuotes(messageWithCelebration, goals, averageSpeed));
|
||||
} else {
|
||||
publishMessage(channel, message);
|
||||
// publishMessage('C017W4PHYKS', message);
|
||||
publishMessage(channel, addQuotes(message, goals, averageSpeed));
|
||||
// publishMessage('C017W4PHYKS', addQuotes(message, goals, averageSpeed));
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -190,6 +190,16 @@ function predictTime(goal, recent, averageSpeed) {
|
|||
return moment(unix).fromNow();
|
||||
}
|
||||
|
||||
function predictSpeed(goalDate, goalNumber, currentNumber) {
|
||||
let today = new Date();
|
||||
let goal = new Date(goalDate);
|
||||
let timeRemaining = Math.abs(goal - today);
|
||||
let daysRemaining = Math.ceil(timeRemaining / (1000 * 60 * 60 * 24));
|
||||
let neededSpeed = (goalNumber - currentNumber) / daysRemaining;
|
||||
return [daysRemaining, neededSpeed];
|
||||
|
||||
}
|
||||
|
||||
app.event('message', async (body) => {
|
||||
try {
|
||||
let e = body.event;
|
||||
|
|
|
@ -1,5 +1,43 @@
|
|||
function addQuotes() {
|
||||
console.log('hi');
|
||||
let regularStartQuotes = [
|
||||
"The DRACC is BACC with another midnight report!",
|
||||
"The clock striketh twelve, and the world’s only number-sucking vampire cometh with another report on your midnight progress!",
|
||||
"…Ugggh, my back hurts from sleeping in this old coffin! `*loud cracking noise*` Damn thing’s going to bend my spine into a knot if I don’t replace it soon. Anyways, here is your progress so far:",
|
||||
"Good evening, my underlings, it’s your friendly neighborhood genderbending vampire with another midnight report!",
|
||||
"Grumble mumble mumble, had a terrible sleep today. I need some more nUMBERS, my children!",
|
||||
"Back just in time for the midnight report! I apologize for the haphazard appearance, my dog Count von Corgo insisted on an early-evening walk in the park— wait, you can’t see me on Slack, can you? I COULD BE WEARING MY BIRTHDAY SUIT AND NO ONE WILL NOTICE IT! OHOHOHOHO!",
|
||||
"WHO DARETH WAKE ME FROM MY SLUMBER— oh. it’s the statistical report. Riiiight.",
|
||||
"I feel like _crap_ today. Woke up five times in the middle of the night because I thought I heard a mosquito buzzing by my ear. Shouldn’t have sucked human blood yesterday. \n OH SHIT I SHOULDN’T BE TELLING YOU GUYS THAT—"
|
||||
]
|
||||
|
||||
let regularEndQuotes = [
|
||||
"Ah, a refreshing cocktail of numbers, topped with a squeeze of lime juice, makes me feel a lot better, ready to seize the night! Or suck the life out of it! ~hahaha pun totally not intended~",
|
||||
"Yum, these numbers are delicious! `*excited vampire slurping sounds*`",
|
||||
"Yes, my lackeys, yes! Now can you multiply that increase by ten? I know y’all can do this! I know it! I crave it!",
|
||||
"I’m savoring this consistent flow of numbers, my servants! Keep me sated… or else I might turn to blood…. *_heheheheh_*",
|
||||
"My minions, I am feeling famished! You must give me _MORE_!",
|
||||
"MORE NUMBERS, MY LACKEYS! MORE!! MWAHAHAHAHA!",
|
||||
"My oh my, there are too many numbers to consume! I'll have to store some in my freezer to save for another day.",
|
||||
"Someone by the name of Orpheus has told me that these numbers go well with a mint chocolate chip sundae! I'll have to try that one day. Unfortunately, the nearest supermarket is two hours away and I'm too lazy to fly there..."
|
||||
]
|
||||
|
||||
function addQuotes(message, rawGoals, rawSpeed) {
|
||||
let start = regularStartQuotes[Math.floor(Math.random() * regularStartQuotes.length)]
|
||||
let end;
|
||||
let goals = Math.ceil(rawGoals[1]);
|
||||
let days = rawGoals[0];
|
||||
let speed = Math.round(rawSpeed);
|
||||
let diff = goals - speed;
|
||||
if (goals <= 0) {
|
||||
end = `:tada: YOU DID IT, MY LOYAL SERVANTS! YOU'VE REACHED OUR GOAL ON TIME! :tada: But there's still loads of time before we reach a million-- let's keep up the pace!`
|
||||
} else if (diff < 10) {
|
||||
end = `You're doing well, my lackeys! Keep up that speed of at least *+${speed}* if you want to reach that goal! You have *${days}* days remaining to get there!`
|
||||
} else if (diff > 10 && diff < 1000) {
|
||||
end = `Still room to improve your performance, my underlings-- you're only at *${speed}* a day! Get that speed up to at least *+${goals}* to get there on time! You have *${days}* days left!`
|
||||
} else if (diff > 1000) {
|
||||
end = `You're slogging behind, my minions! Only *${speed}* a day? RiDONKulous! Get that speed up to at least *+${goals}* to get there on time! Hurry up!!! You have *${days}* days left to get there!`
|
||||
}
|
||||
// let end = regularEndQuotes[Math.floor(Math.random() * regularEndQuotes.length)]
|
||||
return start + "\n" + message + "\n" + end;
|
||||
}
|
||||
|
||||
module.exports = addQuotes;
|
Loading…
Reference in a new issue