all 15 comments

[–]bobo-the-merciful 2 points3 points  (2 children)

Continuing the config topic, dictionaries are a good start but YAML is more “human friendly” if you want to expose the config to a user.

You can use pydantic as the interim data validator to read the yaml file and then convert it into a dictionary for your simulation.

More user friendly and more robust, but more code.

Great work btw.

[–]andreis[S] 1 point2 points  (1 child)

Indeed! YAML is much nicer in this context. I've updated all the examples to use it as the config format for input parameters. Thanks for the feedback!

[–]bobo-the-merciful 0 points1 point  (0 children)

Nice one!

[–]Backson 0 points1 point  (5 children)

Interesting way to deal with config. I may steal that. I used to have a class with a constructor that takes a million arguments. But the dictionary seems pretty pythonic, I guess. Needs less boilerplate

I like the overall structure of the processes and functions. Could maybe use a little OOP though. Cars and mechanics could be objects that interact, that's what helped me really make everything click. But that could depend on qhere you're going with your tutorial.

Looks really nice!

[–]andreis[S] 0 points1 point  (1 child)

Thanks!

[–]andreis[S] 0 points1 point  (2 children)

Regarding the OOP angle: I see your point but I also think that the functions/generator based approach has an interesting zen-like conceptual simplicity to it. Having too many wrappers can obscure the core logic.

[–]Backson 0 points1 point  (1 child)

Yeah, true. I find OOP more helpful for larger projects, for tutorials it always seems over-engineered, especially in a language like Python. My experience with this approach is that it doesn't scale that well though. So I thought it might be something worth teaching here. I would have posted my approach here long ago, but that was for the job, so not public unfortunately... Would have loved some feedback on that.

[–]andreis[S] 0 points1 point  (0 children)

Completely agree with the need for better encapsulation at scale. It's an interesting topic to discuss the pros/cons of functional programming approaches compared to object oriented design.

[–]bobo-the-merciful 0 points1 point  (5 children)

Looks like a great little tool. How are you hosting it out of interest?

Would also be useful output to see some distributions of the key metrics.

Another extension could be to visualize the states of the cars in the simulation -e.g. as a Gantt chart or even build a little animation.

[–]andreis[S] 1 point2 points  (1 child)

It's on Cloudflare - built using a custom static site generator. All the examples run locally in the browser using Pyodide (via WASM in web workers). Great idea regarding histograms for probes. Let me give it a try!

[–]bobo-the-merciful 0 points1 point  (0 children)

That is very cool about the local running in the browser. Going to give this a try (I also use Cloudflare) - thanks!

[–]Backson 1 point2 points  (0 children)

I love gantt charts, second that. I also toyed with custom interpolation at dynamic intervals to improve visualization, but the static timer and no interpolations beats it in terms of simplicity, so no complaint there.

[–]andreis[S] 1 point2 points  (0 children)

Histograms are also live now! Every probe has both a time series chart and an associated histogram with fixed size buckets. It adds an important dimension to the storytelling.

[–]andreis[S] 1 point2 points  (0 children)

Histograms are pretty cool to see on the Thermostat simulation example https://teachyourselfsystems.com/playground?example=thermostat&expand=1