Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,4 @@ cython_debug/

# ADF
agent.log*
precompute
!java/lib/src/main/java/adf_core_python/core/agent/precompute
Empty file.
75 changes: 75 additions & 0 deletions src/adf_core_python/core/agent/precompute/precompute_data.py
Original file line number Diff line number Diff line change
@@ -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)
Loading