summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-04 22:53:47 +0200
committerPaul Buetow <paul@buetow.org>2024-11-04 22:53:47 +0200
commit70e08336fcc32d69dc58d87a1e1b3e5554732264 (patch)
tree4407790335e11ed8895a466681b7e3745a55143f
parentfd43fe299047c1c993678a28cbb84418190060d6 (diff)
add table output for stats
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--internal/colour/colour.go2
-rw-r--r--internal/schedule/schedule.go3
-rw-r--r--internal/schedule/stats.go39
5 files changed, 48 insertions, 2 deletions
diff --git a/go.mod b/go.mod
index 1b14607..a3f3856 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,8 @@ require (
github.com/fatih/color v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/mattn/go-runewidth v0.0.9 // indirect
+ github.com/olekukonko/tablewriter v0.0.5 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
)
diff --git a/go.sum b/go.sum
index 5f0b1c1..b5da267 100644
--- a/go.sum
+++ b/go.sum
@@ -9,6 +9,10 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
+github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
+github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
+github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
diff --git a/internal/colour/colour.go b/internal/colour/colour.go
index aa34232..545153d 100644
--- a/internal/colour/colour.go
+++ b/internal/colour/colour.go
@@ -5,7 +5,7 @@ import "github.com/fatih/color"
var (
Info1f = color.New(color.FgCyan, color.BgBlue, color.Bold).PrintfFunc()
Info2f = color.New(color.FgHiYellow, color.BgHiBlack, color.Bold).PrintfFunc()
- Info3f = color.New(color.FgHiBlack, color.BgHiGreen, color.Bold).PrintfFunc()
+ SInfo3f = color.New(color.FgHiBlack, color.BgHiGreen, color.Bold).SprintfFunc()
Ackf = color.New(color.FgBlack, color.BgHiYellow, color.Bold).PrintfFunc()
Successf = color.New(color.FgWhite, color.BgGreen).PrintfFunc()
)
diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go
index 45901ff..3828b07 100644
--- a/internal/schedule/schedule.go
+++ b/internal/schedule/schedule.go
@@ -27,6 +27,8 @@ func Run(args config.Args, platform string) (entry.Entry, error) {
if err != nil {
return entry.Zero, err
}
+ stats.Render(platform)
+
if stats.queued < args.MinQueued {
_ = prompt.Acknowledge(
fmt.Sprintf("There are only %d messages queued for %s - time to fill it up!",
@@ -34,7 +36,6 @@ func Run(args config.Args, platform string) (entry.Entry, error) {
)
}
- log.Println("For", platform, "stats:", stats)
en, err := selectEntry(dir)
if err != nil && !errors.Is(err, oi.ErrNotFound) {
return en, nil // Unknown error
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go
index cde9de4..e27ad43 100644
--- a/internal/schedule/stats.go
+++ b/internal/schedule/stats.go
@@ -5,9 +5,11 @@ import (
"log"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
+ "codeberg.org/snonux/gos/internal/colour"
"codeberg.org/snonux/gos/internal/entry"
"codeberg.org/snonux/gos/internal/oi"
"codeberg.org/snonux/gos/internal/timestamp"
@@ -29,6 +31,43 @@ func (s stats) String() string {
)
}
+func (s stats) Render(platform string) {
+ var sb strings.Builder
+
+ // data := [][]string{
+ // {"#Posted entries", strconv.Itoa(s.posted)},
+ // {"#Queued entries", strconv.Itoa(s.queued)},
+ // {"Last post (days ago)", fmt.Sprintf("%.02f", s.lastPostDaysAgo)},
+ // {"Since (days)", fmt.Sprintf("%.02f", s.sinceDays)},
+ // {"Posts per day", fmt.Sprintf("%.02f", s.postsPerDay)},
+ // {"Ppd target", fmt.Sprintf("%.02f", s.postsPerDayTarget)},
+ // }
+
+ sep := colour.SInfo3f("+%s+%s+", strings.Repeat("-", 22), strings.Repeat("-", 13))
+ sb.WriteString(sep)
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", platform, "Stat. value"))
+ sb.WriteString("\n")
+ sb.WriteString(sep)
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "Stats since (days)", fmt.Sprintf("%.02f", s.sinceDays)))
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "#Posted entries", strconv.Itoa(s.posted)))
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "#Queued entries", strconv.Itoa(s.queued)))
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "Last post (days ago)", fmt.Sprintf("%.02f", s.lastPostDaysAgo)))
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "Posts per day", fmt.Sprintf("%.02f", s.postsPerDay)))
+ sb.WriteString("\n")
+ sb.WriteString(colour.SInfo3f("| %-20s | %-11s |", "Posts per day target", fmt.Sprintf("%.02f", s.postsPerDayTarget)))
+ sb.WriteString("\n")
+ sb.WriteString(sep)
+ sb.WriteString("\n")
+
+ fmt.Print(sb.String())
+}
+
func newStats(dir string, lookback time.Duration, target int) (stats, error) {
stats := stats{postsPerDayTarget: float64(target) / 7}