From ade5b933d8aaae1cee87c6bba313948a63d853eb Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Sun, 23 Aug 2020 14:31:15 +0200 Subject: [PATCH] better timestamps, adapt default config --- lib/db/index.js | 13 ++++++++----- seeds/fake.js | 6 +++--- src/default.js | 13 ++++++++----- src/store/index.js | 7 +++++++ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/db/index.js b/lib/db/index.js index 9e9a57e..73c9e99 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -5,6 +5,8 @@ * Created by Timo Hocker , August 2020 */ +/* eslint-disable no-sync */ + 'use strict'; const knex = require ('knex'); @@ -13,14 +15,15 @@ const fs = require ('fs'); let db = null; async function init (use_fake_seed) { - // eslint-disable-next-line no-sync - if (use_fake_seed && fs.existsSync ('db.sqlite')) - // eslint-disable-next-line no-sync - fs.unlinkSync ('db.sqlite'); + if (!fs.existsSync ('data')) + fs.mkdirSync ('data'); + + if (use_fake_seed && fs.existsSync ('data/db.sqlite')) + fs.unlinkSync ('data/db.sqlite'); db = knex ({ client: 'sqlite', - connection: { filename: 'db.sqlite' }, + connection: { filename: 'data/db.sqlite' }, migrations: { directory: 'migrations' }, seeds: { directory: 'seeds' }, useNullAsDefault: true diff --git a/seeds/fake.js b/seeds/fake.js index d313c1a..c83c6fd 100644 --- a/seeds/fake.js +++ b/seeds/fake.js @@ -22,9 +22,9 @@ async function create_app (knex) { function create_log (index, simplex) { const data = { - num1: faker.random.number (), - num2: simplex.noise2D (index * 0.1, 0), - num3: simplex.noise2D (index * 0.1, 1000) + light: faker.random.number (), + temperature: simplex.noise2D (index * 0.1, 0), + humidity: simplex.noise2D (index * 0.1, 1000) }; return { app_id: faker.random.arrayElement (apps), diff --git a/src/default.js b/src/default.js index 28cc939..ac248f7 100644 --- a/src/default.js +++ b/src/default.js @@ -9,6 +9,11 @@ export default { sources: [ { name: 'default', + limit: 140, + offset: 0 + }, + { + name: 'secondary', limit: 10, offset: 0 } @@ -40,13 +45,11 @@ export default { ] }, { - source: 'default', + source: 'secondary', type: 'table', columns: [ - 'id', - 'message', - 'data', - 'timestamp' + 'timestamp', + 'data' ] } ] diff --git a/src/store/index.js b/src/store/index.js index c22fd3e..121a0d7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -41,6 +41,13 @@ export default new Vuex.Store ({ .then ((res) => res.json ()) .then ((json) => json.map ((entry) => { entry.data = JSON.parse (entry.data); + const time + = (/(?[0-9]+-[0-9]+-[0-9]+)T(?[0-9]+:[0-9]+:[0-9]+)/u) + .exec ( + new Date (entry.timestamp) + .toISOString () + ); + entry.timestamp = `${time.groups.y} ${time.groups.t}`; return entry; })); logs[source.name] = log;