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