From 93b0de2924acd1a2cd8595e920ce0d6b545782fd Mon Sep 17 00:00:00 2001 From: gravermistakes Date: Sun, 18 Oct 2026 22:15:06 -0700 Subject: [PATCH] economy: add hub.tcl --- core/src/economy/sims/hub.tcl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/src/economy/sims/hub.tcl diff --git a/core/src/economy/sims/hub.tcl b/core/src/economy/sims/hub.tcl new file mode 100644 index 0000000..6460bcf --- /dev/null +++ b/core/src/economy/sims/hub.tcl @@ -0,0 +1,29 @@ +namespace eval ::stomach {} + +oo::class create ::stomach::SimsHub { + variable predictions + constructor {} { set predictions {} } + method publish {sim_type prediction} { + foreach required {value lower_bound upper_bound confidence correctness certainty time_horizon token_ticker recent_shift timestamp} { + if {![dict exists $prediction $required]} { error "prediction_missing_$required" } + } + foreach numeric {value lower_bound upper_bound confidence correctness certainty recent_shift timestamp} { + if {![string is double -strict [dict get $prediction $numeric]]} { error "prediction_${numeric}_not_numeric" } + } + set value [dict get $prediction value]; set lo [dict get $prediction lower_bound]; set hi [dict get $prediction upper_bound] + if {$lo > $value || $value > $hi} { error "prediction_out_of_bounds" } + foreach metric {confidence correctness certainty} { + set v [dict get $prediction $metric] + if {$v < 0 || $v > 10} { error "prediction_${metric}_out_of_range" } + } + dict set prediction sim_type $sim_type + dict set prediction running 1 + dict set predictions $sim_type $prediction + return [dict create status published sim_type $sim_type] + } + method query {sim_type} { + if {![dict exists $predictions $sim_type]} { error "prediction_unavailable" } + return [dict get $predictions $sim_type] + } + method count {} { return [dict size $predictions] } +}