From 7947351ed2dacc61d9640b1854572a333f55c136 Mon Sep 17 00:00:00 2001 From: shinedday <shinedday@gmail.com> Date: Tue, 18 May 2021 09:19:06 +0200 Subject: [PATCH] Add 2 method to add / remove attribute in csv --- pyAmakCore/classes/tools/loggable.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pyAmakCore/classes/tools/loggable.py b/pyAmakCore/classes/tools/loggable.py index a74ba82..094e4f0 100644 --- a/pyAmakCore/classes/tools/loggable.py +++ b/pyAmakCore/classes/tools/loggable.py @@ -14,6 +14,7 @@ class Loggable: def __init__(self): self.__do_log = False self.__file_path = None + self.__ignore_attribute = ["_Agent__amas", "_Agent__environment"] def to_csv(self, cycle: int, var_list: List['Agent']) -> None: """ @@ -22,8 +23,7 @@ class Loggable: if not self.__do_log: return - ignore_attribute = ["_Agent__amas", "_Agent__environment"] - table = [{**{e: x[e] for e in x if e not in ignore_attribute}, + table = [{**{e: x[e] for e in x if e not in self.__ignore_attribute}, **{'nombre_cycle': cycle}} for x in map(vars, var_list)] dataframe = DataFrame(table) @@ -46,3 +46,17 @@ class Loggable: specify path to csv """ self.__file_path = path_to_file + + def add_ignore_attribute(self, attribute: str) -> None: + """ + add attribute in ignored attribute + """ + self.__ignore_attribute.append(attribute) + + def remove_ignore_attribute(self, attribute: str) -> None: + """ + remove attribute in ignored attribute + """ + if attribute not in self.__ignore_attribute: + return + self.__ignore_attribute.remove(attribute) -- GitLab