Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -7,35 +7,39 @@ namespace PowerMonitorManager;
|
||||
|
||||
public sealed class PowerCostCalculationService : IPowerCostCalculationService
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, CostAccumulator> _deviceAccumulators = new();
|
||||
private CostAccumulator? _totalAccumulator;
|
||||
private CostAccumulator? _otherAccumulator;
|
||||
private readonly Lock _accumulatorLock = new();
|
||||
private readonly ConcurrentDictionary<string, CostAccumulator> _deviceAccumulators = new();
|
||||
private readonly Lock _priceLock = new();
|
||||
|
||||
private double _lastKnownPrice;
|
||||
private CostAccumulator? _otherAccumulator;
|
||||
private string _priceSource = "live";
|
||||
private readonly Lock _priceLock = new();
|
||||
private CostAccumulator? _totalAccumulator;
|
||||
|
||||
public double LastKnownPrice
|
||||
{
|
||||
get { lock (_priceLock) { return _lastKnownPrice; } }
|
||||
get
|
||||
{
|
||||
lock (_priceLock)
|
||||
{
|
||||
return _lastKnownPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PriceSource
|
||||
{
|
||||
get { lock (_priceLock) { return _priceSource; } }
|
||||
}
|
||||
|
||||
public void SetPrice(double price)
|
||||
{
|
||||
lock (_priceLock)
|
||||
get
|
||||
{
|
||||
_lastKnownPrice = price;
|
||||
_priceSource = "stale";
|
||||
lock (_priceLock)
|
||||
{
|
||||
return _priceSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RecordCosts(PowerCalculationResult calculation, double nordPoolPrice, int pollIntervalSeconds, DateTime now)
|
||||
public void RecordCosts(PowerCalculationResult calculation, double nordPoolPrice, int pollIntervalSeconds,
|
||||
DateTime now)
|
||||
{
|
||||
lock (_priceLock)
|
||||
{
|
||||
@@ -51,7 +55,8 @@ public sealed class PowerCostCalculationService : IPowerCostCalculationService
|
||||
var totalCost = CalculateCostIncrement(calculation.TotalPowerWatts, effectivePrice, pollIntervalSeconds);
|
||||
GetOrCreateTotalAccumulator(now).AddCost(totalCost, now);
|
||||
|
||||
var otherCost = CalculateCostIncrement(calculation.SmoothedOtherPowerWatts, effectivePrice, pollIntervalSeconds);
|
||||
var otherCost =
|
||||
CalculateCostIncrement(calculation.SmoothedOtherPowerWatts, effectivePrice, pollIntervalSeconds);
|
||||
GetOrCreateOtherAccumulator(now).AddCost(otherCost, now);
|
||||
|
||||
foreach (var (entityId, powerWatts) in calculation.DevicePowerReadings)
|
||||
@@ -78,13 +83,6 @@ public sealed class PowerCostCalculationService : IPowerCostCalculationService
|
||||
}
|
||||
}
|
||||
|
||||
public CostSnapshot GetDeviceCostSnapshot(string entityId)
|
||||
{
|
||||
return _deviceAccumulators.TryGetValue(entityId, out var accumulator)
|
||||
? accumulator.GetSnapshot()
|
||||
: CreateEmptySnapshot();
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, CostSnapshot> GetAllDeviceCostSnapshots()
|
||||
{
|
||||
return _deviceAccumulators.ToDictionary(
|
||||
@@ -92,6 +90,22 @@ public sealed class PowerCostCalculationService : IPowerCostCalculationService
|
||||
kvp => kvp.Value.GetSnapshot());
|
||||
}
|
||||
|
||||
public void SetPrice(double price)
|
||||
{
|
||||
lock (_priceLock)
|
||||
{
|
||||
_lastKnownPrice = price;
|
||||
_priceSource = "stale";
|
||||
}
|
||||
}
|
||||
|
||||
public CostSnapshot GetDeviceCostSnapshot(string entityId)
|
||||
{
|
||||
return _deviceAccumulators.TryGetValue(entityId, out var accumulator)
|
||||
? accumulator.GetSnapshot()
|
||||
: CreateEmptySnapshot();
|
||||
}
|
||||
|
||||
internal static double CalculateCostIncrement(double powerWatts, double pricePerKwh, int pollIntervalSeconds)
|
||||
{
|
||||
var powerKw = powerWatts / PowerMonitorConsts.WattsPerKilowatt;
|
||||
@@ -118,4 +132,4 @@ public sealed class PowerCostCalculationService : IPowerCostCalculationService
|
||||
{
|
||||
return new CostSnapshot { PartialWindow = true };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user