Commit 021f5351 by Ryan McKinley Committed by Torkel Ödegaard

TestData: add option to increase the number of test streams (#17789)

* variable number of points

* add variable number of bands
parent 0a3f977e
...@@ -18,6 +18,7 @@ export const defaultQuery: StreamingQuery = { ...@@ -18,6 +18,7 @@ export const defaultQuery: StreamingQuery = {
speed: 250, // ms speed: 250, // ms
spread: 3.5, spread: 3.5,
noise: 2.2, noise: 2.2,
bands: 1,
}; };
type StreamWorkers = { type StreamWorkers = {
...@@ -42,7 +43,7 @@ export class StreamHandler { ...@@ -42,7 +43,7 @@ export class StreamHandler {
// set stream option defaults // set stream option defaults
query.stream = defaults(query.stream, defaultQuery); query.stream = defaults(query.stream, defaultQuery);
// create stream key // create stream key
const key = req.dashboardId + '/' + req.panelId + '/' + query.refId; const key = req.dashboardId + '/' + req.panelId + '/' + query.refId + '@' + query.stream.bands;
if (this.workers[key]) { if (this.workers[key]) {
const existing = this.workers[key]; const existing = this.workers[key];
...@@ -146,39 +147,47 @@ export class StreamWorker { ...@@ -146,39 +147,47 @@ export class StreamWorker {
export class SignalWorker extends StreamWorker { export class SignalWorker extends StreamWorker {
value: number; value: number;
bands = 1;
constructor(key: string, query: TestDataQuery, request: DataQueryRequest, observer: DataStreamObserver) { constructor(key: string, query: TestDataQuery, request: DataQueryRequest, observer: DataStreamObserver) {
super(key, query, request, observer); super(key, query, request, observer);
setTimeout(() => { setTimeout(() => {
this.stream.series = [this.initBuffer(query.refId)]; this.stream.series = [this.initBuffer(query.refId)];
this.looper(); this.looper();
}, 10); }, 10);
this.bands = query.stream.bands ? query.stream.bands : 0;
} }
nextRow = (time: number) => { nextRow = (time: number) => {
const { spread, noise } = this.query; const { spread, noise } = this.query;
this.value += (Math.random() - 0.5) * spread; this.value += (Math.random() - 0.5) * spread;
return [ const row = [time, this.value];
time, for (let i = 0; i < this.bands; i++) {
this.value, // Value const v = row[row.length - 1];
this.value - Math.random() * noise, // MIN row.push(v - Math.random() * noise); // MIN
this.value + Math.random() * noise, // MAX row.push(v + Math.random() * noise); // MAX
]; }
return row;
}; };
initBuffer(refId: string): SeriesData { initBuffer(refId: string): SeriesData {
const { speed, buffer } = this.query; const { speed, buffer } = this.query;
const data = { const data = {
fields: [ fields: [{ name: 'Time', type: FieldType.time }, { name: 'Value', type: FieldType.number }],
{ name: 'Time', type: FieldType.time },
{ name: 'Value', type: FieldType.number },
{ name: 'Min', type: FieldType.number },
{ name: 'Max', type: FieldType.number },
],
rows: [], rows: [],
refId, refId,
name: 'Signal ' + refId, name: 'Signal ' + refId,
} as SeriesData; } as SeriesData;
for (let i = 0; i < this.bands; i++) {
const suffix = this.bands > 1 ? ` ${i + 1}` : '';
data.fields.push({ name: 'Min' + suffix, type: FieldType.number });
data.fields.push({ name: 'Max' + suffix, type: FieldType.number });
}
console.log('START', data);
const request = this.stream.request; const request = this.stream.request;
this.value = Math.random() * 100; this.value = Math.random() * 100;
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<select <select
ng-model="ctrl.target.stream.type" ng-model="ctrl.target.stream.type"
class="gf-form-input" class="gf-form-input"
ng-options="type for type in ['signal','logs', 'fetch']" ng-options="type for type in ['signal','logs', 'fetch']"
ng-change="ctrl.streamChanged()" /> ng-change="ctrl.streamChanged()" />
</select> </select>
</div> </div>
...@@ -78,6 +78,16 @@ ...@@ -78,6 +78,16 @@
step="0.1" step="0.1"
ng-change="ctrl.streamChanged()" /> ng-change="ctrl.streamChanged()" />
</div> </div>
<div class="gf-form" ng-if="ctrl.target.stream.type === 'signal'">
<label class="gf-form-label query-keyword">Bands</label>
<input type="number"
class="gf-form-input width-5"
placeholder="bands"
ng-model="ctrl.target.stream.bands"
min="0"
step="1"
ng-change="ctrl.streamChanged()" />
</div>
<div class="gf-form gf-form--grow" ng-if="ctrl.target.stream.type === 'fetch'"> <div class="gf-form gf-form--grow" ng-if="ctrl.target.stream.type === 'fetch'">
<label class="gf-form-label query-keyword">URL</label> <label class="gf-form-label query-keyword">URL</label>
<input type="string" <input type="string"
......
...@@ -18,6 +18,7 @@ export interface StreamingQuery { ...@@ -18,6 +18,7 @@ export interface StreamingQuery {
speed: number; speed: number;
spread: number; spread: number;
noise: number; // wiggle around the signal for min/max noise: number; // wiggle around the signal for min/max
bands?: number; // number of bands around the middle van
buffer?: number; buffer?: number;
url?: string; // the Fetch URL url?: string; // the Fetch URL
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment