コード例 #1
0
ファイル: sql_test.py プロジェクト: tejaskumar555/ladybug
def test_sqlite_tabular_data():
    """Test the tabular_data_by_name method."""
    sql_path = './tests/assets/sql/eplusout_monthly.sql'
    sql_obj = SQLiteResult(sql_path)

    data = sql_obj.tabular_data_by_name(
        'Utility Use Per Conditioned Floor Area')
    assert len(data) == 4
    assert len(data['Lighting']) == 6
    col_names = sql_obj.tabular_column_names(
        'Utility Use Per Conditioned Floor Area')
    assert len(col_names) == 6
    assert 'Electricity Intensity' in col_names[0]
コード例 #2
0
ファイル: result.py プロジェクト: coditect/honeybee-energy
def tabular_metadata(result_sql, table_name, output_file):
    """Get a dictionary with the names of a table's rows and columns.

    \b
    Args:
        result_sql: Full path to an SQLite file that was generated by EnergyPlus.
        table_name: Text string for the name of a table within a summary
            report. (eg. 'General').
    """
    try:
        sql_obj = SQLiteResult(result_sql)
        table_dict = sql_obj.tabular_data_by_name(str(table_name))
        row_names = list(table_dict.keys())
        col_names = sql_obj.tabular_column_names(str(table_name))
        output_file.write(json.dumps(
            {'row_names': row_names, 'column_names': col_names}))
    except Exception as e:
        _logger.exception('Failed to retrieve table data from sql file.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
    from honeybee.config import folders
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

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

if all_required_inputs(ghenv.Component):
    if os.name == 'nt':  # we are on windows; use IronPython like usual
        sql_obj = SQLiteResult(_sql)  # create the SQL result parsing object
        results = sql_obj.tabular_data_by_name(_table_name)
        values = list_to_data_tree(list(results.values()))
        row_names = list(results.keys())
        col_names = sql_obj.tabular_column_names(_table_name)

    else:  # we are on Mac; sqlite3 module doesn't work in Mac IronPython
        # Execute the honybee CLI to obtain the results via CPython
        cmds = [
            folders.python_exe_path, '-m', 'honeybee_energy', 'result',
            'tabular-data', _sql, _table_name
        ]
        process = subprocess.Popen(cmds, stdout=subprocess.PIPE)
        stdout = process.communicate()
        results = json.loads(stdout[0])
        values = list_to_data_tree(results)
        cmds = [
            folders.python_exe_path, '-m', 'honeybee_energy', 'result',
            'tabular-metadata', _sql, _table_name
        ]