added share list page
This commit is contained in:
@@ -1,37 +1,15 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
|
||||
"pool-stats/database"
|
||||
"pool-stats/helpers"
|
||||
"pool-stats/models"
|
||||
)
|
||||
|
||||
func parseCreatedate(createdate string) time.Time {
|
||||
parts := strings.Split(createdate, ",")
|
||||
if len(parts) == 2 {
|
||||
sec, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||
nsec, _ := strconv.ParseInt(parts[1], 10, 64)
|
||||
return time.Unix(sec, nsec)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func humanDiff(diff float64) string {
|
||||
units := []string{"", "K", "M", "G", "T"}
|
||||
i := 0
|
||||
for diff >= 1000 && i < len(units)-1 {
|
||||
diff /= 1000
|
||||
i++
|
||||
}
|
||||
return fmt.Sprintf("%.2f%s", diff, units[i])
|
||||
}
|
||||
|
||||
func GetStats(db *clover.DB) ([]models.ShareStat, error) {
|
||||
now := time.Now()
|
||||
ranges := []struct {
|
||||
@@ -50,8 +28,8 @@ func GetStats(db *clover.DB) ([]models.ShareStat, error) {
|
||||
if doc != nil {
|
||||
stats = append(stats, models.ShareStat{
|
||||
Label: "All Time",
|
||||
Diff: humanDiff(doc.Get("SDiff").(float64)),
|
||||
Time: parseCreatedate(doc.Get("CreateDate").(string)).Format(time.RFC822),
|
||||
Diff: helpers.HumanDiff(doc.Get("SDiff").(float64)),
|
||||
Time: helpers.ParseCreateDate(doc.Get("CreateDate").(string)).Format(time.RFC822),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,8 +38,8 @@ func GetStats(db *clover.DB) ([]models.ShareStat, error) {
|
||||
if doc != nil {
|
||||
stats = append(stats, models.ShareStat{
|
||||
Label: r.Label,
|
||||
Diff: humanDiff(doc.Get("SDiff").(float64)),
|
||||
Time: parseCreatedate(doc.Get("CreateDate").(string)).Format(time.RFC822),
|
||||
Diff: helpers.HumanDiff(doc.Get("SDiff").(float64)),
|
||||
Time: helpers.ParseCreateDate(doc.Get("CreateDate").(string)).Format(time.RFC822),
|
||||
})
|
||||
} else {
|
||||
stats = append(stats, models.ShareStat{Label: r.Label, Diff: "-", Time: "-"})
|
||||
|
||||
Reference in New Issue
Block a user