Skip to content

Commit

Permalink
Fix digital states and added recorded default count
Browse files Browse the repository at this point in the history
  • Loading branch information
coderReview committed Jul 7, 2022
1 parent 48f2580 commit 5515b41
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"screenshots": [],
"version": "2.1.0",
"updated": "2022-06-28"
"updated": "2022-07-07"
},
"dependencies": {
"grafanaDependency": ">=8.4.0",
Expand Down
3 changes: 1 addition & 2 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ export class PIWebAPIQueryEditor extends PureComponent<Props, State> {
this.initialLoad(false);
};
componentDidUpdate = () => {
console.log(this.props.data);
if (this.props.data?.state === 'Done' && !!this.props.data?.request?.scopedVars && !this.scopedVarsDone) {
this.scopedVarsDone = true;
this.initialLoad(true);
Expand Down Expand Up @@ -1075,7 +1074,7 @@ export class PIWebAPIQueryEditor extends PureComponent<Props, State> {
})
}
type="number"
placeholder="150000"
placeholder="1000"
/>
</InlineField>
<InlineField label="Recorded Values" labelWidth={LABEL_WIDTH}>
Expand Down
46 changes: 29 additions & 17 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,23 +559,14 @@ export class PiWebAPIDatasource extends DataSourceApi<PIWebAPIQuery, PIWebAPIDat
*
*/
parsePiPointValue(value: any, target: any, isSummary: boolean) {
var num = !isSummary && typeof value.Value === 'object' ? Number(value.Value.Value) : Number(value.Value);
var text = value.Value;
let num = !isSummary && typeof value.Value === 'object' ? value.Value?.Value : value.Value;

if (!value.Good || (target.digitalStates && target.digitalStates.enable)) {
if (!value.Good || !!target.digitalStates?.enable) {
num = !isSummary && typeof value.Value === 'object' ? value.Value.Name : value.Name;
return [num.trim(), new Date(value.Timestamp).getTime()];
}

if (!!isSummary && target.summary.interval === '') {
if (target.digitalStates && target.digitalStates.enable) {
return [num, new Date(value.Timestamp).getTime()];
} else if (!value.Good) {
return [num, new Date(value.Timestamp).getTime()];
} else {
return [!isNaN(num) ? num : 0, new Date(target.endTime).getTime()];
}
}
return [!isNaN(num) ? num : text, new Date(value.Timestamp).getTime()];
return [this.checkNumber(num) ? Number(num) : num.trim(), new Date(value.Timestamp).getTime()];
}

/**
Expand Down Expand Up @@ -657,6 +648,12 @@ export class PiWebAPIDatasource extends DataSourceApi<PIWebAPIQuery, PIWebAPIDat

/** PRIVATE SECTION */

/**
* Check if all items are selected.
*
* @param {any} current the current variable selection
* @return {boolean} true if all value is selected, false otherwise
*/
private isAllSelected(current: any): boolean {
if (!current) {
return false;
Expand All @@ -667,6 +664,16 @@ export class PiWebAPIDatasource extends DataSourceApi<PIWebAPIQuery, PIWebAPIDat
return current.text === 'All';
}

/**
* Check if the value is a number.
*
* @param {any} number the value to check
* @returns {boolean} true if the value is a number, false otherwise
*/
private checkNumber(number: any): boolean {
return typeof number === 'number' && !Number.isNaN(number) && Number.isFinite(number);
}

/**
* Returns a new element path list based on the panel variables.
*
Expand Down Expand Up @@ -712,12 +719,13 @@ export class PiWebAPIDatasource extends DataSourceApi<PIWebAPIQuery, PIWebAPIDat
if (splitPath.length === 0) {
return '';
}
splitPath = splitPath[0].split('\\');
const splitStr = splitPath.length === 0 ? '' : splitPath.pop() ?? '';
if (elementPathArray.length === 0) {
return '';
}
return (elementPathArray.find((e) => path.indexOf(e.path) >= 0)?.variable ?? '') + '|' + splitStr;
splitPath = splitPath[0].split('\\');
const splitStr = splitPath.length === 0 ? '' : splitPath.pop() ?? '';
const foundElement = elementPathArray.find((e) => path.indexOf(e.path) >= 0)?.variable;
return foundElement ? foundElement + '|' + splitStr : splitStr;
}

/**
Expand Down Expand Up @@ -771,7 +779,11 @@ export class PiWebAPIDatasource extends DataSourceApi<PIWebAPIQuery, PIWebAPIDat
} else if (target.interpolate && target.interpolate.enable) {
url += '/interpolated' + timeRange + '&interval=' + intervalTime;
} else if (target.recordedValues && target.recordedValues.enable) {
url += '/recorded' + timeRange + '&maxCount=' + target.recordedValues.maxNumber;
const maxNumber =
target.recordedValues.maxNumber && !isNaN(target.recordedValues.maxNumber)
? target.recordedValues.maxNumber
: 1000;
url += '/recorded' + timeRange + '&maxCount=' + maxNumber;
} else {
url += '/plot' + timeRange + '&intervals=' + query.maxDataPoints;
}
Expand Down

0 comments on commit 5515b41

Please sign in to comment.