diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Models/PrometheusQueryResult.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Models/PrometheusQueryResult.cs index 2192c33..72ef231 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Models/PrometheusQueryResult.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Models/PrometheusQueryResult.cs @@ -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> 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? Values { get; set; } = null; } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index 2b96602..77373e1 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -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 { - 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 backgroundColors = new List { 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 borderColors = new List { 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 labels = new List(); async Task> RandomizeData() { @@ -160,8 +155,10 @@ var r = new Random(DateTime.Now.Millisecond); - return deviceData?.MatrixTypeToTimestampFloatTuple().ValueOrDefault?.Select(x => x.Item2).ToList() ?? new List(); + 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(); } - -} } \ No newline at end of file diff --git a/src/Elektrifikatsiya/docker-compose.dcproj b/src/Elektrifikatsiya/docker-compose.dcproj index 8ee605c..8901d12 100644 --- a/src/Elektrifikatsiya/docker-compose.dcproj +++ b/src/Elektrifikatsiya/docker-compose.dcproj @@ -9,9 +9,6 @@ elektrifikatsiya - - docker-compose.yml - diff --git a/src/Elektrifikatsiya/docker-compose.override.yml b/src/Elektrifikatsiya/docker-compose.override.yml deleted file mode 100644 index 42bf3e9..0000000 --- a/src/Elektrifikatsiya/docker-compose.override.yml +++ /dev/null @@ -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 \ No newline at end of file