fix: speed calculate (#63)

This commit is contained in:
Li Wei authored and GitHub committed 2022-12-16 14:53:07 +08:00
1 parent 0a4be165a5
commit db4003ad4f
4 files changed
+13 -20

No files matched your search

+3 -8
View File
@@ -102,14 +102,9 @@ func (d *Downloader) Setup() error {
current := task.fetcher.Progress().TotalDownloaded()
task.Progress.Used = task.timer.Used()
downloaded := current - task.Progress.Downloaded
usedTime := float64(d.refreshInterval) / 1000
if downloaded == 0 {
task.Progress.Speed = int64(float64(task.Progress.Speed) / (usedTime * 1.55))
} else {
usedTime := float64(d.refreshInterval) / 1000
task.Progress.Speed = int64(float64(current-task.Progress.Downloaded) / usedTime)
}
currUsedTime := float64(d.refreshInterval) / 1000
currSpeed := int64(float64(current-task.Progress.Downloaded) / currUsedTime)
task.Progress.Speed = (task.Progress.Speed + currSpeed) / 2
task.Progress.Downloaded = current
d.emit(EventKeyProgress, task)
+1 -1
View File
@@ -34,7 +34,7 @@ func (cfg *DownloaderConfig) Init() *DownloaderConfig {
}
if cfg.RefreshInterval == 0 {
cfg.RefreshInterval = 500
cfg.RefreshInterval = 350
}
return cfg
}