MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / aggregateNodePeriodStats

Function aggregateNodePeriodStats

internal/usage/summary.go:354–372  ·  view source on GitHub ↗

aggregateNodePeriodStats 按节点汇总时段内的流量增量(来自 daily_usage 原始记录)。

(raw []nodes.NodeDailyUsage, nodeList []nodes.Node)

Source from the content-addressed store, hash-verified

352
353// aggregateNodePeriodStats 按节点汇总时段内的流量增量(来自 daily_usage 原始记录)。
354func aggregateNodePeriodStats(raw []nodes.NodeDailyUsage, nodeList []nodes.Node) []NodePeriodStat {
355 byNode := make(map[string]*NodePeriodStat, len(nodeList))
356 for _, n := range nodeList {
357 ns := &NodePeriodStat{ID: n.ID, Name: n.Name}
358 byNode[n.ID] = ns
359 }
360 for _, r := range raw {
361 if ns, ok := byNode[r.NodeID]; ok {
362 ns.UploadBytes += r.UploadBytes
363 ns.DownloadBytes += r.DownloadBytes
364 ns.TotalBytes += r.UploadBytes + r.DownloadBytes
365 }
366 }
367 result := make([]NodePeriodStat, 0, len(nodeList))
368 for _, n := range nodeList {
369 result = append(result, *byNode[n.ID])
370 }
371 return result
372}

Callers 1

BuildFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected