diff --git a/Heatmap.ipynb b/Heatmap.ipynb new file mode 100644 index 0000000000..9e00eefc70 --- /dev/null +++ b/Heatmap.ipynb @@ -0,0 +1,234 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import gmaps\n", + "import gmaps.datasets\n", + "gmaps.configure(api_key=\"ENTER YOUR KEY YOUR\")" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loaded 8215 Datasets !\n" + ] + } + ], + "source": [ + "#data = gmaps.datasets.load_dataset(\"taxi_rides\")\n", + "import sqlite3\n", + "conn = sqlite3.connect('db.sqlite')\n", + "raw_data = []\n", + "try:\n", + " c = conn.cursor()\n", + " for row in c.execute('SELECT * FROM sightings'):\n", + " raw_data.append(row)\n", + "except Exception as e :\n", + " print(e)\n", + "finally:\n", + " conn.close()\n", + " print(\"Loaded {} Datasets !\".format(len(raw_data)))" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bulbasaur 2 found\n", + "Ivysaur 1 found\n", + "Squirtle 26 found\n", + "Caterpie 559 found\n", + "Metapod 27 found\n", + "Butterfree 2 found\n", + "Weedle 1362 found\n", + "Kakuna 89 found\n", + "Beedrill 12 found\n", + "Pidgey 1680 found\n", + "Pidgeotto 124 found\n", + "Pidgeot 23 found\n", + "Rattata 646 found\n", + "Raticate 19 found\n", + "Spearow 491 found\n", + "Fearow 15 found\n", + "Ekans 18 found\n", + "Pikachu 7 found\n", + "Sandshrew 3 found\n", + "Nidoran♀ 89 found\n", + "Nidorina 3 found\n", + "Nidoran♂ 82 found\n", + "Nidorino 3 found\n", + "Clefairy 39 found\n", + "Clefable 1 found\n", + "Vulpix 8 found\n", + "Jigglypuff 64 found\n", + "Wigglytuff 3 found\n", + "Zubat 801 found\n", + "Golbat 28 found\n", + "Oddish 47 found\n", + "Gloom 1 found\n", + "Paras 287 found\n", + "Parasect 10 found\n", + "Venonat 202 found\n", + "Venomoth 6 found\n", + "Diglett 7 found\n", + "Meowth 67 found\n", + "Psyduck 58 found\n", + "Golduck 2 found\n", + "Mankey 20 found\n", + "Primeape 2 found\n", + "Growlithe 6 found\n", + "Poliwag 53 found\n", + "Poliwhirl 7 found\n", + "Abra 41 found\n", + "Machop 5 found\n", + "Bellsprout 50 found\n", + "Weepinbell 3 found\n", + "Victreebel 1 found\n", + "Tentacool 26 found\n", + "Tentacruel 1 found\n", + "Geodude 10 found\n", + "Graveler 1 found\n", + "Ponyta 9 found\n", + "Slowpoke 24 found\n", + "Slowbro 1 found\n", + "Magnemite 1 found\n", + "Seel 27 found\n", + "Shellder 55 found\n", + "Cloyster 1 found\n", + "Gastly 67 found\n", + "Haunter 9 found\n", + "Drowzee 145 found\n", + "Hypno 4 found\n", + "Krabby 98 found\n", + "Kingler 4 found\n", + "Voltorb 1 found\n", + "Exeggcute 3 found\n", + "Cubone 12 found\n", + "Hitmonlee 12 found\n", + "Lickitung 2 found\n", + "Koffing 28 found\n", + "Rhyhorn 9 found\n", + "Horsea 56 found\n", + "Seadra 3 found\n", + "Goldeen 31 found\n", + "Seaking 2 found\n", + "Staryu 28 found\n", + "Starmie 1 found\n", + "Scyther 1 found\n", + "Electabuzz 2 found\n", + "Magikarp 83 found\n", + "Eevee 349 found\n", + "Jolteon 1 found\n", + "Dratini 6 found\n" + ] + } + ], + "source": [ + "# Check some statistics on the datas\n", + "names = [\"Bulbasaur\", \"Ivysaur\", \"Venusaur\", \"Charmander\", \"Charmeleon\", \"Charizard\", \"Squirtle\", \"Wartortle\", \"Blastoise\", \"Caterpie\", \"Metapod\", \"Butterfree\", \"Weedle\", \"Kakuna\", \"Beedrill\", \"Pidgey\", \"Pidgeotto\", \"Pidgeot\", \"Rattata\", \"Raticate\", \"Spearow\", \"Fearow\", \"Ekans\", \"Arbok\", \"Pikachu\", \"Raichu\", \"Sandshrew\", \"Sandslash\", \"Nidoran♀\", \"Nidorina\", \"Nidoqueen\", \"Nidoran♂\", \"Nidorino\", \"Nidoking\", \"Clefairy\", \"Clefable\", \"Vulpix\", \"Ninetales\", \"Jigglypuff\", \"Wigglytuff\", \"Zubat\", \"Golbat\", \"Oddish\", \"Gloom\", \"Vileplume\", \"Paras\", \"Parasect\", \"Venonat\", \"Venomoth\", \"Diglett\", \"Dugtrio\", \"Meowth\", \"Persian\", \"Psyduck\", \"Golduck\", \"Mankey\", \"Primeape\", \"Growlithe\", \"Arcanine\", \"Poliwag\", \"Poliwhirl\", \"Poliwrath\", \"Abra\", \"Kadabra\", \"Alakazam\", \"Machop\", \"Machoke\", \"Machamp\", \"Bellsprout\", \"Weepinbell\", \"Victreebel\", \"Tentacool\", \"Tentacruel\", \"Geodude\", \"Graveler\", \"Golem\", \"Ponyta\", \"Rapidash\", \"Slowpoke\", \"Slowbro\", \"Magnemite\", \"Magneton\", \"Farfetch'd\", \"Doduo\", \"Dodrio\", \"Seel\", \"Dewgong\", \"Grimer\", \"Muk\", \"Shellder\", \"Cloyster\", \"Gastly\", \"Haunter\", \"Gengar\", \"Onix\", \"Drowzee\", \"Hypno\", \"Krabby\", \"Kingler\", \"Voltorb\", \"Electrode\", \"Exeggcute\", \"Exeggutor\", \"Cubone\", \"Marowak\", \"Hitmonlee\", \"Hitmonchan\", \"Lickitung\", \"Koffing\", \"Weezing\", \"Rhyhorn\", \"Rhydon\", \"Chansey\", \"Tangela\", \"Kangaskhan\", \"Horsea\", \"Seadra\", \"Goldeen\", \"Seaking\", \"Staryu\", \"Starmie\", \"Mr. Mime\", \"Scyther\", \"Jynx\", \"Electabuzz\", \"Magmar\", \"Pinsir\", \"Tauros\", \"Magikarp\", \"Gyarados\", \"Lapras\", \"Ditto\", \"Eevee\", \"Vaporeon\", \"Jolteon\", \"Flareon\", \"Porygon\", \"Omanyte\", \"Omastar\", \"Kabuto\", \"Kabutops\", \"Aerodactyl\", \"Snorlax\", \"Articuno\", \"Zapdos\", \"Moltres\", \"Dratini\", \"Dragonair\", \"Dragonite\", \"Mewtwo\", \"Mew\"]\n", + "for i in range(1,151):\n", + " c = len([d for d in raw_data if d[1] == i])\n", + " if c != 0:\n", + " print(\"{} {} found\".format(names[i-1], c))" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8215\n" + ] + } + ], + "source": [ + "data = [ (float(d[-2]),float(d[-1])) for d in raw_data] #all\n", + "#data = [ (float(d[-2]),float(d[-1])) for d in raw_data if d[1] == 147] #filter by pokemon id\n", + "print(len(data))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "m = gmaps.Map()\n", + "m.add_layer(gmaps.Heatmap(data=data))\n", + "m" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "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.5.1+" + }, + "widgets": { + "state": { + "788cd22939804767905459953764b496": { + "views": [ + { + "cell_index": 4 + } + ] + } + }, + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/README.md b/README.md index b9c3d23013..a4a1917b1b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,18 @@ import db db.Base.metadata.create_all(db.get_engine()) ``` +### Creating Heatmaps + +To create simple heatmaps follow these steps: + +1. Follow the steps [here](https://github.com/pbugnion/gmaps#installation) to set up Jupyter and gmaps +2. Fire up the IPythonNotebook example +3. Enter your gmaps API key +4. Copy the db.sqlite file next to the notebook +5. Execute the commands in the Notebook one after another by pressing SHIFT+ENTER +6. ... +7. Profit + ## License See [LICENSE](LICENSE).