Apply code formatting cleanup across the monitor projects
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#region
|
||||
|
||||
using ShowerMonitorManager.Interface;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ShowerMonitorManager;
|
||||
|
||||
public sealed class HumidityRateCalculator(int windowSize) : IHumidityRateCalculator
|
||||
{
|
||||
private readonly Lock _lock = new();
|
||||
private readonly Queue<(double Humidity, DateTimeOffset Timestamp)> _readings = new();
|
||||
private readonly Lock _lock = new Lock();
|
||||
private readonly Queue<(double Humidity, DateTimeOffset Timestamp)> _readings = new Queue<(double Humidity, DateTimeOffset Timestamp)>();
|
||||
private double? _previousReading;
|
||||
|
||||
public double? PreviousReading
|
||||
@@ -26,7 +30,10 @@ public sealed class HumidityRateCalculator(int windowSize) : IHumidityRateCalcul
|
||||
_readings.Enqueue((humidity, timestamp));
|
||||
_previousReading = humidity;
|
||||
|
||||
while (_readings.Count > windowSize) _readings.Dequeue();
|
||||
while (_readings.Count > windowSize)
|
||||
{
|
||||
_readings.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +41,19 @@ public sealed class HumidityRateCalculator(int windowSize) : IHumidityRateCalcul
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_readings.Count < 2) return 0.0;
|
||||
if (_readings.Count < 2)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
var oldest = _readings.Peek();
|
||||
var newest = _readings.Last();
|
||||
var elapsedMinutes = (newest.Timestamp - oldest.Timestamp).TotalMinutes;
|
||||
|
||||
if (elapsedMinutes <= 0) return 0.0;
|
||||
if (elapsedMinutes <= 0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return (newest.Humidity - oldest.Humidity) / elapsedMinutes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user