Generalize origin routing and remove region from the agent layer
Problem
Region (bra/arg/usa) is hardcoded across three places that should be
region-agnostic:
- Transport (
transport.py, _move_split): Brazilian ports filter out
non-BRA soy with hardcoded exclude_arg / exclude_usa flags. Logic is
negative ("all except…") and leans on untyped getattr reads. Every new
origin needs another exclude_* flag. (Raised in PR
4-allow-for-conditional-events.)
- Wholesaler agent (
trader.py): derives bra/arg/usa_volume from
volume_by_origin using hardcoded origin strings — location living in an agent.
- Reporting (
data_collector.py): the per-region CSV columns require those
named attrs to exist on the agent, because Melodie's DataCollector records by
attribute name.
volume_by_origin (keyed on farmer.origin) is already the region-agnostic
source of truth. Region is a routing + reporting dimension, not agent state.
Fix
- Give each export port an explicit
accepted_origins set (Santos/Paranagua →
{"bra"}) and route only matching-origin volume from volume_by_origin.
Drop the exclude_* params and getattr lookups.
- Remove
bra/arg/usa_volume and all origin string literals from trader.py.
The agent keeps only volume_by_origin.
- Move the origin→region-column projection into the reporting layer, computed
from volume_by_origin. This is the only place region may live.
- Keep the origin→region mapping in exactly one non-agent location.
Acceptance
Note
Branch 31-unify-farmer-trader-… merges first with the compatibility shim in
place (trader.py:140-144, plus the bra/arg/usa_volume attrs). This ticket
then pulls dev and removes that shim — deleting the three attrs, the origin
string literals, and the now-stale comment — as part of the work here.
Ref: transport.py:_move_split, trader.py, data_collector.py
Generalize origin routing and remove region from the agent layer
Problem
Region (bra/arg/usa) is hardcoded across three places that should be
region-agnostic:
transport.py,_move_split): Brazilian ports filter outnon-BRA soy with hardcoded
exclude_arg/exclude_usaflags. Logic isnegative ("all except…") and leans on untyped
getattrreads. Every neworigin needs another
exclude_*flag. (Raised in PR4-allow-for-conditional-events.)trader.py): derivesbra/arg/usa_volumefromvolume_by_originusing hardcoded origin strings — location living in an agent.data_collector.py): the per-region CSV columns require thosenamed attrs to exist on the agent, because Melodie's DataCollector records by
attribute name.
volume_by_origin(keyed onfarmer.origin) is already the region-agnosticsource of truth. Region is a routing + reporting dimension, not agent state.
Fix
accepted_originsset (Santos/Paranagua →{"bra"}) and route only matching-origin volume fromvolume_by_origin.Drop the
exclude_*params andgetattrlookups.bra/arg/usa_volumeand all origin string literals fromtrader.py.The agent keeps only
volume_by_origin.from
volume_by_origin. This is the only place region may live.Acceptance
exclude_*flags intransport.py; routing driven byaccepted_origins.agents/*.py(grep clean:
bra_volume|arg_volume|usa_volume,brazil_farms|argentina_farms|us_farms).volume_by_origin, never named attrs._move_splitand no changeto any agent file.
Result_Simulator_*.csvbyte-identical to apre-change baseline (Santos/Paranagua output unchanged).
Note
Branch
31-unify-farmer-trader-…merges first with the compatibility shim inplace (
trader.py:140-144, plus thebra/arg/usa_volumeattrs). This ticketthen pulls dev and removes that shim — deleting the three attrs, the origin
string literals, and the now-stale comment — as part of the work here.
Ref:
transport.py:_move_split,trader.py,data_collector.py