From b7998ee964cc3b9979ee1efb31c39f0770ff48e3 Mon Sep 17 00:00:00 2001 From: shima004 Date: Mon, 4 Aug 2025 16:40:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20precompute=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=82=92=E7=AE=A1=E7=90=86=E3=81=99=E3=82=8B=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=81=AEPrecomputeData=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - .../core/agent/precompute/__init__.py | 0 .../core/agent/precompute/precompute_data.py | 75 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/adf_core_python/core/agent/precompute/__init__.py create mode 100644 src/adf_core_python/core/agent/precompute/precompute_data.py diff --git a/.gitignore b/.gitignore index 41060c93..ab0dc67d 100644 --- a/.gitignore +++ b/.gitignore @@ -172,5 +172,4 @@ cython_debug/ # ADF agent.log* -precompute !java/lib/src/main/java/adf_core_python/core/agent/precompute diff --git a/src/adf_core_python/core/agent/precompute/__init__.py b/src/adf_core_python/core/agent/precompute/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/adf_core_python/core/agent/precompute/precompute_data.py b/src/adf_core_python/core/agent/precompute/precompute_data.py new file mode 100644 index 00000000..41b2029d --- /dev/null +++ b/src/adf_core_python/core/agent/precompute/precompute_data.py @@ -0,0 +1,75 @@ +import json +import os + +ENCODE = "utf-8" + + +class PrecomputeData: + def __init__(self, dir_path: str) -> None: + """ + Initialize the PrecomputeData object. + + Parameters + ---------- + dir_path : str + The directory path to save the precompute data. + + Raises + ------ + Exception + """ + self._dir_path = dir_path + + def read_json_data(self, module_name: str) -> dict: + """ + Read the precompute data from the file. + + Returns + ------- + dict + The precompute data. + + Raises + ------ + Exception + """ + + with open(f"{self._dir_path}/{module_name}.json", "r", encoding=ENCODE) as file: + return json.load(file) + + def write_json_data(self, data: dict, module_name: str) -> None: + """ + Write the precompute data to the file. + + Parameters + ---------- + data : dict + The data to write. + + Raises + ------ + Exception + """ + if not os.path.exists(self._dir_path): + os.makedirs(self._dir_path) + + with open(f"{self._dir_path}/{module_name}.json", "w", encoding=ENCODE) as file: + json.dump(data, file, indent=4) + + def remove_precompute_data(self) -> None: + """ + Remove the precompute data file. + """ + if os.path.exists(self._dir_path): + os.remove(self._dir_path) + + def is_available(self) -> bool: + """ + Check if the precompute data is available. + + Returns + ------- + bool + True if the precompute data is available, False otherwise. + """ + return os.path.exists(self._dir_path) From 12aea365cfacadd84367aa26197e45d4b7e57a63 Mon Sep 17 00:00:00 2001 From: shima004 Date: Mon, 4 Aug 2025 16:42:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20PrecomputeData=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=AE?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=87=E3=83=B3=E3=83=88=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/agent/precompute/precompute_data.py | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/adf_core_python/core/agent/precompute/precompute_data.py b/src/adf_core_python/core/agent/precompute/precompute_data.py index 41b2029d..3dc33733 100644 --- a/src/adf_core_python/core/agent/precompute/precompute_data.py +++ b/src/adf_core_python/core/agent/precompute/precompute_data.py @@ -5,71 +5,71 @@ class PrecomputeData: - def __init__(self, dir_path: str) -> None: - """ - Initialize the PrecomputeData object. - - Parameters - ---------- - dir_path : str - The directory path to save the precompute data. - - Raises - ------ - Exception - """ - self._dir_path = dir_path - - def read_json_data(self, module_name: str) -> dict: - """ - Read the precompute data from the file. - - Returns - ------- - dict - The precompute data. - - Raises - ------ - Exception - """ - - with open(f"{self._dir_path}/{module_name}.json", "r", encoding=ENCODE) as file: - return json.load(file) - - def write_json_data(self, data: dict, module_name: str) -> None: - """ - Write the precompute data to the file. - - Parameters - ---------- - data : dict - The data to write. - - Raises - ------ - Exception - """ - if not os.path.exists(self._dir_path): - os.makedirs(self._dir_path) - - with open(f"{self._dir_path}/{module_name}.json", "w", encoding=ENCODE) as file: - json.dump(data, file, indent=4) - - def remove_precompute_data(self) -> None: - """ - Remove the precompute data file. - """ - if os.path.exists(self._dir_path): - os.remove(self._dir_path) - - def is_available(self) -> bool: - """ - Check if the precompute data is available. - - Returns - ------- - bool - True if the precompute data is available, False otherwise. - """ - return os.path.exists(self._dir_path) + def __init__(self, dir_path: str) -> None: + """ + Initialize the PrecomputeData object. + + Parameters + ---------- + dir_path : str + The directory path to save the precompute data. + + Raises + ------ + Exception + """ + self._dir_path = dir_path + + def read_json_data(self, module_name: str) -> dict: + """ + Read the precompute data from the file. + + Returns + ------- + dict + The precompute data. + + Raises + ------ + Exception + """ + + with open(f"{self._dir_path}/{module_name}.json", "r", encoding=ENCODE) as file: + return json.load(file) + + def write_json_data(self, data: dict, module_name: str) -> None: + """ + Write the precompute data to the file. + + Parameters + ---------- + data : dict + The data to write. + + Raises + ------ + Exception + """ + if not os.path.exists(self._dir_path): + os.makedirs(self._dir_path) + + with open(f"{self._dir_path}/{module_name}.json", "w", encoding=ENCODE) as file: + json.dump(data, file, indent=4) + + def remove_precompute_data(self) -> None: + """ + Remove the precompute data file. + """ + if os.path.exists(self._dir_path): + os.remove(self._dir_path) + + def is_available(self) -> bool: + """ + Check if the precompute data is available. + + Returns + ------- + bool + True if the precompute data is available, False otherwise. + """ + return os.path.exists(self._dir_path)