MCPcopy Create free account
hub / github.com/Facets-cloud/flow / LoadConstants

Function LoadConstants

internal/stats/model.go:29–50  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

27// silently; a corrupt file yields defaults with a stderr notice. Any field
28// ≤ 0 (including unset) falls back to its individual default.
29func 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.
53type Counts struct {

Callers 3

cmdStatsFunction · 0.92
TestLoadConstantsCorruptFunction · 0.85

Calls 1

DefaultConstantsFunction · 0.85

Tested by 2

TestLoadConstantsCorruptFunction · 0.68