diff --git a/MP.Stats/Components/ChartTS.razor b/MP.Stats/Components/ChartTSer.razor similarity index 100% rename from MP.Stats/Components/ChartTS.razor rename to MP.Stats/Components/ChartTSer.razor diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index cc3f10d5..831e5788 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.14.2202.2117 + 6.14.2202.2119 diff --git a/MP.Stats/Pages/Test.razor b/MP.Stats/Pages/Test.razor index cc04841c..2d5ebb5c 100644 --- a/MP.Stats/Pages/Test.razor +++ b/MP.Stats/Pages/Test.razor @@ -1,145 +1,29 @@ @page "/test" +@using MP.Stats.Components +

Test

-
+ @*
-
-
+
+
-
-
+
+
-
-
+
+
+
*@ +
+ +
+
+
-@code { - PieChart pieChart; - LineChart lineChart; - HorizontalBarChart barChartHoriz; - BarChart barChart; - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - await HandleRedraw(); - } - } - - object horizontalLineChartOptions = new - { - //Title = new - //{ - // Display = true, - // Text = "Line chart sample" - //}, - //Scales = new - //{ - // XAxes = new object[] - // { - // new { - // //ScaleLabel = new { - // //Display = true, LabelString = "value" }, - // Stacked = true - // } - // } - //}, - Tooltips = new - { - Mode = "nearest", - Intersect = false - }, - Hover = new - { - Mode = "nearest", - Intersect = false - }, - Legend = new - { - Display = true, - FullWidth = true - }, - AspectRatio = 2.5 - }; - - async Task HandleRedraw() - { - await pieChart.Clear(); - await pieChart.AddLabelsDatasetsAndUpdate(Labels, GetPieChartDataset()); - - await lineChart.Clear(); - await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset()); - - await barChart.Clear(); - await barChart.AddLabelsDatasetsAndUpdate(Labels, GetBarChartDataset()); - - await barChartHoriz.Clear(); - await barChartHoriz.AddLabelsDatasetsAndUpdate(Labels, GetHorizBarChartDataset()); - } - - PieChartDataset GetPieChartDataset() - { - return new PieChartDataset - { - Label = "# of randoms", - Data = RandomizeData(), - BackgroundColor = backgroundColors, - BorderColor = borderColors - }; - } - - LineChartDataset GetLineChartDataset() - { - return new LineChartDataset - { - Label = "# of randoms", - Data = RandomizeData(), - BackgroundColor = backgroundColors, - BorderColor = borderColors, - Fill = true, - PointRadius = 2, - BorderDash = new List { } - }; - } - - BarChartDataset GetBarChartDataset() - { - return new BarChartDataset - { - Label = "# of randoms", - Data = RandomizeData(), - BackgroundColor = backgroundColors, - BorderColor = borderColors, - HoverBorderWidth = 5 - }; - } - BarChartDataset GetHorizBarChartDataset() - { - return new BarChartDataset - { - Label = "# of randoms", - Data = RandomizeData(), - BackgroundColor = backgroundColors, - BorderColor = borderColors, - HoverBorderWidth = 5 - }; - } - - 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 RandomizeData() - { - var r = new Random(DateTime.Now.Millisecond); - - return new List { r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble() }; - } -} \ No newline at end of file diff --git a/MP.Stats/Pages/Test.razor.cs b/MP.Stats/Pages/Test.razor.cs new file mode 100644 index 00000000..c09d926b --- /dev/null +++ b/MP.Stats/Pages/Test.razor.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP.Stats; +using MP.Stats.Shared; +using Blazorise; +using Blazorise.Charts; +using MP.Data; + +namespace MP.Stats.Pages +{ + public partial class Test + { + PieChart pieChart; + LineChart lineChart; + HorizontalBarChart barChartHoriz; + BarChart barChart; + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await HandleRedraw(); + } + } + + protected override async Task OnInitializedAsync() + { + await HandleRedraw(); + } + + + object horizontalLineChartOptions = new + { + //Title = new + //{ + // Display = true, + // Text = "Line chart sample" + //}, + //Scales = new + //{ + // XAxes = new object[] + // { + // new { + // //ScaleLabel = new { + // //Display = true, LabelString = "value" }, + // Stacked = true + // } + // } + //}, + Tooltips = new + { + Mode = "nearest", + Intersect = false + } + + , + Hover = new + { + Mode = "nearest", + Intersect = false + } + + , + Legend = new + { + Display = true, + FullWidth = true + } + + , + AspectRatio = 2.5 + } + + ; + private async Task HandleRedraw() + { +#if false + await pieChart.Clear(); + await pieChart.AddLabelsDatasetsAndUpdate(Labels, GetPieChartDataset()); + await lineChart.Clear(); + await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset()); + await barChart.Clear(); + await barChart.AddLabelsDatasetsAndUpdate(Labels, GetBarChartDataset()); + await barChartHoriz.Clear(); + await barChartHoriz.AddLabelsDatasetsAndUpdate(Labels, GetHorizBarChartDataset()); +#endif + // calcolo hist frequenza con EFCore: https://entityframeworkcore.com/knowledge-base/60871048/group-by-and-to-dictionary-in-ef-core-3-1 + var rawData = RandomizeData(); + var histDict = rawData.GroupBy(r => r).Select(g => new + { + g.Key, + Count = g.Count() + }).OrderBy(d => d.Key).ToDictionary(x => x.Key, x => x.Count.ToString()); + histData = histDict.Values.ToArray(); + histLabel = histDict.Keys.Select(x => $"{x}").ToArray(); + + + dataList = TSData(DateTime.Today.AddHours(-rawData.Count), rawData).Select(r => new chartJsData.chartJsTSerie() + { x = r.Key, y = r.Value}).ToList(); + } + + protected string[]? histData { get; set; } = null; + + protected string[]? histLabel { get; set; } = null; + protected List? dataList { get; set; } = null; +#if false + + PieChartDataset GetPieChartDataset() + { + return new PieChartDataset { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors }; + } + + LineChartDataset GetLineChartDataset() + { + return new LineChartDataset { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, Fill = true, PointRadius = 2, BorderDash = new List { } }; + } + + BarChartDataset GetBarChartDataset() + { + return new BarChartDataset { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, HoverBorderWidth = 5 }; + } + + BarChartDataset GetHorizBarChartDataset() + { + return new BarChartDataset { Label = "# of randoms", Data = RandomizeData(), BackgroundColor = backgroundColors, BorderColor = borderColors, HoverBorderWidth = 5 }; + } +#endif + + 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) }; + + private List RandomizeData() + { + double mean = 14; + double stdDev = 2; + var r = new Random(DateTime.Now.Millisecond); + + + List answ = new List(); + for (int i = 0; i < 1000; i++) + { + double u1 = 1.0 - r.NextDouble(); // uniform (0,1] random doubles + double u2 = 1.0 - r.NextDouble(); + double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); + double randNormal = mean + stdDev * randStdNormal; // random normal (mean, stdDev^2) + //answ.Add(r.Next(3, 30) * r.NextDouble()); + answ.Add((int)(randNormal * 10)); + } + return answ; + } + + private Dictionary TSData(DateTime inizio, List yData) + { + Dictionary answ = new Dictionary(); + // usando i dati ricevuti aggiunge variabile x = tempo crescente + int idx= 0; + foreach (var item in yData) + { + answ.Add(inizio.AddHours(idx), item); + idx++; + } + // restituisco! + return answ; + } + } +} \ No newline at end of file diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 30e7e27c..9ea7b464 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.14.2202.2117

+

Versione: 6.14.2202.2119


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index aad2ebaf..f76f5e45 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.14.2202.2117 +6.14.2202.2119 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index 0bb9f460..8ed1f779 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.14.2202.2117 + 6.14.2202.2119 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false