数据看板使用字节代替比特

This commit is contained in:
GoEdgeLab
2021-07-11 11:09:41 +08:00
parent 8d1965d997
commit ae96474efa
4 changed files with 42 additions and 17 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"math"
"regexp"
)
@@ -58,7 +57,7 @@ func (this *IndexAction) RunGet(params struct{}) {
if len(resp.DailyTrafficStats) > 0 {
todayTrafficBytes = resp.DailyTrafficStats[len(resp.DailyTrafficStats)-1].Bytes
}
todayTrafficString := numberutils.FormatBits(todayTrafficBytes * 8)
todayTrafficString := numberutils.FormatBytes(todayTrafficBytes)
result := regexp.MustCompile(`^(?U)(.+)([a-zA-Z]+)$`).FindStringSubmatch(todayTrafficString)
if len(result) > 2 {
this.Data["todayTraffic"] = result[1]
@@ -73,7 +72,7 @@ func (this *IndexAction) RunGet(params struct{}) {
statMaps := []maps.Map{}
for _, stat := range resp.HourlyTrafficStats {
statMaps = append(statMaps, maps.Map{
"count": math.Ceil((float64(stat.Bytes)*8/1000/1000/1000)*1000) / 1000,
"bytes": stat.Bytes,
"hour": stat.Hour[8:],
})
}
@@ -85,7 +84,7 @@ func (this *IndexAction) RunGet(params struct{}) {
statMaps := []maps.Map{}
for _, stat := range resp.DailyTrafficStats {
statMaps = append(statMaps, maps.Map{
"count": math.Ceil((float64(stat.Bytes)*8/1000/1000/1000)*1000) / 1000,
"bytes": stat.Bytes,
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
})
}