Skip to content

Commit

Permalink
Merge cf6daf2 into 3869526
Browse files Browse the repository at this point in the history
  • Loading branch information
peuter committed Aug 14, 2023
2 parents 3869526 + cf6daf2 commit 1b31171
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -84,7 +84,7 @@
"xml-js": "^1.6.11"
},
"dependencies": {
"@qooxdoo/framework": "^7.6.0",
"@qooxdoo/framework": "^7.6.1",
"@sentry/browser": "^7.60.1",
"@sentry/tracing": "^7.60.1",
"crc-32": "^1.2.2",
Expand Down
40 changes: 38 additions & 2 deletions source/class/cv/data/Simulation.js
Expand Up @@ -230,6 +230,36 @@ qx.Class.define('cv.data.Simulation', {
if (options) {
let end = Date.now();
let start = Date.now();
let resolution = 60 * 1000;
const dynamicResolution = !Object.prototype.hasOwnProperty.call(generator, 'resolution');
if (dynamicResolution) {
switch (options.series) {
case 'hour':
// every minute
resolution = 60 * 1000;
break;

case 'day':
// every hour
resolution = 60 * 60 * 1000;
break;

case 'week':
// every 6hs
resolution = 6 * 60 * 60 * 1000;
break;
case 'month':
// daily
resolution = 24 * 60 * 60 * 1000;
break;
case 'year':
// monthly
resolution = 30 * 24 * 60 * 60 * 1000;
break;
}
} else {
resolution = generator.resolution;
}
if (options.start) {
if (/^\d{10}$/.test(options.start)) {
// timestamp without millis
Expand All @@ -240,7 +270,7 @@ qx.Class.define('cv.data.Simulation', {
start = new Date(parseInt(options.start)).getTime();
end = new Date(parseInt(options.end)).getTime();
} else {
const match = /end-(\d+)(hour|day|month)/.exec(options.start);
const match = /end-(\d+)(hour|day|week|month|year)/.exec(options.start);
if (match) {
let interval = 0;
switch (match[2]) {
Expand All @@ -250,17 +280,23 @@ qx.Class.define('cv.data.Simulation', {
case 'day':
interval = 24 * 60 * 60 * 1000;
break;
case 'week':
interval = 6 + 24 * 60 * 60 * 1000;
break;
case 'month':
// this is not really precise, but good enough to fake some data
interval = 30 * 24 * 60 * 60 * 1000;
break;
case 'year':
interval = 365 * 24 * 60 * 60 * 1000;
break;
}
start -= parseInt(match[1]) * interval;
}
}
}
let val = 0;
for (let i = start; i <= end; i += generator.resolution) {
for (let i = start; i <= end; i += resolution) {
val = generator.targetValue + (Math.random() - 0.5) * generator.deviation * 2;
data.push([i, val]);
}
Expand Down
6 changes: 5 additions & 1 deletion source/class/cv/io/Mockup.js
Expand Up @@ -213,7 +213,11 @@ qx.Class.define('cv.io.Mockup', {
if (name === 'charts' && map && map.src) {
if (map.src.startsWith('generator:')) {
// the generator also might need the start/end values
return basePath + map.src + '?start=' + map.start + '&end=' + map.end;
let path = basePath + map.src + '?';
for (const key in map) {
path += `&${key}=${map[key]}`;
}
return path;
}
return basePath + map.src;
}
Expand Down
8 changes: 5 additions & 3 deletions source/class/cv/io/timeseries/DemoSource.js
Expand Up @@ -41,12 +41,14 @@ qx.Class.define('cv.io.timeseries.DemoSource', {
};
},

getRequestConfig(start, end) {
getRequestConfig(start, end, series, offset) {
const config = this._baseRequestConfig;
config.url = this._client.getResourcePath('charts', {
src: this._src,
start: start,
end: end
start,
end,
series,
offset
});
return config;
},
Expand Down
23 changes: 21 additions & 2 deletions source/class/cv/ui/structure/tile/components/Chart.js
Expand Up @@ -94,7 +94,7 @@ qx.Class.define('cv.ui.structure.tile.components.Chart', {
currentSeries: {
check: ['hour', 'day', 'week', 'month', 'year'],
init: 'day',
apply: '__updateTimeRange'
apply: '_applyCurrentSeries'
},

currentPeriod: {
Expand Down Expand Up @@ -518,6 +518,25 @@ qx.Class.define('cv.ui.structure.tile.components.Chart', {
this.__updateTitle();
},

_applyCurrentSeries(series) {
const currentSelection = this.getHeader('.popup.series > cv-option[selected="selected"]');
let alreadySelected = false;
if (currentSelection) {
if (currentSelection.getAttribute('key') !== series) {
currentSelection.removeAttribute('selected');
} else {
alreadySelected = true;
}
}
if (!alreadySelected) {
const newSelection = this.getHeader(`.popup.series > cv-option[key="${series}"]`);
if (newSelection) {
newSelection.setAttribute('selected', 'selected');
}
}
this.__updateTimeRange();
},

__updateTimeRange() {
const series = this.getCurrentSeries();

Expand Down Expand Up @@ -580,7 +599,7 @@ qx.Class.define('cv.ui.structure.tile.components.Chart', {
let startTs = Math.round(periodStart.getTime()/1000);
let endTs = Math.round(end.getTime()/1000);
if (this._element.getAttribute('background') === 'true' || !this._element.hasAttribute('selection')) {
// when have no nagivation, we can just use the old relative time range now - interval
// when have no navigation, we can just use the old relative time range now - interval
startTs = endTs - interval;
}
this.setStartTime(startTs);
Expand Down
3 changes: 1 addition & 2 deletions source/resource/demo/media/demo_tile_testmode_data.json
Expand Up @@ -173,8 +173,7 @@
"address": "1/4/25",
"targetValue": 200,
"deviation": 20,
"interval": 2000,
"resolution": 60000
"interval": 2000
}
},
"simulations": {
Expand Down
17 changes: 9 additions & 8 deletions source/rest/manager/composer.json
Expand Up @@ -9,16 +9,16 @@
],
"require": {
"php": "^7.4 || ^8.0",
"slim/slim": "^4.5.0",
"slim/slim": "^4.12.0",
"dyorg/slim-token-authentication": "dev-slim4",
"ybelenko/openapi-data-mocker": "^1.0",
"ybelenko/openapi-data-mocker-server-middleware": "^1.0",
"slim/psr7": "^1.1.0"
"ybelenko/openapi-data-mocker": "^1.1",
"ybelenko/openapi-data-mocker-server-middleware": "^1.2",
"slim/psr7": "^1.6.1"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"overtrue/phplint": "^2.0.2",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^8.0 || ^9.6.10",
"overtrue/phplint": "^2.4.1",
"squizlabs/php_codesniffer": "^3.7.2"
},
"autoload": {
"psr-4": { "OpenAPIServer\\": [
Expand All @@ -36,5 +36,6 @@
"test-models": "phpunit --testsuite Models",
"phpcs": "phpcs",
"phplint": "phplint ./ --exclude=vendor"
}
},
"type": "project"
}

0 comments on commit 1b31171

Please sign in to comment.