the speed progress bar shows test count

This commit is contained in:
mz
2021-11-13 22:57:18 +08:00
parent 8eea8cdd0e
commit 2c46cfcd0f
2 changed files with 15 additions and 6 deletions

View File

@@ -50,7 +50,7 @@ func checkDownloadDefault() {
}
}
func TestDownloadSpeed(ipSet utils.PingDelaySet) (sppedSet utils.DownloadSpeedSet) {
func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSet) {
checkDownloadDefault()
if Disable {
return utils.DownloadSpeedSet(ipSet)
@@ -65,22 +65,25 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (sppedSet utils.DownloadSpeedSe
}
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s下载测速数量%d下载测速队列%d\n", MinSpeed, TestCount, testNum)
bar := utils.NewBar(testNum)
bar := utils.NewBar(TestCount)
for i := 0; i < testNum; i++ {
speed := downloadHandler(ipSet[i].IP)
ipSet[i].DownloadSpeed = speed
bar.Grow(1)
// 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
if speed >= MinSpeed*1024*1024 {
sppedSet = append(sppedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
if len(sppedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn就跳出循环
bar.Grow(1)
speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn就跳出循环
break
}
}
}
bar.Done()
if len(speedSet) == 0 { // 没有符合速度限制的数据,返回所有测试数据
speedSet = utils.DownloadSpeedSet(ipSet)
}
// 按速度排序
sort.Sort(sppedSet)
sort.Sort(speedSet)
return
}