LoadConstants reads ~/.flow/stats.json. A missing file yields defaults silently; a corrupt file yields defaults with a stderr notice. Any field ≤ 0 (including unset) falls back to its individual default.
(path string)
| 27 | // silently; a corrupt file yields defaults with a stderr notice. Any field |
| 28 | // ≤ 0 (including unset) falls back to its individual default. |
| 29 | func LoadConstants(path string) Constants { |
| 30 | def := DefaultConstants() |
| 31 | data, err := os.ReadFile(path) |
| 32 | if err != nil { |
| 33 | return def |
| 34 | } |
| 35 | var c Constants |
| 36 | if err := json.Unmarshal(data, &c); err != nil { |
| 37 | fmt.Fprintf(os.Stderr, "warning: stats.json is malformed (%v); using defaults\n", err) |
| 38 | return def |
| 39 | } |
| 40 | if c.MinutesPerUnattendedRun <= 0 { |
| 41 | c.MinutesPerUnattendedRun = def.MinutesPerUnattendedRun |
| 42 | } |
| 43 | if c.MinutesPerContextSwitch <= 0 { |
| 44 | c.MinutesPerContextSwitch = def.MinutesPerContextSwitch |
| 45 | } |
| 46 | if c.DollarPerHour <= 0 { |
| 47 | c.DollarPerHour = def.DollarPerHour |
| 48 | } |
| 49 | return c |
| 50 | } |
| 51 | |
| 52 | // Counts are the raw inputs to the savings model. |
| 53 | type Counts struct { |