This commit is contained in:
Stefan
2023-04-19 11:09:34 +02:00
parent 12b8004a93
commit f36a65009f
4 changed files with 21 additions and 42 deletions
@@ -1,4 +1,7 @@
using System.Text.Json.Serialization; using System.Diagnostics;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc.Diagnostics;
namespace Elektrifikatsiya.Models; namespace Elektrifikatsiya.Models;
public enum Status public enum Status
@@ -54,19 +57,19 @@ public class PrometheusDataWrapper
List<(double, double)> result = new List<(double, double)>(); List<(double, double)> result = new List<(double, double)>();
if (Result[0]?.Value is null) if (Result[0]?.Values is null || Result[0]?.Values?[0] is null)
{ {
return FluentResults.Result.Fail("There was no result in the Response Body"); return FluentResults.Result.Fail("There was no result in the Response Body");
} }
foreach (PrometheusData prometheusData in Result) foreach (object value in Result[0].Values)
{ {
string[] segment = prometheusData.Value.ToString()!.Split(","); string[] segment = value.ToString()!.Split(",");
result.Add((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2]))); result.Add((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2])));
} }
Debug.WriteLine(result);
return result; return result;
} }
@@ -106,12 +109,7 @@ public class PrometheusDataMetric
public class PrometheusData public class PrometheusData
{ {
public PrometheusDataMetric Metric { get; set; } public PrometheusDataMetric? Metric { get; set; } = null;
public object Value { get; set; } public object? Value { get; set; } = null;
public List<object>? Values { get; set; } = null;
public PrometheusData(PrometheusDataMetric metric, object value)
{
Metric = metric;
Value = value;
}
} }
@@ -118,10 +118,9 @@
async Task HandleRedraw() async Task HandleRedraw()
{ {
labels.Clear();
await lineChart.Clear(); await lineChart.Clear();
await lineChart.AddLabelsDatasetsAndUpdate(labels, await GetLineChartDataset());
await lineChart.AddLabelsDatasetsAndUpdate(Labels, await GetLineChartDataset());
} }
//TODO: insert dataset of current and last voltage usages //TODO: insert dataset of current and last voltage usages
@@ -129,19 +128,15 @@
{ {
return new LineChartDataset<double> return new LineChartDataset<double>
{ {
Label = "# of random number in thousands", Label = "Wattage",
Data = await RandomizeData(), Data = await RandomizeData(),
BackgroundColor = backgroundColors,
BorderColor = borderColors,
Fill = true, Fill = true,
PointRadius = 3, PointRadius = 3,
CubicInterpolationMode = "monotone", CubicInterpolationMode = "monotone",
}; };
} }
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; List<string> labels = new List<string>();
List<string> backgroundColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 0.2f), ChartColor.FromRgba(54, 162, 235, 0.2f), ChartColor.FromRgba(255, 206, 86, 0.2f), ChartColor.FromRgba(75, 192, 192, 0.2f), ChartColor.FromRgba(153, 102, 255, 0.2f), ChartColor.FromRgba(255, 159, 64, 0.2f) };
List<string> borderColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 1f), ChartColor.FromRgba(54, 162, 235, 1f), ChartColor.FromRgba(255, 206, 86, 1f), ChartColor.FromRgba(75, 192, 192, 1f), ChartColor.FromRgba(153, 102, 255, 1f), ChartColor.FromRgba(255, 159, 64, 1f) };
async Task<List<double>> RandomizeData() async Task<List<double>> RandomizeData()
{ {
@@ -160,8 +155,10 @@
var r = new Random(DateTime.Now.Millisecond); var r = new Random(DateTime.Now.Millisecond);
return deviceData?.MatrixTypeToTimestampFloatTuple().ValueOrDefault?.Select(x => x.Item2).ToList() ?? new List<double>(); return deviceData?.MatrixTypeToTimestampFloatTuple().ValueOrDefault?.Select(x =>
} {
labels.Add(DateTimeOffset.FromUnixTimeSeconds(long.Parse($"1{x.Item1}0")).UtcDateTime.ToLocalTime().ToShortTimeString());
return x.Item2;
}).ToList() ?? new List<double>();
} }
} }
@@ -9,9 +9,6 @@
<DockerServiceName>elektrifikatsiya</DockerServiceName> <DockerServiceName>elektrifikatsiya</DockerServiceName>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" /> <None Include="docker-compose.yml" />
<None Include=".dockerignore" /> <None Include=".dockerignore" />
</ItemGroup> </ItemGroup>
@@ -1,13 +0,0 @@
version: '3.4'
services:
elektrifikatsiya:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "80"
- "443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro