diff --git a/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor b/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor index 2a7049e4..d4ca070c 100644 --- a/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor +++ b/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor @@ -32,7 +32,7 @@ @GenAppVisitCard(UvTitle, _uva) - @GenAppVisitCard(UvTitle, _uvta) + @GenAppVisitCard(UvtTitle, _uvta) @GenAppVisitCard(PvTitle, _pva) @@ -133,7 +133,7 @@ @icon - @(rate.ToString("P"))% + @(rate.ToString("P", ZhCN)) }; diff --git a/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor.cs b/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor.cs index f5d6e360..fc174016 100644 --- a/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor.cs +++ b/src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/AppVisitAnalysis.razor.cs @@ -1,6 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. +using System.Globalization; using System.Timers; using GraphQL.Client.Http; using GraphQL.Client.Serializer.SystemTextJson; @@ -20,6 +21,8 @@ public partial class AppVisitAnalysis : TscComponentBase private const string Top10UvtTitle = UvtTitle + " Top10"; private const string Top10PvTitle = PvTitle + " Top10"; + private static readonly CultureInfo ZhCN = new("zh-CN"); + private GraphQLHttpClient _graphClient = null!; private AppVisit? _uva; private AppVisit? _uvta; @@ -137,20 +140,51 @@ private async Task RefreshAppVisitHourAsync() { var response = await _graphClient.SendQueryAsync>(GetAppVisitHourQuery()); - var x = response.Data.Items.Select(u => u.AppVisitHour.TimeKey).ToArray(); - var tuv = response.Data.Items.Select(u => u.AppVisitHour.Tuv).ToArray(); - var yuv = response.Data.Items.Select(u => u.AppVisitHour.Yuv).ToArray(); - var suv = response.Data.Items.Select(u => u.AppVisitHour.Suv).ToArray(); - var tuvt = response.Data.Items.Select(u => u.AppVisitHour.Tuvt).ToArray(); - var yuvt = response.Data.Items.Select(u => u.AppVisitHour.Yuvt).ToArray(); - var suvt = response.Data.Items.Select(u => u.AppVisitHour.Suvt).ToArray(); - var tpv = response.Data.Items.Select(u => u.AppVisitHour.Tpv).ToArray(); - var ypv = response.Data.Items.Select(u => u.AppVisitHour.Ypv).ToArray(); - var spv = response.Data.Items.Select(u => u.AppVisitHour.Spv).ToArray(); + var currentHour = DateTime.UtcNow.Add(CurrentTimeZone.BaseUtcOffset).Hour; + + var x = new List(); + var tuv = new List(); + var yuv = new List(); + var suv = new List(); + var tuvt = new List(); + var yuvt = new List(); + var suvt = new List(); + var tpv = new List(); + var ypv = new List(); + var spv = new List(); + + foreach (var item in response.Data.Items) + { + x.Add(item.AppVisitHour.TimeKey); + if (item.AppVisitHour.TimeNum <= currentHour) + { + tuv.Add(item.AppVisitHour.Tuv); + } + + yuv.Add(item.AppVisitHour.Yuv); + suv.Add(item.AppVisitHour.Suv); + + if (item.AppVisitHour.TimeNum <= currentHour) + { + tuvt.Add(item.AppVisitHour.Tuvt); + } + + yuvt.Add(item.AppVisitHour.Yuvt); + suvt.Add(item.AppVisitHour.Suvt); + + if (item.AppVisitHour.TimeNum <= currentHour) + { + tpv.Add(item.AppVisitHour.Tpv); + } + + ypv.Add(item.AppVisitHour.Ypv); + spv.Add(item.AppVisitHour.Spv); + } _uvOption = GetSharedHourOption(UvTitle, x, tuv, yuv, suv); _uvtOption = GetSharedHourOption(UvtTitle, x, tuvt, yuvt, suvt); _pvOption = GetSharedHourOption(PvTitle, x, tpv, ypv, spv); + StateHasChanged(); } @@ -178,7 +212,6 @@ private async Task RefreshAppVisitPageAsync(AppVisitType type) return GetSharedAppVisitPageOption(keys, data, max); } - private async Task RefreshAppVisitDataAsync() { _uva = await GetAppVisitAsync(AppVisitType.Uv); @@ -239,7 +272,7 @@ private void UpdateMapOption(object data, int max) StateHasChanged(); } - private static object GetSharedHourOption(string title, string[] x, int[] t, int[] y, int[] s) + private static object GetSharedHourOption(string title, List x, List t, List y, List s) { return new { @@ -340,6 +373,11 @@ private static object GetSharedAppVisitPageOption(string[] keys, object[] data, { type = "category", data = keys, + axisLabel = new + { + overflow = "break", + width = 250 + } }, series = new[] { @@ -347,6 +385,7 @@ private static object GetSharedAppVisitPageOption(string[] keys, object[] data, { name = "数量", type = "bar", + barMinWidth = "50%", data = data, label = new { @@ -369,8 +408,8 @@ private static GraphQLHttpRequest GetAppVisitQuery(AppVisitType type) """, AppVisitType.Uvt => """ data1: uvta - data2: yesterdayuvrate - data3: seventhuvrate + data2: yesterdayuvtrate + data3: seventhuvtrate """, AppVisitType.Pv => """ data1: pva @@ -473,7 +512,7 @@ private GraphQLHttpRequest GetAppVisitPageQuery(AppVisitType type) filter = $"path:{{notIn:[{string.Join(",", _urls.Select(x => $"\"{x}\""))}]}}"; } - var r = new GraphQLHttpRequest( + return new GraphQLHttpRequest( $$""" query { cube(limit:10) { @@ -485,10 +524,6 @@ private GraphQLHttpRequest GetAppVisitPageQuery(AppVisitType type) } } """); - - Console.Out.WriteLine("query: " + r.Query); - - return r; } // TODO: Test this method, like value 0 or there has more effective way to implement this method