CSVDataCollector
agent-based modeling, abm, csv, data collection, bptk, bptk-py, python, business prototyping
CSVDataCollector
CSVDataCollector Constructor
CSVDataCollector(prefix=‘csv/’)
A data collector that writes simulation results to CSV files instead of keeping them in memory.
Use it for runs whose results are larger than you want in memory, or when the analysis happens somewhere else — a spreadsheet, R, a BI tool. Each agent type gets its own file below prefix, and so do the recorded events.
The directory is not created for you: make sure prefix exists before the run starts.
from BPTK_Py import Model, CSVDataCollector, SimultaneousScheduler
model = Model(
starttime=1, stoptime=60, dt=1, name="Customer Acquisition",
scheduler=SimultaneousScheduler(),
data_collector=CSVDataCollector(prefix="results/"),
)Parameters
- prefix – String (Default=‘csv/’). The directory the files are written to, including the trailing slash.
CSVDataCollector.collect_agent_statistics
collect_agent_statistics(sim_time, agents)
Called by the scheduler once per timestep. Appends the agents’ statistics to the CSV files.
Parameters
sim_time – Float. The timestep being recorded.
agents – List. The agents to record.
CSVDataCollector.record_event
record_event(time, event)
Appends one event to the event file.
Parameters
time – Float. The timestep at which the event was sent.
event – Event. The event to record.
CSVDataCollector.statistics
statistics()
Returns the statistics collected so far.
Returns
A dictionary.
CSVDataCollector.reset
reset()
Discards what has been collected. Call it before re-running a model with the same collector.
To learn how to write a collector of your own, see Custom Data Collectors.