diff --git a/honeybee_grasshopper_energy/json/HB_Read_Generation_Result.json b/honeybee_grasshopper_energy/json/HB_Read_Generation_Result.json index dc60a56..6c49f8e 100644 --- a/honeybee_grasshopper_energy/json/HB_Read_Generation_Result.json +++ b/honeybee_grasshopper_energy/json/HB_Read_Generation_Result.json @@ -1,5 +1,5 @@ { - "version": "1.8.0", + "version": "1.8.1", "nickname": "GenerationResult", "outputs": [ [ @@ -50,7 +50,7 @@ } ], "subcategory": "6 :: Result", - "code": "\nimport os\nimport subprocess\nimport json\nfrom collections import OrderedDict\n\ntry:\n from ladybug.datacollection import HourlyContinuousCollection, \\\n MonthlyCollection, DailyCollection\n from ladybug.sql import SQLiteResult\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.generation import generation_summary_from_sql, \\\n generation_data_from_sql\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\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\n# The SQLite3 module doesn't work in IronPython on Mac, so we must make a call\n# to the Honeybee CLI (which runs on CPython) to get the results.\ndef get_results_mac(sql_files):\n from collections import OrderedDict\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'generation-summary']\n cmds.extend(sql_files)\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n results = json.loads(stdout[0])\n return results\n\n\ndef serialize_data(data_dicts):\n \"\"\"Reserialize a list of collection dictionaries.\"\"\"\n if len(data_dicts) == 0 or data_dicts[0] is None:\n return [None] * len(data_dicts)\n elif data_dicts[0]['type'] == 'HourlyContinuous':\n return [HourlyContinuousCollection.from_dict(data) for data in data_dicts]\n elif data_dicts[0]['type'] == 'Monthly':\n return [MonthlyCollection.from_dict(data) for data in data_dicts]\n elif data_dicts[0]['type'] == 'Daily':\n return [DailyCollection.from_dict(data) for data in data_dicts]\n\nDC_OUTPUT = 'Generator Produced DC Electricity Energy'\ncustom_env = os.environ.copy()\ncustom_env['PYTHONHOME'] = ''\n\n\nif all_required_inputs(ghenv.Component):\n dc_power = []\n if os.name == 'nt': # we are on windows; use IronPython like usual\n result_dict = generation_summary_from_sql(_sql)\n production, consumption = generation_data_from_sql(_sql)\n for sql_f in _sql:\n sql_obj = SQLiteResult(sql_f)\n dc_data = sql_obj.data_collections_by_output_name(DC_OUTPUT)\n dc_power.extend(dc_data)\n\n else: # we are on Mac; sqlite3 module doesn't work in Mac IronPython\n # Execute the honybee CLI to obtain the results via CPython\n result_dict = get_results_mac(_sql)\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'generation-data']\n cmds.extend(_sql)\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n data_dicts = json.loads(stdout[0])\n production, consumption = serialize_data(data_dicts)\n\n for sql_f in _sql:\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'data-by-outputs', sql_f, DC_OUTPUT]\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n data_dicts = json.loads(stdout[0])\n dc_data = serialize_data(data_dicts[0])\n dc_power.extend(dc_data)\n\n # output the separate summary results\n site_totals = (\n result_dict['total_production'],\n result_dict['total_consumption']\n )\n utility_totals = (\n result_dict['production_used_on_site'],\n result_dict['production_surplus_sold'],\n result_dict['consumption_purchased']\n )\n\n # group the generator results by identifier\n dc_dict = OrderedDict()\n for g_data in dc_power:\n gen_id = g_data.header.metadata['System'].split('..')[0]\n g_data.header.metadata['System'] = gen_id\n try:\n dc_dict[gen_id] += g_data\n except KeyError:\n dc_dict[gen_id] = g_data\n dc_power = [dcp for dcp in dc_dict.values()]\n", + "code": "\nimport os\nimport subprocess\nimport json\nfrom collections import OrderedDict\n\ntry:\n from ladybug.datacollection import HourlyContinuousCollection, \\\n MonthlyCollection, DailyCollection\n from ladybug.sql import SQLiteResult\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee_energy.result.generation import generation_summary_from_sql, \\\n generation_data_from_sql\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\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\n# The SQLite3 module doesn't work in IronPython on Mac, so we must make a call\n# to the Honeybee CLI (which runs on CPython) to get the results.\ndef get_results_mac(sql_files):\n from collections import OrderedDict\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'generation-summary']\n cmds.extend(sql_files)\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n results = json.loads(stdout[0])\n return results\n\n\ndef serialize_data(data_dicts):\n \"\"\"Reserialize a list of collection dictionaries.\"\"\"\n if len(data_dicts) == 0 or data_dicts[0] is None:\n return [None] * len(data_dicts)\n elif data_dicts[0]['type'] == 'HourlyContinuous':\n return [HourlyContinuousCollection.from_dict(data) for data in data_dicts]\n elif data_dicts[0]['type'] == 'Monthly':\n return [MonthlyCollection.from_dict(data) for data in data_dicts]\n elif data_dicts[0]['type'] == 'Daily':\n return [DailyCollection.from_dict(data) for data in data_dicts]\n\nDC_OUTPUT = 'Generator Produced DC Electricity Energy'\ncustom_env = os.environ.copy()\ncustom_env['PYTHONHOME'] = ''\n\n\nif all_required_inputs(ghenv.Component):\n dc_power = []\n if os.name == 'nt': # we are on windows; use IronPython like usual\n result_dict = generation_summary_from_sql(_sql)\n production, consumption = generation_data_from_sql(_sql)\n for sql_f in _sql:\n sql_obj = SQLiteResult(sql_f)\n dc_data = sql_obj.data_collections_by_output_name(DC_OUTPUT)\n dc_power.extend(dc_data)\n\n else: # we are on Mac; sqlite3 module doesn't work in Mac IronPython\n # Execute the honybee CLI to obtain the results via CPython\n result_dict = get_results_mac(_sql)\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'generation-data']\n cmds.extend(_sql)\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n data_dicts = json.loads(stdout[0])\n production, consumption = serialize_data(data_dicts)\n\n for sql_f in _sql:\n cmds = [folders.python_exe_path, '-m', 'honeybee_energy', 'result',\n 'data-by-outputs', sql_f, DC_OUTPUT]\n process = subprocess.Popen(cmds, stdout=subprocess.PIPE, env=custom_env)\n stdout = process.communicate()\n data_dicts = json.loads(stdout[0])\n dc_data = serialize_data(data_dicts[0])\n dc_power.extend(dc_data)\n\n # output the separate summary results\n site_totals = (\n result_dict['total_production'],\n result_dict['total_consumption']\n )\n utility_totals = (\n result_dict['production_used_on_site'],\n result_dict['production_surplus_sold'],\n result_dict['consumption_purchased']\n )\n\n # group the generator results by identifier\n if len(dc_power) != 0 and not isinstance(dc_power[0], (float, int)):\n dc_dict = OrderedDict()\n for g_data in dc_power:\n gen_id = g_data.header.metadata['System'].split('..')[0]\n g_data.header.metadata['System'] = gen_id\n try:\n dc_dict[gen_id] += g_data\n except KeyError:\n dc_dict[gen_id] = g_data\n dc_power = [dcp for dcp in dc_dict.values()]\n", "category": "HB-Energy", "name": "HB Read Generation Result", "description": "Parse electricity generation results from an energy simulation SQL result file.\n-" diff --git a/honeybee_grasshopper_energy/src/HB Read Generation Result.py b/honeybee_grasshopper_energy/src/HB Read Generation Result.py index 46c89c5..1d024db 100644 --- a/honeybee_grasshopper_energy/src/HB Read Generation Result.py +++ b/honeybee_grasshopper_energy/src/HB Read Generation Result.py @@ -39,7 +39,7 @@ ghenv.Component.Name = 'HB Read Generation Result' ghenv.Component.NickName = 'GenerationResult' -ghenv.Component.Message = '1.8.0' +ghenv.Component.Message = '1.8.1' ghenv.Component.Category = 'HB-Energy' ghenv.Component.SubCategory = '6 :: Result' ghenv.Component.AdditionalHelpFromDocStrings = '0' @@ -144,12 +144,13 @@ def serialize_data(data_dicts): ) # group the generator results by identifier - dc_dict = OrderedDict() - for g_data in dc_power: - gen_id = g_data.header.metadata['System'].split('..')[0] - g_data.header.metadata['System'] = gen_id - try: - dc_dict[gen_id] += g_data - except KeyError: - dc_dict[gen_id] = g_data - dc_power = [dcp for dcp in dc_dict.values()] + if len(dc_power) != 0 and not isinstance(dc_power[0], (float, int)): + dc_dict = OrderedDict() + for g_data in dc_power: + gen_id = g_data.header.metadata['System'].split('..')[0] + g_data.header.metadata['System'] = gen_id + try: + dc_dict[gen_id] += g_data + except KeyError: + dc_dict[gen_id] = g_data + dc_power = [dcp for dcp in dc_dict.values()] diff --git a/honeybee_grasshopper_energy/user_objects/HB Read Generation Result.ghuser b/honeybee_grasshopper_energy/user_objects/HB Read Generation Result.ghuser index e025938..e9dbd50 100644 Binary files a/honeybee_grasshopper_energy/user_objects/HB Read Generation Result.ghuser and b/honeybee_grasshopper_energy/user_objects/HB Read Generation Result.ghuser differ