Extra: Venue 20 electrics#

Hide code cell source
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
import pandas as pd

# comment out the stuff that takes a long time to process in the public data.
# df = pd.read_csv("venue-20/venue_20_electricity_one_week_detail.csv")

# df['timestamp'] = pd.to_datetime(df['timestamp'])
# df["total_kW"] = (df['field3']+df['field2']+df['field1'])/1000
# df = df.fillna(value=0)


# phase1trace = go.Scatter(customdata=df, 
#                     y=df['field1'], 
#                     x = df['timestamp'], 
#                     mode='lines', 
#                     hoverinfo='all', 
#                     name='phase 1',
#                     )

# phase2trace = go.Scatter(customdata=df, 
#                     y=df['field2'], 
#                     x = df['timestamp'], 
#                     mode='lines', 
#                     hoverinfo='all', 
#                     name='phase 2',
#                     )
# phase3trace = go.Scatter(customdata=df, 
#                     y=df['field3'], 
#                     x = df['timestamp'], 
#                     mode='lines', 
#                     hoverinfo='all', 
#                     name='phase 3',
#                     )

# g = go.FigureWidget(data=[phase1trace,phase2trace,phase3trace])
# g.layout.title = 'CurrentCost clamp-on meter readings - one week only'
# g.layout.xaxis.title= 'timestamp'
# g.layout.yaxis.title = "Watts"
# g.layout.width = 1000
# g.layout.height = 500

# fig = go.Figure(g)

# fig.update_layout(
#     hovermode='x unified',
#     hoverlabel=dict(
#         bgcolor="white",
#         # font_size=16,
#         font_family="Rockwell"
#     )
# )

# # Add range slider
# fig.update_layout(
#     xaxis=dict(
#         rangeselector=dict(
#             buttons=list([
#                 dict(
#                      label="All",
#                      step="all"
#                      ),
#                                 dict(count=1,
#                      label="Hour",
#                      step="hour",
#                      stepmode="todate"),
#                 dict(count=1,
#                      label="Day",
#                      step="day",
#                      stepmode="backward"),
#                 dict(count=7,
#                      label="Week",
#                      step="day",
#                      stepmode="backward"),
#                 dict(count=1,
#                      label="Year",
#                      step="year",
#                      stepmode="backward")
#             ])
#         ),
#         rangeslider=dict(
#             visible=True,
#         ),
#         type="date"
#     )
# )


# fig.show()

# hist = go.Histogram(customdata=df, 
#                     x=(df['total_kW']), 
#                     name='sum of phases',
#                     xbins = {'size': 1}
#                     #nbinsx = 15
# )
 
# hist_g = go.FigureWidget()
# hist_g.layout.title = 'Histogram of total kW spot readings over 1 week'
# hist_g.layout.xaxis.title= 'kW draw'
# hist_g.layout.yaxis.title = "number of spot readings"
# hist_g.layout.width = 1000
# hist_g.layout.height = 500

# hist_fig = go.Figure(hist_g)
# hist_fig.add_trace(hist)
# hist_fig.show()
Hide code cell source
# preprocessed downsampled data and stored in this file - see downsample-data.py

s = pd.read_csv("venue-20/venue_20_electricity_downsampled.csv")
s['timestamp'] = pd.to_datetime(s['timestamp'])
s = s.fillna(value=0)

downsampled_tot_trace = go.Scatter(customdata=s, 
                    y=s['total_kW'],
                    x = s['timestamp'], 
                    mode='lines', 
                    hoverinfo='all', 
                    name='total',
                    )

g3 = go.FigureWidget(data=[downsampled_tot_trace])
g3.layout.title = 'CurrentCost clamp-on meter readings - aggregated for half hour slots'
g3.layout.xaxis.title= 'timestamp'
g3.layout.yaxis.title = "kW"
g3.layout.width = 1000
g3.layout.height = 500

fig3 = go.Figure(g3)

fig3.update_layout(
    hovermode='x unified',
    hoverlabel=dict(
        bgcolor="white",
        # font_size=16,
        font_family="Rockwell"
    )
)

# Add range slider
fig3.update_layout(
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(
                     label="All",
                     step="all"
                     ),
                                dict(count=1,
                     label="Hour",
                     step="hour",
                     stepmode="todate"),
                dict(count=1,
                     label="Day",
                     step="day",
                     stepmode="backward"),
                dict(count=7,
                     label="Week",
                     step="day",
                     stepmode="backward"),
                dict(count=1,
                     label="Year",
                     step="year",
                     stepmode="backward")
            ])
        ),
        rangeslider=dict(
            visible=True,
        ),
        type="date"
    )
)


fig3.show()
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 3
      1 # preprocessed downsampled data and stored in this file - see downsample-data.py
----> 3 s = pd.read_csv("venue-20/venue_20_electricity_downsampled.csv")
      4 s['timestamp'] = pd.to_datetime(s['timestamp'])
      5 s = s.fillna(value=0)

File /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:912, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)
    899 kwds_defaults = _refine_defaults_read(
    900     dialect,
    901     delimiter,
   (...)
    908     dtype_backend=dtype_backend,
    909 )
    910 kwds.update(kwds_defaults)
--> 912 return _read(filepath_or_buffer, kwds)

File /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:577, in _read(filepath_or_buffer, kwds)
    574 _validate_names(kwds.get("names", None))
    576 # Create the parser.
--> 577 parser = TextFileReader(filepath_or_buffer, **kwds)
    579 if chunksize or iterator:
    580     return parser

File /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:1407, in TextFileReader.__init__(self, f, engine, **kwds)
   1404     self.options["has_index_names"] = kwds["has_index_names"]
   1406 self.handles: IOHandles | None = None
-> 1407 self._engine = self._make_engine(f, self.engine)

File /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pandas/io/parsers/readers.py:1661, in TextFileReader._make_engine(self, f, engine)
   1659     if "b" not in mode:
   1660         mode += "b"
-> 1661 self.handles = get_handle(
   1662     f,
   1663     mode,
   1664     encoding=self.options.get("encoding", None),
   1665     compression=self.options.get("compression", None),
   1666     memory_map=self.options.get("memory_map", False),
   1667     is_text=is_text,
   1668     errors=self.options.get("encoding_errors", "strict"),
   1669     storage_options=self.options.get("storage_options", None),
   1670 )
   1671 assert self.handles is not None
   1672 f = self.handles.handle

File /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/pandas/io/common.py:859, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    854 elif isinstance(handle, str):
    855     # Check whether the filename is to be opened in binary mode.
    856     # Binary mode does not support 'encoding' and 'newline'.
    857     if ioargs.encoding and "b" not in ioargs.mode:
    858         # Encoding
--> 859         handle = open(
    860             handle,
    861             ioargs.mode,
    862             encoding=ioargs.encoding,
    863             errors=errors,
    864             newline="",
    865         )
    866     else:
    867         # Binary mode
    868         handle = open(handle, ioargs.mode)

FileNotFoundError: [Errno 2] No such file or directory: 'venue-20/venue_20_electricity_downsampled.csv'

Summarised by day in kilowatt-hours.

Hide code cell source
d = pd.read_csv("venue-20/venue_20_electricity_by_day.csv")
d['timestamp'] = pd.to_datetime(d['timestamp'])
d = d.fillna(value=0)


#print(d.sample)
#d = d.fillna(value=0)

daily_trace = go.Bar(customdata=d, 
                    y=d['kwh'], 
                    x = d['timestamp'], 
                    #mode='bars', 
                    hoverinfo='all', 
                    name='sum of phases'
)

summ_g = go.FigureWidget(data=[daily_trace])
summ_g.layout.title = 'Estimated daily electricity use'
summ_g.layout.xaxis.title= 'timestamp'
summ_g.layout.yaxis.title = "kilowatt-hours"
summ_g.layout.width = 1000
summ_g.layout.height = 500

summ_fig = go.Figure(summ_g)
summ_fig.show()