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;
public enum Status
@@ -44,7 +47,7 @@ public class PrometheusDataWrapper
ResultType = resultType;
Result = result;
}
public FluentResults.Result<List<(double, double)>> MatrixTypeToTimestampFloatTuple()
{
if (ResultType != ResultType.Matrix)
@@ -54,19 +57,19 @@ public class PrometheusDataWrapper
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");
}
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])));
}
Debug.WriteLine(result);
return result;
}
@@ -106,12 +109,7 @@ public class PrometheusDataMetric
public class PrometheusData
{
public PrometheusDataMetric Metric { get; set; }
public object Value { get; set; }
public PrometheusData(PrometheusDataMetric metric, object value)
{
Metric = metric;
Value = value;
}
public PrometheusDataMetric? Metric { get; set; } = null;
public object? Value { get; set; } = null;
public List<object>? Values { get; set; } = null;
}
@@ -118,10 +118,9 @@
async Task HandleRedraw()
{
labels.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
@@ -129,19 +128,15 @@
{
return new LineChartDataset<double>
{
Label = "# of random number in thousands",
Label = "Wattage",
Data = await RandomizeData(),
BackgroundColor = backgroundColors,
BorderColor = borderColors,
Fill = true,
PointRadius = 3,
CubicInterpolationMode = "monotone",
};
}
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
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) };
List<string> labels = new List<string>();
async Task<List<double>> RandomizeData()
{
@@ -160,8 +155,10 @@
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>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</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