{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bike Speed versus Grade\n",
    "\n",
    "Like most people, I bike slower when I'm going up a steep hill than on a flat road. But how much slower?\n",
    "To answer that, I downloaded data on my past rides \n",
    "from [Strava](https://www.strava.com/athletes/575579) and manipulated the `data` to create two lists, `X` holding the number of feet of climbing per mile for each ride, and `Y` holding the speed in miles per hour for each corresponding ride. (Notice that I only keep rides longer than 30 miles, so these should all be at a similar level of seriousness.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import csv\n",
    "\n",
    "def hours(sec):    return float(sec) / 60 / 60\n",
    "def feet(meters):  return float(meters) * 100 / 2.54 / 12\n",
    "def miles(meters): return feet(meters) / 5280\n",
    "def getcsv(fname): return [r for r in csv.reader(open(fname)) if miles(r[0]) > 30]\n",
    "\n",
    "# A file with three fields per line: distance (m), climb (m), elapsed time (sec)\n",
    "data = getcsv('dist-climb-time.csv') \n",
    "X    = [feet(climb) / miles(dist) for (dist, climb, time) in data]\n",
    "Y    = [miles(dist) / hours(time) for (dist, climb, time) in data]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now I'll plot `X` versus `Y`, along with a best-fit polynomial to the points.\n",
    "(I use a polynomial of degree two because the raw data looks like a curve, not a straight line,\n",
    "and because a cubic polynomial seems like too many degress of freedom for y noisy data.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYFNXVwOHfmWHYd0FEUQYQMIoGHBRRo4Msoqi4r0Rx\nQ41RgokRt88lJjFxIcRI3MW44Yog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OIyBE4VUjgVM2c6Nbrh+bT7ZjJ4HEG+WorIn3dY5SJyF7q\nzCGxUkROcpeLiPzS3eZ7nGqwWE4SkRK3/aCze4yXgIvEGaIcEekmzqQ6fpoOXBJ6ISKpNo6bgLJE\nYLJCVefiDKP7Hs7sUIuAb2Osfj1OVct84Kuw5TcAh4jIEpwqotXuvt8HrgGmi8h7OPPTts9w/JuA\nE4G/ici7OO0dB7pvnwGc6y5fwrYpUScAl7uN3l0i9+nG/zbO93Ghe0Z+H05j8AJxJjS/G/+v3C8F\neruN0+8DF/p8PJNnbPRRkzWhemdxZmF6FRih7rzNxUZExuM03D6d61iMsTYCk033iHODVUOcOv2i\nTALG5Bu7IjDGmCJnbQTGGFPkLBEYY0yRs0RgjDFFzhKBMcYUOUsExhhT5CwRGGNMkft/K7+oEXNR\nGaIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x116d67eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0 ft/mile: 13.8 mph\n",
      " 20 ft/mile: 13.8 mph\n",
      " 40 ft/mile: 13.5 mph\n",
      " 60 ft/mile: 13.0 mph\n",
      " 80 ft/mile: 12.1 mph\n",
      "100 ft/mile: 11.0 mph\n",
      "120 ft/mile:  9.6 mph\n",
      "140 ft/mile:  7.8 mph\n"
     ]
    }
   ],
   "source": [
    "def poly(X, Y, n):\n",
    "    \"Return best degree-n polynomial to fit X, Y data.\"\n",
    "    C = np.polyfit(X, Y, n)[::-1] # Array of coefficients, reversed\n",
    "    return lambda x: sum(C[i] * x ** i for i in range(n + 1))  \n",
    "\n",
    "def show(X, Y, grades=range(0, 141, 20), degree=2): \n",
    "    plt.plot(X, Y, '+')\n",
    "    F = poly(X, Y, degree)\n",
    "    plt.plot(grades, [F(x) for x in grades], '-')\n",
    "    plt.ylabel('speed in miles per hour')\n",
    "    plt.xlabel('grade in feet per mile')\n",
    "    plt.grid()\n",
    "    plt.show()\n",
    "    for g in grades:\n",
    "        print('{:3} ft/mile: {:4.1f} mph'.format(g, F(g)))\n",
    "             \n",
    "show(X, Y)     "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So, it looks like I go about 14 mph when the road is fairly flat, with a lot of variability from 12 to 16 mph, depending more on my level of effort than on the grade of the road. But from 60 ft/mile and up, speed falls off quickly at 1 mph for every 20 ft/mile, and by 140 ft/mile, I'm down to 7.8 mph. Note that 140 ft/mile is only 2.7% grade, but if you figure a typical route is 1/3 up, 1/3 down, and 1/3 flatish, then that's 8% grade on the up part."
   ]
  }
 ],
 "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.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
