Commit Graph

75 Commits

Author SHA1 Message Date
Huamonarch
ae7834adaa refactor: 算法子类化 — LogicAlg/BoundAlg/BoundHoldAlg/FeedbackAlg 消除 exp_type_ 分支
将 ExpBase::mon_proc() 中的 exp_type_ 分支逻辑提取为 4 个子类,通过 doMonProc() 虚函数实现多态分发:
- LogicAlg (exp_type 1):实时逻辑判断
- BoundAlg (exp_type 2):监控变量上下限检测
- BoundHoldAlg (exp_type 5):持续超限检测(继承 BoundAlg)
- FeedbackAlg (exp_type 3/4):动作反馈处理

ExpBase 新增纯虚函数 doMonProc() 和钩子函数 doInitExtend(),
init() 和 mon_proc() 中所有类型分支替换为虚函数委托调用。
2026-05-15 14:37:15 +08:00
Huamonarch
4f8eecd828 refactor: 提取 StatCollector 统计学习组件
将 ExpBase::cron_proc() 中的 DAA::STA 统计学习逻辑提取到独立的
StatCollector 工具类,统一管理分布统计的生命周期(样本累积、分布
初始化、DB2 持久化、置信区间更新)。同时将 exec_task() 与
task_mon_pro() 中的任务相关 STA 操作也委托给 StatCollector。

新增:
- eqpalg/utility/stat_collector.h  -- StatCollector 接口
- eqpalg/utility/stat_collector.cpp -- StatCollector 实现

修改:
- eqpalg/algs/exp_base.h  -- 替换 sta_ptr_ 为 stat_collector_
- eqpalg/algs/exp_base.cpp -- cron_proc/reload_ci_dist/reset_dev_data/
                               exec_task/task_mon_pro 委托给 StatCollector
2026-05-15 14:21:36 +08:00
Huamonarch
b9cf5f4e9e refactor: 提取 BoundChecker 上下限检测组件
从 ExpBase 提取 detect_up_down() 逻辑和哨兵值处理至独立的 BoundChecker 类。
将 DetectMode 从 struct 升级为 enum class。
2026-05-15 14:09:56 +08:00
Huamonarch
c4bcb6610b refactor: 删除旧反馈状态方法和标志(已由 FbStateMachine 替代) 2026-05-15 13:57:20 +08:00
Huamonarch
0106e553a0 refactor: 集成 FbStateMachine 到 ExpBase::mon_proc() 2026-05-15 13:36:30 +08:00
Huamonarch
fad4ee8e38 test: FbStateMachine 状态转换单元测试 2026-05-15 13:27:27 +08:00
Huamonarch
9f66fc10b3 feat: FbStateMachine 状态转换 + 变量操作实现 2026-05-15 13:22:16 +08:00
Huamonarch
f2f6d6ffb1 feat: 添加 FbStateMachine 头文件 2026-05-15 13:19:19 +08:00
Huamonarch
e9b2c178ba refactor: 删除 ExpModule 类(已被 ExpressionEngine 替代) 2026-05-15 13:15:05 +08:00
Huamonarch
3f8d281596 fix: 清理 ExpBase 子类中的 exp_act_/exp_feedback_/exp_result_ 残留引用
将 exp_bound、exp_times、exp_sample2D 中对已删除成员的引用替换为
expr_engine_->evaluate()/evaluateBool() 调用。
exp_sample2D 中原来绑定 exp_feedback_ 和 exp_result_ 的 sample_X/sample_Y
表达式现在通过 expr_engine_->registerExpression() 注册。
2026-05-15 13:14:17 +08:00
Huamonarch
38d0942a6c refactor: 非 ExpBase 算法适配 ExpressionEngine API 2026-05-15 13:08:30 +08:00
Huamonarch
7c2fe7f7bb refactor: ExpBase 表达式管理迁移到 ExpressionEngine 2026-05-15 12:59:11 +08:00
Huamonarch
96ca4d02bb refactor: AlgBase 从 ExpModule 迁移到 ExpressionEngine 2026-05-15 12:38:49 +08:00
Huamonarch
f10da49f65 test: ExpressionEngine 单元测试用例 2026-05-15 12:35:31 +08:00
Huamonarch
693d3b5197 feat: ExpressionEngine firstFill + printVars 实现 2026-05-15 12:32:20 +08:00
Huamonarch
e575efdc8a feat: ExpressionEngine FunVars 控制 + hold 变量管理 2026-05-15 12:30:11 +08:00
Huamonarch
50173683db feat: ExpressionEngine 变量刷新实现(MEMORY + IHDB) 2026-05-15 12:27:58 +08:00
Huamonarch
da9eb2ea2e feat: ExpressionEngine 核心实现(注册 + 求值) 2026-05-15 12:25:30 +08:00
Huamonarch
2f7ca1e123 feat: 添加 ExpressionEngine 头文件声明 2026-05-15 12:17:27 +08:00
Huamonarch
ec8e44ce5d test: 为 eqpalg 添加测试基础设施(test_harness + test_main) 2026-05-15 12:15:14 +08:00
Huamonarch
1ff51483e7 在 .gitignore 中添加 Claude Code 相关条目(.claude/、CLAUDE.md) 2026-05-15 09:14:56 +08:00
Huamonarch
65863b326f 为 RNG 模块添加 CTest 单元测试,覆盖常量/线性/漂移/正弦/复合/布尔/注册表/阀对等模型 2026-05-15 09:14:02 +08:00
Huamonarch
b99cd0a73c Add change documentation for 2026-05-13 eqpalg fixes and optimizations
Covers 9 commits: TaskRecord compile fixes, dual-layer ShmSpinLock,
rm -rf cleanup, update_cold handshake fix, ExpTimes DB robustness
and async persistence with AsyncDbWorker.
2026-05-13 17:10:09 +08:00
Huamonarch
672412e5a8 docs: add RNG changelog documenting all 2026-05-13 changes 2026-05-13 17:07:41 +08:00
Huamonarch
1e781a7c03 feat: add ! negation operator for boolean models
Prefix any boolean model reference with ! to negate its output.
Works with all boolean models: !toggle_2s, !valve_px_std:toggle_2s, !bool_50, etc.
2026-05-13 16:56:30 +08:00
Huamonarch
e4233cc23d fix: add period_ms to linear and drift models to prevent unbounded divergence
Without period, y=k*t+b and y=base+drift_rate*t grow infinitely, which is
unrealistic for industrial simulation. period_ms makes t wrap modulo the period,
producing sawtooth patterns that simulate per-cycle behavior (e.g. tension build-up
per coil, sensor drift per shift).
2026-05-13 16:34:00 +08:00
Huamonarch
256aa07c1c docs: add comprehensive RNG project README 2026-05-13 16:14:42 +08:00
Huamonarch
47dd4fad4b fix: qualify is_same_v with std:: in FlowData constructor 2026-05-13 16:02:27 +08:00
Huamonarch
f41ce0c40f fix: GuassRand use sigma as stddev directly instead of sqrt(sigma) 2026-05-13 15:53:25 +08:00
Huamonarch
5ee17627e9 fix: address code review issues
- read_csv.hpp: replace std::exit(1) with std::runtime_error throw
- read_csv.hpp: remove duplicate #pragma once
- RNG.cc: wrap JSON load in try-catch to prevent crash on missing config
- Generator.cc: fix comments to reflect actual 3-pass structure
2026-05-13 15:46:06 +08:00
Huamonarch
d9b4ee8eb3 fix: prevent ValvePairModel stuck-state by freezing prev_action during delay 2026-05-13 15:43:56 +08:00
Huamonarch
10bb9937d6 chore: remove unused BaseData.h 2026-05-13 15:33:36 +08:00
Huamonarch
7385b7cc6e build: add model/ source directory to CMake 2026-05-13 15:27:22 +08:00
Huamonarch
022993ab5a feat: load rng_models.json on startup 2026-05-13 15:26:19 +08:00
Huamonarch
4821cb9d36 refactor: replace hardcoded signal mappings with ModelRegistry 2026-05-13 15:24:32 +08:00
Huamonarch
b4bb27f1e5 feat: add ModelRegistry with JSON loading and composite model
Add CompositeModel for combining base+noise models, ModelRegistry singleton
with JSON-based model template loading, per-instance-key model isolation,
and inline CSV/valve pair/composite syntax parsing in createModel.
2026-05-13 15:20:51 +08:00
Huamonarch
4f83e41c0c feat: add ValvePairModel with jitter/flash/over-delay 2026-05-13 15:15:14 +08:00
Huamonarch
3ce03911c3 feat: add 3 boolean signal models 2026-05-13 15:13:31 +08:00
Huamonarch
2ef663af81 feat: add CsvReplayModel for CSV data replay 2026-05-13 15:12:04 +08:00
Huamonarch
afd753f803 feat: add 7 analog signal models (constant, normal, linear, sine, uniform, spike, drift) 2026-05-13 15:10:37 +08:00
Huamonarch
6afce89326 feat: add IModel base interface 2026-05-13 15:07:59 +08:00
Huamonarch
ae5f55c8ac feat: add rng_models.json with model templates 2026-05-13 15:07:06 +08:00
Huamonarch
70a976fe58 chore: add .worktrees/ to .gitignore 2026-05-13 15:04:31 +08:00
Huamonarch
7339801f2f docs: add RNG parameterized models implementation plan
11 tasks covering JSON config, 14 model classes, ModelRegistry factory,
Generator refactoring, valve_pair linking, and CMake updates.
2026-05-13 15:02:58 +08:00
Huamonarch
302aa82e38 docs: add valve_pair jitter/over-delay fault simulation params
delay_jitter_ms for natural timing variation, delay_over_prob/delay_over_ms
for simulating occasional valve timeout faults (e.g. once per day).
2026-05-13 14:47:35 +08:00
Huamonarch
a93801fea5 docs: fix rng_models.json path to absolute Linux path 2026-05-13 14:38:17 +08:00
Huamonarch
71feae9e79 docs: add RNG parameterized models design spec
Config-driven random number generation with model templates in JSON and
signal-to-model binding via DB2 tables[1] field. Supports 9 analog modes,
4 boolean modes including valve_pair timing simulation.
2026-05-13 14:32:58 +08:00
Huamonarch
11e5a6aeef Use angle-bracket include for async_db_worker.h
Matches codebase convention: all includes use <> paths, never "".
2026-05-13 13:51:49 +08:00
Huamonarch
f80a917ab7 Async-ify ExpTimes DB persistence with global singleton worker thread
Add AsyncDbWorker: a persistent background thread with dedup queue that
executes DB2 writes asynchronously, keeping the mon 20ms cycle free of
blocking I/O.

Changes:
- async_db_worker.h/.cc: singleton worker, submit() with rule_id dedup,
  drain_and_stop() for clean shutdown
- eqp_stat.h/.cc: new update_static(ruleid, shear_times, running_time)
  overload that skips redundant DB reads for known values (reduces
  5 SELECTs to 3 per persist cycle)
- exp_times.cc: extract persist_exp_times() as a standalone function,
  update_history_times() snapshots values and submits to worker
  (returns immediately), reset_dev_data() uses direct SHM update
- eqpalg_icei.cpp: alg_mgr_.reset() → drain_and_stop() in destructor
  ensures all algorithm threads are stopped before draining the worker

Risk: re-run cmake .. to pick up the new async_db_worker.cc file.
2026-05-13 13:32:50 +08:00
Huamonarch
6ed178b367 Fix: protect update_history_times snapshot restore from DB failures
Three fixes in update_history_times():
1. Wrap DB operations in try-catch — exception no longer skips the
   snapshot restore, preventing permanent loss of accumulated counts
2. Treat get_history_times() -1 return (DB failure) as skip, not as
   "record exists" → no more silent UPDATE on non-existent rows
3. Only call update_static and advance last_load_time_ on success,
   so a failed persist retries on the next cycle instead of waiting
   another rw_time_ minutes
2026-05-13 12:59:16 +08:00