实现峰值带宽和平均带宽两种带宽算法

This commit is contained in:
刘祥超
2023-02-27 10:47:25 +08:00
parent e89e11c421
commit e13abfc09e
12 changed files with 404 additions and 181 deletions

View File

@@ -16,7 +16,7 @@ import (
func TestServerBandwidthStatDAO_UpdateServerBandwidth(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
err := dao.UpdateServerBandwidth(tx, 1, 1, timeutil.Format("Ymd"), timeutil.Format("Hi"), 1024)
err := dao.UpdateServerBandwidth(tx, 1, 1, timeutil.Format("Ymd"), timeutil.FormatTime("Hi", time.Now().Unix()/300*300), 1024, 300)
if err != nil {
t.Fatal(err)
}
@@ -30,7 +30,7 @@ func TestSeverBandwidthStatDAO_InsertManyStats(t *testing.T) {
for i := 0; i < count; i++ {
var day = timeutil.Format("Ymd", time.Now().AddDate(0, 0, -rands.Int(0, 200)))
var minute = fmt.Sprintf("%02d%02d", rands.Int(0, 23), rands.Int(0, 59))
err := dao.UpdateServerBandwidth(tx, 1, 1, day, minute, 1024)
err := dao.UpdateServerBandwidth(tx, 1, 1, day, minute, 1024, 300)
if err != nil {
t.Fatal(err)
}
@@ -41,13 +41,14 @@ func TestSeverBandwidthStatDAO_InsertManyStats(t *testing.T) {
func TestServerBandwidthStatDAO_FindMonthlyPercentile(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
t.Log(dao.FindMonthlyPercentile(tx, 23, timeutil.Format("Ym"), 95))
t.Log(dao.FindMonthlyPercentile(tx, 23, timeutil.Format("Ym"), 95, false))
t.Log(dao.FindMonthlyPercentile(tx, 23, timeutil.Format("Ym"), 95, true))
}
func TestServerBandwidthStatDAO_FindAllServerStatsWithMonth(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
stats, err := dao.FindAllServerStatsWithMonth(tx, 23, timeutil.Format("Ym"))
stats, err := dao.FindAllServerStatsWithMonth(tx, 23, timeutil.Format("Ym"), false)
if err != nil {
t.Fatal(err)
}
@@ -59,7 +60,7 @@ func TestServerBandwidthStatDAO_FindAllServerStatsWithMonth(t *testing.T) {
func TestServerBandwidthStatDAO_FindAllServerStatsWithDay(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
stats, err := dao.FindAllServerStatsWithDay(tx, 23, timeutil.Format("Ymd"))
stats, err := dao.FindAllServerStatsWithDay(tx, 23, timeutil.Format("Ymd"), false)
if err != nil {
t.Fatal(err)
}
@@ -82,7 +83,7 @@ func TestServerBandwidthStatDAO_Clean(t *testing.T) {
func TestServerBandwidthStatDAO_FindHourlyBandwidthStats(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
stats, err := dao.FindHourlyBandwidthStats(tx, 23, 24)
stats, err := dao.FindHourlyBandwidthStats(tx, 23, 24, false)
if err != nil {
t.Fatal(err)
}
@@ -92,7 +93,7 @@ func TestServerBandwidthStatDAO_FindHourlyBandwidthStats(t *testing.T) {
func TestServerBandwidthStatDAO_FindDailyBandwidthStats(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
stats, err := dao.FindDailyBandwidthStats(tx, 23, 14)
stats, err := dao.FindDailyBandwidthStats(tx, 23, 14, false)
if err != nil {
t.Fatal(err)
}
@@ -102,7 +103,7 @@ func TestServerBandwidthStatDAO_FindDailyBandwidthStats(t *testing.T) {
func TestServerBandwidthStatDAO_FindBandwidthStatsBetweenDays(t *testing.T) {
var dao = models.NewServerBandwidthStatDAO()
var tx *dbs.Tx
stats, err := dao.FindBandwidthStatsBetweenDays(tx, 23, timeutil.Format("Ymd", time.Now().AddDate(0, 0, -2)), timeutil.Format("Ymd"))
stats, err := dao.FindBandwidthStatsBetweenDays(tx, 23, timeutil.Format("Ymd", time.Now().AddDate(0, 0, -2)), timeutil.Format("Ymd"), false)
if err != nil {
t.Fatal(err)
}