diff --git a/docs/data/upload_tutorial_example_data.csv b/docs/data/upload_tutorial_example_data.csv index 44d420c5..03947e37 100644 --- a/docs/data/upload_tutorial_example_data.csv +++ b/docs/data/upload_tutorial_example_data.csv @@ -1,25 +1,4 @@ -id;variable;unit;year;value -0;Antimatter price;Euro (2010) / GJ;2020;3 -1;Antimatter price;Euro (2010) / GJ;2030;3.3 -2;Antimatter price;Euro (2010) / GJ;2040;3.33 -3;Antimatter price;Euro (2010) / GJ;2050;4.44 -4;Fusion price;Euro (2010) / GJ;2020;1.7 -5;Fusion price;Euro (2010) / GJ;2030;1.7 -6;Fusion price;Euro (2010) / GJ;2040;1.7 -7;Fusion price;Euro (2010) / GJ;2050;1.7 -8;Naquadria price;Euro (2010) / GJ;2020;10.0 -9;Naquadria price;Euro (2010) / GJ;2030;18.1 -10;Naquadria price;Euro (2010) / GJ;2040;26.2 -11;Naquadria price;Euro (2010) / GJ;2050;32.3 -12;Power Cristals price;Euro (2010) / GJ;2020;5.5 -13;Power Cristals price;Euro (2010) / GJ;2030;9.9 -14;Power Cristals price;Euro (2010) / GJ;2040;11.11 -15;Power Cristals price;Euro (2010) / GJ;2050;14.4 -16;CO2 certificate price ;Euro (2010) / ton;2020;40 -17;CO2 certificate price ;Euro (2010) / ton;2030;80 -18;CO2 certificate price ;Euro (2010) / ton;2040;160 -19;CO2 certificate price ;Euro (2010) / ton;2050;320 -20;Gross domestic product;Billion Euro (2000);2020;1000 -21;Gross domestic product;Billion Euro (2010);2030;2000 -22;Gross domestic product;Billion Euro (2010);2040;3000 -23;Gross domestic product;Billion Euro (2010);2050;4000 +name,is_active,capacity_mw,installation_datetime_utc,location +unit1,True,1.2,2010-02-03 00:00:00,POINT(53.12 8.345) +unit2,False,2.1,2010-01-08, +unit3,True,100,2010-01-02 10:30:00,Point(55.34 7.34) diff --git a/docs/data/upload_tutorial_example_data.metadata.json b/docs/data/upload_tutorial_example_data.metadata.json new file mode 100644 index 00000000..4d272f23 --- /dev/null +++ b/docs/data/upload_tutorial_example_data.metadata.json @@ -0,0 +1,44 @@ +{ + "id": "test_table_74864", + "keywords": ["energy", "installations", "geo"], + "languages": ["EN"], + "resources": [ + { + "name": "test_table_74864", + "schema": { + "fields": [ + { + "name": "id", + "type": "integer", + "description": "numerical id of this data point" + }, + { + "name": "name", + "type": "string", + "description": "name of installation" + }, + { + "name": "is_active", + "type": "boolean", + "description": "true/false if installation is active" + }, + { + "name": "capacity_mw", + "type": "number", + "description": "installed capacity in MW" + }, + { + "name": "installation_datetime_utc", + "type": "string", + "description": "date (and time) when installation was build" + }, + { + "name": "location", + "type": " geojson", + "description": "point location of installation" + } + ] + } + } + ] +} diff --git a/docs/tutorials/api/01_api_download.ipynb b/docs/tutorials/api/01_api_download.ipynb index 7cc464a4..c6c3dd96 100644 --- a/docs/tutorials/api/01_api_download.ipynb +++ b/docs/tutorials/api/01_api_download.ipynb @@ -196,7 +196,7 @@ ], "source": [ "# Add (multiple) where filters to the url\n", - "res = req.get(table_api_url + \"rows/?where=id<10\")\n", + "res = req.get(table_api_url + \"rows/?where=id<2&where=year=2021\")\n", "data = res.json()\n", "\n", "# show results in notebook\n", diff --git a/docs/tutorials/api/01_api_upload.ipynb b/docs/tutorials/api/01_api_upload.ipynb index 6db7028c..7b8bcb63 100644 --- a/docs/tutorials/api/01_api_upload.ipynb +++ b/docs/tutorials/api/01_api_upload.ipynb @@ -65,7 +65,7 @@ "\n", "topic = 'sandbox'\n", "table = f'test_table_{randint(0, 100000)}'\n", - "token = environ.get(\"OEP_API_TOKEN\") or getpass.getpass('Enter your OEP API token:')\n", + "token = environ.get(\"OEP_API_TOKEN\") or getpass('Enter your OEP API token:')\n", "\n", "# for read/write, we need to add authorization header\n", "auth_headers = {'Authorization': 'Token %s' % token}\n", @@ -155,6 +155,13 @@ " \"capacity_mw\": 2.1,\n", " \"installation_datetime_utc\": \"2010-01-08\",\n", " \"location\": null\n", + " },\n", + " {\n", + " \"name\": \"unit3\",\n", + " \"is_active\": true,\n", + " \"capacity_mw\": 100.0,\n", + " \"installation_datetime_utc\": \"2010-01-02 10:30:00\",\n", + " \"location\": \"Point(55.34 7.34)\"\n", " }\n", "]\n" ] @@ -164,7 +171,7 @@ "# TODO: explain required data structure\n", "\n", "# get example data (from csv)\n", - "df = pd.read_csv(\"https://gist.githubusercontent.com/wingechr/4b6a6301a37a2131c10b2eb412b288e9/raw/782c94009fe12486ffc7a232fd852fcda2e835bc/oep_example1.data.csv\")\n", + "df = pd.read_csv(\"https://raw.githubusercontent.com/OpenEnergyPlatform/academy/production/docs/data/upload_tutorial_example_data.csv\")\n", "\n", "# optionally: clean up nan values\n", "df = df.astype(object).where(pd.notnull(df), None)\n", @@ -209,65 +216,27 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"id\": \"test_table_74864\",\n", - " \"keywords\": [\n", - " \"energy\",\n", - " \"installations\",\n", - " \"geo\"\n", - " ],\n", - " \"languages\": [\n", - " \"EN\"\n", - " ],\n", - " \"resources\": [\n", - " {\n", - " \"name\": \"test_table_74864\",\n", - " \"schema\": {\n", - " \"fields\": [\n", - " {\n", - " \"name\": \"id\",\n", - " \"type\": \"integer\",\n", - " \"description\": \"numerical id of this data point\"\n", - " },\n", - " {\n", - " \"name\": \"name\",\n", - " \"type\": \"string\",\n", - " \"description\": \"name of installation\"\n", - " },\n", - " {\n", - " \"name\": \"is_active\",\n", - " \"type\": \"boolean\",\n", - " \"description\": \"true/false if installation is active\"\n", - " },\n", - " {\n", - " \"name\": \"capacity_mw\",\n", - " \"type\": \"number\",\n", - " \"description\": \"installed capacity in MW\"\n", - " },\n", - " {\n", - " \"name\": \"installation_datetime_utc\",\n", - " \"type\": \"string\",\n", - " \"description\": \"date (and time) when installation was build\"\n", - " },\n", - " {\n", - " \"name\": \"location\",\n", - " \"type\": \" geojson\",\n", - " \"description\": \"point location of installation\"\n", - " }\n", - " ]\n", - " }\n", - " }\n", - " ]\n", - "}\n" + "ename": "JSONDecodeError", + "evalue": "Extra data: line 1 column 4 (char 3)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mc:\\Users\\c.winger\\nobackup\\bin\\python\\lib\\site-packages\\requests\\models.py\u001b[0m in \u001b[0;36mjson\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 970\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 971\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mcomplexjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 972\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mJSONDecodeError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\c.winger\\nobackup\\bin\\python\\lib\\json\\__init__.py\u001b[0m in \u001b[0;36mloads\u001b[1;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[0;32m 345\u001b[0m parse_constant is None and object_pairs_hook is None and not kw):\n\u001b[1;32m--> 346\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0m_default_decoder\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 347\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcls\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\c.winger\\nobackup\\bin\\python\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self, s, _w)\u001b[0m\n\u001b[0;32m 339\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 340\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mJSONDecodeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Extra data\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 341\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mJSONDecodeError\u001b[0m: Extra data: line 1 column 4 (char 3)", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mJSONDecodeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mC:\\Users\\C4495~1.WIN\\nobackup\\tmp/ipykernel_12800/3890873945.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# get metadata (from example file)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mmetadata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mreq\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"https://raw.githubusercontent.com/OpenEnergyPlatform/academy/production/docs/data/upload_tutorial_example_data.metadata.json\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;31m# show results in notebook\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdumps\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmetadata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindent\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\c.winger\\nobackup\\bin\\python\\lib\\site-packages\\requests\\models.py\u001b[0m in \u001b[0;36mjson\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 973\u001b[0m \u001b[1;31m# Catch JSON-related errors and raise as requests.JSONDecodeError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 974\u001b[0m \u001b[1;31m# This aliases json.JSONDecodeError and simplejson.JSONDecodeError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 975\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mRequestsJSONDecodeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdoc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpos\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 976\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 977\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mproperty\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mJSONDecodeError\u001b[0m: Extra data: line 1 column 4 (char 3)" ] } ], "source": [ "# get metadata (from example file)\n", - "metadata = req.get(\"https://gist.githubusercontent.com/wingechr/228d76ea759e92feca53910794cba477/raw/ac95def814f385b85e8372194723e5fb81672796/oep_example1.metadata.json\").json()\n", + "metadata = req.get(\"https://raw.githubusercontent.com/OpenEnergyPlatform/academy/production/docs/data/upload_tutorial_example_data.metadata.json\").json()\n", "\n", "# show results in notebook\n", "print(json.dumps(metadata, indent=4))" @@ -275,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -301,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [