You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dps specifically needs to be checked otherwise *math.Inf or *math.NaN values can mess with the json encoding resulting in a fatal crash as the encoding library does not handle these values for you.
data_def.go changes:
import (
"errors"
"fmt"
"log"
"reflect"
"math"
)
// -- snipped
func generateData(fin *financialReport, name string) float64 {
log.Println("Generating data: ", name)
switch name {
case "GrossMargin":
//Do this only when the parsing is complete for required fields
if isCollectedDataSet(fin.Ops, "Revenue") && isCollectedDataSet(fin.Ops, "CostOfSales") {
log.Println("Generating Gross Margin")
if !math.IsInf(fin.Ops.Revenue - fin.Ops.CostOfSales, 0) && !math.IsNaN(fin.Ops.Revenue - fin.Ops.CostOfSales){
return fin.Ops.Revenue - fin.Ops.CostOfSales
}
}
case "Dps":
if isCollectedDataSet(fin.Cf, "Dividends") {
if isCollectedDataSet(fin.Ops, "WAShares") {
if !math.IsInf(round(fin.Cf.Dividends * -1 / fin.Ops.WAShares), 0) && !math.IsNaN(round(fin.Cf.Dividends * -1 / fin.Ops.WAShares)){
return round(fin.Cf.Dividends * -1 / fin.Ops.WAShares)
}
} else if isCollectedDataSet(fin.Entity, "ShareCount") {
if !math.IsInf(round(fin.Cf.Dividends * -1 / fin.Entity.ShareCount), 0) && !math.IsNaN(round(fin.Cf.Dividends * -1 / fin.Entity.ShareCount)){
return round(fin.Cf.Dividends * -1 / fin.Entity.ShareCount)
}
}
}
case "OpExpense":
if isCollectedDataSet(fin.Ops, "Revenue") &&
isCollectedDataSet(fin.Ops, "CostOfSales") &&
isCollectedDataSet(fin.Ops, "OpIncome") {
if !math.IsInf(round(fin.Ops.Revenue - fin.Ops.CostOfSales - fin.Ops.OpIncome),0) && !math.IsNaN(round(fin.Ops.Revenue - fin.Ops.CostOfSales - fin.Ops.OpIncome)) {
return round(fin.Ops.Revenue - fin.Ops.CostOfSales - fin.Ops.OpIncome)
}
}
}
return 0
}
The text was updated successfully, but these errors were encountered:
The reason for NaN should have either been a parse error with getting the field, in which case the CollectedData should have been false, or if the WAS or Shares is 0. Which again would have been a parsing error. What is the scenario in which you run into this case and need this check. The check in itself is harmless, but I am trying to understand why to get there
Dps specifically needs to be checked otherwise *math.Inf or *math.NaN values can mess with the json encoding resulting in a fatal crash as the encoding library does not handle these values for you.
data_def.go changes:
The text was updated successfully, but these errors were encountered: