Display actually relevant stats

This commit is contained in:
Jeffrey Serio 2023-03-25 18:19:02 -05:00
parent 90bc1df230
commit 1d2c5295bf
2 changed files with 19 additions and 33 deletions

35
main.go
View File

@ -5,9 +5,9 @@ import (
"html/template"
"os"
"sort"
"strconv"
"time"
"github.com/hekmon/cunits/v2"
"github.com/hekmon/transmissionrpc"
)
@ -64,10 +64,11 @@ type SessionStat struct {
}
type TorrentInfo struct {
Name string
HashString string
DateAdded time.Time
UploadedEver string
Name string
DateAdded time.Time
TotalSize cunits.Bits
PeersConnected int64
PeersGettingFromUs int64
}
type TorrentStatsPageData struct {
@ -116,37 +117,19 @@ func main() {
}
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 {
fmt.Fprintln(os.Stderr, err)
} else {
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 {
iInt, err := strconv.ParseInt(torrentInfo[i].UploadedEver, 10, 64)
if err != nil {
panic(err)
}
jInt, err := strconv.ParseInt(torrentInfo[j].UploadedEver, 10, 64)
if err != nil {
panic(err)
}
return iInt > jInt
return torrentInfo[i].Name < torrentInfo[j].Name
})
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{
Date: time.Now().Format(time.UnixDate),
SessionStats: sessionStats,

View File

@ -42,24 +42,27 @@
</table>
<h2>Torrent Info</h2>
<p>In descending order from the most total uploaded.</p>
{{range .TorrentInfo}}
<table style="width:100%">
<tr>
<td>Name</td>
<td class="name">{{.Name}}</td>
</tr>
<tr>
<td>Hash</td>
<td>{{.HashString}}</td>
</tr>
<tr>
<td>Date Added</td>
<td>{{.DateAdded}}</td>
</tr>
<tr>
<td>Total Uploaded</td>
<td>{{.UploadedEver}}</td>
<td>Total Size</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>
</table>
{{end}}