mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-22 07:39:26 +08:00
rebuild tcping
This commit is contained in:
24
utils/csv.go
24
utils/csv.go
@@ -9,19 +9,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type PingData struct {
|
||||
IP net.IPAddr
|
||||
Count int
|
||||
Received int
|
||||
Delay time.Duration
|
||||
}
|
||||
|
||||
type CloudflareIPData struct {
|
||||
ip net.IPAddr
|
||||
pingCount int
|
||||
pingReceived int
|
||||
*PingData
|
||||
recvRate float32
|
||||
downloadSpeed float32
|
||||
pingTime time.Duration
|
||||
}
|
||||
|
||||
func (cf *CloudflareIPData) getRecvRate() float32 {
|
||||
if cf.recvRate == 0 {
|
||||
pingLost := cf.pingCount - cf.pingReceived
|
||||
cf.recvRate = float32(pingLost) / float32(cf.pingCount)
|
||||
pingLost := cf.Count - cf.Received
|
||||
cf.recvRate = float32(pingLost) / float32(cf.Count)
|
||||
}
|
||||
return cf.recvRate
|
||||
}
|
||||
@@ -41,11 +45,11 @@ func ExportCsv(filePath string, data []CloudflareIPData) {
|
||||
|
||||
func (cf *CloudflareIPData) toString() []string {
|
||||
result := make([]string, 6)
|
||||
result[0] = cf.ip.String()
|
||||
result[1] = strconv.Itoa(cf.pingCount)
|
||||
result[2] = strconv.Itoa(cf.pingReceived)
|
||||
result[0] = cf.IP.String()
|
||||
result[1] = strconv.Itoa(cf.Count)
|
||||
result[2] = strconv.Itoa(cf.Received)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
|
||||
result[4] = cf.pingTime.String()
|
||||
result[4] = cf.Delay.String()
|
||||
result[5] = strconv.FormatFloat(float64(cf.downloadSpeed)/1024/1024, 'f', 2, 32)
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user