diff --git a/research/04_visualizing_restaurants.ipynb b/research/04_visualizing_restaurants.ipynb new file mode 100644 index 0000000..fa80020 --- /dev/null +++ b/research/04_visualizing_restaurants.ipynb @@ -0,0 +1,227 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# A Restaurant's Customers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook helps to visualize the customers a restaurant faces." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[32murban-meal-delivery\u001b[0m, version \u001b[34m0.3.0\u001b[0m\n" + ] + } + ], + "source": [ + "!umd --version" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from urban_meal_delivery import db" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext lab_black" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Settings" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Choose `\"Bordeaux\"`, `\"Lyon\"`, or `\"Paris\"`." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "city_name = \"Paris\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load the Data" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "city = db.session.query(db.City).filter_by(name=city_name).one()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "restaurants = (\n", + " db.session.query(db.Restaurant)\n", + " .join(db.Address)\n", + " .filter(db.Address.city == city)\n", + " .all()\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1153" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(restaurants)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Visualization" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Choose a restaurant from the `restaurants` list." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "restaurant = restaurants[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Set `order_counts=True` to also show the number of orders per customer, indicated as differently sized dots. However, this option may be computationally heavy. The restaurant's location appears as a red dot while the customer's delivery locations are blue." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "restaurant.clear_map().draw(order_counts=True)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/research/05_visualizing_customers.ipynb b/research/05_visualizing_customers.ipynb new file mode 100644 index 0000000..13c443b --- /dev/null +++ b/research/05_visualizing_customers.ipynb @@ -0,0 +1,230 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# A Customer's Orders" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook helps to visualize where a given customer placed his orders." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[32murban-meal-delivery\u001b[0m, version \u001b[34m0.3.0\u001b[0m\n" + ] + } + ], + "source": [ + "!umd --version" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from urban_meal_delivery import db" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext lab_black" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Settings" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Choose `\"Bordeaux\"`, `\"Lyon\"`, or `\"Paris\"`." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "city_name = \"Paris\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load the Data" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "city = db.session.query(db.City).filter_by(name=city_name).one()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "customers = (\n", + " db.session.query(db.Customer)\n", + " .join(db.Order)\n", + " .join(db.Address, db.Order.pickup_address_id == db.Address.id)\n", + " .filter(db.Address.city == city)\n", + " .all()\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "113144" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(customers)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Visualization" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Choose a customer from the `customers` list." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "customer = customers[1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Set `order_counts=True` to also show the number of orders per customer, indicated by differently sized dots.\n", + "\n", + "The customer's delivery locations appear as blue dots while the restaurants' pickup locations are red." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer.clear_map().draw(order_counts=True)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}