app.services.dsl_simulation_service module¶
Service that dry-runs a persisted DSL strategy without touching points, wallets, or user state.
Used by the POST /v1/strategies/custom/{id}/simulate endpoint so a
designer can iterate on rule logic before publishing. The service is the
only place that combines the strategy definition (loaded via
StrategyDefinitionService, which enforces realm scoping), the
precompute pipeline, and the timeout-wrapped interpreter run. Everything
else is plain data shuffling.
Mocks: when request.mockState is provided, the analytics service is
not called for the mocked paths. This makes simulations deterministic
and lets designers see the consequences of “what if the user had X
measurements?” without manipulating production data.
- class app.services.dsl_simulation_service.DslSimulationService(strategy_definition_service, user_points_analytics_service)[source]¶
Bases:
BaseService- Parameters:
strategy_definition_service (StrategyDefinitionService)
user_points_analytics_service (UserPointsAnalyticsService)
- async simulate(*, id, realmId, request)[source]¶
Run a custom strategy’s AST against simulated input without persisting.
Loads the strategy definition (scoped to
realmId) and executes its AST over the provided simulation request, returning the computed points and trace so authors can preview behaviour before publishing.- Parameters:
id (str) – Strategy definition identifier.
realmId (Any) – Realm/tenant the strategy belongs to.
request (SimulationRequest) – Simulated event input.
- Returns:
SimulationResponse – The simulated scoring result and trace.
- Raises:
DslValidationError – If the strategy has no AST to simulate.
- Return type:
SimulationResponse
- async simulate_inline(*, realmId, request)[source]¶
Dry-run an AST supplied inline.
No DB lookup and nothing persisted, so “Probar” no longer spawns orphan DRAFT rows and tests the exact AST on the editor canvas (including unsaved edits).
realmIdis accepted for symmetry withsimulate()and to keep the door open for per-tenant analytics scoping; the sandbox run itself is bounded by the same node/depth/timeout limits regardless of tenant.- Parameters:
realmId (Any)
request (InlineSimulationRequest)
- Return type:
SimulationResponse