Backend changes for Displaying consumption and production.
MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
+import SiteArea, { SiteAreaValueTypes } from '../../../../types/SiteArea';
import { ActionsResponse } from '../../../../types/GlobalType';
import AppAuthError from '../../../../exception/AppAuthError';
@@ -14,7 +15,6 @@ import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
import OCPPUtils from '../../../ocpp/utils/OCPPUtils';
import { ServerAction } from '../../../../types/Server';
-import SiteArea from '../../../../types/SiteArea';
import { SiteAreaDataResult } from '../../../../types/DataResult';
import SiteAreaSecurity from './security/SiteAreaSecurity';
import SiteAreaStorage from '../../../../storage/mongodb/SiteAreaStorage';
@@ -255,14 +255,27 @@ export default class SiteAreaService {
// Check and Get Site Area
const siteArea = await UtilsService.checkAndGetSiteAreaAuthorization(
req.tenant, req.user, filteredRequest.SiteAreaID, Action.READ, action);
- // Get the ConsumptionValues
- const consumptions = await ConsumptionStorage.getSiteAreaConsumptions(req.user.tenantID, {
+ // Get the Asset Consumption Values
+ siteArea.values.assetConsumptions = await ConsumptionStorage.getSiteAreaConsumptions(req.user.tenantID, {
siteAreaID: filteredRequest.SiteAreaID,
startDate: filteredRequest.StartDate,
- endDate: filteredRequest.EndDate
+ endDate: filteredRequest.EndDate,
+ type: SiteAreaValueTypes.ASSET_CONSUMPTIONS
+ }, [ 'startedAt', 'instantAmps', 'instantWatts', 'limitAmps', 'limitWatts' ]);
+ // Get the Charging Station Consumption Values
+ siteArea.values.chargingStationConsumptions = await ConsumptionStorage.getSiteAreaConsumptions(req.user.tenantID, {
+ siteAreaID: filteredRequest.SiteAreaID,
+ startDate: filteredRequest.StartDate,
+ endDate: filteredRequest.EndDate,
+ type: SiteAreaValueTypes.CHARGING_STATION_CONSUMPTIONS
+ }, [ 'startedAt', 'instantAmps', 'instantWatts', 'limitAmps', 'limitWatts' ]);
+ // Get the Asset production values
+ siteArea.values.assetProductions = await ConsumptionStorage.getSiteAreaConsumptions(req.user.tenantID, {
+ siteAreaID: filteredRequest.SiteAreaID,
+ startDate: filteredRequest.StartDate,
+ endDate: filteredRequest.EndDate,
+ type: SiteAreaValueTypes.ASSET_PRODUCTIONS
}, [ 'startedAt', 'instantAmps', 'instantWatts', 'limitAmps', 'limitWatts' ]);
- // Assign
- siteArea.values = consumptions;
// Return
res.json(siteArea);
next();

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -7,6 +7,7 @@ import { DataResult } from '../../types/DataResult';
import DatabaseUtils from './DatabaseUtils';
import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
+import { SiteAreaValueTypes } from '../../types/SiteArea';
import Tenant from '../../types/Tenant';
import Utils from '../../utils/Utils';
@@ -183,7 +184,7 @@ export default class ConsumptionStorage {
}
static async getSiteAreaConsumptions(tenantID: string,
- params: { siteAreaID: string; startDate: Date; endDate: Date },
+ params: { siteAreaID: string; startDate: Date; endDate: Date, type: SiteAreaValueTypes },
projectFields?: string[]): Promise<Consumption[]> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getSiteAreaConsumptions');
@@ -207,6 +208,17 @@ export default class ConsumptionStorage {
if (params.endDate) {
filters.startedAt.$lte = Utils.convertToDate(params.endDate);
}
+ // Type of query
+ if (params.type && params.type === SiteAreaValueTypes.ASSET_CONSUMPTIONS) {
+ filters.instantWatts.$gte = 0;
+ filters.assetID.$ne = null;
+ } else if (params.type && params.type === SiteAreaValueTypes.ASSET_PRODUCTIONS) {
+ filters.instantWatts.$lt = 0;
+ filters.assetID.$ne = null;
+ } else if (params.type && params.type === SiteAreaValueTypes.CHARGING_STATION_CONSUMPTIONS) {
+ // filters.instantWatts.$gte = 0;
+ filters.chargeBoxID.$ne = null;
+ }
// Create Aggregation
const aggregation = [];
// Filters

MODIFY
src/types/SiteArea.ts
src/types/SiteArea.ts
@@ -8,6 +8,17 @@ import { OpeningTimes } from './OpeningTimes';
import Site from '../types/Site';
import { SiteAreaAuthorizationActions } from './Authorization';
+export enum SiteAreaValueTypes {
+ ASSET_CONSUMPTIONS = 'AssetConsumptions',
+ ASSET_PRODUCTIONS = 'AssetProductions',
+ CHARGING_STATION_CONSUMPTIONS = 'ChargingStationConsumptions'
+}
+export interface SiteAreaValues {
+ assetConsumptions: Consumption[];
+ assetProductions: Consumption[];
+ chargingStationConsumptions: Consumption[];
+}
+
export default interface SiteArea extends CreatedUpdatedProps, SiteAreaAuthorizationActions {
id: string;
name: string;
@@ -23,7 +34,7 @@ export default interface SiteArea extends CreatedUpdatedProps, SiteAreaAuthoriza
accessControl: boolean;
chargingStations: ChargingStation[];
connectorStats: ConnectorStats;
- values: Consumption[];
+ values: SiteAreaValues;
distanceMeters?: number;
openingTimes?: OpeningTimes;
}

Backend changes for Displaying consumption and production.