M3: add sims/scheduler.tcl

This commit is contained in:
2026-10-18 22:47:22 -07:00
parent 78592d4b0f
commit 56fa2c3850
+21
View File
@@ -0,0 +1,21 @@
namespace eval ::stomach {}
oo::class create ::stomach::HorizonClock {
variable ratios simulated
constructor {} {
set ratios [dict create tick_hourly 90 daily 2160 weekly 15120 monthly 64800 annual 788000 five_year 3942000]
set simulated {}
dict for {h r} $ratios { dict set simulated $h 0.0 }
}
method horizons {} { return [dict keys $ratios] }
method ratio {horizon} {
if {![dict exists $ratios $horizon]} { error "unknown_horizon" }
return [dict get $ratios $horizon]
}
method advance {wall_seconds} {
if {![string is double -strict $wall_seconds] || $wall_seconds < 0} { error "invalid_wall_seconds" }
dict for {h r} $ratios { dict set simulated $h [expr {[dict get $simulated $h] + $wall_seconds*$r}] }
return $simulated
}
method state {} { return $simulated }
}