diff --git a/src/datasources/asset-calibration/AssetCalibrationDataSource.test.ts b/src/datasources/asset-calibration/AssetCalibrationDataSource.test.ts index 0effd8c..f86a1d1 100644 --- a/src/datasources/asset-calibration/AssetCalibrationDataSource.test.ts +++ b/src/datasources/asset-calibration/AssetCalibrationDataSource.test.ts @@ -13,6 +13,7 @@ import { AssetCalibrationQuery, AssetCalibrationTimeBasedGroupByType, CalibrationForecastResponse, + ColumnDescriptorType, } from "./types"; let datastore: AssetCalibrationDataSource, backendServer: MockProxy @@ -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 }] }, + { 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: "Location1", type: ColumnDescriptorType.StringValue }] }, + { name: "", values: [2], columnDescriptors: [{ value: "Model2", type: ColumnDescriptorType.StringValue }, { value: "Location1", 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 = { diff --git a/src/datasources/asset-calibration/AssetCalibrationDataSource.ts b/src/datasources/asset-calibration/AssetCalibrationDataSource.ts index 249b95b..1d2d11f 100644 --- a/src/datasources/asset-calibration/AssetCalibrationDataSource.ts +++ b/src/datasources/asset-calibration/AssetCalibrationDataSource.ts @@ -14,6 +14,7 @@ import { AssetModel, AssetsResponse, CalibrationForecastResponse, + FieldDTOWithDescriptor, } from './types'; import { SystemMetadata } from "../system/types"; import { defaultOrderBy, defaultProjection } from "../system/constants"; @@ -61,6 +62,7 @@ export class AssetCalibrationDataSource extends DataSourceBase { + field.name = this.createColumnNameFromDescriptor(field as FieldDTOWithDescriptor); switch (field.name) { case AssetCalibrationForecastKey.Day: field.values = field.values!.map(this.formatDateForDay) @@ -83,13 +85,19 @@ export class AssetCalibrationDataSource extends DataSourceBase descriptor.value).join(' - '); + } + formatDateForDay(date: string): string { return new Date(date).toISOString().split('T')[0]; } diff --git a/src/datasources/asset-calibration/__snapshots__/AssetCalibrationDataSource.test.ts.snap b/src/datasources/asset-calibration/__snapshots__/AssetCalibrationDataSource.test.ts.snap index 6a01cfe..cb730c4 100644 --- a/src/datasources/asset-calibration/__snapshots__/AssetCalibrationDataSource.test.ts.snap +++ b/src/datasources/asset-calibration/__snapshots__/AssetCalibrationDataSource.test.ts.snap @@ -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, @@ -31,6 +43,12 @@ exports[`queries asset calibration forecast with month groupBy 1`] = ` { "fields": [ { + "columnDescriptors": [ + { + "type": "Time", + "value": "Month", + }, + ], "name": "Month", "values": [ "January 2022", @@ -39,6 +57,12 @@ exports[`queries asset calibration forecast with month groupBy 1`] = ` ], }, { + "columnDescriptors": [ + { + "type": "Count", + "value": "Assets", + }, + ], "name": "Assets", "values": [ 1, @@ -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, @@ -111,8 +147,8 @@ exports[`queries calibration forecast with model and location groupBy 1`] = ` { "name": "Group", "values": [ - "Model1 - Localtion1", - "Model2 - Localtion1", + "Model1 - Location1", + "Model2 - Location1", ], }, { @@ -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", @@ -165,6 +207,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = ` ], }, { + "columnDescriptors": [ + { + "type": "StringValue", + "value": "Location1", + }, + ], "name": "Location1", "values": [ 1, @@ -173,6 +221,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = ` ], }, { + "columnDescriptors": [ + { + "type": "StringValue", + "value": "Location2", + }, + ], "name": "Location2", "values": [ 2, @@ -181,6 +235,12 @@ exports[`queries calibration forecast with month and location groupBy 1`] = ` ], }, { + "columnDescriptors": [ + { + "type": "StringValue", + "value": "Location3", + }, + ], "name": "Location3", "values": [ 4, diff --git a/src/datasources/asset-calibration/types.ts b/src/datasources/asset-calibration/types.ts index 4d3e0fc..7e07760 100644 --- a/src/datasources/asset-calibration/types.ts +++ b/src/datasources/asset-calibration/types.ts @@ -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: ColumnDescriptorType +} + +export enum ColumnDescriptorType { + Time = "Time", + Count = "Count", + StringValue = "StringValue", + MinionId = "MinionId", }