Skip to content

Commit

Permalink
allow reporting of property
Browse files Browse the repository at this point in the history
  • Loading branch information
jensdebruijn committed Oct 11, 2024
1 parent 025631d commit 0efddb9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions honeybees/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import sys
import re
from collections.abc import Iterable
import os
import numpy as np
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0efddb9

Please sign in to comment.