changed sendJson param and removed not needed file mode
removed instantaneous speed; update only if percentage delta > 0.1 removed instantaneous speed; update only if percentage delta > 0.1
This commit is contained in:
parent
2509420ba5
commit
1532b2a8c8
@ -61,7 +61,7 @@ func (c *Client) Download(pack *DCCSend) {
|
|||||||
PercCompletion: 0,
|
PercCompletion: 0,
|
||||||
File: pack.File,
|
File: pack.File,
|
||||||
}
|
}
|
||||||
file, err := os.OpenFile(filepath.Join(c.DownloadFolder, pack.File), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
file, err := os.OpenFile(filepath.Join(c.DownloadFolder, pack.File), os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Progress <- DownloadProgress{
|
c.Progress <- DownloadProgress{
|
||||||
PercCompletion: -1,
|
PercCompletion: -1,
|
||||||
@ -85,8 +85,8 @@ func (c *Client) Download(pack *DCCSend) {
|
|||||||
|
|
||||||
defer con.Close()
|
defer con.Close()
|
||||||
|
|
||||||
var avgSpeed float64
|
var speed float64
|
||||||
var prevTime int64 = -1
|
var prevPerc float64
|
||||||
secondsElapsed := int64(0)
|
secondsElapsed := int64(0)
|
||||||
totalBytes := uint64(0)
|
totalBytes := uint64(0)
|
||||||
buf := make([]byte, 0, 4*1024)
|
buf := make([]byte, 0, 4*1024)
|
||||||
@ -118,31 +118,25 @@ func (c *Client) Download(pack *DCCSend) {
|
|||||||
|
|
||||||
now := time.Now().UnixNano()
|
now := time.Now().UnixNano()
|
||||||
secondsElapsed = (now - start) / 1e9
|
secondsElapsed = (now - start) / 1e9
|
||||||
avgSpeed = round2(float64(totalBytes) / (float64(secondsElapsed)))
|
speed = round2(float64(totalBytes) / (float64(secondsElapsed)))
|
||||||
speed := 0.0
|
secondsToGo := round2((float64(pack.Length) - float64(totalBytes)) / speed)
|
||||||
|
|
||||||
if prevTime < 0 {
|
|
||||||
speed = avgSpeed
|
|
||||||
} else {
|
|
||||||
speed = round2(1e9 * float64(cycleBytes) / (float64(now - prevTime)))
|
|
||||||
}
|
|
||||||
secondsToGo := (float64(pack.Length) - float64(totalBytes)) / speed
|
|
||||||
prevTime = now
|
|
||||||
con.Write(byteRead(totalBytes))
|
con.Write(byteRead(totalBytes))
|
||||||
c.Progress <- DownloadProgress{
|
if percentage-prevPerc >= 0.1 {
|
||||||
InstSpeed: humanReadableByteCount(speed, true),
|
prevPerc = percentage
|
||||||
AvgSpeed: humanReadableByteCount(avgSpeed, true),
|
c.Progress <- DownloadProgress{
|
||||||
PercCompletion: percentage,
|
Speed: humanReadableByteCount(speed, true),
|
||||||
BytesRemaining: humanReadableByteCount(float64(pack.Length-totalBytes), false),
|
PercCompletion: percentage,
|
||||||
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
|
BytesRemaining: humanReadableByteCount(float64(pack.Length-totalBytes), false),
|
||||||
SecondsElapsed: secondsElapsed,
|
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
|
||||||
SecondsToGo: secondsToGo,
|
SecondsElapsed: secondsElapsed,
|
||||||
File: pack.File,
|
SecondsToGo: secondsToGo,
|
||||||
|
File: pack.File,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
con.Write(byteRead(totalBytes))
|
con.Write(byteRead(totalBytes))
|
||||||
c.Progress <- DownloadProgress{
|
c.Progress <- DownloadProgress{
|
||||||
AvgSpeed: humanReadableByteCount(avgSpeed, true),
|
Speed: humanReadableByteCount(speed, true),
|
||||||
PercCompletion: 100,
|
PercCompletion: 100,
|
||||||
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
|
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
|
||||||
SecondsElapsed: secondsElapsed,
|
SecondsElapsed: secondsElapsed,
|
||||||
@ -156,8 +150,7 @@ type DownloadProgress struct {
|
|||||||
BytesCompleted string `json:"bytes_completed"`
|
BytesCompleted string `json:"bytes_completed"`
|
||||||
BytesRemaining string `json:"bytes_remaining"`
|
BytesRemaining string `json:"bytes_remaining"`
|
||||||
PercCompletion float64 `json:"perc_completion"`
|
PercCompletion float64 `json:"perc_completion"`
|
||||||
AvgSpeed string `json:"avg_speed"`
|
Speed string `json:"speed"`
|
||||||
InstSpeed string `json:"speed"`
|
|
||||||
SecondsElapsed int64 `json:"elapsed"`
|
SecondsElapsed int64 `json:"elapsed"`
|
||||||
SecondsToGo float64 `json:"eta"`
|
SecondsToGo float64 `json:"eta"`
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func (i *ircHandler) run() {
|
|||||||
i.log("Connected")
|
i.log("Connected")
|
||||||
}
|
}
|
||||||
case progress := <-i.client.Progress:
|
case progress := <-i.client.Progress:
|
||||||
i.state.sendJSON("progress", progress.ToJSON())
|
i.state.sendJSON("pm", Message{Server: i.client.Host, From: "@dcc", Content: progress.ToJSON()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user