Skip to content

Commit

Permalink
feat: update the merge json files code
Browse files Browse the repository at this point in the history
  • Loading branch information
OmaymaMahjoub committed Jan 26, 2024
1 parent 0f418e3 commit 46b492a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ Here `run_1` to `run_n` correspond to the number of independent runs in a given
#### Data Tooling
[**Pull Neptune Data**](marl_eval/json_tools/pull_neptune_data.py): `pull_neptune_data` connects to a Neptune project, retrieves experiment data from specific systems and tags, and downloads it to a local directory. This function is particularly useful when there is a need to pull data from multiple experiments.

[**JSON Files Merging Script**](marl_eval/json_tools/merge_json_files.py): We offer a function called `concatenate_files` that reads json files from a specified directory, concatenates their contents into a single structured dictionary,
and ensures uniqueness of seed numbers within the data. It handles nested json structures and saves the concatenated
result into a new json file. Designed primarily for managing and aggregating json data from multiple files in experimental setups.
[**JSON Files Merging Script**](marl_eval/json_tools/merge_json_files.py): We offer a function called `concatenate_files` that can be found in `marl_eval/utils` that reads json files from a specified directory and concatenates their contents into a single structured dictionary, and ensures uniqueness of seed numbers within the data. It handles nested json structures and saves the concatenated result into a new json file. Designed primarily for managing and aggregating json data from multiple files in experimental setups.

> 📌 Using `pull_neptune_data` alongside `concatenate_files` forms an effective workflow, first generating multiple JSON files from experiments and then merging them into a single file, ready for use in marl-eval. This approach streamlines data preparation.
Expand Down
12 changes: 7 additions & 5 deletions marl_eval/json_tools/merge_json_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ def _read_json_files(directory: str) -> list:
"""Reads all JSON files in a directory and returns a list of JSON objects."""
json_data = []

for filename in os.listdir(directory):
if filename.endswith(".json"):
file_path = os.path.join(directory, filename)
with open(file_path) as file:
json_data.append(json.load(file))
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith(".json"):
file_path = os.path.join(root, filename)
with open(file_path) as file:
json_data.append(json.load(file))

return json_data


Expand Down

0 comments on commit 46b492a

Please sign in to comment.