diff --git a/.drone.yml b/.drone.yml index 2b5bc8c..6dc3021 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,6 +2,11 @@ kind: pipeline name: default steps: + - name: version + image: alpine + commands: + - echo "module.exports = '$(date)';" > version.js + - name: docker build image: plugins/docker settings: diff --git a/index.js b/index.js index 4c5b620..780144c 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ * Created by Timo Hocker , August 2020 */ +/* eslint-disable no-console */ // @ts-nocheck 'use strict'; @@ -15,9 +16,12 @@ const api = require ('./lib/api'); const http_proxy = require ('express-http-proxy'); const history_fallback = require ('connect-history-api-fallback'); const { argv } = require ('yargs'); +const version = require ('./version'); const is_dev = argv.dev; +console.log (`starting appreports build ${version}`); + (async () => { await db.init (is_dev); @@ -32,7 +36,6 @@ const is_dev = argv.dev; app.use (express.static ('dist')); app.listen (3000, () => { - // eslint-disable-next-line no-console console.log ('listening on 3000'); }); }) (); diff --git a/lib/api/dump.js b/lib/api/dump.js index ae854a5..621ecdc 100644 --- a/lib/api/dump.js +++ b/lib/api/dump.js @@ -1,3 +1,10 @@ +/* + * Copyright (C) Sapphirecode - All Rights Reserved + * This file is part of appreports which is released under GPL-3.0-or-later. + * See file 'LICENSE' for full license details. + * Created by Timo Hocker , August 2020 + */ + /* eslint-disable no-console */ 'use strict'; diff --git a/package.json b/package.json index 43f1cdd..1b3db04 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "express-http-proxy": "^1.6.2", "faker": "^4.1.0", "knex": "^0.21.2", - "simplex-noise": "^2.4.0", "sqlite3": "^5.0.0", "vue": "^2.6.11", "vue-chartjs": "^3.5.0", @@ -47,4 +46,4 @@ "name": "Timo Hocker", "email": "timo@scode.ovh" } -} +} \ No newline at end of file diff --git a/seeds/fake.js b/seeds/fake.js index c83c6fd..702a374 100644 --- a/seeds/fake.js +++ b/seeds/fake.js @@ -8,7 +8,6 @@ 'use strict'; const faker = require ('faker'); -const sn = require ('simplex-noise'); const apps = []; @@ -20,17 +19,23 @@ async function create_app (knex) { apps.push (id); } -function create_log (index, simplex) { +let last_t = 0; +let last_h = 0; + +function create_log (timestamp) { + last_t += faker.random.number (3) - 1; + last_h += faker.random.number (2) - 1; + const data = { - light: faker.random.number (), - temperature: simplex.noise2D (index * 0.1, 0), - humidity: simplex.noise2D (index * 0.1, 1000) + light: faker.random.number (10), + temperature: last_t, + humidity: last_h }; return { app_id: faker.random.arrayElement (apps), message: faker.random.words (), data: JSON.stringify (data), - timestamp: faker.date.recent () + timestamp }; } @@ -41,10 +46,11 @@ async function seed (knex) { // eslint-disable-next-line no-await-in-loop await create_app (knex); - const simplex = (new sn); - const log = (Array (20)) + const log = (Array (1000)) .fill (() => null) - .map ((a, index) => create_log (index, simplex)); + .map (() => faker.date.recent (30)) + .sort () + .map ((t) => create_log (t)); await knex.batchInsert ('log', log, 10); } diff --git a/src/App.vue b/src/App.vue index 17e0184..9b5909a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,11 +1,21 @@ diff --git a/src/components/ChartView.vue b/src/components/ChartView.vue index ca7df20..a90b0ee 100644 --- a/src/components/ChartView.vue +++ b/src/components/ChartView.vue @@ -38,9 +38,19 @@ export default { }, chart_options () { return { - scales: { - yAxes: this.yaxis.map ( - (y, index) => ({ id: index }) + animation: { duration: 0 }, + responsiveAnimationDuration: 0, + scales: { + yAxes: this.yaxis.map ( + (y, index) => { + const range = {}; + if (typeof y.min_value === 'number') + range.suggestedMin = y.min_value; + if (typeof y.max_value === 'number') + range.suggestedMax = y.max_value; + + return { id: index, ticks: range }; + } ) } }; diff --git a/src/components/ConfigEditor.vue b/src/components/ConfigEditor.vue index 98eaf70..3b4b0ac 100644 --- a/src/components/ConfigEditor.vue +++ b/src/components/ConfigEditor.vue @@ -116,7 +116,11 @@ export default { } }, data () { - return { temp: this.value }; + let val = this.value; + if (typeof val === 'undefined') + val = this.create_default (this.template); + + return { temp: val }; }, computed: { config: { @@ -124,8 +128,14 @@ export default { return this.temp; }, set (val) { - this.$emit ('input', val); - this.temp = val; + let mapped = val; + if (this.template.type === 'number') { + mapped = parseFloat (val); + if (isNaN (mapped)) + mapped = 0; + } + this.$emit ('input', mapped); + this.temp = mapped; } } }, diff --git a/src/default.js b/src/default.js index ac248f7..35f6a3f 100644 --- a/src/default.js +++ b/src/default.js @@ -25,16 +25,20 @@ export default { x: 'timestamp', y: [ { - label: 'temperature', - field: 'data/temperature', - color: '#ff0000', - fill: '#0000' + label: 'temperature', + field: 'data/temperature', + color: '#ff0000', + fill: '#0000', + min_value: 10, + max_value: 40 }, { - label: 'humidity', - field: 'data/humidity', - color: '#0000ff', - fill: '#0000' + label: 'humidity', + field: 'data/humidity', + color: '#0000ff', + fill: '#0000', + min_value: 100, + max_value: 0 }, { label: 'light', diff --git a/src/template.js b/src/template.js index 2c87444..4410838 100644 --- a/src/template.js +++ b/src/template.js @@ -68,7 +68,9 @@ export default { { type: 'string', name: 'label' }, { type: 'string', name: 'field' }, { type: 'string', name: 'color' }, - { type: 'string', name: 'fill' } + { type: 'string', name: 'fill' }, + { type: 'number', name: 'min_value' }, + { type: 'number', name: 'max_value' } ] } } diff --git a/version.js b/version.js new file mode 100644 index 0000000..e3d7874 --- /dev/null +++ b/version.js @@ -0,0 +1,10 @@ +/* + * Copyright (C) Sapphirecode - All Rights Reserved + * This file is part of appreports which is released under GPL-3.0-or-later. + * See file 'LICENSE' for full license details. + * Created by Timo Hocker , August 2020 + */ + +'use strict'; + +module.exports = 'development'; diff --git a/yarn.lock b/yarn.lock index 8c21dd9..f422882 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7940,11 +7940,6 @@ simple-swizzle@^0.2.2: dependencies: is-arrayish "^0.3.1" -simplex-noise@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/simplex-noise/-/simplex-noise-2.4.0.tgz#81b3458fb22dccc3bc8dd9a977c73797f86f523a" - integrity sha512-OjyDWm/QZjVbMrPxDVi9b2as+SeNn9EBXlrWVRlFW+TSyWMSXouDryXkQN0vf5YP+QZKobrmkvx1eQYPLtuqfw== - slash@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"