Commit f98f7ccd authored by Andreas Müller's avatar Andreas Müller
Browse files

Small timestamp fix

parent ced5aa3f
......@@ -108,7 +108,8 @@ namespace CovidTable.Services
using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
try
{
DateTime newDate = DateTime.MinValue;
DateTime latestTimestamp = DateTime.MinValue;
DateTime currentTimestamp = DateTime.Today;
foreach (var entry in dataset.Features.Select(f => f.Attributes))
{
#region Base data
......@@ -149,19 +150,19 @@ namespace CovidTable.Services
#region History
if (!DateTime.TryParseExact(entry.Timestamp, "dd.MM.yyyy, HH:mm 'Uhr'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime dt))
dt = DateTime.Today;
if (DateTime.TryParseExact(entry.Timestamp, "dd.MM.yyyy, HH:mm 'Uhr'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime dt))
currentTimestamp = dt;
var bundeslandHistory = await dbContext.StateHistory
.Where(h => h.StateId == state.Id)
.Where(h => h.Timestamp == dt)
.Where(h => h.Timestamp == currentTimestamp)
.FirstOrDefaultAsync(cancellationToken);
if (bundeslandHistory == null)
{
bundeslandHistory = new StateHistory
{
State = state,
Timestamp = dt
Timestamp = currentTimestamp
};
await dbContext.StateHistory.AddAsync(bundeslandHistory, cancellationToken);
}
......@@ -169,17 +170,17 @@ namespace CovidTable.Services
var kommuneHistory = await dbContext.CommuneHistory
.Where(h => h.CommuneId == commune.Id)
.Where(h => h.Timestamp == dt)
.Where(h => h.Timestamp == currentTimestamp)
.FirstOrDefaultAsync(cancellationToken);
if (kommuneHistory == null)
{
kommuneHistory = new CommuneHistory
{
Commune = commune,
Timestamp = dt
Timestamp = currentTimestamp
};
await dbContext.CommuneHistory.AddAsync(kommuneHistory, cancellationToken);
newDate = dt;
latestTimestamp = currentTimestamp;
}
kommuneHistory.Cases = entry.CommuneCases;
kommuneHistory.Deaths = entry.CommuneDeaths;
......@@ -242,12 +243,12 @@ namespace CovidTable.Services
await transaction.CommitAsync(cancellationToken);
logger.LogInformation("Cases: Data update finished");
if (newDate != DateTime.MinValue)
if (latestTimestamp != DateTime.MinValue)
{
logger.LogDebug($"Cases: Latest cases from {newDate:yyyy-MM-dd'T'HH:mm:ssK}");
logger.LogDebug($"Cases: Latest cases from {latestTimestamp:yyyy-MM-dd'T'HH:mm:ssK}");
var push = scope.ServiceProvider.GetService<PushService>();
push?.Enqueue($"Daten wurden aktualisiert.\nStand: {newDate:dd.MM.yyyy HH:mm}");
push?.Enqueue($"Daten wurden aktualisiert.\nStand: {latestTimestamp:dd.MM.yyyy HH:mm}");
continue;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment