fixed calculation of asset variation
MODIFY
src/scheduler/tasks/AssetGetConsumptionTask.ts
src/scheduler/tasks/AssetGetConsumptionTask.ts
@@ -94,15 +94,16 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
}
private async checkFluctuationSinceLastSmartChargingRun(tenant: Tenant, asset: Asset) {
- const consumptionIncrease = asset.currentInstantWatts - asset.powerWattsLastSmartChargingRun;
- if (consumptionIncrease > 0) {
- const assetFluctuationRange = new Decimal(asset.staticValueWatt).mul(asset.fluctuationPercent / 100).toNumber();
- const assetFluctuationRangeUsage = new Decimal(100 * consumptionIncrease).div(assetFluctuationRange).toNumber();
- if (assetFluctuationRangeUsage > 50) {
+ const consumptionVariation = asset.currentInstantWatts - asset.powerWattsLastSmartChargingRun;
+ if (consumptionVariation < 0 || Utils.isNullOrUndefined(asset.variationThresholdPercent)) {
+ return;
+ }
+ const variationThreshold = new Decimal(asset.staticValueWatt).mul(asset.variationThresholdPercent / 100).toNumber();
+ if (variationThreshold < consumptionVariation) {
// Smart Charging must be active
if (Utils.isTenantComponentActive(tenant, TenantComponents.SMART_CHARGING)) {
if (asset.siteArea && asset.siteArea.smartCharging) {
- const siteAreaLock = await LockingHelper.tryCreateSiteAreaSmartChargingLock(tenant.id, asset.siteArea, 30 * 1000);
+ const siteAreaLock = await LockingHelper.createSiteAreaSmartChargingLock(tenant.id, asset.siteArea, 30 * 1000);
if (siteAreaLock) {
try {
const smartCharging = await SmartChargingFactory.getSmartChargingImpl(tenant.id);
@@ -118,7 +119,6 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
}
}
}
- }
private assignAssetConsumption(asset: Asset, consumption: AbstractCurrentConsumption) {
// Assign

MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -491,6 +491,7 @@ export default class AssetService {
asset.siteID = siteArea ? siteArea.siteID : null,
asset.assetType = filteredRequest.assetType;
asset.excludeFromSmartCharging = filteredRequest.excludeFromSmartCharging;
+ asset.variationThresholdPercent = filteredRequest.variationThresholdPercent;
asset.fluctuationPercent = filteredRequest.fluctuationPercent;
asset.staticValueWatt = filteredRequest.staticValueWatt;
asset.coordinates = filteredRequest.coordinates;

MODIFY
src/server/rest/v1/service/security/AssetSecurity.ts
src/server/rest/v1/service/security/AssetSecurity.ts
@@ -66,6 +66,7 @@ export default class AssetSecurity {
filteredRequest.siteAreaID = sanitize(request.siteAreaID),
filteredRequest.assetType = sanitize(request.assetType),
filteredRequest.excludeFromSmartCharging = UtilsSecurity.filterBoolean(sanitize(request.excludeFromSmartCharging));
+ filteredRequest.variationThresholdPercent = sanitize(request.variationThresholdPercent),
filteredRequest.fluctuationPercent = sanitize(request.fluctuationPercent),
filteredRequest.staticValueWatt = sanitize(request.staticValueWatt),
filteredRequest.image = request.image;

MODIFY
src/storage/mongodb/AssetStorage.ts
src/storage/mongodb/AssetStorage.ts
@@ -53,6 +53,8 @@ export default class AssetStorage {
(coordinate) => Utils.convertToFloat(coordinate)) : [],
assetType: assetToSave.assetType,
excludeFromSmartCharging: Utils.convertToBoolean(assetToSave.excludeFromSmartCharging),
+ variationThresholdPercent: Utils.convertToFloat(assetToSave.variationThresholdPercent),
+ powerWattsLastSmartChargingRun: Utils.convertToBoolean(assetToSave.powerWattsLastSmartChargingRun),
fluctuationPercent: Utils.convertToFloat(assetToSave.fluctuationPercent),
staticValueWatt: Utils.convertToFloat(assetToSave.staticValueWatt),
dynamicAsset: assetToSave.dynamicAsset,

MODIFY
src/types/Asset.ts
src/types/Asset.ts
@@ -20,6 +20,7 @@ export default interface Asset extends CreatedUpdatedProps, AbstractCurrentConsu
meterID?: string;
values: Consumption[],
excludeFromSmartCharging?: boolean,
+ variationThresholdPercent?: number,
powerWattsLastSmartChargingRun?: number
}

fixed calculation of asset variation