diff --git a/CHANGELOG.md b/CHANGELOG.md index f4fed11..a1d3e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,12 +20,15 @@ Here is a template for new release sections ``` ## [Unreleased] - -## [0.0.7] 2019-08-29 - ### Added - CHANGELOG +### Changed +- updated link to the examples/tutorials ([#24](https://github.com/OpenEnergyPlatform/oedialect/pull/24)) + +### Removed +- notebook example ([#24](https://github.com/OpenEnergyPlatform/oedialect/pull/24)) + ## [0.0.6] 2019-08-29 ### Added diff --git a/README.md b/README.md index ae09e50..a3797e3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ This repository is licensed under [GNU Affero General Public License v3.0 (AGPL- pip install oedialect -## Example +## Tutorials -You can find a basic example [here](doc/example/oedialect_basic_example.ipynb). +You can find tutorials and examples [here](https://github.com/OpenEnergyPlatform/examples/tree/master/api). diff --git a/doc/example/oedialect_basic_example.ipynb b/doc/example/oedialect_basic_example.ipynb deleted file mode 100644 index 1375add..0000000 --- a/doc/example/oedialect_basic_example.ipynb +++ /dev/null @@ -1,255 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\"OpenEnergy\n", - "\n", - "# OpenEnergyPlatform\n", - "
\n", - "## Usage of OpenEnergyPlatform API-Dialect (oedialect)\n", - "Repository: https://github.com/openego/oedialect" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "__copyright__ = \"Reiner Lemoine Institut\"\n", - "__license__ = \"GNU Affero General Public License Version 3 (AGPL-3.0)\"\n", - "__url__ = \"https://github.com/openego/data_processing/blob/master/LICENSE\"\n", - "__author__ = \"henhuy, Ludee, nesnoj\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import getpass\n", - "import sqlalchemy as sa\n", - "from sqlalchemy.orm import sessionmaker\n", - "import oedialect" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Whitespaces are not a problem for setting up the url!\n", - "user = input('Enter OEP-username:')\n", - "token = getpass.getpass('Token:')" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# Create Engine:\n", - "OEP_URL = 'oep.iks.cs.ovgu.de'\n", - "OED_STRING = 'postgresql+oedialect://{user}:{token}@{OEP_URL}'.format(user=user,\n", - " token=token,\n", - " OEP_URL=OEP_URL)\n", - "\n", - "engine = sa.create_engine(OED_STRING)\n", - "metadata = sa.MetaData(bind=engine)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup a Table" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "table_name = 'example_dialect_table'\n", - "schema_name = 'sandbox'\n", - "\n", - "ExampleTable = sa.Table(\n", - " table_name,\n", - " metadata,\n", - " sa.Column('name', sa.VARCHAR(50)),\n", - " sa.Column('age', sa.INTEGER),\n", - " sa.Column('stadtname', sa.VARCHAR(50)),\n", - " schema=schema_name\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create the new Table" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "conn = engine.connect()\n", - "print('Connection established')\n", - "if not engine.dialect.has_table(conn, table_name, schema_name):\n", - " ExampleTable.create()\n", - " print('Created table')\n", - "else:\n", - " print('Table already exists')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Insert data into Table" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Session = sessionmaker(bind=engine)\n", - "session = Session()\n", - "try:\n", - " insert_statement = ExampleTable.insert().values(\n", - " [\n", - " dict(name='Peter', age=25),\n", - " dict(name='Inge', age=42),\n", - " dict(name='Horst', age=69)\n", - " ]\n", - " )\n", - " session.execute(insert_statement)\n", - " session.commit()\n", - " print('Insert successful!')\n", - "except Exception as e:\n", - " session.rollback()\n", - " raise\n", - " print('Insert incomplete!')\n", - "finally:\n", - " session.close()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Select from Table" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Session = sessionmaker(bind=engine)\n", - "session = Session()\n", - "print(session.query(ExampleTable).all())\n", - "session.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "Session = sessionmaker(bind=engine)\n", - "session = Session()\n", - "df = pd.DataFrame(session.query(ExampleTable).all())\n", - "session.close()\n", - "df" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Update data in Table" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# ????" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3.0 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.3" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/doc/example/readme.md b/doc/example/readme.md new file mode 100644 index 0000000..e1db734 --- /dev/null +++ b/doc/example/readme.md @@ -0,0 +1,3 @@ +## Examples + +Tutorials on jupyter notebooks can be found [here](https://github.com/OpenEnergyPlatform/examples/tree/master/api) \ No newline at end of file