Python code for converting experiments XML to listing

Recently, I asked for experiment listings (https://forum.netlogo.org/t/experiment-listing/738).

In his answer @ERSUCC suggested that I could transform an XML export to any required format.
I took up the challenge and created a Python program for doing that. (As I said quick-and-dirty and not-so-perfect; though a bit less quick, a bit less dirty, and less imperfect than I thought at first.)

The accompanying ZIP-file contains the code and input and outputs for the Wolf Sheep Predation model. It is free for anyone interested. (Oh, I can’t upload ZIP. I’ll post the files separately.)

For the first attempt, I used regular expressions. They work for many cases, but break on CDATA.
Then, I started on using an XML parser. My experiences with JDOM (Java) in the past were not encouraging, but Python’s low-threshold library works very intuitively!

The output is not perfect and not exactly as the example I posted earlier, but good enough for my current purposes.

1 Like

Here are the Python files:

exp_listing_write.py (2.2 KB)

exp_listing_utils.py (1.1 KB)

exp_listing_read_dom.py (4.1 KB)

exp_listing_main.py (487 Bytes)

exp_listing_base.py (1.5 KB)

And another Python file for the regular expression parser (I’m also only allowed to upload 5 files at a time)

exp_listing_read_re.py (9.8 KB)

And these are the input (XML), and outputs (CSV and renamed HTML) for the example model:

Wolf Sheep Predation-experiments.csv (5.9 KB)

Wolf Sheep Predation-experiments_html.txt (11.5 KB)

Wolf Sheep Predation-experiments.xml (11.1 KB)

This has become rather long. Please start reading at the top…

Very cool, it’s good to hear that you were able to find a solution! If you’re comfortable using GitHub, I would recommend uploading your scripts there, so you can have a persistent link to them. It would also help to make it more discoverable for the NetLogo community. Let us know if you are interested and need any help doing that!

Isaac B.

1 Like

Hi Isaac,

Thank you for the compliment.

Technically it would not be a big deal uploading the code – with examples – to GitHub.

But I consider this code as only a Proof-of-Concept, and then quick-and-dirty as such.

In my opinion, for GitHub it should at least have the level of a prototype.
This would need some proper Software Engineering. As a former teacher of Software Engineering (next to Agent Based Modeling), I would be ashamed to put quick-and-dirty code on GitHub amongst properly engineered projects.

For the current code, I did not do any version management, no design, no thorough testing, and no documentation at all (now I think of it, not even header comments…)
The code was tested on all experiments from NetLogo’s Example Library, some models I had at hand, and of course the model that triggered the question in the first place. But that’s it.

I don’t have any plans to do further development.

Anybody interested, feel free to pick it up.

Mark

That makes sense, thanks for the clarification. There is certainly no obligation to upload it anywhere!

1 Like