mirror of
https://codeberg.org/hyperreal/go-transmission-stats
synced 2024-11-25 12:13:42 +01:00
Display actually relevant stats
This commit is contained in:
parent
90bc1df230
commit
1d2c5295bf
35
main.go
35
main.go
@ -5,9 +5,9 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hekmon/cunits/v2"
|
||||||
"github.com/hekmon/transmissionrpc"
|
"github.com/hekmon/transmissionrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -64,10 +64,11 @@ type SessionStat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TorrentInfo struct {
|
type TorrentInfo struct {
|
||||||
Name string
|
Name string
|
||||||
HashString string
|
DateAdded time.Time
|
||||||
DateAdded time.Time
|
TotalSize cunits.Bits
|
||||||
UploadedEver string
|
PeersConnected int64
|
||||||
|
PeersGettingFromUs int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type TorrentStatsPageData struct {
|
type TorrentStatsPageData struct {
|
||||||
@ -116,37 +117,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var torrentInfo = []TorrentInfo{}
|
var torrentInfo = []TorrentInfo{}
|
||||||
torrents, err := transmissionbt.TorrentGet([]string{"name", "hashString", "addedDate", "uploadedEver"}, nil)
|
torrents, err := transmissionbt.TorrentGet([]string{"name", "addedDate", "totalSize", "peersConnected", "peersGettingFromUs"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
} else {
|
} else {
|
||||||
for _, torrent := range torrents {
|
for _, torrent := range torrents {
|
||||||
torrentInfo = append(torrentInfo, TorrentInfo{Name: *torrent.Name, HashString: *torrent.HashString, DateAdded: *torrent.AddedDate, UploadedEver: strconv.FormatInt(*torrent.UploadedEver, 10)})
|
torrentInfo = append(torrentInfo, TorrentInfo{Name: *torrent.Name, DateAdded: *torrent.AddedDate, TotalSize: *torrent.TotalSize, PeersConnected: *torrent.PeersConnected, PeersGettingFromUs: *torrent.PeersGettingFromUs})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(torrentInfo, func(i, j int) bool {
|
sort.Slice(torrentInfo, func(i, j int) bool {
|
||||||
iInt, err := strconv.ParseInt(torrentInfo[i].UploadedEver, 10, 64)
|
return torrentInfo[i].Name < torrentInfo[j].Name
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
jInt, err := strconv.ParseInt(torrentInfo[j].UploadedEver, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return iInt > jInt
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for i := range torrentInfo {
|
|
||||||
parsedInt, err := strconv.ParseInt(torrentInfo[i].UploadedEver, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
torrentInfo[i].UploadedEver = byteCountIEC(parsedInt)
|
|
||||||
}
|
|
||||||
|
|
||||||
data := TorrentStatsPageData{
|
data := TorrentStatsPageData{
|
||||||
Date: time.Now().Format(time.UnixDate),
|
Date: time.Now().Format(time.UnixDate),
|
||||||
SessionStats: sessionStats,
|
SessionStats: sessionStats,
|
||||||
|
@ -42,24 +42,27 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Torrent Info</h2>
|
<h2>Torrent Info</h2>
|
||||||
<p>In descending order from the most total uploaded.</p>
|
|
||||||
{{range .TorrentInfo}}
|
{{range .TorrentInfo}}
|
||||||
<table style="width:100%">
|
<table style="width:100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Name</td>
|
<td>Name</td>
|
||||||
<td class="name">{{.Name}}</td>
|
<td class="name">{{.Name}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>Hash</td>
|
|
||||||
<td>{{.HashString}}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Date Added</td>
|
<td>Date Added</td>
|
||||||
<td>{{.DateAdded}}</td>
|
<td>{{.DateAdded}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total Uploaded</td>
|
<td>Total Size</td>
|
||||||
<td>{{.UploadedEver}}</td>
|
<td>{{.TotalSize}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Peers Connected</td>
|
||||||
|
<td>{{.PeersConnected}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Peers Getting From Us</td>
|
||||||
|
<td>{{.PeersGettingFromUs}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user