Remove https config.
Default timezone on create new telemetry by data received.
This commit is contained in:
Фролов 2022-01-10 18:12:31 +05:00
parent 90a0aa9e5b
commit 0050427ccf
6 changed files with 54 additions and 7 deletions

View File

@ -55,6 +55,7 @@ SELECT timescaledb_pre_restore();
Terminal:
```
sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak
sudo pg_restore -Fc -d postgres dump_2021-11-26.bak
```
OR psql:
```

View File

@ -5,7 +5,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;IDE0090;IDE0063;IDE0066</NoWarn>
<NoWarn>1701;1702;IDE0090;IDE0063;IDE0066;IDE0054</NoWarn>
</PropertyGroup>
<ItemGroup>

View File

@ -40,7 +40,6 @@ namespace AsbCloudInfrastructure.Services
if (dtos == default || !dtos.Any())
return 0;
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
var dtosList = dtos.OrderBy(d => d.Date).ToList();
var dtoMinDate = dtosList.First().Date;
@ -55,8 +54,9 @@ namespace AsbCloudInfrastructure.Services
foreach (var duplicate in duplicates)
dtosList.Remove(duplicate);
}
var timezone = telemetryService.GetTimezone(idTelemetry);
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
var timezone = telemetryService.GetTimezone(idTelemetry);
var entities = dtosList.Select(dto => {
var entity = Convert(dto, timezone.Hours);
@ -171,5 +171,23 @@ namespace AsbCloudInfrastructure.Services
public abstract TDto Convert(TModel src, double timezoneOffset);
public abstract TModel Convert(TDto src, double timezoneOffset);
private static double AssumeTimezoneOffset(DateTime nearToCurrentDate)
{
var offset = 5d;
if (nearToCurrentDate.Kind == DateTimeKind.Unspecified)
{
var now = DateTime.UtcNow;
var minutes = 60 * (now.Hour - nearToCurrentDate.Hour) + now.Minute - nearToCurrentDate.Minute;
var minutesPositive = (1440_0000 + minutes) % 1440; //60*24
var halfsHours = Math.Round(1d * minutesPositive / 30d); // quarters are ignored
var hours = halfsHours / 2;
offset = hours < 12 ? hours : 24 - hours;
}
if (nearToCurrentDate.Kind == DateTimeKind.Local)
offset = TimeZoneInfo.Local.BaseUtcOffset.TotalHours;
return offset;
}
}
}

View File

@ -178,7 +178,16 @@ namespace AsbCloudInfrastructure.Services
}
private Telemetry GetOrCreateTelemetryByUid(string uid)
=> cacheTelemetry.GetOrCreate(t => t.RemoteUid == uid, () => new Telemetry { RemoteUid = uid });
=> cacheTelemetry.GetOrCreate(t => t.RemoteUid == uid, () => new Telemetry
{
RemoteUid = uid,
TimeZone = new SimpleTimezone
{
Hours = 5,
IsOverride = false,
TimeZoneId = "default",
}
});
public async Task<int> MergeAsync(int from, int to, CancellationToken token)
{

View File

@ -13,7 +13,7 @@
"LocalConnection": "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"
},
"AllowedHosts": "*",
"Urls": "http://0.0.0.0:5000;https://0.0.0.0:5001" //,
"Urls": "http://0.0.0.0:5000",//;https://0.0.0.0:5001" //,
// See https man: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0
//"Kestrel": {
// "Endpoints": {

View File

@ -17,9 +17,28 @@ namespace ConsoleApp1
class Program
{
private static double AssumeTimezoneOffset(DateTime nearToCurrentDate)
{
var offset = 5d;
if (nearToCurrentDate.Kind == DateTimeKind.Unspecified)
{
var now = DateTime.UtcNow;
var minutes = 60 * (now.Hour - nearToCurrentDate.Hour) + now.Minute - nearToCurrentDate.Minute;
var minutesPositive = (1440_0000 + minutes) % 1440; //60*24
var halfsHours = Math.Round(1d * minutesPositive / 30d); // quarters are ignored
var hours = halfsHours / 2;
offset = hours < 12 ? hours : 24 - hours ;
}
if (nearToCurrentDate.Kind == DateTimeKind.Local)
offset = TimeZoneInfo.Local.BaseUtcOffset.TotalHours;
return offset;
}
static void Main(/*string[] args*/)
{
DbDemoDataService.AddDemoData();
var o = AssumeTimezoneOffset(new DateTime(2022, 01, 10, 15, 40, 00));
//DbDemoDataService.AddDemoData();
//.GetAwaiter().GetResult();
Console.WriteLine("End of Test");