<jupyter_start><jupyter_text>This script shows the visualization of electricity, water and gas consumption using carpet plotsTo get started, first run the 'Synchronize data' script Imports and paths<jupyter_code>import os
import sys
import pytz
import time
import inspect
import numpy as np
import pandas as pd
import datetime as dt
import tmpo

from opengrid_dev import config
from opengrid_dev.library import houseprint

c=config.Config()

try:
    if os.path.exists(c.get('tmpo', 'data')):
        path_to_tmpo_data = c.get('tmpo', 'data')
except:
    path_to_tmpo_data = None

# configuration for the plots
DEV = c.get('env', 'type') == 'dev' # DEV is True if we are in development environment, False if on the droplet
print("Environment configured for development: {}".format(DEV))
if not DEV:
    # production environment: don't try to display plots
    # these lines has to be BEFORE any plt import, also in other packages.
    import matplotlib
    matplotlib.use('Agg') 

from opengrid_dev.library import plotting
import matplotlib.pyplot as plt
from matplotlib.dates import MinuteLocator, HourLocator, DateFormatter, AutoDateLocator, num2date

if DEV:
    if c.get('env', 'plots') == 'inline':
        %matplotlib inline
    else:
        %matplotlib qt
else:
    pass # don't try to render plots

plt.rcParams['figure.figsize'] = 16,8

# path to data
#path_to_data = c.get('data', 'folder')
#if not os.path.exists(path_to_data):
#    raise IOError("Provide your path to the data in your config.ini file. ")
#else:
#    path_to_fig = os.path.join(path_to_data, 'figures')
#    if not os.path.isdir(path_to_fig): os.makedirs(path_to_fig)
c.get('data','folder')<jupyter_output><empty_output><jupyter_text>Loading meta data and user variables<jupyter_code>hp = houseprint.Houseprint()

end = pd.Timestamp(time.time(), unit='s')
start = end - pd.Timedelta('21 days')
hp.save('new_houseprint.pkl')
hp = houseprint.load_houseprint_from_file('new_houseprint.pkl')
pd.__version__
%%bash
pip install --upgrade pandas<jupyter_output><empty_output><jupyter_text>Plotting<jupyter_code>hp.sync_tmpos()<jupyter_output><empty_output><jupyter_text>Water sensors<jupyter_code>water_sensors = hp.get_sensors(sensortype='water')
print("{} water sensors".format(len(water_sensors)))
for sensor in water_sensors:
    ts = sensor.get_data(head=start, tail=end)
    if not ts.dropna().empty:
        plotting.carpet(ts, title=' - '.join([sensor.device.key, sensor.description, sensor.key]), zlabel=r'Flow [l/min]')
        #plt.savefig(os.path.join(path_to_fig, 'carpet_'+sensor.type+'_'+sensor.key), dpi=100)
        if not DEV:
            plt.close()<jupyter_output><empty_output><jupyter_text>Gas sensors<jupyter_code>gas_sensors = hp.get_sensors(sensortype=('gas'))
print("{} gas sensors".format(len(gas_sensors)))
for sensor in gas_sensors:
    ts = sensor.get_data(head=start, tail=end)
    if not ts.dropna().empty:
        plotting.carpet(ts, title=' - '.join([sensor.device.key, sensor.description, sensor.key]), zlabel=r'Gas consumption [W]')
        #plt.savefig(os.path.join(path_to_fig, 'carpet_'+sensor.type+'_'+sensor.key), dpi=100)
        if not DEV:
            plt.close()<jupyter_output><empty_output><jupyter_text>Electricity sensors<jupyter_code>elec_sensors = hp.get_sensors(sensortype=('electricity'))
print("{} electricity sensors".format(len(elec_sensors)))
for sensor in elec_sensors:
    if not sensor.key.startswith('565de'): # 3E's sensor creates ram issues on the droplet.  To be fixed in tmpo?
        ts = sensor.get_data(head=start, tail=end)
        if not ts.dropna().empty:
            plotting.carpet(ts, title=' - '.join([sensor.device.key, sensor.description, sensor.key]), zlabel=r'Power [W]')
            #plt.savefig(os.path.join(path_to_fig, 'carpet_'+sensor.type+'_'+sensor.key), dpi=100)
            if not DEV:
                plt.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13015629003330773, 'fraction_numerical': 0.004868050217781194, 'mean_word_length': 4.724340175953079, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '611048', 'license': 'Apache-2.0', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1317, 'n_words': 311, 'path': 'opengrid_dev/notebooks/Analysis/CarpetPlot.ipynb', 'repo_name': 'opengridcc/opengrid_dev', 'size': '3903'}