Skip to content

Commit

Permalink
Merge pull request pkuehnel#1350 from pkuehnel/feat/autoUpdateChargin…
Browse files Browse the repository at this point in the history
…gProcessesAfterChargingDetailsFix

feat(ChargingCostService): update charging processes after detail fix
  • Loading branch information
pkuehnel authored Jul 7, 2024
2 parents b485cb8 + b5c1a8b commit 4703bae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Contracts/IChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public interface IChargingCostService
Task ConvertToNewChargingProcessStructure();
Task AddFirstChargePrice();
Task FixConvertedChargingDetailSolarPower();
Task UpdateChargingProcessesAfterChargingDetailsFix();
}
1 change: 1 addition & 0 deletions TeslaSolarCharger/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async Task DoStartupStuff(WebApplication webApplication, ILogger<Program> logger
await chargingCostService.ConvertToNewChargingProcessStructure().ConfigureAwait(false);
await chargingCostService.FixConvertedChargingDetailSolarPower().ConfigureAwait(false);
await chargingCostService.AddFirstChargePrice().ConfigureAwait(false);
await chargingCostService.UpdateChargingProcessesAfterChargingDetailsFix().ConfigureAwait(false);
await configJsonService.UpdateAverageGridVoltage().ConfigureAwait(false);

var carConfigurationService = webApplication.Services.GetRequiredService<ICarConfigurationService>();
Expand Down
12 changes: 11 additions & 1 deletion TeslaSolarCharger/Server/Services/ChargingCostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,24 @@ public async Task FixConvertedChargingDetailSolarPower()
}
await scopedTscContext.SaveChangesAsync().ConfigureAwait(false);
}
}

public async Task UpdateChargingProcessesAfterChargingDetailsFix()
{
logger.LogTrace("{method}()", nameof(UpdateChargingProcessesAfterChargingDetailsFix));
var chargingProcessesConverted =
await teslaSolarChargerContext.TscConfigurations.AnyAsync(c => c.Key == constants.ChargingDetailsSolarPowerShareFixed).ConfigureAwait(false);
if (chargingProcessesConverted)
{
return;
}
await tscOnlyChargingCostService.UpdateChargePricesOfAllChargingProcesses().ConfigureAwait(false);
teslaSolarChargerContext.TscConfigurations.Add(new TscConfiguration()
{
Key = constants.ChargingDetailsSolarPowerShareFixed,
Value = "true",
});
await teslaSolarChargerContext.SaveChangesAsync().ConfigureAwait(false);

}

public async Task DeleteChargePriceById(int id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private async Task FinalizeChargingProcess(ChargingProcess chargingProcess)
decimal usedGridEnergyWh = 0;
decimal cost = 0;
chargingProcess.EndDate = chargingDetails.Last().TimeStamp;
var prices = await GetPricesInTimeSpan(chargingProcess.StartDate, chargingProcess.EndDate.Value); //When a charging process is stopped and resumed later, the last charging detail is too old and should not be used because it would use the last value dring the whole time althoug the car was not charging
var prices = await GetPricesInTimeSpan(chargingDetails.First().TimeStamp, chargingProcess.EndDate.Value); //When a charging process is stopped and resumed later, the last charging detail is too old and should not be used because it would use the last value dring the whole time althoug the car was not charging
var maxChargingDetailsDuration = TimeSpan.FromSeconds(constants.ChargingDetailsAddTriggerEveryXSeconds).Add(TimeSpan.FromSeconds(10));
for (var index = 1; index < chargingDetails.Count; index++)
{
Expand Down

0 comments on commit 4703bae

Please sign in to comment.