lots of stuff

This commit is contained in:
2020-09-19 01:16:43 +02:00
parent 36c5ff9a73
commit f469d78ce3
15 changed files with 351 additions and 1133 deletions

View File

@@ -1,6 +1,29 @@
import NeDB from 'nedb-promises'
import day from 'dayjs'
export const Logs = NeDB.create({
filename: 'logs.db',
autoload: true,
})
export function normalizeTimestamp(timestamp) {
// Normalize every dato to 15 minutes
const t = day(timestamp)
const min = t.minute()
return t
.millisecond(0)
.second(0)
.minute(min - (min % 15))
.toDate()
}
export async function insertLog({ timestamp, host, seconds }) {
Logs.update(
{
host,
timestamp,
},
{ $inc: { seconds } },
{ upsert: true }
)
}