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 = {
speed: 250, // ms
spread: 3.5,
noise: 2.2,
bands: 1,
};
type StreamWorkers = {
......@@ -42,7 +43,7 @@ export class StreamHandler {
// set stream option defaults
query.stream = defaults(query.stream, defaultQuery);
// 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]) {
const existing = this.workers[key];
......@@ -146,39 +147,47 @@ export class StreamWorker {
export class SignalWorker extends StreamWorker {
value: number;
bands = 1;
constructor(key: string, query: TestDataQuery, request: DataQueryRequest, observer: DataStreamObserver) {
super(key, query, request, observer);
setTimeout(() => {
this.stream.series = [this.initBuffer(query.refId)];
this.looper();
}, 10);
this.bands = query.stream.bands ? query.stream.bands : 0;
}
nextRow = (time: number) => {
const { spread, noise } = this.query;
this.value += (Math.random() - 0.5) * spread;
return [
time,
this.value, // Value
this.value - Math.random() * noise, // MIN
this.value + Math.random() * noise, // MAX
];
const row = [time, this.value];
for (let i = 0; i < this.bands; i++) {
const v = row[row.length - 1];
row.push(v - Math.random() * noise); // MIN
row.push(v + Math.random() * noise); // MAX
}
return row;
};
initBuffer(refId: string): SeriesData {
const { speed, buffer } = this.query;
const data = {
fields: [
{ name: 'Time', type: FieldType.time },
{ name: 'Value', type: FieldType.number },
{ name: 'Min', type: FieldType.number },
{ name: 'Max', type: FieldType.number },
],
fields: [{ name: 'Time', type: FieldType.time }, { name: 'Value', type: FieldType.number }],
rows: [],
refId,
name: 'Signal ' + refId,
} 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;
this.value = Math.random() * 100;
......
......@@ -78,6 +78,16 @@
step="0.1"
ng-change="ctrl.streamChanged()" />
</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'">
<label class="gf-form-label query-keyword">URL</label>
<input type="string"
......
......@@ -18,6 +18,7 @@ export interface StreamingQuery {
speed: number;
spread: number;
noise: number; // wiggle around the signal for min/max
bands?: number; // number of bands around the middle van
buffer?: number;
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