• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark-tools / 13609444145

01 Mar 2025 10:31PM CUT coverage: 98.438%. Remained the same
13609444145

push

github

web-flow
Tweak README example docstrings (#3)

630 of 640 relevant lines covered (98.44%)

133.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/reporter/callback.go
1
package reporter
2

3
import (
4
        "github.com/mlange-42/ark-tools/observer"
5
        "github.com/mlange-42/ark/ecs"
6
)
7

8
// RowCallback reporter calling a function on each update, using an [observer.Row].
9
type RowCallback struct {
10
        Observer       observer.Row                  // Observer to get data from.
11
        UpdateInterval int                           // Update interval in model ticks.
12
        HeaderCallback func(header []string)         // Called with the header of the observer during initialization.
13
        Callback       func(step int, row []float64) // Called with step and data row on each update (subject to UpdateInterval).
14
        Final          bool                          // Whether Callback should be called on finalization only, instead of on every tick.
15
        step           int64
16
}
17

18
// Initialize the system
19
func (s *RowCallback) Initialize(w *ecs.World) {
2✔
20
        s.Observer.Initialize(w)
2✔
21
        if s.UpdateInterval == 0 {
4✔
22
                s.UpdateInterval = 1
2✔
23
        }
2✔
24
        if s.HeaderCallback != nil {
4✔
25
                s.HeaderCallback(s.Observer.Header())
2✔
26
        }
2✔
27
        s.step = 0
2✔
28
}
29

30
// Update the system
31
func (s *RowCallback) Update(w *ecs.World) {
6✔
32
        s.Observer.Update(w)
6✔
33

6✔
34
        if !s.Final && s.step%int64(s.UpdateInterval) == 0 {
9✔
35
                values := s.Observer.Values(w)
3✔
36
                s.Callback(int(s.step), values)
3✔
37
        }
3✔
38

39
        s.step++
6✔
40
}
41

42
// Finalize the system
43
func (s *RowCallback) Finalize(w *ecs.World) {
2✔
44
        if !s.Final {
3✔
45
                return
1✔
46
        }
1✔
47
        values := s.Observer.Values(w)
1✔
48
        s.Callback(int(s.step), values)
1✔
49
}
50

51
// TableCallback reporter calling a function on each update, using an [observer.Table].
52
type TableCallback struct {
53
        Observer       observer.Table                    // Observer to get data from.
54
        UpdateInterval int                               // Update interval in model ticks.
55
        HeaderCallback func(header []string)             // Called with the header of the observer during initialization.
56
        Callback       func(step int, table [][]float64) // Called with step and data table on each update (subject to UpdateInterval).
57
        Final          bool                              // Whether Callback should be called on finalization only, instead of on every tick.
58
        step           int64
59
}
60

61
// Initialize the system
62
func (s *TableCallback) Initialize(w *ecs.World) {
2✔
63
        s.Observer.Initialize(w)
2✔
64
        if s.UpdateInterval == 0 {
4✔
65
                s.UpdateInterval = 1
2✔
66
        }
2✔
67
        if s.HeaderCallback != nil {
4✔
68
                s.HeaderCallback(s.Observer.Header())
2✔
69
        }
2✔
70
        s.step = 0
2✔
71
}
72

73
// Update the system
74
func (s *TableCallback) Update(w *ecs.World) {
6✔
75
        s.Observer.Update(w)
6✔
76

6✔
77
        if !s.Final && s.step%int64(s.UpdateInterval) == 0 {
9✔
78
                values := s.Observer.Values(w)
3✔
79
                s.Callback(int(s.step), values)
3✔
80
        }
3✔
81

82
        s.step++
6✔
83
}
84

85
// Finalize the system
86
func (s *TableCallback) Finalize(w *ecs.World) {
2✔
87
        if !s.Final {
3✔
88
                return
1✔
89
        }
1✔
90
        values := s.Observer.Values(w)
1✔
91
        s.Callback(int(s.step), values)
1✔
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc