From 0efddb95dd5adb19337f7d391a4dca2ee8a4f6b9 Mon Sep 17 00:00:00 2001 From: Jens de Bruijn Date: Fri, 11 Oct 2024 16:51:21 +0200 Subject: [PATCH] allow reporting of property --- honeybees/reporter.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/honeybees/reporter.py b/honeybees/reporter.py index 0cba01c..a246649 100644 --- a/honeybees/reporter.py +++ b/honeybees/reporter.py @@ -20,6 +20,7 @@ """ import sys +import re from collections.abc import Iterable import os import numpy as np @@ -400,13 +401,23 @@ def extract_agent_data(self, name: str, conf: dict) -> None: conf: Dictionary with report configuration for values. """ agents = getattr(self.model.agents, conf["type"]) + varname = conf["varname"] + fancy_index = re.search(r"\[.*?\]", varname) + if fancy_index: + fancy_index = fancy_index.group(0) + varname = varname.replace(fancy_index, "") + try: - values = eval(f"agents.{conf['varname']}") + values = getattr(agents, varname) except AttributeError: print( - f"Trying to export '{conf['varname']}', but no such attribute exists for agent type '{conf['type']}'" + f"Trying to export '{varname}', but no such attribute exists for agent type '{conf['type']}'" ) values = None + + if fancy_index: + values = eval(f"values{fancy_index}") + if "split" in conf and conf["split"]: for ID, admin_values in zip(agents.ids, values): self.parse_agent_data((name, ID), admin_values, agents, conf)