Skip to content

Commit

Permalink
节点统计新增项目统计
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 22, 2023
1 parent 8240cc2 commit 6644166
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
32 changes: 32 additions & 0 deletions Stardust.Server/Services/NodeStatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void DoNodeStat(Object state)
CityStat(dt, GetSelects(dt));
ArchStat(dt, GetSelects(dt));
VendorStat(dt, GetSelects(dt));
ProjectStat(dt, GetSelects(dt));
}
}
catch (Exception ex)
Expand Down Expand Up @@ -358,4 +359,35 @@ private void VendorStat(DateTime date, ConcatExpression selects)
// 删除多余统计项
sts.Delete();
}

private void ProjectStat(DateTime date, ConcatExpression selects)
{
var category = "项目";
var list = SearchGroup(date.AddYears(-1), selects & _.ProjectId, _.ProjectId);
var sts = NodeStat.FindAllByDate(category, date);
foreach (var node in list)
{
var key = node.ProjectId + "";
if (key.Length > 50) key = key[..50];
var st = sts.FirstOrDefault(e => e.Key == key);
if (st == null)
st = NodeStat.GetOrAdd(category, date, key);
else
sts.Remove(st);

st.LinkItem = node.ProjectName;
st.Total = node.ID;
st.Actives = node["activeT1"].ToInt();
st.ActivesT7 = node["activeT7"].ToInt();
st.ActivesT30 = node["activeT30"].ToInt();
st.News = node["newT1"].ToInt();
st.NewsT7 = node["newT7"].ToInt();
st.NewsT30 = node["newT30"].ToInt();

st.Update();
}

// 删除多余统计项
sts.Delete();
}
}
19 changes: 15 additions & 4 deletions Stardust.Web/Areas/Nodes/Controllers/NodeStatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ protected override IEnumerable<NodeStat> Search(Pager p)
var start = p["dtStart"].ToDateTime();
var end = p["dtEnd"].ToDateTime();

// 默认分类
if (category.IsNullOrEmpty()) p["category"] = category = "操作系统";

// 带有分类没有key也没有日期时,显示今天
if (!category.IsNullOrEmpty() && key.IsNullOrEmpty() && start.Year < 2000)
{
start = end = DateTime.Today;
p["dtStart"] = start.ToString("yyyy-MM-dd");
p["dtEnd"] = end.ToString("yyyy-MM-dd");
}

// 默认排序
if (!category.IsNullOrEmpty() && !key.IsNullOrEmpty() && start.Year < 2000 && p.Sort.IsNullOrEmpty())
{
Expand Down Expand Up @@ -140,18 +151,18 @@ protected override IEnumerable<NodeStat> Search(Pager p)
&& start.Year > 2000 && start.Date == end.Date && list.Count > 0)
{
// 饼图不要显示空的统计项
var list2 = list.Where(e => !e.Key.IsNullOrEmpty() && e.Key != "0").ToList();
var list2 = list.Where(e => !e.LinkItem.IsNullOrEmpty()).ToList();

var chart = new ECharts { Height = 400 };
chart.AddPie(list2, _.Total, e => new NameValue(e.Key, e.Total));
chart.AddPie(list2, _.Total, e => new NameValue(e.LinkItem, e.Total));

//list2 = list.OrderByDescending(e => e.ActivesT7).ToList();
var chart2 = new ECharts { Height = 400 };
chart2.AddPie(list2, _.ActivesT30, e => new NameValue(e.Key, e.ActivesT30));
chart2.AddPie(list2, _.ActivesT30, e => new NameValue(e.LinkItem, e.ActivesT30));

//list2 = list.OrderByDescending(e => e.NewsT7).ToList();
var chart3 = new ECharts { Height = 400 };
chart3.AddPie(list, _.NewsT7, e => new NameValue(e.Key, e.NewsT7));
chart3.AddPie(list, _.NewsT7, e => new NameValue(e.LinkItem, e.NewsT7));

ViewBag.Charts = new[] { chart2 };
ViewBag.Charts2 = new[] { chart };
Expand Down

0 comments on commit 6644166

Please sign in to comment.