In [30]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select substr(op_date, 1, 2) as month, name, orispl_code, unitid, avg(heat_input) as avg_heat, \
avg(gload) as avg_gen, op_hour, state from data where fuel_actual is 'NG' and state is not 'CA'  group by op_hour, substr(op_date, 1, 2), \
orispl_code, unitid \
order by orispl_code, unitid, substr(op_date, 1, 2), op_hour", con)
table.to_csv('not_ca_ng_avg.csv')

In [37]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select substr(op_date, 1, 2) as month, name, orispl_code, unitid, avg(heat_input) as avg_heat, \
avg(gload) as avg_gen, op_hour, state from data where fuel_actual is not 'NG' group by op_hour, substr(op_date, 1, 2), \
orispl_code, unitid \
order by orispl_code, unitid, substr(op_date, 1, 2), op_hour", con)
table.to_csv('not_ng_avg.csv')

In [38]:
import csv
with open('not_ng_avg.csv', 'rb') as csvfile:
    reader = csv.DictReader(csvfile)
    unit_months = {}
    for row in reader:
        identifier = row['state'] + "; " + row['name'] + "; Unit " + row['unitid'] + "; Month " + row['month']
        if identifier not in unit_months.keys():
            unit_months[identifier] = []
        unit_months[identifier].append((int(row['op_hour']), float(row['avg_gen']), float(row['avg_heat'])))

In [43]:
for key in unit_months:
    for entry in unit_months[key]:
        hour = entry[0]
        if (hour < 10) or (hour > 15): continue
        if (entry[1] > 0 and 1.2 * entry[1] < unit_months[key][(hour + 6) % 24][1]) and (1.2 * entry[1] < unit_months[key][(hour + 18) % 24][1]):
            print key + " at hour " + str(hour)
            print entry[1]
            print unit_months[key][(hour + 6) % 24][1]
            print unit_months[key][(hour + 18) % 24][1]


AZ; Navajo Generating Station; Unit 1; Month 12 at hour 13
577.580645161
776.903225806
717.258064516
AZ; Navajo Generating Station; Unit 1; Month 12 at hour 14
569.967741935
765.258064516
715.451612903
AZ; Irvington Generating Station; Unit 4; Month 02 at hour 10
41.5517241379
64.5172413793
52.1034482759
AZ; Irvington Generating Station; Unit 4; Month 02 at hour 11
41.0344827586
76.8620689655
57.8620689655
AZ; Irvington Generating Station; Unit 4; Month 02 at hour 12
46.8275862069
82.3793103448
60.1379310345
AZ; Irvington Generating Station; Unit 4; Month 02 at hour 13
52.0344827586
78.9655172414
67.2413793103
AZ; Irvington Generating Station; Unit 4; Month 03 at hour 10
70.9677419355
86.9677419355
89.8064516129
AZ; Irvington Generating Station; Unit 4; Month 03 at hour 11
72.6129032258
92.7419354839
94.9032258065
AZ; Irvington Generating Station; Unit 4; Month 03 at hour 12
75.3870967742
113.451612903
102.64516129
AZ; Navajo Generating Station; Unit 2; Month 01 at hour 13
424.548387097
655.967741935
559.612903226
AZ; Navajo Generating Station; Unit 2; Month 01 at hour 14
426.548387097
639.967741935
565.322580645
AZ; Navajo Generating Station; Unit 2; Month 01 at hour 15
428.0
594.290322581
540.387096774
WY; Jim Bridger; Unit BW71; Month 01 at hour 14
387.129032258
474.387096774
474.032258065
WY; Jim Bridger; Unit BW71; Month 01 at hour 15
390.129032258
474.806451613
473.677419355
WA; Centralia; Unit BW21; Month 11 at hour 12
309.833333333
447.133333333
404.133333333
WA; Centralia; Unit BW21; Month 11 at hour 13
303.333333333
407.9
424.266666667
WA; Centralia; Unit BW21; Month 11 at hour 14
300.166666667
366.166666667
388.0
UT; Hunter; Unit 3; Month 11 at hour 13
330.633333333
428.6
402.533333333
UT; Hunter; Unit 2; Month 03 at hour 13
287.870967742
374.548387097
368.387096774
UT; Hunter; Unit 2; Month 03 at hour 14
276.935483871
391.774193548
357.870967742
UT; Hunter; Unit 2; Month 03 at hour 15
272.193548387
397.903225806
340.35483871
NV; North Valmy; Unit 1; Month 01 at hour 13
115.516129032
165.064516129
142.580645161
UT; Intermountain; Unit 2SGA; Month 12 at hour 12
497.322580645
857.548387097
599.967741935
UT; Intermountain; Unit 2SGA; Month 12 at hour 13
486.290322581
849.806451613
706.0
UT; Intermountain; Unit 2SGA; Month 12 at hour 14
485.032258065
843.516129032
722.129032258
UT; Intermountain; Unit 2SGA; Month 12 at hour 15
513.032258065
834.096774194
636.548387097
CO; Craig; Unit C2; Month 01 at hour 13
275.741935484
337.612903226
335.193548387
AZ; Coronado Generating Station; Unit U2B; Month 01 at hour 13
337.548387097
424.580645161
411.387096774
AZ; Coronado Generating Station; Unit U2B; Month 01 at hour 14
329.516129032
421.806451613
408.032258065
UT; Huntington; Unit 2; Month 03 at hour 13
254.193548387
330.612903226
327.967741935
UT; Huntington; Unit 2; Month 03 at hour 14
243.612903226
359.870967742
324.483870968
UT; Huntington; Unit 2; Month 03 at hour 15
240.483870968
376.193548387
319.580645161
UT; Huntington; Unit 2; Month 04 at hour 13
255.2
314.166666667
313.1
UT; Huntington; Unit 1; Month 11 at hour 11
311.233333333
419.666666667
383.433333333
UT; Huntington; Unit 1; Month 11 at hour 12
308.666666667
422.366666667
403.766666667
UT; Huntington; Unit 1; Month 11 at hour 13
310.5
419.433333333
419.466666667
UT; Huntington; Unit 1; Month 11 at hour 14
322.933333333
421.433333333
395.166666667
UT; Intermountain; Unit 1SGA; Month 12 at hour 12
484.516129032
857.387096774
608.0
UT; Intermountain; Unit 1SGA; Month 12 at hour 13
483.225806452
853.419354839
716.0
UT; Intermountain; Unit 1SGA; Month 12 at hour 14
490.580645161
848.35483871
732.935483871
UT; Intermountain; Unit 1SGA; Month 12 at hour 15
515.774193548
843.032258065
646.483870968
AZ; Irvington Generating Station; Unit 4; Month 11 at hour 11
11.4666666667
14.3333333333
14.2333333333
UT; Huntington; Unit 2; Month 12 at hour 12
344.903225806
423.516129032
426.387096774
UT; Huntington; Unit 2; Month 12 at hour 13
325.580645161
428.419354839
429.677419355
UT; Huntington; Unit 2; Month 12 at hour 14
313.387096774
431.387096774
422.870967742
UT; Huntington; Unit 2; Month 12 at hour 15
316.516129032
432.387096774
398.838709677
UT; Huntington; Unit 2; Month 11 at hour 11
293.233333333
410.2
373.066666667
UT; Huntington; Unit 2; Month 11 at hour 12
290.8
426.533333333
407.666666667
UT; Huntington; Unit 2; Month 11 at hour 13
292.433333333
419.133333333
427.4
UT; Huntington; Unit 2; Month 11 at hour 14
304.266666667
418.266666667
398.066666667
AZ; Apache Station; Unit 2; Month 12 at hour 11
94.8064516129
155.483870968
118.419354839
AZ; Apache Station; Unit 2; Month 12 at hour 12
91.0
164.322580645
137.580645161
AZ; Apache Station; Unit 2; Month 12 at hour 13
87.2258064516
165.064516129
150.806451613
AZ; Apache Station; Unit 2; Month 12 at hour 14
86.4516129032
164.387096774
146.967741935
AZ; Apache Station; Unit 2; Month 12 at hour 15
89.3548387097
156.161290323
110.967741935
AZ; Apache Station; Unit 2; Month 11 at hour 12
90.3666666667
171.8
126.2
AZ; Apache Station; Unit 2; Month 11 at hour 13
91.4666666667
170.9
132.2
AZ; Apache Station; Unit 2; Month 11 at hour 14
93.1666666667
160.466666667
121.933333333
MT; Hardin Generating Station; Unit U1; Month 11 at hour 10
1.56666666667
2.03333333333
2.23333333333
MT; Hardin Generating Station; Unit U1; Month 11 at hour 11
1.46666666667
2.03333333333
2.23333333333
AZ; Cholla; Unit 1; Month 01 at hour 15
20.064516129
26.4516129032
25.4838709677
AZ; Cholla; Unit 1; Month 02 at hour 12
50.8275862069
64.3448275862
67.1379310345
AZ; Cholla; Unit 1; Month 02 at hour 13
49.4827586207
65.6896551724
67.4137931034
AZ; Cholla; Unit 1; Month 02 at hour 14
46.5862068966
66.0344827586
65.5517241379
MT; Colstrip; Unit 2; Month 03 at hour 14
172.322580645
218.709677419
223.064516129
MT; Colstrip; Unit 2; Month 03 at hour 15
172.451612903
212.35483871
212.419354839
AZ; Coronado Generating Station; Unit U2B; Month 12 at hour 13
320.806451613
417.903225806
392.35483871
AZ; Coronado Generating Station; Unit U2B; Month 12 at hour 14
312.64516129
414.35483871
393.096774194
WY; Jim Bridger; Unit BW72; Month 01 at hour 14
386.129032258
470.387096774
471.677419355
WY; Jim Bridger; Unit BW72; Month 01 at hour 15
388.129032258
471.064516129
466.451612903
WY; Jim Bridger; Unit BW73; Month 02 at hour 14
347.965517241
422.206896552
418.620689655
MT; Colstrip; Unit 3; Month 03 at hour 13
505.064516129
609.838709677
625.580645161
MT; Colstrip; Unit 3; Month 03 at hour 14
493.580645161
620.258064516
627.290322581
MT; Colstrip; Unit 3; Month 03 at hour 15
477.35483871
608.35483871
611.709677419
AZ; Cholla; Unit 3; Month 03 at hour 11
162.741935484
199.741935484
196.580645161
AZ; Cholla; Unit 3; Month 03 at hour 12
162.677419355
207.387096774
203.064516129
AZ; Navajo Generating Station; Unit 3; Month 02 at hour 13
380.448275862
589.896551724
482.655172414
AZ; Navajo Generating Station; Unit 3; Month 02 at hour 14
375.655172414
571.172413793
474.862068966
AZ; Navajo Generating Station; Unit 3; Month 01 at hour 13
368.516129032
566.774193548
465.806451613
AZ; Navajo Generating Station; Unit 3; Month 01 at hour 14
372.774193548
566.032258065
479.838709677
AZ; Navajo Generating Station; Unit 3; Month 01 at hour 15
383.903225806
540.967741935
463.193548387
WA; Centralia; Unit BW22; Month 11 at hour 12
305.166666667
452.833333333
406.266666667
WA; Centralia; Unit BW22; Month 11 at hour 13
298.9
411.333333333
433.633333333
WA; Centralia; Unit BW22; Month 11 at hour 14
300.466666667
368.066666667
398.4
AZ; Apache Station; Unit 3; Month 12 at hour 11
123.677419355
183.870967742
161.322580645
AZ; Apache Station; Unit 3; Month 12 at hour 12
116.451612903
188.580645161
174.516129032
AZ; Apache Station; Unit 3; Month 12 at hour 13
116.451612903
189.032258065
182.806451613
AZ; Apache Station; Unit 3; Month 12 at hour 14
117.032258065
188.032258065
181.258064516
AZ; Apache Station; Unit 3; Month 12 at hour 15
122.903225806
187.677419355
161.64516129
AZ; Apache Station; Unit 3; Month 11 at hour 12
48.3666666667
82.8333333333
58.6
AZ; Apache Station; Unit 3; Month 11 at hour 13
51.1333333333
81.2
61.6666666667
UT; Huntington; Unit 2; Month 02 at hour 13
300.103448276
362.827586207
361.413793103
UT; Huntington; Unit 2; Month 02 at hour 14
298.344827586
381.413793103
366.75862069
UT; Huntington; Unit 2; Month 02 at hour 15
299.137931034
396.620689655
359.24137931
AZ; Navajo Generating Station; Unit 1; Month 01 at hour 13
434.903225806
672.451612903
556.580645161
AZ; Navajo Generating Station; Unit 1; Month 01 at hour 14
427.322580645
664.612903226
556.935483871
AZ; Navajo Generating Station; Unit 1; Month 01 at hour 15
427.516129032
636.741935484
533.451612903
AZ; Navajo Generating Station; Unit 1; Month 02 at hour 12
407.034482759
589.620689655
526.482758621
AZ; Navajo Generating Station; Unit 1; Month 02 at hour 13
408.517241379
610.586206897
555.482758621
AZ; Navajo Generating Station; Unit 1; Month 02 at hour 14
410.413793103
609.275862069
526.034482759
AZ; Coronado Generating Station; Unit U1B; Month 01 at hour 14
328.677419355
405.580645161
419.225806452
AZ; Coronado Generating Station; Unit U1B; Month 01 at hour 15
325.967741935
399.612903226
410.064516129
AZ; Springerville Generating Station; Unit 4; Month 12 at hour 13
296.612903226
389.903225806
361.903225806
AZ; Springerville Generating Station; Unit 4; Month 12 at hour 14
290.677419355
382.516129032
367.032258065
AZ; Cholla; Unit 1; Month 12 at hour 11
3.54838709677
4.8064516129
7.70967741935
AZ; Cholla; Unit 1; Month 12 at hour 12
3.48387096774
5.16129032258
8.64516129032
AZ; Cholla; Unit 1; Month 12 at hour 13
1.41935483871
5.12903225806
9.51612903226
AZ; Cholla; Unit 1; Month 12 at hour 14
1.29032258065
5.16129032258
8.83870967742
AZ; Cholla; Unit 1; Month 12 at hour 15
2.06451612903
5.22580645161
5.70967741935
WY; Jim Bridger; Unit BW72; Month 11 at hour 14
335.2
413.933333333
403.6
AZ; Springerville Generating Station; Unit 4; Month 01 at hour 13
296.774193548
382.516129032
400.935483871
AZ; Springerville Generating Station; Unit 4; Month 01 at hour 14
294.935483871
374.290322581
380.064516129
AZ; Navajo Generating Station; Unit 2; Month 11 at hour 13
491.9
693.2
609.466666667
AZ; Navajo Generating Station; Unit 2; Month 12 at hour 12
598.096774194
799.451612903
719.967741935
AZ; Navajo Generating Station; Unit 2; Month 12 at hour 13
584.451612903
801.935483871
741.548387097
AZ; Navajo Generating Station; Unit 2; Month 12 at hour 14
584.580645161
801.451612903
738.032258065
AZ; Cholla; Unit 3; Month 12 at hour 11
41.2580645161
52.7096774194
54.7096774194
AZ; Cholla; Unit 3; Month 12 at hour 12
40.8709677419
57.1935483871
54.5806451613
AZ; Cholla; Unit 3; Month 12 at hour 13
40.4516129032
59.2580645161
54.5483870968
AZ; Cholla; Unit 3; Month 12 at hour 14
35.4838709677
61.2903225806
53.9677419355
AZ; Cholla; Unit 3; Month 12 at hour 15
35.8387096774
62.1290322581
50.0322580645
WY; Jim Bridger; Unit BW71; Month 11 at hour 14
338.3
408.866666667
407.066666667
AZ; Navajo Generating Station; Unit 3; Month 12 at hour 13
524.225806452
737.064516129
666.516129032
AZ; Navajo Generating Station; Unit 3; Month 12 at hour 14
515.838709677
742.516129032
663.548387097
AZ; Navajo Generating Station; Unit 3; Month 12 at hour 15
529.483870968
738.903225806
639.129032258
UT; Hunter; Unit 1; Month 03 at hour 13
288.516129032
384.580645161
369.548387097
UT; Hunter; Unit 1; Month 03 at hour 14
277.096774194
399.322580645
353.774193548
UT; Hunter; Unit 1; Month 03 at hour 15
273.548387097
402.096774194
339.741935484
MT; Colstrip; Unit 4; Month 03 at hour 14
510.0
626.741935484
649.806451613
MT; Colstrip; Unit 4; Month 03 at hour 15
491.129032258
620.483870968
630.548387097
UT; Huntington; Unit 1; Month 12 at hour 13
347.580645161
443.387096774
438.322580645
UT; Huntington; Unit 1; Month 12 at hour 14
335.709677419
444.741935484
431.967741935
UT; Huntington; Unit 1; Month 12 at hour 15
341.129032258
444.129032258
409.806451613
AZ; Apache Station; Unit 2; Month 01 at hour 12
88.9032258065
158.677419355
135.032258065
AZ; Apache Station; Unit 2; Month 01 at hour 13
85.8709677419
158.225806452
148.870967742
AZ; Apache Station; Unit 2; Month 01 at hour 14
84.6129032258
151.387096774
143.225806452
AZ; Apache Station; Unit 2; Month 01 at hour 15
87.6129032258
143.967741935
132.516129032
AZ; Apache Station; Unit 2; Month 02 at hour 12
56.6551724138
110.965517241
75.4137931034
AZ; Apache Station; Unit 2; Month 02 at hour 13
57.1379310345
116.034482759
82.4482758621
AZ; Apache Station; Unit 2; Month 02 at hour 14
58.3448275862
110.413793103
80.1379310345
AZ; Apache Station; Unit 3; Month 01 at hour 12
93.5483870968
155.193548387
127.580645161
AZ; Apache Station; Unit 3; Month 01 at hour 13
88.8387096774
157.935483871
138.419354839
AZ; Apache Station; Unit 3; Month 01 at hour 14
86.0967741935
154.677419355
136.096774194
AZ; Apache Station; Unit 3; Month 01 at hour 15
88.6129032258
150.870967742
127.709677419
UT; Huntington; Unit 1; Month 02 at hour 13
284.275862069
362.620689655
344.344827586
UT; Huntington; Unit 1; Month 02 at hour 14
282.724137931
369.517241379
342.379310345
UT; Intermountain; Unit 1SGA; Month 04 at hour 14
75.3333333333
95.3
96.5
AZ; Apache Station; Unit 3; Month 02 at hour 12
95.1724137931
157.103448276
134.965517241
AZ; Apache Station; Unit 3; Month 02 at hour 13
95.5172413793
160.0
152.551724138
AZ; Apache Station; Unit 3; Month 02 at hour 14
95.1379310345
153.689655172
144.586206897
AZ; Apache Station; Unit 3; Month 02 at hour 15
98.3793103448
142.24137931
119.206896552

In [39]:
for key in unit_months:
    for entry in unit_months[key]:
        hour = entry[0]
        if (hour < 10) or (hour > 16): continue
        if (entry[1] > 0 and 1.5 * entry[1] < unit_months[key][(hour + 6) % 24][1]) and (1.5 * entry[1] < unit_months[key][(hour + 18) % 24][1]):
            print key + " at hour " + str(hour)
            print entry[1]
            print unit_months[key][(hour + 6) % 24][1]
            print unit_months[key][(hour + 18) % 24][1]


AZ; Apache Station; Unit 2; Month 12 at hour 12
91.0
164.322580645
137.580645161
AZ; Apache Station; Unit 2; Month 12 at hour 13
87.2258064516
165.064516129
150.806451613
AZ; Apache Station; Unit 2; Month 12 at hour 14
86.4516129032
164.387096774
146.967741935
AZ; Apache Station; Unit 3; Month 12 at hour 13
116.451612903
189.032258065
182.806451613
AZ; Apache Station; Unit 3; Month 12 at hour 14
117.032258065
188.032258065
181.258064516
AZ; Cholla; Unit 1; Month 12 at hour 13
1.41935483871
5.12903225806
9.51612903226
AZ; Cholla; Unit 1; Month 12 at hour 14
1.29032258065
5.16129032258
8.83870967742
AZ; Cholla; Unit 1; Month 12 at hour 15
2.06451612903
5.22580645161
5.70967741935
AZ; Cholla; Unit 3; Month 12 at hour 14
35.4838709677
61.2903225806
53.9677419355
AZ; Apache Station; Unit 2; Month 01 at hour 12
88.9032258065
158.677419355
135.032258065
AZ; Apache Station; Unit 2; Month 01 at hour 13
85.8709677419
158.225806452
148.870967742
AZ; Apache Station; Unit 2; Month 01 at hour 14
84.6129032258
151.387096774
143.225806452
AZ; Apache Station; Unit 2; Month 01 at hour 15
87.6129032258
143.967741935
132.516129032
AZ; Apache Station; Unit 3; Month 01 at hour 13
88.8387096774
157.935483871
138.419354839
AZ; Apache Station; Unit 3; Month 01 at hour 14
86.0967741935
154.677419355
136.096774194
AZ; Apache Station; Unit 3; Month 02 at hour 13
95.5172413793
160.0
152.551724138
AZ; Apache Station; Unit 3; Month 02 at hour 14
95.1379310345
153.689655172
144.586206897

In [49]:
import sqlite3
import pandas
con = sqlite3.connect('2016.db')
table = pandas.read_sql("select avg(heat_input), avg(gload), unitid, op_hour from data where substr(op_date, 1, 2) is '12' and name is 'Intermountain' group by unitid, op_hour order by unitid", con)
table.to_csv('intermountain_duck.csv')

In [50]:


In [ ]: