-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb8daff
commit b1b7a90
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "1adfb8c3", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "OptionError", | ||
"evalue": "\"No such keys(s): 'display.max_columnwidth'\"", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mOptionError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn[1], line 7\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mjson\u001b[39;00m\n\u001b[1;32m 6\u001b[0m pd\u001b[38;5;241m.\u001b[39mset_option(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdisplay.max_rows\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m----> 7\u001b[0m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_option\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdisplay.max_columnwidth\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m engine \u001b[38;5;241m=\u001b[39m create_engine(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmysql+mysqlconnector://root:secret@localhost:3306/serlo\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 11\u001b[0m connection \u001b[38;5;241m=\u001b[39m engine\u001b[38;5;241m.\u001b[39mraw_connection()\n", | ||
"File \u001b[0;32m~/.local/lib/python3.8/site-packages/pandas/_config/config.py:261\u001b[0m, in \u001b[0;36mCallableDynamicDoc.__call__\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 260\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m T:\n\u001b[0;32m--> 261\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;18;43m__func__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n", | ||
"File \u001b[0;32m~/.local/lib/python3.8/site-packages/pandas/_config/config.py:156\u001b[0m, in \u001b[0;36m_set_option\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 153\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_set_option() got an unexpected keyword argument \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mkwarg\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 155\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(args[::\u001b[38;5;241m2\u001b[39m], args[\u001b[38;5;241m1\u001b[39m::\u001b[38;5;241m2\u001b[39m]):\n\u001b[0;32m--> 156\u001b[0m key \u001b[38;5;241m=\u001b[39m \u001b[43m_get_single_key\u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msilent\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 158\u001b[0m o \u001b[38;5;241m=\u001b[39m _get_registered_option(key)\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m o \u001b[38;5;129;01mand\u001b[39;00m o\u001b[38;5;241m.\u001b[39mvalidator:\n", | ||
"File \u001b[0;32m~/.local/lib/python3.8/site-packages/pandas/_config/config.py:121\u001b[0m, in \u001b[0;36m_get_single_key\u001b[0;34m(pat, silent)\u001b[0m\n\u001b[1;32m 119\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m silent:\n\u001b[1;32m 120\u001b[0m _warn_if_deprecated(pat)\n\u001b[0;32m--> 121\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m OptionError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo such keys(s): \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mrepr\u001b[39m(pat)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 122\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(keys) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 123\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m OptionError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPattern matched multiple keys\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", | ||
"\u001b[0;31mOptionError\u001b[0m: \"No such keys(s): 'display.max_columnwidth'\"" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sqlalchemy import create_engine\n", | ||
"import pandas as pd\n", | ||
"import mysql.connector\n", | ||
"import json\n", | ||
"\n", | ||
"pd.set_option(\"display.max_rows\", None)\n", | ||
"pd.set_option(\"display.max_columnwidth\", None)\n", | ||
"\n", | ||
"engine = create_engine(\"mysql+mysqlconnector://root:secret@localhost:3306/serlo\")\n", | ||
"\n", | ||
"connection = engine.raw_connection()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b7efe388", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_sql(\n", | ||
" \"\"\"\n", | ||
" SELECT entity.id, type.name as type, value FROM entity_revision_field\n", | ||
" JOIN entity ON entity_revision_id = current_revision_id \n", | ||
" JOIN type ON type.id = entity.type_id \n", | ||
" WHERE value LIKE '%\"plugin\":\"injection\"%';\n", | ||
" \"\"\",\n", | ||
" con=engine,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "99cf1880", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_injection_states(content, states=None):\n", | ||
" if states is None:\n", | ||
" states = []\n", | ||
"\n", | ||
" if isinstance(content, str):\n", | ||
" content = json.loads(content)\n", | ||
" for key, value in content.items():\n", | ||
" if key == \"plugin\" and value == \"injection\":\n", | ||
" states.append(content[\"state\"])\n", | ||
" if isinstance(value, dict):\n", | ||
" get_injection_states(value, states)\n", | ||
" elif isinstance(value, list):\n", | ||
" for element in value:\n", | ||
" get_injection_states(element, states)\n", | ||
" return states" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "54adec18", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df[\"states\"] = df[\"value\"].map(get_injection_states)\n", | ||
"df = df.drop(\"value\", axis=1)\n", | ||
"\n", | ||
"df" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.8.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |