{ "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 }