{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Visualization of electricity consumption with focus on night time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import time\n",
    "import inspect\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from opengrid import config\n",
    "from opengrid.library import plotting\n",
    "from opengrid.library import houseprint\n",
    "\n",
    "c=config.Config()\n",
    "\n",
    "try:\n",
    "    if os.path.exists(c.get('tmpo', 'data')):\n",
    "        path_to_tmpo_data = c.get('tmpo', 'data')\n",
    "except:\n",
    "    path_to_tmpo_data = None\n",
    "    \n",
    "%matplotlib inline\n",
    "plt.rcParams['figure.figsize'] = 16,8\n",
    "\n",
    "# path to data\n",
    "path_to_data = c.get('data', 'folder')\n",
    "if not os.path.exists(path_to_data):\n",
    "    raise IOError(\"Provide your path to the data in your config.ini file.  This is a folder containing a 'zip' and 'csv' subfolder.\")\n",
    "else:\n",
    "    path_to_fig = os.path.join(path_to_data, 'figures')\n",
    "    if not os.path.isdir(path_to_fig): os.makedirs(path_to_fig)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "hp = houseprint.load_houseprint_from_file('new_houseprint.pkl')\n",
    "hp.init_tmpo(path_to_tmpo_data=path_to_tmpo_data)\n",
    "\n",
    "#set start date\n",
    "number_of_days = 60\n",
    "start = pd.Timestamp(time.time() - number_of_days*86400, unit='s')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sensor = hp.get_sensors(sensortype='electricity')[0]\n",
    "df = sensor.get_data(head = start)\n",
    "df = df.diff()*60 #from Wh/min to W"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plotting.carpet(df, title=sensor.device.key, zlabel=r'Power [W]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plotting.fanchart(df, title=sensor.device.key, ylabel=r'Power [W]', start_hour=0, end_hour=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "begin = pd.Timestamp('20150701')\n",
    "end = begin + pd.Timedelta('1 day')\n",
    "df.truncate(begin,end).plot(title=sensor.device.key)\n",
    "plt.xlabel(begin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "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.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
