jakobaxelsson / sossim

A system-of-systems (SoS) simulator
MIT License
0 stars 0 forks source link

Add data collection #22

Open jakobaxelsson opened 10 months ago

jakobaxelsson commented 10 months ago

Support is needed for data collection and visualization. A rudimentary first version has been implemented. The approach taken is as follows:

The current implementation has several drawbacks or limitations:

jakobaxelsson commented 10 months ago

UI bug fixed. Problem was that the simulation view had initially style attribute "display: grid". When switching to data view, this became "display: none", and when switching back, it became "display: block". Solution was to add an extra div level above these, and doing the show/hide on that level.

jakobaxelsson commented 10 months ago

Improved data collection to use a separate table for each agent class. Updated user interface so that user interface can choose which table to see.

jakobaxelsson commented 10 months ago

With a data collector that has data in several tables, it is less obvious how to save it to a file for easy processing. Mesa provides functionality for getting each table as a data frame, and it would be possible to save that as a csv file. Then, one could make a zip file of all the tables (and maybe also add the configuration to that file, for reference).

However, to make this work both in browser and the normal file system, it might be necessary to create the zip file in memory first like this:

import io
import zipfile

zip_buffer = io.BytesIO()

with zipfile.ZipFile(zip_buffer, "a",
                     zipfile.ZIP_DEFLATED, False) as zip_file:
    for file_name, data in [('1.txt', io.BytesIO(b'111')),
                            ('2.txt', io.BytesIO(b'222'))]:
        zip_file.writestr(file_name, data.getvalue())

content = zip_buffer.getvalue()

The content can then be passed to the UI save_file_as function or to a normal file write in batch mode.

jakobaxelsson commented 10 months ago

File save and load is now re-implemented. The main file format is a zip file which contains as a minimum a manifest file with metainformation and a configuration file. If any data has been collected, this is also added with one separate csv file for each class. If profiling was enabled (in batch mode) the output of that is added.

Reading and writing files has been implemented both in batch (through command line flags) and interactive mode. Currently, the purpose of reading a file is to reuse a configuration. This accepts either a zip archive that contains the configuration file, or just the configuration file on its own.