eppy3000.dbm_functions package¶
Submodules¶
eppy3000.dbm_functions.json2dbm module¶
Functions to create the dbm file for EPJ schema
- Question:
Why Store the EPJ Schema in a database (the database is dbm here)
- Response:
The EPJ Schema is a large file. The file is about 10 megabytes and only parts of it are used with an EPJ file (a specific model). Storing this in a databse opens up the option of loading only the needed parts of the EPJ schema into memory. With the EPJ schema being less memory intensive, it may be possible to open multple versions of EPJ files and it’s corresponding EPJ schema.
- eppy3000.dbm_functions.json2dbm.create_groupsindex(fname, dbmname)[source]¶
create the groupindex for the schema
- eppy3000.dbm_functions.json2dbm.create_index(fname, dbmname)[source]¶
create the indices for reference and object_list in the schema dbm
It creates an index for the dbm created by the
function create_schemadbm()
. Many EPJObjects in the E+ schema have reference names (apart from their key word name). Fields in other EPJObjects can refer to another EPJObjects using the reference names. Without an index, one would have to search through the entire database to find the EPJObjects being pointed to. The index allows you to quickly find the EPJObject.The index is stored as a seperate dbm (from the dbm for the EPJ schema). If the main dbm is named schema, by convention, the index dbm is called schema_ref_index, although it can be called anything.
The index is structured in the following way:
The keys are the reference names (called reference in the EPJObjects [and in the schema file])
So a key:value in the dbm will look like:
example for SurfaceNames:
{'SurfaceNames':{'objlist': ['BuildingSurface:Detailed', 'Wall:Detailed', 'RoofCeiling:Detailed', .... ], 'reflist': ['FenestrationSurface:Detailed.building_surface_name', 'Window.building_surface_name', 'Door.building_surface_name', 'GlazedDoor.building_surface_name', .... ]}} # 'objlist' -> will give the list of EPJObjects that that are also called 'SurfaceNames' # 'reflist' -> list of EPJObjects.Fieldname that refer to 'SurfaceNames'
- Parameters:
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO
dbmname (str) – Name of the dbm file. If
dbmname='schema'
, it will generateschema.dir, schema.dat, schema.bak
- Return type:
None
- eppy3000.dbm_functions.json2dbm.create_schemadbm(fname, dbmname)[source]¶
create the schema dbm
Python has a built-in key-value database called
dbm
. This function is used to save the E+Schema in akey:value
format indbm
. Thekey
is the name of the EPJObject. Thevalue
is a string representation of json value of that EPJObject from the schema filedbm.dumb format is used to save the file, since it has greatest cross-platform compatability. The dbm.dumb generates three files (
*.dir, *.dat, *.bak
). So ifdbmname='schema'
, it will generateschema.dir, schema.dat, schema.bak
- Parameters:
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO
dbmname (str) – Name of the dbm file. If
dbmname='schema'
, it will generateschema.dir, schema.dat, schema.bak
- Return type:
None
eppy3000.dbm_functions.schemaindbm module¶
explore the schema in the dbm
- eppy3000.dbm_functions.schemaindbm.db_in_memory(fname=None)[source]¶
creates the dbm in memory
Loads the schema file (fname) as a dict. The dict is structured identical to the dbm. Use this when you want fast operations and don’t want to use the dbm. right now it is used to creat the index for the dbm
- Parameters:
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO
- Returns:
key:value (str:str) where key=EPJOject, value=str from schema file
- Return type:
dict
- eppy3000.dbm_functions.schemaindbm.get_a_refschema(key, fname=None)[source]¶
get a reference key from the reference schema
- eppy3000.dbm_functions.schemaindbm.get_arrayfield(key, fieldname, arrayfieldname, aschema=None, fname=None)[source]¶
get the array field of a field
- eppy3000.dbm_functions.schemaindbm.get_arrayfieldnames(key, fieldname, aschema=None, fname=None)[source]¶
get the array fieldnames of a field
- eppy3000.dbm_functions.schemaindbm.get_aschema(key, fname=None)[source]¶
gets a schema
Returns the schema of an EPJObject, when key=EPJObject name
- Parameters:
key (string) – The name of the EPJObject
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO. Default value is ‘./schema’
- Returns:
schema of the EPJObject as a dict
- Return type:
dict
- eppy3000.dbm_functions.schemaindbm.get_field(key, fieldname, aschema=None, fname=None)[source]¶
get the field of a schema if already have aschema, it avoids disk access
- eppy3000.dbm_functions.schemaindbm.get_name(key, aschema=None, fname=None)[source]¶
get the attributes of name field of the schema
Returns the attributes of the name field of the schema as a dict. Returns None if there is no name field. Extracts it from the aschema, or from fname. Using aschema if you already have it avoids disk access, by not using fname.
- Parameters:
key (string) – The name of the EPJObject
aschema (dict) – this is the schema of EPJObject, extracted using the function get_aschema
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO. Default value is ‘./schema’
- Returns:
attributes of the name field of aschema
- Return type:
dict
- eppy3000.dbm_functions.schemaindbm.get_props(key, aschema=None, fname=None)[source]¶
gets the properties of a schema
Returns fields of the schema as a dict. In the schema file , it is called properties. Hence the name get_props(). Some of the fileds may have array inside with array fieldnames. The fieldname within the arrays can be extracted using get_arrayfieldnames().
Extracts the results from the aschema, or from fname. Using aschema if you already have it, avoids disk access, by not using fname.
- Parameters:
key (string) – The name of the EPJObject
aschema (dict) – this is the schema of EPJObject, extracted using the function get_aschema
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO. Default value is ‘./schema’
- Returns:
{fieldname1:dict(), fieldname2:dict()}
- Return type:
dict
- eppy3000.dbm_functions.schemaindbm.get_refschemakeys(fname=None)[source]¶
get all the ref schema keys
- eppy3000.dbm_functions.schemaindbm.get_schemakeys(fname=None)[source]¶
get all the schema keys
Opens the dbm as D and returns D.keys() -> a set-like object providing a view on D’s keys
- Parameters:
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO
- Returns:
D.keys() -> a set-like object providing a view on D’s keys, where D is the dbm
- Return type:
list
- eppy3000.dbm_functions.schemaindbm.get_schemaversion(fname=None)[source]¶
get the schema version / E+ version
Returns the energyplus version, that is stored in the schema
- Parameters:
fname (string, StringIO) – filename of the E+Schema file OR the contents of the E+Schema file in a StringIO
- Returns:
returns the version. example: b’9.6.0’
- Return type:
bytes
Module contents¶
This module contains functions that work DBM database
The “Energy+.schema.epJSON” is stored in DBM
“Energy+.schema.epJSON” is indexed for ‘references’ and ‘object_list’ and the indices are stored in DBM
- This module contains code to do the following:
write “Energy+.schema.epJSON” into DBM
create the index and save into DBM
Read the DBM
use the indices in DBM