{ "cells": [ { "cell_type": "markdown", "id": "5556432f", "metadata": {}, "source": [ "# Tutorial X: ..." ] }, { "cell_type": "markdown", "id": "8899e69a", "metadata": {}, "source": [ "This Tutorial demonstrates ..." ] }, { "cell_type": "markdown", "id": "e2d40c36", "metadata": {}, "source": [ "# Toolkit Release" ] }, { "cell_type": "code", "execution_count": 1, "id": "7fb5a07b", "metadata": {}, "outputs": [], "source": [ "#pip install sir3stoolkit" ] }, { "cell_type": "markdown", "id": "7887be8d", "metadata": {}, "source": [ "# Imports" ] }, { "cell_type": "markdown", "id": "529d4ff7", "metadata": {}, "source": [ "## DLL References" ] }, { "cell_type": "markdown", "id": "bbfb80b5", "metadata": {}, "source": [ "The Toolkit requires the Sir3S_Toolkit.dll included in SIR 3S installations (from Quebec and Up). Furthermore the Sir3S_Repository.Interfaces.dll is required to input native SIR 3S datatypes into some Toolkit functions." ] }, { "cell_type": "code", "execution_count": 2, "id": "6ddc5056", "metadata": {}, "outputs": [], "source": [ "import clr as clr" ] }, { "cell_type": "code", "execution_count": 3, "id": "0f91d207", "metadata": {}, "outputs": [], "source": [ "SIR3S_SIRGRAF_DIR = r\"C:\\3S\\SIR 3S Entwicklung\\SirGraf-90-15-00-11_Quebec_x64\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "ae3916b9", "metadata": {}, "outputs": [], "source": [ "clr.AddReference(SIR3S_SIRGRAF_DIR+r\"\\Sir3S_Repository.Interfaces\")\n", "import Sir3S_Repository.Interfaces as Interfaces" ] }, { "cell_type": "code", "execution_count": 5, "id": "d5f592be", "metadata": {}, "outputs": [], "source": [ "clr.AddReference(SIR3S_SIRGRAF_DIR+r\"\\Sir3S_Toolkit\")\n", "import Sir3S_Toolkit" ] }, { "cell_type": "markdown", "id": "13085702", "metadata": {}, "source": [ "## PythonWrapperToolkit" ] }, { "cell_type": "code", "execution_count": 6, "id": "48372080", "metadata": {}, "outputs": [], "source": [ "import sir3stoolkit" ] }, { "cell_type": "markdown", "id": "e12d61e9", "metadata": {}, "source": [ "The core of sir3stoolkit is a Python Wrapper around C#, that can be used to read, write, etc. to a SIR 3S Model. In the future pure python subpackages may be added." ] }, { "cell_type": "code", "execution_count": 7, "id": "f1baf699", "metadata": {}, "outputs": [], "source": [ "from sir3stoolkit.core import wrapper" ] }, { "cell_type": "code", "execution_count": 8, "id": "89da1276", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sir3stoolkit" ] }, { "cell_type": "markdown", "id": "6d982834", "metadata": {}, "source": [ "The [wrapper package](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.Initialize_Toolkit) has to be initialized with reference to a SIR Graf installation." ] }, { "cell_type": "code", "execution_count": 10, "id": "817b0ebf", "metadata": {}, "outputs": [], "source": [ "wrapper.Initialize_Toolkit(SIR3S_SIRGRAF_DIR)" ] }, { "cell_type": "markdown", "id": "0352dd43", "metadata": {}, "source": [ "# Initialization" ] }, { "cell_type": "markdown", "id": "e14ffe06", "metadata": {}, "source": [ "Toolkit contains two classes: [SIR3S_Model](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_Model)(model and data) and [SIR3S_View](https://3sconsult.github.io/sir3stoolkit/references/sir3stoolkit.core.html#sir3stoolkit.core.wrapper.SIR3S_View)(depiction in SIR Graf). All Toolkit functionality is accessed via the methods of these classes." ] }, { "cell_type": "code", "execution_count": 13, "id": "7e40a5af", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s = wrapper.SIR3S_Model()" ] }, { "cell_type": "code", "execution_count": 14, "id": "3770c93f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialization complete\n" ] } ], "source": [ "s3s_view = wrapper.SIR3S_View()" ] }, { "cell_type": "markdown", "id": "b21a7ab7", "metadata": {}, "source": [ "# Create New Model" ] }, { "cell_type": "markdown", "id": "c837828c", "metadata": {}, "source": [ "We are using the NewModel() function of SIR3S_Model() to create a new db3 file." ] }, { "cell_type": "code", "execution_count": null, "id": "28f84fbf", "metadata": {}, "outputs": [], "source": [ "dbFilePath=r\"Toolkit_TutorialX_Model.db3\"" ] }, { "cell_type": "code", "execution_count": null, "id": "de952a07", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "New model is created with the model identifier: M-1-0-1\n" ] } ], "source": [ "s3s.NewModel(dbName=dbFilePath,\n", " providerType=Interfaces.SirDBProviderType.SQLite, \n", " namedInstance=\"\", \n", " netType=Interfaces.NetworkType.Undefined,\n", " modelDescription=\"Tutorial X Model\",\n", " userID=\"\", \n", " password=\"\")" ] }, { "cell_type": "markdown", "id": "b9b93bdc", "metadata": {}, "source": [ "Now the Model has been created and is opened. All Toolkit commands now apply to this model until another one is opened. If there already existed a model file with this path and name, a new model with the same name but incremented model identifier is created." ] }, { "cell_type": "code", "execution_count": 17, "id": "4de889e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Undefined\n" ] } ], "source": [ "print(s3s.GetNetworkType()) # to check that the model is responsive" ] }, { "cell_type": "markdown", "id": "34309a14", "metadata": {}, "source": [ "# Open Model" ] }, { "cell_type": "code", "execution_count": null, "id": "0918738e", "metadata": {}, "outputs": [], "source": [ "dbFilePath=r\"Toolkit_TutorialX_Model.db3\"" ] }, { "cell_type": "code", "execution_count": 19, "id": "e984b61e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Model is open for further operation\n" ] } ], "source": [ "s3s.OpenModel(dbName=dbFilePath, \n", " providerType=Interfaces.SirDBProviderType.SQLite, \n", " Mid=\"M-1-0-1\", \n", " saveCurrentlyOpenModel=False, \n", " namedInstance=\"\", \n", " userID=\"\", \n", " password=\"\")" ] }, { "cell_type": "markdown", "id": "e2490549", "metadata": {}, "source": [ "Now the Model has been opened the previous one was close without saving it. All Toolkit commands now apply to this model until another one is opened." ] }, { "cell_type": "code", "execution_count": 20, "id": "8e3adb92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DistrictHeating\n" ] } ], "source": [ "print(s3s.GetNetworkType()) # to check that the correct model is responsive, model we are trying to open was createdd with type District Heating" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 5 }