diff options
| author | Paul Buetow <paul@buetow.org> | 2024-11-04 22:53:47 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-11-04 22:53:47 +0200 |
| commit | 70e08336fcc32d69dc58d87a1e1b3e5554732264 (patch) | |
| tree | 4407790335e11ed8895a466681b7e3745a55143f /internal/schedule | |
| parent | fd43fe299047c1c993678a28cbb84418190060d6 (diff) | |
add table output for stats
Diffstat (limited to 'internal/schedule')
| -rw-r--r-- | internal/schedule/schedule.go | 3 | ||||
| -rw-r--r-- | internal/schedule/stats.go | 39 |
2 files changed, 41 insertions, 1 deletions
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} |
