Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analyze): Add a component to get HOYs/datetimes from Data #283

Merged
merged 1 commit into from Jan 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added ladybug_grasshopper/icon/LB Data DateTimes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions ladybug_grasshopper/json/LB_Data_DateTimes.json
@@ -0,0 +1,29 @@
{
"version": "1.4.0",
"nickname": "DataDT",
"outputs": [
[
{
"access": "None",
"name": "hoys",
"description": "Numbers for the, hours, days or months of the year in the data collection.",
"type": null,
"default": null
}
]
],
"inputs": [
{
"access": "item",
"name": "_data",
"description": "An hourly, daily, or monthly collection from which hours, days, or\nmonths of the year will be retrieved.",
"type": "System.Object",
"default": null
}
],
"subcategory": "1 :: Analyze Data",
"code": "\ntry:\n from ladybug.dt import DateTime\n from ladybug.datacollection import HourlyDiscontinuousCollection, DailyCollection, \\\n MonthlyCollection, MonthlyPerHourCollection\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 if isinstance(_data, HourlyDiscontinuousCollection):\n hoys = [dt.hoy for dt in _data.datetimes]\n elif isinstance(_data, (MonthlyCollection, DailyCollection)):\n hoys = _data.datetimes\n elif isinstance(_data, MonthlyPerHourCollection):\n hoys = [DateTime(dt[0], 1, dt[1], dt[2]).hoy for dt in _data.datetimes]\n else:\n raise ValueError('Expected data collection. Got {}.'.format(type(data)))\n",
"category": "Ladybug",
"name": "LB Data DateTimes",
"description": "Get the hours, days, or months of the year associated with the values of a data collection.\n-"
}
50 changes: 50 additions & 0 deletions ladybug_grasshopper/src/LB Data DateTimes.py
@@ -0,0 +1,50 @@
# Ladybug: A Plugin for Environmental Analysis (GPL)
# This file is part of Ladybug.
#
# Copyright (c) 2022, 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>

"""
Get the hours, days, or months of the year associated with the values of a data collection.
-

Args:
_data: An hourly, daily, or monthly collection from which hours, days, or
months of the year will be retrieved.

Returns:
hoys: Numbers for the, hours, days or months of the year in the data collection.
"""

ghenv.Component.Name = 'LB Data DateTimes'
ghenv.Component.NickName = 'DataDT'
ghenv.Component.Message = '1.4.0'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '1 :: Analyze Data'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:
from ladybug.dt import DateTime
from ladybug.datacollection import HourlyDiscontinuousCollection, DailyCollection, \
MonthlyCollection, MonthlyPerHourCollection
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):
if isinstance(_data, HourlyDiscontinuousCollection):
hoys = [dt.hoy for dt in _data.datetimes]
elif isinstance(_data, (MonthlyCollection, DailyCollection)):
hoys = _data.datetimes
elif isinstance(_data, MonthlyPerHourCollection):
hoys = [DateTime(dt[0], 1, dt[1], dt[2]).hoy for dt in _data.datetimes]
else:
raise ValueError('Expected data collection. Got {}.'.format(type(data)))
Binary file not shown.