Clear Qodana findings in monitor runtime code
- Guard logger calls with IsEnabled so value-type arguments are not boxed when the level is disabled - Make helper members static, narrow write-only properties to init or private get, and delete members no call site reaches - Flatten nested conditionals and convert if/else chains into switch and ternary form - Drop the unused *MonitorInit interfaces; NetDaemon instantiates the concrete app classes - Drop the unused IConfiguration parameter from AddNordPool and AddPowerMonitor, and the unused IEntityManager.CreateEntitiesAsync - Remove the ignored parameters of the boiler run-time tracker stub - Pin the NordPool DTO price mapping explicitly so the getter use is visible to static analysis - Fail Qodana on any finding and record the registration changes in AGENTS.md
This commit is contained in:
@@ -28,13 +28,21 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
|
||||
if ((TodayNordPoolPrice?.Prices == null || TodayNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today))
|
||||
{
|
||||
logger.LogInformation("Fetching today's prices from API for CET date: {Today}", today);
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Fetching today's prices from API for CET date: {Today}", today);
|
||||
}
|
||||
|
||||
TodayNordPoolPrice = await FetchPricesForDateWithRetryAsync(today, "today");
|
||||
}
|
||||
|
||||
if ((TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0) && ShouldFetchNewPrices(today.AddDays(1)))
|
||||
{
|
||||
logger.LogInformation("Fetching tomorrow's prices from API for CET date: {Tomorrow}", today.AddDays(1));
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Fetching tomorrow's prices from API for CET date: {Tomorrow}", today.AddDays(1));
|
||||
}
|
||||
|
||||
TomorrowNordPoolPrice = await FetchPricesForDateWithRetryAsync(today.AddDays(1), "tomorrow");
|
||||
}
|
||||
|
||||
@@ -46,30 +54,35 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
{
|
||||
var index = GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index, TodayNordPoolPrice?.Prices?.Count ?? 0);
|
||||
|
||||
if (DayQuartersIndex != index)
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
{
|
||||
if (TodayNordPoolPrice?.Prices != null && TodayNordPoolPrice.Prices.Count > index)
|
||||
{
|
||||
var price = TodayNordPoolPrice.Prices[index].Price;
|
||||
logger.LogDebug("Current time quarter index: {Index}, Total prices available: {Count}", index, TodayNordPoolPrice?.Prices?.Count ?? 0);
|
||||
}
|
||||
|
||||
if (price.HasValue)
|
||||
{
|
||||
CurrentPrice = price.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("Price at index {Index} is null", index);
|
||||
}
|
||||
if (DayQuartersIndex == index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TodayNordPoolPrice?.Prices != null && TodayNordPoolPrice.Prices.Count > index)
|
||||
{
|
||||
var price = TodayNordPoolPrice.Prices[index].Price;
|
||||
|
||||
if (price.HasValue)
|
||||
{
|
||||
CurrentPrice = price.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}", index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
|
||||
logger.LogWarning("Price at index {Index} is null", index);
|
||||
}
|
||||
|
||||
DayQuartersIndex = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("Cannot get price for index {Index}. Prices is null: {IsNull}, Prices count: {Count}", index, TodayNordPoolPrice?.Prices == null, TodayNordPoolPrice?.Prices?.Count ?? 0);
|
||||
}
|
||||
|
||||
DayQuartersIndex = index;
|
||||
}
|
||||
|
||||
public double GetCurrentPrice()
|
||||
@@ -94,17 +107,14 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TomorrowNordPoolPrice?.Prices == null || TomorrowNordPoolPrice.Prices.Count == 0)
|
||||
if (TomorrowNordPoolPrice?.Prices is { Count: > 0 })
|
||||
{
|
||||
var currentHour = DateTime.Now.Hour;
|
||||
|
||||
if (currentHour >= 13)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
var currentHour = DateTime.Now.Hour;
|
||||
|
||||
return currentHour >= 13;
|
||||
}
|
||||
|
||||
public void RollOverPrices(DateOnly today)
|
||||
@@ -172,27 +182,31 @@ public class NordPoolPriceService(Services services, IMapper mapper, ILogger<Nor
|
||||
return priceResult != null ? mapper.Map<NordPoolPriceResultDto, NordPoolPrice>(priceResult) : new NordPoolPrice();
|
||||
}
|
||||
|
||||
internal NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
|
||||
internal static NordPoolPrice AdjustedNordPoolPrice(NordPoolPrice todayNordPoolPrice)
|
||||
{
|
||||
var recalculatedPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>()
|
||||
};
|
||||
|
||||
if (todayNordPoolPrice.Prices != null)
|
||||
if (todayNordPoolPrice.Prices is null)
|
||||
{
|
||||
foreach (var price in todayNordPoolPrice.Prices)
|
||||
return recalculatedPrice;
|
||||
}
|
||||
|
||||
foreach (var price in todayNordPoolPrice.Prices)
|
||||
{
|
||||
if (price.Price is null)
|
||||
{
|
||||
if (price.Price != null)
|
||||
{
|
||||
recalculatedPrice.Prices.Add(new NordPoolDayPrice
|
||||
{
|
||||
Start = price.Start,
|
||||
End = price.End,
|
||||
Price = PriceCorrection(price.Price.Value)
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
recalculatedPrice.Prices.Add(new NordPoolDayPrice
|
||||
{
|
||||
Start = price.Start,
|
||||
End = price.End,
|
||||
Price = PriceCorrection(price.Price.Value)
|
||||
});
|
||||
}
|
||||
|
||||
return recalculatedPrice;
|
||||
|
||||
Reference in New Issue
Block a user