summaryrefslogtreecommitdiff
path: root/zeitgeist.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@kesim.org>2024-11-29 11:55:32 +0100
committerÖzgür Kesim <oec@kesim.org>2024-11-29 11:55:32 +0100
commit86b8ff46b79d7b1f47374966dbdfdebe7f21e41a (patch)
tree6e22822fe7299fac68978e5a0204a8e13e7f9553 /zeitgeist.go
parent489ad5ede8d25130638aecbcdf5bb2190d516094 (diff)
sorted iterator added
Diffstat (limited to 'zeitgeist.go')
-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
+ }
+ }
+ }
+}