BarChart module

26 views
Skip to first unread message

WouterD

unread,
May 11, 2020, 1:35:35 PM5/11/20
to ProjectMesa
Hi everyone!

I'm struggling with the data collection for a bar chart. My model consists of several groups of agents and for one of those groups I would like to create a bar chart. However, when collecting the data (see below) the other groups of agents are also being considered, leaving NaN values in the created dataframe. This leads to the model not being displayed.

The lines that I'm using to retrieve the agent data (AGV is the agent name) are the following:

        self.datacollector = DataCollector(
                                            agent_reporters={
                                            "Energ": lambda x: x.energy if x.type=='AGV' else None }
                                            ) 


Does someone know a way to work around this issue?

Thank you in advance!

Tom Pike

unread,
May 11, 2020, 7:41:26 PM5/11/20
to ProjectMesa
Have your tied pass instead of None as below. Its an iterator so you want to skip not add None. 

self.datacollector = DataCollector(
                                            agent_reporters={
                                            "Energ": lambda x: x.energy if x.type=='AGV' else pass }
                                            ) 

WouterD

unread,
May 12, 2020, 3:01:16 AM5/12/20
to ProjectMesa
Thanks for your reply!

I tried pass, continue, ... statements but those give 'invalid syntax' errors.


Op dinsdag 12 mei 2020 01:41:26 UTC+2 schreef Tom Pike:

Vincent Hess

unread,
May 12, 2020, 3:14:32 AM5/12/20
to WouterD, ProjectMesa
Have you tried leaving out the else statement completely?

--
Project repos: github.com/projectmesa
---
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectmesa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectmesa/c7d1b7c1-170b-47fa-9db0-0747c07ed6d7%40googlegroups.com.

WouterD

unread,
May 12, 2020, 3:32:17 AM5/12/20
to ProjectMesa
Yes, but that gives a syntax error as well.

For now, I modified the 'datacollection' file in mesa (in my directory ofcourse :p) to remove NaN values from the dataframe it returns.



Op dinsdag 12 mei 2020 09:14:32 UTC+2 schreef Corvince:
Have you tried leaving out the else statement completely?

WouterD <wouter.d...@gmail.com> schrieb am Di., 12. Mai 2020, 09:01:
Thanks for your reply!

I tried pass, continue, ... statements but those give 'invalid syntax' errors.


Op dinsdag 12 mei 2020 01:41:26 UTC+2 schreef Tom Pike:
Have your tied pass instead of None as below. Its an iterator so you want to skip not add None. 

self.datacollector = DataCollector(
                                            agent_reporters={
                                            "Energ": lambda x: x.energy if x.type=='AGV' else pass }
                                            ) 


On Monday, May 11, 2020 at 2:35:35 PM UTC-3, WouterD wrote:
Hi everyone!

I'm struggling with the data collection for a bar chart. My model consists of several groups of agents and for one of those groups I would like to create a bar chart. However, when collecting the data (see below) the other groups of agents are also being considered, leaving NaN values in the created dataframe. This leads to the model not being displayed.

The lines that I'm using to retrieve the agent data (AGV is the agent name) are the following:

        self.datacollector = DataCollector(
                                            agent_reporters={
                                            "Energ": lambda x: x.energy if x.type=='AGV' else None }
                                            ) 


Does someone know a way to work around this issue?

Thank you in advance!

--
Project repos: github.com/projectmesa
---
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to proje...@googlegroups.com.

Corvince

unread,
May 12, 2020, 3:42:26 AM5/12/20
to ProjectMesa
Ah, yes, it is still a ternary operator and requires the else statement.

Alternatively you don't need to use a lambda function, but can use any function. So you should be able to define something like:

def get_energy(agent):
   
if agent.type == "AGV":
       
return agent.energy

Corvince

unread,
May 12, 2020, 3:43:29 AM5/12/20
to ProjectMesa
On second thought forget about this. It will still implicitly return None for any other agent type, so this won't work either. Sorry for the confusion

WouterD

unread,
May 12, 2020, 3:50:49 AM5/12/20
to ProjectMesa
No problem, I appreciate the response.

I'll just stick with removing the NaNs from the dataframe until something else comes up :)


Op dinsdag 12 mei 2020 09:43:29 UTC+2 schreef Corvince:
Reply all
Reply to author
Forward
0 new messages