Skip to content

Commit 829ff36

Browse files
Fix Damage Instances, Actions, Reactions statistics cannot be below 1.00 (#2446)
* Fixes the aggregator being unable to correct count damage instances, actions, etc, which occur 0 times in some iterations * Fix undefined AddMultiple function * Adjusted each aggregator to decide if it needs to pad each StreamStat * Revert change to metadata aggregator * Fix aura aggregator not incrementing iter
1 parent bed481d commit 829ff36

8 files changed

Lines changed: 35 additions & 0 deletions

File tree

pkg/agg/actions/actions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717

1818
type buffer struct {
1919
characterActions []map[string]*calc.StreamStats
20+
iters uint
2021
}
2122

2223
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -44,13 +45,15 @@ func (b *buffer) Add(result stats.Result) {
4445
b.characterActions[i][k].Add(v)
4546
}
4647
}
48+
b.iters++
4749
}
4850

4951
func (b *buffer) Flush(result *model.SimulationStatistics) {
5052
result.CharacterActions = make([]*model.SourceStats, len(b.characterActions))
5153
for i, c := range b.characterActions {
5254
source := make(map[string]*model.DescriptiveStats)
5355
for k, s := range c {
56+
agg.PadStreamStatToCount(s, b.iters)
5457
source[k] = agg.ToDescriptiveStats(s)
5558
}
5659

pkg/agg/aura/aura.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717

1818
type buffer struct {
1919
auraUptime []map[string]*calc.StreamStats
20+
iters uint
2021
}
2122

2223
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -40,13 +41,15 @@ func (b *buffer) Add(result stats.Result) {
4041
b.auraUptime[i][k].Add(float64(v) / float64(result.Duration) * 100)
4142
}
4243
}
44+
b.iters++
4345
}
4446

4547
func (b *buffer) Flush(result *model.SimulationStatistics) {
4648
result.TargetAuraUptime = make([]*model.SourceStats, len(b.auraUptime))
4749
for i, c := range b.auraUptime {
4850
source := make(map[string]*model.DescriptiveStats)
4951
for k, s := range c {
52+
agg.PadStreamStatToCount(s, b.iters)
5053
source[k] = agg.ToDescriptiveStats(s)
5154
}
5255

pkg/agg/damage/damage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type buffer struct {
6161
cumulativeContrib [][]*calc.StreamStats
6262
// first index is for target, 2nd for iteration
6363
cumulativeDamage []runs
64+
iters uint
6465
}
6566

6667
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -218,18 +219,21 @@ func (b *buffer) Add(result stats.Result) {
218219
},
219220
)
220221
}
222+
b.iters++
221223
}
222224

223225
func (b *buffer) Flush(result *model.SimulationStatistics) {
224226
result.ElementDps = make(map[string]*model.DescriptiveStats)
225227
for k, v := range b.elementDPS {
226228
if v.Mean() > 0 {
229+
agg.PadStreamStatToCount(v, b.iters)
227230
result.ElementDps[k] = agg.ToDescriptiveStats(v)
228231
}
229232
}
230233

231234
result.TargetDps = make(map[int32]*model.DescriptiveStats)
232235
for k, v := range b.targetDPS {
236+
agg.PadStreamStatToCount(v, b.iters)
233237
result.TargetDps[int32(k)] = agg.ToDescriptiveStats(v)
234238
}
235239

@@ -243,6 +247,7 @@ func (b *buffer) Flush(result *model.SimulationStatistics) {
243247
elements := make(map[string]*model.DescriptiveStats)
244248
for k, v := range em {
245249
if v.Mean() > 0 {
250+
agg.PadStreamStatToCount(v, b.iters)
246251
elements[k] = agg.ToDescriptiveStats(v)
247252
}
248253
}
@@ -256,6 +261,7 @@ func (b *buffer) Flush(result *model.SimulationStatistics) {
256261
for i, t := range b.dpsByTarget {
257262
targets := make(map[int32]*model.DescriptiveStats)
258263
for k, v := range t {
264+
agg.PadStreamStatToCount(v, b.iters)
259265
targets[int32(k)] = agg.ToDescriptiveStats(v)
260266
}
261267

@@ -288,6 +294,7 @@ func (b *buffer) Flush(result *model.SimulationStatistics) {
288294
for i, c := range b.sourceDPS {
289295
source := make(map[string]*model.DescriptiveStats)
290296
for k, s := range c {
297+
agg.PadStreamStatToCount(s, b.iters)
291298
source[k] = agg.ToDescriptiveStats(s)
292299
}
293300

@@ -300,6 +307,7 @@ func (b *buffer) Flush(result *model.SimulationStatistics) {
300307
for i, c := range b.sourceDamageInstances {
301308
source := make(map[string]*model.DescriptiveStats)
302309
for k, s := range c {
310+
agg.PadStreamStatToCount(s, b.iters)
303311
source[k] = agg.ToDescriptiveStats(s)
304312
}
305313

pkg/agg/energy/energy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717

1818
type buffer struct {
1919
sourceEnergy []map[string]*calc.StreamStats
20+
iters uint
2021
}
2122

2223
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -44,13 +45,15 @@ func (b *buffer) Add(result stats.Result) {
4445
b.sourceEnergy[i][k].Add(v)
4546
}
4647
}
48+
b.iters++
4749
}
4850

4951
func (b *buffer) Flush(result *model.SimulationStatistics) {
5052
result.TotalSourceEnergy = make([]*model.SourceStats, len(b.sourceEnergy))
5153
for i, c := range b.sourceEnergy {
5254
source := make(map[string]*model.DescriptiveStats)
5355
for k, s := range c {
56+
agg.PadStreamStatToCount(s, b.iters)
5457
source[k] = agg.ToDescriptiveStats(s)
5558
}
5659

pkg/agg/overview/overview.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type buffer struct {
2323
hps *calc.Sample
2424
shp *calc.Sample
2525
totalDamage calc.StreamStats
26+
iters uint
2627
}
2728

2829
func newSample(itr int) *calc.Sample {
@@ -79,6 +80,7 @@ func (b *buffer) Add(result stats.Result) {
7980
b.rps.Xs[iX] /= b.duration.Xs[iX]
8081
b.hps.Xs[iX] /= b.duration.Xs[iX]
8182
b.eps.Xs[iX] /= b.duration.Xs[iX]
83+
b.iters++
8284
}
8385

8486
func (b *buffer) Flush(result *model.SimulationStatistics) {

pkg/agg/reaction/reaction.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717

1818
type buffer struct {
1919
sourceReactions []map[string]*calc.StreamStats
20+
iters uint
2021
}
2122

2223
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -44,13 +45,15 @@ func (b *buffer) Add(result stats.Result) {
4445
b.sourceReactions[i][k].Add(v)
4546
}
4647
}
48+
b.iters++
4749
}
4850

4951
func (b *buffer) Flush(result *model.SimulationStatistics) {
5052
result.SourceReactions = make([]*model.SourceStats, len(b.sourceReactions))
5153
for i, c := range b.sourceReactions {
5254
source := make(map[string]*model.DescriptiveStats)
5355
for k, s := range c {
56+
agg.PadStreamStatToCount(s, b.iters)
5457
source[k] = agg.ToDescriptiveStats(s)
5558
}
5659

pkg/agg/shield/shield.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func init() {
3333
type buffer struct {
3434
shieldHP map[string]map[string]*stats.WeightedStreamStats
3535
uptime map[string]*calc.StreamStats
36+
iters uint
3637
}
3738

3839
func NewAgg(cfg *info.ActionList) (agg.Aggregator, error) {
@@ -82,6 +83,7 @@ func (b *buffer) Add(result stats.Result) {
8283
}
8384
}
8485
b.uptime["effective"].Add(effectiveUptime / float64(result.Duration))
86+
b.iters++
8587
}
8688

8789
func (b *buffer) Flush(result *model.SimulationStatistics) {

pkg/agg/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import (
77
"github.com/genshinsim/gcsim/pkg/model"
88
)
99

10+
// If the count is smaller than ss.Count, nothing will happen.
11+
// Otherwise, 0s will be added to ss until ss.Count is equal to count.
12+
func PadStreamStatToCount(ss *stats.StreamStats, count uint) {
13+
if count < ss.Count {
14+
return
15+
}
16+
for range count - ss.Count {
17+
ss.Add(0)
18+
}
19+
}
20+
1021
func ToDescriptiveStats(ss *stats.StreamStats) *model.DescriptiveStats {
1122
sd := ss.StdDev()
1223
if math.IsNaN(sd) {

0 commit comments

Comments
 (0)