IntegralPy
The new IntegralPy library can be used to control INTEGRAL from Python-Script: loading grid data, editing grid data, start calculations.
Quick-start Video: (for better quality go to article media “Anhänge” → “Dateien” and download the video)
IMPORTANT NOTE TO VIDEO: in the current INTEGRAL versions the control paramaters for ProtobufGridIO & VisuService are visible by default. There is no need to activate them through macro command which is depicted in the video.
For comments, questions and access to IntegralPy Python-library (the wheel files from video) contact eimantas.survila@fgh-ma.de
VisuService Integral Start
Video: (for better quality go to article media “Anhänge” → “Dateien” and download the video)
Activate both “Nutze ProtobufGridIO API lokal” and “Nutze Web-Visualisierung …”.
Open VisuService through the button in INTEGRAL:
Documentation IntegralPy
Activate the ProtobufGridIO in INTEGRAL
Go to control parameters and activate “Nutze ProtobufGridIO API lokal”
Importing the library
import integralpy
Methods
integralpy.connect(host)
Returns session object
session.load_grid_file(local_path)
Loads a grid from xml-file and returns a grid object.
session.load_grid_file_cim(local_paths)
Loads a grid from a list of zip-files and returns a grid object.
local_paths an array of strings with local path information
session.get_current_grid()
Returns the grid object of currently loaded grid
grid.calculate_base_load_flow()
Starts the Grundlastfluss calculation for the currently loaded grid.
grid.get_base_load_flow_results()
Prototype version (up to change in near future): returns a string which entails the result tables as CSV. The individual tables are separated by the following string: "== TABLE SEPERATION =="
grid.import_from_db(db_name, db_server_ip, db_username, db_password, db_server_port)
Imports a grid from database.
db_name - Database name for the grid which should be imported
db_server_ip - The IP address of the database server
db_username - The username of the database
db_password - The password of the database user
db_server_port - The port of the database server (Note: db_server_port must be a string)
grid.export_to_db(db_name, db_server_ip, db_username, db_password, db_server_port)
Exports the current grid to database.
db_name - Database name for the grid which should be imported
db_server_ip - The IP address of the database server
db_username - The username of the database
db_password - The password of the database user
db_server_port - The port of the database server (Note: db_server_port must be a string)
grid.get(type, attr, ids)
Returns either a single object or a list of objects
type is either list or single type from integralpy.Type
attr is a list of attributes from integralpy.Attribute
ids is either single id or list of ids
The fields of the returned objects can be changed. For example
leitung.kurzname = “new short name”. See exmpla at the bottom of the page.
grid.write(objects)
Sends back the objects which could be altered in Python script back to INTEGRAL which updates its data model with new information from these objects.
objects is either a single object or list of objects
grid.create(type)
type is a single type
Creates a new object in INTEGRAL and returns it.
grid.remove_attribute(type, attr, ids)
Removes the given attributes from the given objects.
type is either list or single type from integralpy.Type
attr is a list of attributes from integralpy.Attribute
ids is either single id or list of ids
grid.remove(objects)
Removes the objects from INTEGRAL data model.
objects is either a single object or list of objects
Examples of using IntegralPy:
from integralpy import connect
if __name__ == "__main__":
session = connect("localhost:7321")
path = "ks-a1.xml"
session.load_grid_file(path)
from integralpy import connect, Type, Attribute
if __name__ == "__main__":
session = connect()
file_path_rel = "ks-a1.xml"
netz = session.load_grid_file(file_path_rel)
# if the grid is already loaded:
netz = session.get_current_grid()
objects = netz.get(
type=Type.LEITUNG,
attr=[Attribute.LEITUNG.KURZNAME, Attribute.LEITUNG.BEZEICHNER],
)
print(objects)
netzeinspeisung = netz.get(ids=772)
print(netzeinspeisung)
import integralpy
if __name__ == "__main__":
session = integralpy.connect("localhost:7321")
file_path = "ks-a1.xml"
netz = session.load_grid_file(file_path)
new_leitung = netz.create(type=integralpy.Type.LEITUNG)
leitung = netz.get(ids=1175)
leitung.kurzname = "Something different"
netz.write(leitung)
print("new_leitung", leitung)