diff options
| author | Paul Buetow <paul@buetow.org> | 2024-09-28 11:48:25 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-09-28 11:48:25 +0300 |
| commit | 9dda6355b81f6e6b93fc67d846657a388fcce4b7 (patch) | |
| tree | c02302ab96885f5238e6a20c215115083f52ff37 /internal/schedule/stats.go | |
| parent | 262af22115291863609319b6b0f313873891e15f (diff) | |
can hit and not hit the target
Diffstat (limited to 'internal/schedule/stats.go')
| -rw-r--r-- | internal/schedule/stats.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go index a969272..aac3737 100644 --- a/internal/schedule/stats.go +++ b/internal/schedule/stats.go @@ -13,20 +13,21 @@ import ( // Posting stats type stats struct { - posted int - queued int - sinceDays float64 - postsPerDay float64 + posted int + queued int + sinceDays float64 + postsPerDay float64 + postsPerDayTarget float64 } func (s stats) String() string { - return fmt.Sprintf("posted:%d,queued:%d,sinceDays:%v,postsPerDay:%v", - s.posted, s.queued, s.sinceDays, s.postsPerDay, + return fmt.Sprintf("posted:%d,queued:%d,sinceDays:%v,postsPerDay:%v >? %v", + s.posted, s.queued, s.sinceDays, s.postsPerDay, s.postsPerDayTarget, ) } -func newStats(dir string, lookback time.Duration) (stats, error) { - var stats stats +func newStats(dir string, lookback time.Duration, target int) (stats, error) { + stats := stats{postsPerDayTarget: float64(target) / 7} if err := stats.gatherPostedStats(dir, pastTime(lookback)); err != nil { return stats, err @@ -38,6 +39,10 @@ func newStats(dir string, lookback time.Duration) (stats, error) { return stats, nil } +func (s stats) targetHit() bool { + return s.postsPerDayTarget <= s.postsPerDay +} + func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error { ch, err := oi.ReadDirFilter(dir, func(file os.DirEntry) bool { return strings.HasSuffix(file.Name(), ".posted") @@ -69,7 +74,7 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error { since := now.Sub(oldest) s.sinceDays = since.Abs().Hours() / 24 - s.postsPerDay = float64(s.posted) / s.sinceDays + s.postsPerDay = float64(s.posted) / float64(s.sinceDays) return errors.Join(errs...) } |
