2020-09-18 21:00:59 +02:00
|
|
|
import NeDB from 'nedb-promises'
|
2020-09-19 01:16:43 +02:00
|
|
|
import day from 'dayjs'
|
2020-09-18 21:00:59 +02:00
|
|
|
|
|
|
|
export const Logs = NeDB.create({
|
|
|
|
filename: 'logs.db',
|
|
|
|
autoload: true,
|
|
|
|
})
|
2020-09-19 01:16:43 +02:00
|
|
|
|
|
|
|
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 }
|
|
|
|
)
|
|
|
|
}
|