# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# %reset
# from __future__ import division

import numpy as np
from sklearn import preprocessing
import math
from matplotlib import pyplot as plt
from matplotlib import patches as patches
import pandas as pd
from numpy import *

# %matplotlib inline

# +

file_name = '../Emilio Caba/Final_data_cleaned_missing_houses.csv'
#file_name = '../Emilio Caba/Combined_data.csv'
df = pd.read_csv(file_name)

df = df.rename(columns={'ID-nummer' : 'Index'})
df = df.set_index('Index')
df.index = pd.to_datetime(df.index)

#this cell is used to combine the 2 parts of the full dataframe (production and consumption)
production = df.iloc[0:,0:28]
consumption = df.iloc[0:,28:57]

col_names = ['H0' + str(col) if col < 10 else 'H' + str(col) for col in range(1,29)]

#production.columns = col_names
#consumption.columns = col_names



# +
df_prod = production.sum(axis=1)
df_cons = consumption.sum(axis=1)

df_prod = df_prod.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )
df_cons = df_cons.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )
# -

df_cons

# +
x = df_prod.index

plt.plot(x, df_cons, alpha=0.5)
plt.plot(x, df_prod, alpha=0.5)
plt.title('title')
plt.ylabel('Kwh')
plt.xlabel('xlabel')
plt.show()

# +
plt.plot(x, df_cons, 'r') # plotting t, a separately 
plt.plot(x, df_prod, 'b', alpha=0.8) # plotting t, b separately


plt.show()




# +

# Prepare Data
#x = df_prod.index
x = df.index
y1 = df_cons
y2 = df_prod
mycolors = ['tab:green', 'tab:red']      
columns = ['Delivery Electricity Current', 'Use Electricity Current']

# Draw Plot 
fig, ax = plt.subplots(1, 1, figsize=(16,9), dpi= 80)
ax.fill_between(x, y1=y1, y2=0, label=columns[1], alpha=0.7, color=mycolors[1], linewidth=2)
ax.fill_between(x, y1=y2, y2=0, label=columns[0], alpha=0.5, color=mycolors[0], linewidth=2)



# Decorations
ax.set_title('Total consumption vs production', fontsize=18)

ax.legend(loc='best', fontsize=12)

# Lighten borders
plt.gca().spines["top"].set_alpha(0)
plt.gca().spines["bottom"].set_alpha(.3)
plt.gca().spines["right"].set_alpha(0)
plt.gca().spines["left"].set_alpha(.3)


plt.ylabel('Amperes')
plt.xlabel('time')
plt.show()

# +

# Prepare Data


production = production.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )
consumption = consumption.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )



x = df.index
y1 = consumption['H07_cons']
y2 = production['H07_prod']
mycolors = ['tab:green', 'tab:red']      
columns = ['Delivery Electricity Current', 'Use Electricity Current']

# Draw Plot 
fig, ax = plt.subplots(1, 1, figsize=(16,9), dpi= 80)
ax.fill_between(x, y1=y1, y2=0, label=columns[1], alpha=0.7, color=mycolors[1], linewidth=2)
ax.fill_between(x, y1=y2, y2=0, label=columns[0], alpha=0.5, color=mycolors[0], linewidth=2)



# Decorations
ax.set_title('House 7 current', fontsize=18)

ax.legend(loc='best', fontsize=12)

# Lighten borders
plt.gca().spines["top"].set_alpha(0)
plt.gca().spines["bottom"].set_alpha(.3)
plt.gca().spines["right"].set_alpha(0)
plt.gca().spines["left"].set_alpha(.3)


plt.ylabel('Amperes')
plt.xlabel('time')
plt.show()
# -

df_prod.max()



consumption['H07_cons']

# +

production = production.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )
consumption = consumption.apply(lambda kwh: (kwh / (1/4) * 1000)/230 )

# -

production









StarcoderdataJupyterScriptsDedupFiltered