fixed invalid date bug. less bugs, crappier code
This commit is contained in:
parent
8169c7794c
commit
6d02676b77
1 changed files with 15 additions and 16 deletions
31
api/app.js
31
api/app.js
|
@ -105,12 +105,6 @@ function findMean(arr) {
|
||||||
return totalSum / arr.length;
|
return totalSum / arr.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function predictTime(goal) {
|
|
||||||
let daysLeft = (goal - latest) / averageSpeed
|
|
||||||
let unix = new Date(Date.now() + daysLeft * 86400000)
|
|
||||||
return moment(unix).fromNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addData(db, object) {
|
async function addData(db, object) {
|
||||||
base(db).create(object, function(err, record){
|
base(db).create(object, function(err, record){
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -137,21 +131,20 @@ async function report() {
|
||||||
let oldest = await fetchOldest(channel);
|
let oldest = await fetchOldest(channel);
|
||||||
let latest = await fetchLatest(channel);
|
let latest = await fetchLatest(channel);
|
||||||
let diff = latest - oldest;
|
let diff = latest - oldest;
|
||||||
addData('increase', {
|
// addData('increase', {
|
||||||
"Date": moment().subtract(1, "days").format("YYYY-MM-DD"),
|
// "Date": moment().subtract(1, "days").format("YYYY-MM-DD"),
|
||||||
"increase": diff,
|
// "increase": diff,
|
||||||
"stats": [
|
// "stats": [
|
||||||
"rec2XI8QAsPr7EMVB"
|
// "rec2XI8QAsPr7EMVB"
|
||||||
]
|
// ]
|
||||||
})
|
// })
|
||||||
let newStats = await getStats();
|
let newStats = await getStats();
|
||||||
console.log(newStats.fields);
|
|
||||||
averageSpeed = newStats.fields.average.toFixed(3);
|
averageSpeed = newStats.fields.average.toFixed(3);
|
||||||
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
||||||
let thousandsTime = predictTime(thousandsGoal)
|
let thousandsTime = predictTime(thousandsGoal, latest);
|
||||||
let tenThousandsGoal = Math.ceil(latest / 5000) * 5000;
|
let tenThousandsGoal = Math.ceil(latest / 5000) * 5000;
|
||||||
let pastThousandsGoal = Math.floor(latest / 1000) * 1000;
|
let pastThousandsGoal = Math.floor(latest / 1000) * 1000;
|
||||||
let tenThousandsTime = predictTime(tenThousandsGoal)
|
let tenThousandsTime = predictTime(tenThousandsGoal, latest);
|
||||||
let message =
|
let message =
|
||||||
"Nice! Today we've went from *" +
|
"Nice! Today we've went from *" +
|
||||||
oldest +
|
oldest +
|
||||||
|
@ -179,6 +172,12 @@ async function report() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function predictTime(goal, recent) {
|
||||||
|
let daysLeft = (goal - recent) / averageSpeed;
|
||||||
|
let unix = new Date(Date.now() + daysLeft * 86400000);
|
||||||
|
return moment(unix).fromNow();
|
||||||
|
}
|
||||||
|
|
||||||
app.event('message', async (body) => {
|
app.event('message', async (body) => {
|
||||||
try {
|
try {
|
||||||
let e = body.event;
|
let e = body.event;
|
||||||
|
|
Loading…
Add table
Reference in a new issue