Skip to content

Commit

Permalink
fix: calculate grade, avoid NaN/Inf number
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Nov 24, 2023
1 parent 89be699 commit d5a7e21
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/wasm/activity-service/preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package preprocessor

import (
"math"

"github.com/muktihari/openactivity-fit/activity"
"github.com/muktihari/openactivity-fit/geomath"
"github.com/muktihari/openactivity-fit/kit"
Expand Down Expand Up @@ -192,10 +190,12 @@ func (p *Preprocessor) CalculateGrade(records []*activity.Record) {
run = d
}

grade := rise / run * 100
if math.IsInf(grade, 0) {
if rise == 0 || run == 0 {
continue
}

grade := rise / run * 100

rec.Grade = &grade
}
}
Expand Down

0 comments on commit d5a7e21

Please sign in to comment.