-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add command to filter a JSON array by key:value
This is required to handle models with sensor groups
- Loading branch information
1 parent
0f9a2c1
commit 522fbf0
Showing
3 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[ | ||
{ | ||
"name": "west_window", | ||
"identifier": "west_window", | ||
"count": 96, | ||
"group": "apertures" | ||
}, | ||
{ | ||
"name": "east_window", | ||
"identifier": "east_window", | ||
"count": 96, | ||
"group": "apertures" | ||
}, | ||
{ | ||
"name": "north_window", | ||
"identifier": "north_window", | ||
"count": 64, | ||
"group": "apertures" | ||
}, | ||
{ | ||
"name": "south_window", | ||
"identifier": "south_window", | ||
"count": 64, | ||
"group": "apertures" | ||
}, | ||
{ | ||
"name": "Occ_Regions_East_T3_area", | ||
"identifier": "Occ_Regions_East_T3_area", | ||
"count": 1436, | ||
"group": "occ_regions" | ||
}, | ||
{ | ||
"name": "Occ_Regions_North_area", | ||
"identifier": "Occ_Regions_North_area", | ||
"count": 1106, | ||
"group": "occ_regions" | ||
}, | ||
{ | ||
"name": "Occ_Regions_West_T3_area", | ||
"identifier": "Occ_Regions_West_T3_area", | ||
"count": 1146, | ||
"group": "occ_regions" | ||
}, | ||
{ | ||
"name": "Occ_Regions_South_T4_area", | ||
"identifier": "Occ_Regions_South_T4_area", | ||
"count": 906, | ||
"group": "occ_regions" | ||
}, | ||
{ | ||
"name": "ground_floor", | ||
"identifier": "ground_floor", | ||
"count": 3196, | ||
"group": "daylight_grids" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from click.testing import CliRunner | ||
from honeybee_radiance_folder.cli import filter_json_file | ||
import json | ||
import os | ||
|
||
|
||
def test_filter_file(): | ||
runner = CliRunner() | ||
input_file = './tests/assets/project_folder/grid_info.json' | ||
output_file = './tests/assets/temp/grid_filtered_0.json' | ||
result = runner.invoke( | ||
filter_json_file, [ | ||
input_file, 'group:daylight_grids', '--output-file', output_file | ||
] | ||
) | ||
assert result.exit_code == 0 | ||
# check the file is created | ||
with open(output_file) as inf: | ||
data = json.load(inf) | ||
assert len(data) == 1 | ||
os.unlink(output_file) | ||
|
||
|
||
def test_filter_file_remove(): | ||
runner = CliRunner() | ||
input_file = './tests/assets/project_folder/grid_info.json' | ||
output_file = './tests/assets/project_folder/grid_filtered_1.json' | ||
result = runner.invoke( | ||
filter_json_file, [ | ||
input_file, 'group:daylight_grids', '--output-file', output_file, '--remove' | ||
] | ||
) | ||
assert result.exit_code == 0 | ||
# check the file is created | ||
with open(output_file) as inf: | ||
data = json.load(inf) | ||
assert len(data) == 8 | ||
os.unlink(output_file) |