Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/alkerezs/implement column descriptors #70

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.14.0](https://github.com/ni/systemlink-grafana-plugins/compare/v3.13.0...v3.14.0) (2024-09-19)


### Features

* **asset:** add calibration forecast property only row formatting ([#68](https://github.com/ni/systemlink-grafana-plugins/issues/68)) ([162d782](https://github.com/ni/systemlink-grafana-plugins/commit/162d7826c9219ccfc1fc807aae2a61ea0b6b031d))

## [3.13.0](https://github.com/ni/systemlink-grafana-plugins/compare/v3.12.1...v3.13.0) (2024-09-11)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "systemlink-grafana-plugins",
"version": "3.13.0",
"version": "3.14.0",
"description": "Plugins for visualizing data from SystemLink services",
"private": true,
"scripts": {
Expand Down
103 changes: 52 additions & 51 deletions src/datasources/asset-calibration/AssetCalibrationDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AssetCalibrationQuery,
AssetCalibrationTimeBasedGroupByType,
CalibrationForecastResponse,
ColumnDescriptorType,
} from "./types";

let datastore: AssetCalibrationDataSource, backendServer: MockProxy<BackendSrv>
Expand All @@ -23,83 +24,83 @@ beforeEach(() => {

const monthGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Month", values: ["2022-01-01T00:00:00.0000000Z", "2022-02-01T00:00:00.0000000Z", "2022-03-01T00:00:00.0000000Z"] },
{ name: "Assets", values: [1, 0, 3] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: ["2022-01-01T00:00:00.0000000Z", "2022-02-01T00:00:00.0000000Z", "2022-03-01T00:00:00.0000000Z"], columnDescriptors: [{ value: "Month", type: ColumnDescriptorType.Time }] },
kkerezsi marked this conversation as resolved.
Show resolved Hide resolved
{ name: "", values: [1, 0, 3], columnDescriptors: [{ value: "Assets", type: ColumnDescriptorType.Count }] }
]
}
}

const weekGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
const dayGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Day", values: ["2022-01-01T00:00:00.0000000Z", "2022-01-02T00:00:00.0000000Z", "2022-01-03T00:00:00.0000000Z"] },
{ name: "Assets", values: [1, 2, 2] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: ["2022-01-01T00:00:00.0000000Z", "2022-01-02T00:00:00.0000000Z", "2022-01-03T00:00:00.0000000Z"], columnDescriptors: [{ value: "Day", type: ColumnDescriptorType.Time }] },
{ name: "", values: [1, 2, 2], columnDescriptors: [{ value: "Assets", type: ColumnDescriptorType.Count }] }
]
}
}

const dayGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
const weekGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Week", values: ["2022-01-03T00:00:00.0000000Z", "2022-01-10T00:00:00.0000000Z", "2022-01-17T00:00:00.0000000Z"] },
{ name: "Assets", values: [1, 2, 2] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: ["2022-01-03T00:00:00.0000000Z", "2022-01-10T00:00:00.0000000Z", "2022-01-17T00:00:00.0000000Z"], columnDescriptors: [{ value: "Week", type: ColumnDescriptorType.Time }] },
{ name: "", values: [1, 2, 2], columnDescriptors: [{ value: "Assets", type: ColumnDescriptorType.Count }] }
]
}
}

const locationGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Location1", values: [1] },
{ name: "Location2", values: [2] },
{ name: "Location3", values: [3] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: [1], columnDescriptors: [{ value: "Location1", type: ColumnDescriptorType.StringValue }] },
{ name: "", values: [2], columnDescriptors: [{ value: "Location2", type: ColumnDescriptorType.StringValue }] },
{ name: "", values: [3], columnDescriptors: [{ value: "Location3", type: ColumnDescriptorType.StringValue }] }
]
}
}

const modelGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Model1", values: [1] },
{ name: "Model2", values: [2] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: [1], columnDescriptors: [{ value: "Model1", type: ColumnDescriptorType.StringValue }] },
{ name: "", values: [2], columnDescriptors: [{ value: "Model2", type: ColumnDescriptorType.StringValue }] }
]
}
}

const emptyGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
]
}
calibrationForecast: {
columns: [
]
}
}

const modelLocationGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Model1 - Localtion1", values: [1] },
{ name: "Model2 - Localtion1", values: [2] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: [1], columnDescriptors: [{ value: "Model1", type: ColumnDescriptorType.StringValue }, { value: "Localtion1", type: ColumnDescriptorType.StringValue }] },
kkerezsi marked this conversation as resolved.
Show resolved Hide resolved
{ name: "", values: [2], columnDescriptors: [{ value: "Model2", type: ColumnDescriptorType.StringValue }, { value: "Localtion1", type: ColumnDescriptorType.StringValue }] }
]
}
}

const monthLocationGroupCalibrationForecastResponseMock: CalibrationForecastResponse =
{
calibrationForecast: {
columns: [
{ name: "Month", values: ["2022-01-01T00:00:00.0000000Z", "2022-02-01T00:00:00.0000000Z", "2022-03-01T00:00:00.0000000Z"] },
{ name: "Location1", values: [1, 2, 3] },
{ name: "Location2", values: [2, 4, 1] },
{ name: "Location3", values: [4, 3, 1] },
]
}
calibrationForecast: {
columns: [
{ name: "", values: ["2022-01-01T00:00:00.0000000Z", "2022-02-01T00:00:00.0000000Z", "2022-03-01T00:00:00.0000000Z"], columnDescriptors: [{ value: "Month", type: ColumnDescriptorType.Time }] },
{ name: "", values: [1, 2, 3], columnDescriptors: [{ value: "Location1", type: ColumnDescriptorType.StringValue }] },
{ name: "", values: [2, 4, 1], columnDescriptors: [{ value: "Location2", type: ColumnDescriptorType.StringValue }] },
{ name: "", values: [4, 3, 1], columnDescriptors: [{ value: "Location3", type: ColumnDescriptorType.StringValue }] }
]
}
}

const monthBasedCalibrationForecastQueryMock: AssetCalibrationQuery = {
Expand Down
12 changes: 10 additions & 2 deletions src/datasources/asset-calibration/AssetCalibrationDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AssetModel,
AssetsResponse,
CalibrationForecastResponse,
FieldDTOWithDescriptor,
} from './types';
import { SystemMetadata } from "../system/types";
import { defaultOrderBy, defaultProjection } from "../system/constants";
Expand Down Expand Up @@ -61,6 +62,7 @@ export class AssetCalibrationDataSource extends DataSourceBase<AssetCalibrationQ

processResultsGroupedByTime(result: DataFrameDTO) {
result.fields.forEach(field => {
field.name = this.createColumnNameFromDrescriptor(field as FieldDTOWithDescriptor);
switch (field.name) {
case AssetCalibrationForecastKey.Day:
field.values = field.values!.map(this.formatDateForDay)
Expand All @@ -83,13 +85,19 @@ export class AssetCalibrationDataSource extends DataSourceBase<AssetCalibrationQ
formattedFields.push({ name: "Assets", values: [] } as FieldDTO);

for (let columnIndex = 0; columnIndex < result.fields.length; columnIndex++) {
formattedFields[0].values!.push(result.fields[columnIndex].name)
formattedFields[1].values!.push(result.fields[columnIndex].values?.at(0))
const columnName = this.createColumnNameFromDrescriptor(result.fields[columnIndex] as FieldDTOWithDescriptor);
const columnValue = result.fields[columnIndex].values?.at(0);
formattedFields[0].values!.push(columnName);
formattedFields[1].values!.push(columnValue);
}

result.fields = formattedFields;
}

createColumnNameFromDrescriptor(field: FieldDTOWithDescriptor): string {
kkerezsi marked this conversation as resolved.
Show resolved Hide resolved
return field.columnDescriptors.map(descriptor => descriptor.value).join(' - ');
}

formatDateForDay(date: string): string {
return new Date(date).toISOString().split('T')[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ exports[`queries asset calibration forecast with day groupBy 1`] = `
{
"fields": [
{
"name": "Week",
"columnDescriptors": [
{
"type": "Time",
"value": "Day",
},
],
"name": "Day",
"values": [
"2022-01-03 : 2022-01-09",
"2022-01-10 : 2022-01-16",
"2022-01-17 : 2022-01-23",
"2022-01-01",
"2022-01-02",
"2022-01-03",
],
},
{
"columnDescriptors": [
{
"type": "Count",
"value": "Assets",
},
],
"name": "Assets",
"values": [
1,
Expand All @@ -31,6 +43,12 @@ exports[`queries asset calibration forecast with month groupBy 1`] = `
{
"fields": [
{
"columnDescriptors": [
{
"type": "Time",
"value": "Month",
},
],
"name": "Month",
"values": [
"January 2022",
Expand All @@ -39,6 +57,12 @@ exports[`queries asset calibration forecast with month groupBy 1`] = `
],
},
{
"columnDescriptors": [
{
"type": "Count",
"value": "Assets",
},
],
"name": "Assets",
"values": [
1,
Expand All @@ -57,14 +81,26 @@ exports[`queries asset calibration forecast with week groupBy 1`] = `
{
"fields": [
{
"name": "Day",
"columnDescriptors": [
{
"type": "Time",
"value": "Week",
},
],
"name": "Week",
"values": [
"2022-01-01",
"2022-01-02",
"2022-01-03",
"2022-01-03 : 2022-01-09",
"2022-01-10 : 2022-01-16",
"2022-01-17 : 2022-01-23",
],
},
{
"columnDescriptors": [
{
"type": "Count",
"value": "Assets",
},
],
"name": "Assets",
"values": [
1,
Expand Down Expand Up @@ -157,6 +193,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
{
"fields": [
{
"columnDescriptors": [
{
"type": "Time",
"value": "Month",
},
],
"name": "Month",
"values": [
"January 2022",
Expand All @@ -165,6 +207,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
],
},
{
"columnDescriptors": [
{
"type": "StringValue",
"value": "Location1",
},
],
"name": "Location1",
"values": [
1,
Expand All @@ -173,6 +221,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
],
},
{
"columnDescriptors": [
{
"type": "StringValue",
"value": "Location2",
},
],
"name": "Location2",
"values": [
2,
Expand All @@ -181,6 +235,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
],
},
{
"columnDescriptors": [
{
"type": "StringValue",
"value": "Location3",
},
],
"name": "Location3",
"values": [
4,
Expand Down
18 changes: 17 additions & 1 deletion src/datasources/asset-calibration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,21 @@ export enum AssetFilterProperties {
}

export interface CalibrationForecastModel {
columns: FieldDTO[],
columns: FieldDTOWithDescriptor[],
}

export interface FieldDTOWithDescriptor extends FieldDTO {
columnDescriptors: ColumnDescriptor[]
}

export interface ColumnDescriptor {
value: string
type: string
kkerezsi marked this conversation as resolved.
Show resolved Hide resolved
kkerezsi marked this conversation as resolved.
Show resolved Hide resolved
}

export enum ColumnDescriptorType {
Time = "Time",
Count = "Count",
StringValue = "StringValue",
MinionId = "MinionId",
}