summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zeitgeist.go40
1 files changed, 38 insertions, 2 deletions
diff --git a/zeitgeist.go b/zeitgeist.go
index eb47ea6..3abf395 100644
--- a/zeitgeist.go
+++ b/zeitgeist.go
@@ -7,8 +7,10 @@ import (
"encoding/json"
"flag"
"fmt"
+ "iter"
"log"
"log/slog"
+ "maps"
"os"
"path/filepath"
"regexp"
@@ -925,7 +927,7 @@ func (p *Project) TotalWP(name string) (tot *WPTotals, e error) {
},
Tasks: make(map[string]*Totals),
}
- for tn, t := range wp.Tasks {
+ for tn, t := range wp.SortedTasks() {
tot.Tasks[tn] = &Totals{
Budgeted: t.Budget,
Planned: p.Planned.FilterWPTask(name, tn).Total(),
@@ -954,6 +956,17 @@ func (p *Project) Totals() (at *AllTotals) {
return at
}
+func (t *AllTotals) SortedWP() iter.Seq2[string, *WPTotals] {
+ return func(yield func(k string, v *WPTotals) bool) {
+ for _, k := range slices.Sorted(maps.Keys(t.WP)) {
+ v := t.WP[k]
+ if !yield(k, v) {
+ break
+ }
+ }
+ }
+}
+
func renderParallel(content ...[]string) []string {
maxh := 0
maxw := make([]int, len(content))
@@ -998,7 +1011,8 @@ func (p *Project) ParallelWPTotals(tmpl ...string) ([]string, error) {
totals := p.Totals()
content := [][]string{}
- for name, wpt := range totals.WP {
+ for _, name := range slices.Sorted(maps.Keys(totals.WP)) {
+ wpt := totals.WP[name]
buf := &bytes.Buffer{}
data := struct {
WP string
@@ -1016,3 +1030,25 @@ func (p *Project) ParallelWPTotals(tmpl ...string) ([]string, error) {
func (p *Project) DaysRemaining() []FullDate {
return p.Workdays(p.Today.Year(), p.Today.Month(), p.Today.Day())
}
+
+func (p *Project) SortedWorkpackages() iter.Seq2[string, Workpackage] {
+ return func(yield func(k string, v Workpackage) bool) {
+ for _, k := range slices.Sorted(maps.Keys(p.Workpackages)) {
+ v := p.Workpackages[k]
+ if !yield(k, v) {
+ break
+ }
+ }
+ }
+}
+
+func (wp *Workpackage) SortedTasks() iter.Seq2[string, Task] {
+ return func(yield func(k string, v Task) bool) {
+ for _, k := range slices.Sorted(maps.Keys(wp.Tasks)) {
+ v := wp.Tasks[k]
+ if !yield(k, v) {
+ break
+ }
+ }
+ }
+}