RECORD¶
Counts or measures something as entities pass (a count, a time between arrivals, a defect, a cost) in a user-named statistic, without delaying them.
A zero-time block that updates a user-defined statistic and forwards the entity unchanged.
Statistics live on the simulation context (ctx.user_stats), keyed by stat_name, so two RECORD blocks writing to the same name share one collector -- core/schema/ rejects a same-name pair with different kinds at load time, before a run can hit the mismatch here.
expr is the increment for "count", the observed value for "tally", the new level for "time_persistent", and ignored for "time_between" (it tallies the gap since the statistic's last arrival; the first arrival records nothing).
kind="cost" is the one kind that builds no collector: expr is a MONEY amount added to the cost item stat_name every time an entity passes -- an ordering cost, a changeover cost, a lost-sale penalty. It joins the model's Total Cost and is itemised in the cost_summary frame.
Family: stats. Python builder: m.record(...).
Typical uses¶
Use RECORD to measure something as entities pass, without delaying them: a count of defects, the time between arrivals, a value per order, a cost. The result is a named statistic in the user_summary frame. To change an attribute or a variable, use ASSIGN.
Behaviour and rules¶
The kind sets what is recorded. count adds expr to a running total. tally collects expr as an observation and reports its mean and spread. time_between records the gap since the previous arrival and ignores expr, and the first arrival records nothing. time_persistent sets a level to expr and reports its time average.
Two RECORD blocks with the same stat_name share one statistic. They must have the same kind, or a check reports an error. The default expr is 1, which makes count a simple counter.
The kind cost builds no statistic. It adds expr, an amount of money, to the cost item stat_name each time an entity passes. The item joins the total cost and the cost_summary frame, grouped under category. The warm-up clears user statistics and event costs.
Ports¶
- Inputs: any number of incoming links.
- Outputs: one outgoing link.
Parameters¶
| Parameter | Type | Default | Required | Quantity | Unit key | Description |
|---|---|---|---|---|---|---|
stat_name |
str | '' |
yes | Name of the user statistic; two RECORD blocks with the same name share one collector. | ||
kind |
str | 'count' |
"count" (running total of expr), "tally" (mean of expr), "time_between" (mean gap between arrivals), "time_persistent" (time-average level of expr) or "cost" (adds expr to a named cost item and to Total Cost). | |||
expr |
str | '1' |
Expression evaluated at each arrival; ignored for kind=time_between. | |||
category |
str | '' |
Cost category this item is grouped under in the cost_summary frame; used by kind=cost only. |
Statistics¶
Every run fills system and entity_summary (see the KPI reference). The example below also fills:
| Frame | Columns |
|---|---|
user_summary |
Run, Statistic, Kind, Count, Value, Min, Max, Std |
material_flow_summary |
Run, From, To, Entities |
Problem codes¶
A check of the model reports these about this block:
| Code | Meaning |
|---|---|
E_RECORD_KIND |
A RECORD block's kind is not a known user-statistic kind. |
E_RECORD_KIND_CONFLICT |
Two RECORD blocks give the same statistic different kinds. |
E_RECORD_STAT_NAME |
A RECORD block has an empty stat_name. |
Example¶
The snippet seeds itself; its output is from a run made when this page was generated.
from nagasim import build as nb
m = nb.Model(time_limit=100)
arrive = m.create(distribution=nb.Exponential(rate=1.0))
arrive >> m.record(stat_name="orders", kind="count") >> m.dispose()
results = m.run(seed=1)
print(results["user_summary"].to_string(index=False))
Run Statistic Kind Count Value Min Max Std
1 orders count 100 100.0 NaN NaN NaN
Used in¶
Bundled models: Biogas plant (library assets), Emergency department: staffing game, Hub day: electrifying the ground support equipment, Container terminal: electrification, Container terminal: quay to yard, Hub day: turnaround workload (crews, ground equipment, on-time departures) and 12 more.
Guides: Costing, Coming from AnyLogic, Coming from Arena, How do I share a site's power limit between chargers?, Entities and attributes, Expressions and variables and 1 more.