<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Demo caching
This notebook shows how caching of daily results is organised. First we show the low-level approach, then a high-level function is used.
Low-level approach
Step1:  We demonstrate the caching for the minimal daily water consumption (should be close to zero unless there is a water leak).  We create a cache object by specifying what we like to store and retrieve through this object.  The cached data is saved as a single csv per sensor in a folder specified in the opengrid.cfg.  Add the path to a folder where you want these csv-files to be stored as follows to your opengrid.cfg
[data]
folder
Step2:  If this is the first time you run this demo, no cached data will be found, and you get an empty graph. 
Let's store some results in this cache.  We start from the water consumption of last week.
Step3:  We use the method daily_min() from the analysis module to obtain a dataframe with daily minima for each sensor.
Step4:  Now we can get the daily water minima from the cache directly. Pass a start or end date to limit the returned dataframe.
Step5:  A high-level cache function
The caching of daily results is very similar for all kinds of results.  Therefore, a high-level function is defined that can be parametrised to cache a lot of different things.
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
from opengrid.library import misc
from opengrid.library import houseprint
from opengrid.library import caching
import charts
hp = houseprint.Houseprint()
Explanation: Demo caching
This notebook shows how caching of daily results is organised. First we show the low-level approach, then a high-level function is used.
Low-level approach
End of explanation
cache_water = caching.Cache(variable='water_daily_min')
df_cache = cache_water.get(sensors=hp.get_sensors(sensortype='water'))
charts.plot(df_cache.ix[-8:], stock=True, show='inline')
Explanation: We demonstrate the caching for the minimal daily water consumption (should be close to zero unless there is a water leak).  We create a cache object by specifying what we like to store and retrieve through this object.  The cached data is saved as a single csv per sensor in a folder specified in the opengrid.cfg.  Add the path to a folder where you want these csv-files to be stored as follows to your opengrid.cfg
[data]
folder: path_to_folder
End of explanation
hp.sync_tmpos()
start = pd.Timestamp('now') - pd.Timedelta(weeks=1)
df_water = hp.get_data(sensortype='water', head=start, )
df_water.info()
Explanation: If this is the first time you run this demo, no cached data will be found, and you get an empty graph. 
Let's store some results in this cache.  We start from the water consumption of last week.
End of explanation
daily_min = analysis.DailyAgg(df_water, agg='min').result
daily_min.info()
daily_min
cache_water.update(daily_min)
Explanation: We use the method daily_min() from the analysis module to obtain a dataframe with daily minima for each sensor.
End of explanation
sensors = hp.get_sensors(sensortype='water') # sensor objects
charts.plot(cache_water.get(sensors=sensors, start=start, end=None), show='inline', stock=True)
Explanation: Now we can get the daily water minima from the cache directly. Pass a start or end date to limit the returned dataframe.
End of explanation
import pandas as pd
from opengrid.library import misc
from opengrid.library import houseprint
from opengrid.library import caching
from opengrid.library import analysis
import charts   
hp = houseprint.Houseprint()
#hp.sync_tmpos()
sensors = hp.get_sensors(sensortype='water')
caching.cache_results(hp=hp, sensors=sensors, resultname='water_daily_min', AnalysisClass=analysis.DailyAgg, agg='min')
cache = caching.Cache('water_daily_min')
daily_min = cache.get(sensors = sensors, start = '20151201')
charts.plot(daily_min, stock=True, show='inline')
Explanation: A high-level cache function
The caching of daily results is very similar for all kinds of results.  Therefore, a high-level function is defined that can be parametrised to cache a lot of different things.
End of explanation
<END_TASK>