<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# This notebook assumes to be running from your FireCARES VM (eg. python manage.py shell_plus --notebook --no-browser)\n",
    "\n",
    "import sys\n",
    "import os\n",
    "import time\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import psycopg2\n",
    "sys.path.insert(0, os.path.realpath('..'))\n",
    "import folium\n",
    "from pretty import pprint\n",
    "from IPython.display import display\n",
    "from django.contrib.gis.geos import GEOSGeometry\n",
    "\n",
    "pd.set_option(\"display.max_rows\",100)\n",
    "\n",
    "def display_geom(geom):\n",
    "    _map = folium.Map(location=[geom.centroid.y, geom.centroid.x],\n",
    "                      tiles='Stamen Toner')\n",
    "    _map.choropleth(geo_str=geom.geojson, line_weight=0, fill_opacity=0.2, fill_color='green')\n",
    "    ll = geom.extent[1::-1]\n",
    "    ur = geom.extent[3:1:-1]\n",
    "    _map.fit_bounds([ll, ur])\n",
    "\n",
    "    return _map\n",
    "\n",
    "nfirs = psycopg2.connect('service=nfirs')\n",
    "fc = psycopg2.connect('service=firecares')\n",
    "parcels = psycopg2.connect('service=parcels')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Total departments/stations in FireCARES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "q = \"\"\"\n",
    "select *\n",
    "from\n",
    "    (select count(1) as total_departments from firestation_firedepartment) total_departments,\n",
    "    (select count(1) as total_stations from firestation_firestation) total_stations\n",
    "\"\"\"\n",
    "\n",
    "pd.read_sql_query(q, fc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Covered population"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "q = \"\"\"\n",
    "select sum(fd.population) as total_population\n",
    "from firestation_firedepartment fd\n",
    "\"\"\"\n",
    "\n",
    "pd.read_sql_query(q, fc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Total incidents and building fires"<commit_msg>Additional statistics<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# This notebook assumes to be running from your FireCARES VM (eg. python manage.py shell_plus --notebook --no-browser)\n",
    "\n",
    "import sys\n",
    "import os\n",
    "import time\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import psycopg2\n",
    "import django\n",
    "sys.path.insert(0, os.path.realpath('..'))\n",
    "import folium\n",
    "django.setup()\n",
    "from pretty import pprint\n",
    "from IPython.display import display\n",
    "from django.contrib.gis.geos import GEOSGeometry\n",
    "\n",
    "pd.set_option(\"display.max_rows\",100)\n",
    "\n",
    "def display_geom(geom):\n",
    "    _map = folium.Map(location=[geom.centroid.y, geom.centroid.x],\n",
    "                      tiles='<NAME>')\n",
    "    _map.choropleth(geo_str=geom.geojson, line_weight=0, fill_opacity=0.2, fill_color='green')\n",
    "    ll = geom.extent[1::-1]\n",
    "    ur = geom.extent[3:1:-1]\n",
    "    _map.fit_bounds([ll, ur])\n",
    "\n",
    "    return _map\n",
    "\n",
    "nfirs = psycopg2.connect('service=nfirs')\n",
    "fc = psycopg2.connect('service=firecares')\n",
    "parcels = psycopg2.connect('service=parcels')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Total departments/stations in FireCARES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "q = \"\"\"\n",
    "select *\n",
    "from\n",
    "    (select count(1) as total_departments from firestation_firedepartment) total_departments,\n",
    "    (select count(1) as total_stations from firestation_firestation) total_stations\n",
    "\"\"\"\n",
    "\n",
    "pd.read_sql_query(q, fc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Covered population"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "q = \"\"\"\n",
    "select sum(fd.population) as total_population\n",
    "from firestation_firedepartment fd\n",
    "\"\"\"\n",
    "\n",
    "pd.read_sql_query(q, fc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Covered area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from firecares.firestation.models import FireDepartment\n",
    "\n",
    "deps = FireDepartment.objects.filter(population__isnull=False).exclude(population=0)\n",
    "\n",
    "areas = filter(lambda x: x[1] is not None, map(lambda x: (x.id, x.geom_area), deps))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sum(a[1] for a in areas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "len(areas)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Total incidents and building fires"
{'fraction_non_alphanumeric': 0.207439446366782, 'fraction_numerical': 0.006747404844290658, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 77, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6793369', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2197, 'n_words': 395}