-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(OldTscConfigPriceService): can get prices based on old configura…
…tion
- Loading branch information
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
TeslaSolarCharger/Server/Services/GridPrice/Contracts/IOldTscConfigPriceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using TeslaSolarCharger.Server.Services.GridPrice.Dtos; | ||
|
||
namespace TeslaSolarCharger.Server.Services.GridPrice.Contracts; | ||
|
||
public interface IOldTscConfigPriceService : IPriceDataService | ||
{ | ||
} |
50 changes: 50 additions & 0 deletions
50
TeslaSolarCharger/Server/Services/GridPrice/OldTscConfigPriceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using TeslaSolarCharger.Model.Contracts; | ||
using TeslaSolarCharger.Server.Services.GridPrice.Contracts; | ||
using TeslaSolarCharger.Server.Services.GridPrice.Dtos; | ||
|
||
namespace TeslaSolarCharger.Server.Services.GridPrice; | ||
|
||
public class OldTscConfigPriceService (ILogger<OldTscConfigPriceService> logger, | ||
ITeslaSolarChargerContext teslaSolarChargerContext) : IOldTscConfigPriceService | ||
{ | ||
public async Task<IEnumerable<Price>> GetPriceData(DateTimeOffset from, DateTimeOffset to, string? configString) | ||
{ | ||
logger.LogTrace("{method}({from}, {to}, {configString})", nameof(GetPriceData), from, to, configString); | ||
if (!int.TryParse(configString, out var id)) | ||
{ | ||
logger.LogError("Invalid configString: {configString}", configString); | ||
throw new ArgumentException("Invalid configString", nameof(configString)); | ||
} | ||
var price = await teslaSolarChargerContext.ChargePrices.FirstAsync(p => p.Id == id); | ||
if (!price.AddSpotPriceToGridPrice) | ||
{ | ||
return new List<Price>() | ||
{ | ||
new() | ||
{ | ||
ValidFrom = from, | ||
ValidTo = to, Value = price.GridPrice, | ||
SolarPrice = price.SolarPrice, | ||
}, | ||
}; | ||
} | ||
var spotPrices = await teslaSolarChargerContext.SpotPrices | ||
.Where(p => p.EndDate >= from && p.StartDate <= to) | ||
.OrderBy(p => p.StartDate) | ||
.ToListAsync(); | ||
var result = new List<Price>(); | ||
foreach (var spotPrice in spotPrices) | ||
{ | ||
var gridPriceDuringThisSpotPrice = price.GridPrice + spotPrice.Price + spotPrice.Price * price.SpotPriceCorrectionFactor; | ||
result.Add(new Price | ||
{ | ||
ValidFrom = new DateTimeOffset(spotPrice.StartDate, TimeSpan.Zero), | ||
ValidTo = new DateTimeOffset(spotPrice.EndDate, TimeSpan.Zero), | ||
Value = gridPriceDuringThisSpotPrice, | ||
SolarPrice = price.SolarPrice, | ||
}); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters