Skip to content

flatten_kpis

Python reference for nagasim.experiments.flatten_kpis.

Flatten the scalar KPI frames of a results dict into one long table.

Takes the system, resource, store, entity, user and cost frames, everything but "timeseries" (a curve rather than one number), numbers only. The keys are stable, so a scenario comparison or a precision target can name a KPI without knowing which frame it came from::

system/<Metric>              system/Avg Throughput Time
resource/<name>/<column>     resource/Agents/Usage % (snapshot)
store/<name>/<column>
entity/<type>/<column>
user/<statistic>             the RECORD statistic's own Value
plugin/<name>                a plugin's ctx.record_kpi value
slot/<block>/<column>        a queue row's slots, e.g. slot/Bay/Overflows
cost/<item>/Amount           a fixed, per-event or peak cost
stop/<belt>/<index>/<column> a conveyor stop, e.g. stop/Line/0/Avg Wait
divert/<belt>/<index>/<column> a conveyor divert, e.g. divert/Line/0/Diverted
merge/<belt>/<index>/<column>  a conveyor merge, e.g. merge/Line/0/Merged

Parameters:

Name Type Description Default
results dict

The result of nagasim.api.run_model.

required

Returns:

Type Description
DataFrame

Columns Run, KPI and Value.

See Also

nagasim.api.run_model : Produces the results. nagasim.experiments.run_until_precision : Takes one of these keys as its target.

Examples:

>>> from pathlib import Path
>>> import nagasim
>>> from nagasim import api, experiments
>>> path = Path(nagasim.__file__).parent / "models" / "single_server.json"
>>> results = api.run_model(str(path), replications=1, run_length=200, warmup=20, seed=0)
>>> flat = experiments.flatten_kpis(results)
>>> list(flat.columns)
['Run', 'KPI', 'Value']
>>> "system/Total Entities Completed" in set(flat["KPI"])
True