Commit 8155f69d authored by Bogdan's avatar Bogdan

User_Demand Visualizations

parent 931efc95
...@@ -30,7 +30,7 @@ from db.repository import * ...@@ -30,7 +30,7 @@ from db.repository import *
repo = Repository() repo = Repository()
def deleteWHOOLEData(): def deleteSimilarityData():
repo.delete_all_similarity_data() repo.delete_all_similarity_data()
def processData(): def processData():
...@@ -45,14 +45,14 @@ def mainViz(): ...@@ -45,14 +45,14 @@ def mainViz():
# inputSimListOfDict = json.loads(r.content) # inputSimListOfDict = json.loads(r.content)
# big set # big set
print("Opening JSON") print("Opening JSON")
with open('resultSimilarityDictN86400C3388.json') as json_file: with open('resultSimilarityDictN100800C4206.json') as json_file:
inputSimListOfDict = json.load(json_file) inputSimListOfDict = json.load(json_file)
print("Opened JSON") print("Opened JSON")
demandLayerListOfDict = [] demandLayerListOfDict = []
for simDict in inputSimListOfDict: for simDict in inputSimListOfDict:
if simDict['cluster_layer']=='Demand_Layer': if simDict['cluster_layer']=='User_Demand_Layer':
demandLayerListOfDict.append(simDict) demandLayerListOfDict.append(simDict)
# { # {
...@@ -75,38 +75,61 @@ def mainViz(): ...@@ -75,38 +75,61 @@ def mainViz():
distributionHeating = dict() distributionHeating = dict()
distributionPrice = dict() distributionPrice = dict()
distributionPosition = dict() distributionPosition = dict()
distributionTotal_Demand = dict()
for entry in demandLayerListOfDict: for entry in demandLayerListOfDict:
similVal = entry['similarityValues'] similVal = entry['similarityValues']
if checkKey(distributionSolar,similVal['Solar_Production_Layer']): try:
distributionSolar[similVal['Solar_Production_Layer']] +=1 if checkKey(distributionSolar,similVal['Solar_Production_Layer']):
else: distributionSolar[similVal['Solar_Production_Layer']] +=1
if(similVal['Solar_Production_Layer']< 45000): else:
distributionSolar[similVal['Solar_Production_Layer']] = 1 if(similVal['Solar_Production_Layer']< 45000):
distributionSolar[similVal['Solar_Production_Layer']] = 1
if checkKey(distributionEnergy,similVal['Energy_Consumption_Layer']): except:
distributionEnergy[similVal['Energy_Consumption_Layer']] +=1 pass
else: try:
if(similVal['Energy_Consumption_Layer']< 45000): if checkKey(distributionEnergy,similVal['Energy_Consumption_Layer']):
distributionEnergy[similVal['Energy_Consumption_Layer']] = 1 distributionEnergy[similVal['Energy_Consumption_Layer']] +=1
else:
if checkKey(distributionHeating,similVal['Heating_Consumption_Layer']): if(similVal['Energy_Consumption_Layer']< 45000):
distributionHeating[similVal['Heating_Consumption_Layer']] +=1 distributionEnergy[similVal['Energy_Consumption_Layer']] = 1
else: except:
if(similVal['Heating_Consumption_Layer']< 45000): pass
distributionHeating[similVal['Heating_Consumption_Layer']] = 1 try:
if checkKey(distributionHeating,similVal['Heating_Consumption_Layer']):
if checkKey(distributionPrice,similVal['Price_Layer']): distributionHeating[similVal['Heating_Consumption_Layer']] +=1
distributionPrice[similVal['Price_Layer']] +=1 else:
else: if(similVal['Heating_Consumption_Layer']< 45000):
if(similVal['Price_Layer']< 45000): distributionHeating[similVal['Heating_Consumption_Layer']] = 1
distributionPrice[similVal['Price_Layer']] = 1 except:
pass
if checkKey(distributionPosition,similVal['Position_Layer']):
distributionPosition[similVal['Position_Layer']] +=1 try:
else: if checkKey(distributionPrice,similVal['Price_Layer']):
if(similVal['Position_Layer']< 45000): distributionPrice[similVal['Price_Layer']] +=1
distributionPosition[similVal['Position_Layer']] = 1 else:
if(similVal['Price_Layer']< 45000):
distributionPrice[similVal['Price_Layer']] = 1
except:
pass
try:
if checkKey(distributionPosition,similVal['Location_Layer']):
distributionPosition[similVal['Location_Layer']] +=1
else:
if(similVal['Location_Layer']< 45000):
distributionPosition[similVal['Location_Layer']] = 1
except:
pass
try:
if checkKey(distributionTotal_Demand,similVal['Demand_Layer']):
distributionTotal_Demand[similVal['Demand_Layer']] +=1
else:
if(similVal['Demand_Layer']< 45000):
distributionTotal_Demand[similVal['Demand_Layer']] = 1
except:
pass
print("\nFinishedListDistrib\n") print("\nFinishedListDistrib\n")
...@@ -120,37 +143,49 @@ def mainViz(): ...@@ -120,37 +143,49 @@ def mainViz():
#fig.suptitle('') #fig.suptitle('')
#fig.text(0.5, 0.04, 'Euclidean Distance', ha='center', va='center') #fig.text(0.5, 0.04, 'Euclidean Distance', ha='center', va='center')
list1 = sorted(distributionSolar.items()) # list1 = sorted(distributionSolar.items())
x2,y2 = zip(*list1) # x2,y2 = zip(*list1)
plt.bar(x2,y2,color='purple',label="Solar", width=0.2) # plt.bar(x2,y2,color='purple',label="Solar Production", width=0.2)
plt.legend() # plt.legend()
plt.set_title('Solar') # plt.title('Solar Production')
#plt.yscale('log')
# list1 = sorted(distributionEnergy.items()) # list1 = sorted(distributionEnergy.items())
# x,y = zip(*list1) # x,y = zip(*list1)
# plt.bar(x, y, color='blue',label="Energy", width=0.2) # plt.bar(x, y, color='blue',label="Energy Consumption", width=0.2)
# plt.legend() # plt.legend()
# plt.set_title('Energy') # plt.title('Energy Consumption')
# plt.yscale('log')
# list1 = sorted(distributionHeating.items()) # list1 = sorted(distributionHeating.items())
# x3,y3 = zip(*list1) # x3,y3 = zip(*list1)
# plt.bar(x3,y3,color='red',label="Heating", width=0.2) # plt.bar(x3,y3,color='red',label="Heating Consumption", width=0.3)
# plt.legend() # plt.legend()
# plt.set_title('Heating') # plt.title('Heating Consumption')
# plt.yscale('log')
# list1 = sorted(distributionPrice.items()) # list1 = sorted(distributionPrice.items())
# x4,y4 = zip(*list1) # x4,y4 = zip(*list1)
# plt.bar(x4,y4,color='green',label="Price", width=0.2) # plt.bar(x4,y4,color='green',label="Price", width=0.2)
# plt.legend() # plt.legend()
# plt.set_title('Price') # plt.title('Price')
# plt.yscale('log')
# list1 = sorted(distributionPosition.items()) # list1 = sorted(distributionPosition.items())
# x5,y5 = zip(*list1) # x5,y5 = zip(*list1)
# plt.bar(x5,y5,color='grey',label="Location", width=0.2) # plt.bar(x5,y5,color='grey',label="Location", width=0.2)
# plt.legend() # plt.legend()
# plt.set_title('Position') # plt.title('Location')
# plt.yscale('log')
list1 = sorted(distributionTotal_Demand.items())
x6,y6 = zip(*list1)
plt.bar(x6,y6,color='black',label="Total Demand", width=0.2)
plt.legend()
plt.title('Total Demand')
plt.yscale('log')
...@@ -179,8 +214,10 @@ def checkKey(dict, key): ...@@ -179,8 +214,10 @@ def checkKey(dict, key):
#print("Not present") #print("Not present")
return False return False
#deleteWHOOLEData()
#processData()
#deleteSimilarityData()
#processData()
mainViz() mainViz()
import json
import numpy as np
import matplotlib.pyplot as plt
def mainViz():
print("Opening JSON")
with open('EnergyDataSubset.json') as json_file:
inputDict = json.load(json_file)
distributionSolar= dict()
distributionEnergy = dict()
distributionHeating = dict()
distributionPrice = dict()
distributionDemand = dict()
for entry in inputDict:
try:
sVal=round(float(entry['Solar_Production_kWh']),2)
if(checkKey(distributionSolar,sVal)):
distributionSolar[sVal] += 1
else:
distributionSolar[sVal] = 1
except Exception as E:
print(E)
try:
eVal=round(float(entry['Energy_Consumption_kWh']),2)
if(checkKey(distributionEnergy,eVal)):
distributionEnergy[eVal] += 1
else:
distributionEnergy[eVal] = 1
except:
pass
try:
hVal=round(float(entry['Heating_Consumption_kWh']),2)
if(hVal > 0):
if(checkKey(distributionHeating,hVal)):
distributionHeating[hVal] += 1
else:
distributionHeating[hVal] = 1
except:
pass
try:
pVal=round(float(entry['Price_AUD_MWh']),2)
if(checkKey(distributionPrice,pVal)):
distributionPrice[pVal] += 1
else:
distributionPrice[pVal] = 1
except:
pass
try:
tdVal=round(float(entry['Total_Demand_MWh']),2)
if(checkKey(distributionDemand,tdVal)):
distributionDemand[tdVal] += 1
else:
distributionDemand[tdVal] = 1
except:
pass
plt.ylabel('Nr. of Entries')
# ### SOLAR
# list1 = sorted(distributionSolar.items())
# x2,y2 = zip(*list1)
# plt.bar(x2,y2,color='purple',label="Solar", width=0.005)
# plt.legend()
# plt.title('Solar Production')
# plt.xlabel('kWh')
# plt.show()
# plt.xlabel('Unit of measurement')
# plt.ylabel('Nr. of Entries')
# plt.xticks(np.linspace(0,4.5,num=20))
# ### ENERGY
# list1 = sorted(distributionEnergy.items())
# x2,y2 = zip(*list1)
# plt.bar(x2,y2,color='blue',label="Energy", width=0.005)
# plt.legend()
# plt.title('Energy Consumption')
# plt.xlabel('kWh')
# plt.show()
#plt.xticks(np.linspace(0,4.5,num=20))
## Heating
list1 = sorted(distributionHeating.items())
x2,y2 = zip(*list1)
plt.bar(x2,y2,color='red',label="Heating", width=0.01)
plt.legend()
plt.title('Heating Consumption')
plt.xlabel('kWh')
plt.show()
## Price
# #plt.xticks(np.linspace(0,100,num=10))
# list1 = sorted(distributionPrice.items())
# x2,y2 = zip(*list1)
# plt.bar(x2,y2,color='green',label="Price", width=0.5)
# plt.legend()
# plt.title('Price')
# plt.xlabel('MWh')
# plt.show()
### Demand
#plt.xticks(np.linspace(0,100,num=10))
# list1 = sorted(distributionDemand.items())
# x2,y2 = zip(*list1)
# plt.bar(x2,y2,color='gray',label="Demand", width=5)
# plt.legend()
# plt.title('Total Demand')
# plt.xlabel('MWh')
# plt.show()
print("FIN")
def checkKey(dict, key):
if key in dict.keys():
#print("Present, ", end =" ")
#print(str(key)+ " : " + str(dict[key] ))
return True
else:
#print("Not present")
return False
mainViz()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment