Skip to content

Commit

Permalink
Use parameter for timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
just-seba committed Sep 23, 2024
1 parent 6b18902 commit c7eb12b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public async Task<NumberOfSamples> TakeSamples(DateTimeOffset timestamp)
var sb = new StringBuilder();
foreach (var factory in _sqlFactories)
{
sb.AppendLine(factory.GetSamplingSql(timestamp, GetTableName));
sb.AppendLine(factory.GetSamplingSql(GetTableName, "{0}"));
}

var count = await _context.Database.ExecuteSqlRawAsync(sb.ToString());
var count = await _context.Database.ExecuteSqlRawAsync(sb.ToString(), timestamp);

return NumberOfSamples.From(count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace OpenEMS.Infrastructure.Analytics;

public interface IDbContextDeviceSamplingSqlFactory
{
string GetSamplingSql(DateTimeOffset timestamp, Func<Type, string> tableNameProvider);
string GetSamplingSql(Func<Type, string> tableNameProvider, string timestampParam);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

namespace OpenEMS.Infrastructure.Analytics;

public class ProducerSamplingSqlFactory : PostgreSqlDeviceSamplingSqlFactory
public class PostgreSqlProducerSamplingSqlFactory : IDbContextDeviceSamplingSqlFactory
{
protected override string GetSamplingSql(
string timestampSqlValue,
Func<Type, string> tableNameProvider
)
public string GetSamplingSql(Func<Type, string> tableNameProvider, string timestampParam)
{
var sql = $"""
INSERT INTO "{tableNameProvider(typeof(ProducerSample))}" (
Expand All @@ -20,7 +17,7 @@ Func<Type, string> tableNameProvider
)
SELECT
"{nameof(Producer.Id)}",
{timestampSqlValue},
{timestampParam},
"{nameof(Producer.CurrentPowerProduction)}",
"{nameof(Producer.TotalEnergyProduction)}_{nameof(
Producer.TotalEnergyProduction.Value
Expand Down

0 comments on commit c7eb12b

Please sign in to comment.