Skip to content

Commit

Permalink
fix(analyze): Add a component to filter data by a pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed May 30, 2024
1 parent 8413368 commit 844523e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
Binary file added ladybug_grasshopper/icon/LB Apply Pattern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ladybug_grasshopper/json/LB_Apply_Conditional_Statement.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "1.8.1",
"version": "1.8.2",
"nickname": "Statement",
"outputs": [
[
{
"access": "None",
"name": "data",
"description": "A list of Data Collections that have been filtered by the statement_.",
"description": "A list of Data Collections that have been filtered by the _statement.",
"type": null,
"default": null
}
Expand Down
36 changes: 36 additions & 0 deletions ladybug_grasshopper/json/LB_Apply_Pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "1.8.0",
"nickname": "Pattern",
"outputs": [
[
{
"access": "None",
"name": "data",
"description": "A list of Data Collections that have been filtered by the _pattern.",
"type": null,
"default": null
}
]
],
"inputs": [
{
"access": "list",
"name": "_data",
"description": "A Data Collection or list of aligned Data Collections to be filtered\nby a pattern.",
"type": "System.Object",
"default": null
},
{
"access": "list",
"name": "_pattern",
"description": "A list of True/False values. Typically, list has a length matching\nthe length of the Data Collection(s)'s values. However, it can also\nbe a pattern to be repeated over the Data Collection(s)'s values.",
"type": "bool",
"default": null
}
],
"subcategory": "1 :: Analyze Data",
"code": "\ntry:\n from ladybug.datacollection import BaseCollection\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n data = []\n for dat in _data:\n assert isinstance(dat, BaseCollection), '_data must be a data' \\\n ' collection. Got {}.'.format(type(dat))\n data.append(dat.filter_by_pattern(_pattern))",
"category": "Ladybug",
"name": "LB Apply Pattern",
"description": "Filter a data collection or list of data collections by a pattern of True/False\nvalues. True values will be kept while False values will be filtered out.\n-"
}
4 changes: 2 additions & 2 deletions ladybug_grasshopper/src/LB Apply Conditional Statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
than 80 and the third collection is greater than 2.
Returns:
data: A list of Data Collections that have been filtered by the statement_.
data: A list of Data Collections that have been filtered by the _statement.
"""

ghenv.Component.Name = 'LB Apply Conditional Statement'
ghenv.Component.NickName = 'Statement'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Message = '1.8.2'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '3'
Expand Down
49 changes: 49 additions & 0 deletions ladybug_grasshopper/src/LB Apply Pattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Ladybug: A Plugin for Environmental Analysis (GPL)
# This file is part of Ladybug.
#
# Copyright (c) 2024, Ladybug Tools.
# You should have received a copy of the GNU Affero General Public License
# along with Ladybug; If not, see <http://www.gnu.org/licenses/>.
#
# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later>

"""
Filter a data collection or list of data collections by a pattern of True/False
values. True values will be kept while False values will be filtered out.
-
Args:
_data: A Data Collection or list of aligned Data Collections to be filtered
by a pattern.
_pattern: A list of True/False values. Typically, list has a length matching
the length of the Data Collection(s)'s values. However, it can also
be a pattern to be repeated over the Data Collection(s)'s values.
Returns:
data: A list of Data Collections that have been filtered by the _pattern.
"""

ghenv.Component.Name = 'LB Apply Pattern'
ghenv.Component.NickName = 'Pattern'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:
from ladybug.datacollection import BaseCollection
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
data = []
for dat in _data:
assert isinstance(dat, BaseCollection), '_data must be a data' \
' collection. Got {}.'.format(type(dat))
data.append(dat.filter_by_pattern(_pattern))
Binary file not shown.
Binary file not shown.

0 comments on commit 844523e

Please sign in to comment.