Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
add upload rate display
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Jul 25, 2019
1 parent 2065686 commit 91f27bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions engine/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Torrent struct {
Name string
Loaded bool
Downloaded int64
Uploaded int64
Size int64
Files []*File
//cloud torrent
Expand All @@ -20,6 +21,7 @@ type Torrent struct {
DoneCmdCalled bool
Percent float32
DownloadRate float32
UploadRate float32
SeedRatio float32
Stats torrent.TorrentStats
t *torrent.Torrent
Expand Down Expand Up @@ -84,24 +86,28 @@ func (torrent *Torrent) updateLoaded(t *torrent.Torrent) {
totalCompleted += file.Completed
}

torrent.Stats = t.Stats()
now := time.Now()
bytes := t.BytesCompleted()
ulbytes := torrent.Stats.BytesWrittenData.Int64()

// calculate rate
if !torrent.updatedAt.IsZero() {
dt := float32(now.Sub(torrent.updatedAt))
db := float32(bytes - torrent.Downloaded)
rate := db * (float32(time.Second) / dt)
if rate >= 0 {
torrent.DownloadRate = rate
}
dtinv := float32(time.Second) / float32(now.Sub(torrent.updatedAt))

dldb := float32(bytes - torrent.Downloaded)
torrent.DownloadRate = dldb * dtinv

uldb := float32(ulbytes - torrent.Uploaded)
torrent.UploadRate = uldb * dtinv
}

torrent.Downloaded = bytes
torrent.Uploaded = ulbytes

torrent.updatedAt = now
torrent.Percent = percent(bytes, torrent.Size)
torrent.Done = (bytes == torrent.Size)
torrent.Stats = t.Stats()

// calculate ratio
bRead := torrent.Stats.BytesReadData.Int64()
Expand Down
4 changes: 2 additions & 2 deletions static/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions static/files/template/torrents.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h5 class="right">
<div>Peers (Active / Pending / HalfOpen / Total):
{{ t.Stats.ActivePeers }}/{{ t.Stats.PendingPeers }}/{{ t.Stats.HalfOpenPeers }}/{{ t.Stats.TotalPeers }}
</div>
<div>Up / Down: {{ t.Stats.BytesWritten | bytes }} / {{ t.Stats.BytesRead | bytes }} | Ratio: {{ t.SeedRatio | round }}</div>
<div>Up: {{ t.Stats.BytesWritten | bytes }} / Down: {{ t.Stats.BytesRead | bytes }} / Ratio: {{ t.SeedRatio | round }}</div>
</div>
<div class="ui blue progress" ng-class="{active: t.Percent > 0 && t.Percent < 100}">
<div class="bar" ng-style="{width: t.Percent + '%'}">
Expand Down Expand Up @@ -66,7 +66,7 @@ <h5 class="right">
<span ng-class="{muted:t.Downloaded == 0}">{{t.Downloaded | bytes}}</span>
<span> / {{t.Size | bytes}}</span>
<span> - {{t.Percent }}% </span>
<span style="font-weight:bold" ng-class="{muted:t.DownloadRate == 0}"> - {{t.DownloadRate | bytes}}/s</span>
<span style="font-weight:bold" ng-class="{muted:t.DownloadRate == 0}"> - ↑{{t.UploadRate | bytes}}/s - ↓{{t.DownloadRate | bytes}}/s</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 91f27bd

Please sign in to comment.