summaryrefslogtreecommitdiff
path: root/internal
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 /internal
parentfd43fe299047c1c993678a28cbb84418190060d6 (diff)
add table output for stats
Diffstat (limited to 'internal')
-rw-r--r--internal/colour/colour.go2
-rw-r--r--internal/schedule/schedule.go3
-rw-r--r--internal/schedule/stats.go39
3 files changed, 42 insertions, 2 deletions
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}