Closed narc98 closed 2 weeks ago
For clarification purposes, I tried creating a simple "TextData" element and adding it to the call to the ModularServer constructor (throws a "AttributeError: 'TextData' object has no attribute 'package_includes'). I also tried the sample code concept from the docs/modular-visualization.rst file (lines 117-165), but that throws the same error. If I just add the missing variables to the "AttributeElement" class, then the server will open, but a "TypeError: render() takes 1 positional argument but 2 were given" (line 322 from ModularVisualization.py). I can't trace why multiple arguments are being passed there (I have not modified any of the base Mesa code).
That's definitely a good idea! The documentation on readthedocs was slightly out of date; that's fixed now. Can you post your code on here or in a gist or something? That'll make it easier to see what the issue is.
https://gist.github.com/narc98/3bd3b0617958047d19ef5a4227818c1e
Sure. I'm working on a model where drones (agents) depart a location and search a given area and report back to a Command/Control agent if they find any objects. My "Operator" class just has some basic movement behaviors (moveToPos(pos), stayCloseToPos(distance), etc..). Each step, I'd like to show what's in the C2.investigate and C2.tracking dictionaries in the main window.
Thanks very much for taking a look, Nate
@dmasad
this is easy to do with solara and covered in some of the examples on read the docs.
For example:
def get_happy_agents(model):
"""Display a text count of how many happy agents there are."""
return solara.Markdown(f"**Happy agents: {model.happy}**")
...
page = SolaraViz(
model1,
components=[
make_space_component(agent_portrayal),
make_plot_measure("happy"),
get_happy_agents,
],
model_params=model_params,
)
https://mesa.readthedocs.io/latest/examples/virus_on_network.html
def get_resistant_susceptible_ratio(model):
ratio = model.resistant_susceptible_ratio()
ratio_text = r"$\infty$" if ratio is math.inf else f"{ratio:.2f}"
infected_text = str(number_infected(model))
return f"Resistant/Susceptible Ratio: {ratio_text}<br>Infected Remaining: {infected_text}"
(sorry wrong button)
Your project is a great launching pad for my ABM work. I'm curious if there's a mechanism to add something like a TextData element to the overall server window (for instance, the Wolf/Sheep ModularServer). I have added a few different charts to monitor variables in my model but would like to add another module that simply displays the contents of a dictionary (concept in the attached picture). This behavior either doesn't exist or I can't solve how to add that element to the server (which I presume is probably the case). Thanks for any help anyone can offer.
Nate