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

Fixes für geänderte Umstände

- Monat September wird korrekt eingelesen
- Änderung des R-Werts auf Github als Quelle
parent adf2bc32
{
"version": 1,
"isRoot": true,
"tools": {
"unclassified.dotnetsshdeploy": {
"version": "0.4.1",
"commands": [
"ssh-deploy"
]
}
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ using CovidTable.Database;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
......@@ -13,13 +12,11 @@ namespace CovidTable.Controllers
{
public class HomeController : Controller
{
private readonly ILogger logger;
private readonly ServerDbContext dbContext;
private readonly IConfiguration configuration;
public HomeController(ILogger<HomeController> logger, ServerDbContext dbContext, IConfiguration configuration)
public HomeController(ServerDbContext dbContext, IConfiguration configuration)
{
this.logger = logger;
this.dbContext = dbContext;
this.configuration = configuration;
}
......@@ -75,6 +72,7 @@ namespace CovidTable.Controllers
}
var latestItem = dbContext.Reproduction
.Where(r => r.Value != null)
.OrderByDescending(r => r.Timestamp)
.FirstOrDefault();
......@@ -88,14 +86,16 @@ namespace CovidTable.Controllers
{
new JObject
{
["title"] = "4-Tages-R-Wert",
//["title"] = "4-Tages-R-Wert",
["title"] = "7-Tages-R-Wert",
["timestamp"] = latestItem.Timestamp,
["value"] = latestItem.Day4Num,
["min"] = latestItem.Day4Min,
["max"] = latestItem.Day4Max
["value"] = latestItem.Value,
["min"] = latestItem.Minimum,
["max"] = latestItem.Maximum
}
};
/* INFO: RKI moved to github and removed 4-day reproduction
latestItem = dbContext.Reproduction
.Where(r => r.Day7Num != null)
.OrderByDescending(r => r.Timestamp)
......@@ -110,7 +110,7 @@ namespace CovidTable.Controllers
["min"] = latestItem.Day7Min,
["max"] = latestItem.Day7Max
});
}
}*/
ViewData["Reproduction"] = reprod;
}
......@@ -358,17 +358,17 @@ namespace CovidTable.Controllers
var list = dbContext.Reproduction
.Where(r => r.Timestamp >= oldest)
.OrderBy(r => r.Timestamp)
.Select(r => new Reproduction
{
Timestamp = r.Timestamp,
Day4Num = r.Day4Num,
Day4Min = r.Day4Min,
Day4Max = r.Day4Max,
Day7Num = r.Day7Num,
Day7Min = r.Day7Min,
Day7Max = r.Day7Max
})
.ToList();
//.Select(r => new Reproduction
//{
// Timestamp = r.Timestamp,
// Day4Num = r.Day4Num,
// Day4Min = r.Day4Min,
// Day4Max = r.Day4Max,
// Day7Num = r.Day7Num,
// Day7Min = r.Day7Min,
// Day7Max = r.Day7Max
//})
return Json(list);
}
......
......@@ -16,34 +16,34 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AMWD.Common" Version="5.0.5" />
<PackageReference Include="AMWD.Common.AspNetCore" Version="5.0.5" />
<PackageReference Include="AMWD.Common.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="AMWD.Common" Version="5.0.109" />
<PackageReference Include="AMWD.Common.AspNetCore" Version="5.0.109" />
<PackageReference Include="AMWD.Common.EntityFrameworkCore" Version="5.0.109" />
<PackageReference Include="LumenWorksCsvReader" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.3">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
<PackageReference Include="PdfPig" Version="0.1.4" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Telegram.Bot" Version="15.7.1" />
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.3.0">
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Telegram.Bot" Version="16.0.2" />
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="WebPush" Version="1.0.11" />
<PackageReference Include="WebPush" Version="1.0.12" />
</ItemGroup>
<ItemGroup>
......
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CovidTable.Database
{
......@@ -9,16 +8,10 @@ namespace CovidTable.Database
[Key]
public DateTime Timestamp { get; set; }
public float Day4Num { get; set; }
public float? Value { get; set; }
public float Day4Min { get; set; }
public float? Minimum { get; set; }
public float Day4Max { get; set; }
public float? Day7Num { get; set; }
public float? Day7Min { get; set; }
public float? Day7Max { get; set; }
public float? Maximum { get; set; }
}
}
-- Covid Table
-- RKI moved to github and removed 4-day-reproduction.
alter table reproduction
rename column day7_min to minimum;
alter table reproduction
rename column day7_num to value;
alter table reproduction
rename column day7_max to maximum;
alter table reproduction
drop column day4_min,
drop column day4_num,
drop column day4_max;
\ No newline at end of file
-- Covid Table
-- RKI moved to github and removed 4-day-reproduction.
alter table reproduction rename to reproduction_old;
create table reproduction (
timestamp text(20) not null primary key,
minimum real,
value real,
maximum real
);
insert into reproduction (timestamp, minimum, value, maximum)
select timestamp, day7_min, day7_num, day7_max from reproduction_old;
drop table reproduction_old;
\ No newline at end of file
......@@ -21,13 +21,14 @@ namespace CovidTable.Services
public class UpdateService : IHostedService
{
private const string CasesUrl = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=OBJECTID,GEN,BEZ,EWZ,cases,deaths,BL,BL_ID,last_update,cases7_per_100k,EWZ_BL,cases7_bl_per_100k&outSR=4326&f=json";
private const string ReproductionUrl = "https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Projekte_RKI/Nowcasting_Zahlen_csv.csv?__blob=publicationFile";
//private const string ReproductionUrl = "https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Projekte_RKI/Nowcasting_Zahlen_csv.csv?__blob=publicationFile";
private const string ReproductionUrl = "https://raw.githubusercontent.com/robert-koch-institut/SARS-CoV-2-Nowcasting_und_-R-Schaetzung/main/Nowcast_R_aktuell.csv";
//private const string VaccinationUrl = "https://impfdashboard.de/static/data/germany_vaccinations_timeseries_v2.tsv";
private readonly ILogger logger;
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly CultureInfo de = new CultureInfo("de-DE");
private readonly CultureInfo de = new("de-DE");
private CancellationTokenSource cts;
private Task casesTask = Task.CompletedTask;
private Task reproductionTask = Task.CompletedTask;
......@@ -316,7 +317,8 @@ namespace CovidTable.Services
using var response = await client.GetAsync(ReproductionUrl, cancellationToken);
if (response.IsSuccessStatusCode)
{
using var csv = new CsvReader(await response.Content.ReadAsStreamAsync(cancellationToken), true, Encoding.UTF8, ';', false, 60);
//using var csv = new CsvReader(await response.Content.ReadAsStreamAsync(cancellationToken), true, Encoding.UTF8, ';', false, 60);
using var csv = new CsvReader(await response.Content.ReadAsStreamAsync(cancellationToken), true, Encoding.UTF8, ',', false, 60);
using var scope = serviceScopeFactory.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ServerDbContext>();
......@@ -326,6 +328,7 @@ namespace CovidTable.Services
var newDate = DateTime.MinValue;
while (!cancellationToken.IsCancellationRequested && csv.ReadNextRecord())
{
/* INFO: RKI moved to github and removed 4-day reproduction
if (DateTime.TryParseExact(csv["Datum"], "dd.MM.yyyy", de, DateTimeStyles.None, out var timestamp) &&
float.TryParse(csv["Schätzer_Reproduktionszahl_R"], NumberStyles.Float, de, out float rRaw))
{
......@@ -358,6 +361,42 @@ namespace CovidTable.Services
entry.Day7Min = float.Parse(csv["UG_PI_7_Tage_R_Wert"], de);
entry.Day7Max = float.Parse(csv["OG_PI_7_Tage_R_Wert"], de);
}
}*/
string val = csv["PS_7_Tage_R_Wert"];
string min = csv["UG_PI_7_Tage_R_Wert"];
string max = csv["OG_PI_7_Tage_R_Wert"];
if (val.StartsWith("."))
val = "0" + val;
if (min.StartsWith("."))
min = "0" + min;
if (max.StartsWith("."))
max = "0" + max;
if (DateTime.TryParseExact(csv["Datum"], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var timestamp) &&
float.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out float rVal))
{
// only update last 3 months days
if (dbDate != null && timestamp < ((DateTime)dbDate).AddMonths(-6))
continue;
var entry = await dbContext.Reproduction
.Where(r => r.Timestamp == timestamp)
.FirstOrDefaultAsync(cancellationToken);
if (entry == null)
{
entry = new Reproduction
{
Timestamp = timestamp
};
await dbContext.Reproduction.AddAsync(entry, cancellationToken);
newDate = timestamp;
}
entry.Value = rVal;
entry.Minimum = float.Parse(min, CultureInfo.InvariantCulture);
entry.Maximum = float.Parse(max, CultureInfo.InvariantCulture);
}
}
await dbContext.SaveChangesAsync(cancellationToken);
......@@ -444,6 +483,7 @@ namespace CovidTable.Services
string url = $"https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Situationsberichte/{date.ToString("MMM", de)}_{date:yyyy}/{date:yyyy-MM-dd}-de.pdf?__blob=publicationFile";
url = url.Replace("Mär", "Maerz");
url = url.Replace("Mrz", "Maerz");
url = url.Replace("Sep", "Sept");
using var response = await client.GetAsync(url, cancellationToken);
if (response.IsSuccessStatusCode)
{
......
......@@ -210,8 +210,8 @@
<thead class="thead-dark">
<tr>
<th scope="col" title="Erkrankungsbeginn">Datum</th>
<th scope="col">4-Tage-R-Wert</th>
<th scope="col">7-Tage-R-Wert</th>
<!--<th scope="col">4-Tages-R-Wert</th>-->
<th scope="col">7-Tages-R-Wert</th>
</tr>
</thead>
<tbody>
......
......@@ -239,7 +239,8 @@
.addClass('text-center')
.append($('<span/>')
.addClass('fas fa-circle')
.css('color', getColor(row.incidence)))
.css('color', getColor(row.incidence))
.attr('title', de.format(row.incidence)))
.appendTo(tr);
$('<td/>').attr('title', 'Einwohner: ' + de.format(row.residents)).text(row.name).appendTo(tr);
......@@ -894,13 +895,30 @@
let table = $('#r-table tbody');
table.children().remove();
let day4 = null, day7 = null, first = true;
//let day4 = null, day7 = null, first = true;
let day = null, first = true;
for (let entry of response) {
let tr = $('<tr/>').prependTo(table);
let dt = luxon.DateTime.fromISO(entry.timestamp);
$('<td/>').text(dt.toFormat("dd.MM.yyyy")).appendTo(tr);
if (entry.value === null) {
$('<td/>').html('&mdash;').appendTo(tr);
}
else {
let add = '';
if (!first) {
let delta = entry.value - day;
add = ' (<span class="text-' + (delta > 0 ? 'danger' : delta < 0 ? 'success' : 'muted') + '">' + (delta > 0 ? '+' : '') + de.format(delta) + '</span>)';
}
day = entry.value;
$('<td/>').html(de.format(day) + add + ' [' + de.format(entry.minimum) + ' - ' + de.format(entry.maximum) + ']').appendTo(tr);
first = false;
}
/* INFO: RKI moved to github and removed 4-day reproduction
let add = '';
if (!first) {
let delta = entry.day4Num - day4;
......@@ -922,7 +940,7 @@
$('<td/>').html(de.format(day7) + add + ' [' + de.format(entry.day7Min) + ' - ' + de.format(entry.day7Max) + ']').appendTo(tr);
}
first = false;
first = false;*/
}
$('#r')
......@@ -953,27 +971,31 @@
fill: false,
data: []
});
graphData.datasets.push({
label: '4 Tage',
borderColor: 'lightcoral',
backgroundColor: 'lightcoral',
borderWidth: 2,
pointRadius: 1,
fill: false,
data: []
});
//graphData.datasets.push({
// label: '4 Tage',
// borderColor: 'lightcoral',
// backgroundColor: 'lightcoral',
// borderWidth: 2,
// pointRadius: 1,
// fill: false,
// data: []
//});
for (let entry of data) {
let date = luxon.DateTime.fromISO(entry.timestamp).toJSDate();
graphData.datasets[0].data.push({
t: date,
y: entry.day7Num
});
graphData.datasets[1].data.push({
t: date,
y: entry.day4Num
y: entry.value
});
//graphData.datasets[0].data.push({
// t: date,
// y: entry.day7Num
//});
//graphData.datasets[1].data.push({
// t: date,
// y: entry.day4Num
//});
}
new Chart(graph, {
......
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