mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: smooth speed calculation (#99)
This commit is contained in:
1 parent
e77441f0de
commit
701ea59035
2 files changed
+17
-4
No files matched your search
@@ -29,6 +29,7 @@ type Task struct {
|
||||
fetcher fetcher.Fetcher
|
||||
timer *util.Timer
|
||||
lock *sync.Mutex
|
||||
speedArr []int64
|
||||
}
|
||||
|
||||
func NewTask() *Task {
|
||||
@@ -54,6 +55,18 @@ func (t *Task) clone() *Task {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Task) calcSpeed(downloaded int64, usedTime float64) int64 {
|
||||
t.speedArr = append(t.speedArr, downloaded)
|
||||
if len(t.speedArr) > 6 {
|
||||
t.speedArr = t.speedArr[1:]
|
||||
}
|
||||
var total int64
|
||||
for _, v := range t.speedArr {
|
||||
total += v
|
||||
}
|
||||
return int64(float64(total) / float64(len(t.speedArr)) / usedTime)
|
||||
}
|
||||
|
||||
type DownloaderConfig struct {
|
||||
Controller *controller.Controller
|
||||
FetchBuilders []fetcher.FetcherBuilder
|
||||
|
||||
Reference in new issue
Block a user