/
overallEnergyAverage.py
executable file
·88 lines (56 loc) · 2.13 KB
/
overallEnergyAverage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Author = Joseph Cameron
# overallEnergyAverage.py
# Gives average daily energy demand curves for all aggregated users
# USAGE
# Boxplot = python overallEnergyAverage.py -b
# Line Graph = python overallEnergyAverage.py -n
# --------------------------------------------------
# PARSE ARGUMENTS
import argparse
parser = argparse.ArgumentParser(description='Display an aggragated average over a day for each hour, minute or second.')
group = parser.add_mutually_exclusive_group()
group.add_argument('-b', '--boxplot', action='store_true', help='Display a Boxplot.')
group.add_argument('-n', '--noboxplot', action='store_true', help='Do not display a Boxplot.')
args = parser.parse_args()
# --------------------------------------------------
# IMPORT STATEMENTS
import pandas as pd
from datetime import datetime
import csv
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pickle
import sys
import glob
# --------------------------------------------------
# READ DATA
headers = ['Time', 'Sensor Value']
# Files within this directory
files = sorted(glob.glob('DailyAveEnergyCSV/*.csv'))
ideal_data = pd.DataFrame()
framelist = []
for f in files:
df = pd.read_csv(f, names = headers, skiprows = 1)
framelist.append(df)
ideal_data = pd.concat(framelist, ignore_index = True)
# --------------------------------------------------
# CREATE BOXPLOT
if args.boxplot:
dailyData = ideal_data.boxplot(column='Sensor Value', by=['Time'], showmeans=True)
# CREATE MEAN LINE GRAPH
else:
dailyData = ideal_data.groupby("Time").mean().plot()
#-----------------------------------------------------
# SAVE/SHOW RESULTS
# Variable used to create pickles
#pickleVar = ideal_data
# Properly format the y-axis label
plt.ylabel("Watt Hours")
# Title
plt.title("Aggregated Average Hourly Energy Demand")
# Toggle comment if figure should be shown first
plt.show()
# Saving Pickle for future interactivity in the 'Pickles' directory
#pickle.dump(pickleVar, file('Pickles/' + sys.argv[3] + '_Figure.pickle','w'))
# Save Figure in the 'Figures' directory
#plt.savefig('EnergyFigures/' + sys.argv[3][-14:] + '_DailyAverage_Figure.png', dpi=1000)