{
"metadata": {
"orig_nbformat": 4,
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
},
"kernelspec": {
"name": "python",
"display_name": "Pyolite",
"language": "python"
}
},
"nbformat_minor": 4,
"nbformat": 4,
"cells": [
{
"cell_type": "code",
"source": "import micropip\nawait micropip.install('ipywidgets')\nawait micropip.install('requests')\nfrom ipywidgets import interact, interactive, fixed, interact_manual\nimport ipywidgets as widgets\nimport requests # Import the requests library\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\nprint(\"Done\")\n",
"metadata": {
"trusted": true
},
"execution_count": 1,
"outputs": [
{
"name": "stderr",
"text": "/lib/python3.9/site-packages/pandas/compat/__init__.py:117: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.\n warnings.warn(msg)\n",
"output_type": "stream"
},
{
"name": "stdout",
"text": "Done\n",
"output_type": "stream"
}
]
},
{
"cell_type": "code",
"source": "import json\nfrom pyodide import to_js\nfrom IPython.display import JSON\nfrom js import Object, fetch\nprint(\"Done\")",
"metadata": {
"trusted": true
},
"execution_count": 2,
"outputs": [
{
"name": "stdout",
"text": "Done\n",
"output_type": "stream"
}
]
},
{
"cell_type": "code",
"source": "from IPython.core.display import display, HTML\ndisplay(HTML(\"\"))\ndisplay(HTML(\"\"))\ndisplay(HTML(\"\"))\ndisplay(HTML(\"\"))\n\nresp = await fetch('http://localhost:5000/api/districtstotal?startdate=2021-08-31&enddate=2021-09-31',\n method=\"GET\",\n headers=Object.fromEntries(to_js({ \"Content-Type\": \"application/json\" })),\n)\nres = await resp.text()\npayload =json.loads(res)\n#print(payload)\n",
"metadata": {
"tags": [
"hide_input",
"hide_output"
],
"trusted": true
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": "data=pd.json_normalize(payload['data'])\nselected=data[[\"datetext\", \"counttext\",\"location.formattedAddress\"]]\nprint('Dataset feactched as selected dataframe')\n#print(selected)\n#list(selected.columns.values)",
"metadata": {
"trusted": true
},
"execution_count": 4,
"outputs": [
{
"name": "stdout",
"text": "Dataset feactched as selected dataframe\n",
"output_type": "stream"
}
]
},
{
"cell_type": "code",
"source": "filtedVals= selected[selected['location.formattedAddress'].str.contains('Nuwara Eliya, Sri Lanka')]\nprint('By defult Nuwara Eliya District selected')\nprint('For other district select it form the dropdown below >>>')\n\n\n\ndef f(x):\n print(\"District changed to %s\" % x)\n filtedVals=selected[selected['location.formattedAddress'].str.contains(x)]\n print(filtedVals)\n pivoted = pd.DataFrame(filtedVals.pivot_table(values='counttext', index='datetext', columns='location.formattedAddress', aggfunc='sum'))\n return pivoted\n\ninteract(f, x=['Nuwara Eliya, Sri Lanka', 'Badulla, Sri Lanka', 'Kurunegala, Sri Lanka']);\n\n",
"metadata": {
"trusted": true
},
"execution_count": 5,
"outputs": [
{
"name": "stdout",
"text": "By defult Nuwara Eliya District selected\nFor other district select it form the dropdown below >>>\n",
"output_type": "stream"
},
{
"output_type": "display_data",
"data": {
"text/plain": "interactive(children=(Dropdown(description='x', options=('Nuwara Eliya, Sri Lanka', 'Badulla, Sri Lanka', 'Kur…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "74bec51337a640919336c1c1689650d7"
}
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": "",
"metadata": {},
"execution_count": null,
"outputs": []
}
]
}