openstudio-calibration 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +23 -8
  5. data/Gemfile +0 -3
  6. data/Jenkinsfile +6 -2
  7. data/README.md +2 -2
  8. data/Rakefile +5 -5
  9. data/lib/measures/TimeseriesObjectiveFunction/README.md +5 -171
  10. data/lib/measures/TimeseriesObjectiveFunction/measure.rb +2 -6
  11. data/lib/measures/TimeseriesObjectiveFunction/measure.xml +89 -13
  12. data/lib/measures/TimeseriesObjectiveFunction/resources/report.html.erb +2 -0
  13. data/lib/measures/TimeseriesPlot/README.md +5 -35
  14. data/lib/measures/TimeseriesPlot/measure.xml +27 -11
  15. data/lib/measures/TimeseriesPlot/resources/report.html.erb +2 -0
  16. data/lib/measures/zone_report/README.md +2 -2
  17. data/lib/measures/zone_report/measure.rb +1 -1
  18. data/lib/measures/zone_report/measure.xml +14 -12
  19. data/lib/{openstudio-calibration-measures.rb → openstudio-calibration.rb} +1 -1
  20. data/lib/openstudio/{calibration_measures.rb → calibration.rb} +2 -2
  21. data/lib/openstudio/{calibration_measures → calibration}/extension.rb +1 -1
  22. data/lib/openstudio/{calibration_measures → calibration}/version.rb +2 -2
  23. data/openstudio-calibration.gemspec +38 -0
  24. metadata +37 -54
  25. data/lib/measures/AddMonthlyUtilityData/tests/AddMonthlyUtilityData_Test.rb +0 -88
  26. data/lib/measures/AddMonthlyUtilityData/tests/electric_billed_usages.json +0 -198
  27. data/lib/measures/AddMonthlyUtilityData/tests/gas_billed_usages.json +0 -198
  28. data/lib/measures/CalibrationReports/tests/CalibrationReports_Test.rb +0 -523
  29. data/lib/measures/CalibrationReports/tests/ExampleModel.osm +0 -10497
  30. data/lib/measures/CalibrationReports/tests/ExampleModelNoDemandInput.osm +0 -10560
  31. data/lib/measures/CalibrationReports/tests/ExampleModelNoGasInput.osm +0 -10456
  32. data/lib/measures/CalibrationReports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +0 -8768
  33. data/lib/measures/CalibrationReportsEnhanced/tests/CalibrationReportsEnhanced_Test.rb +0 -734
  34. data/lib/measures/CalibrationReportsEnhanced/tests/ExampleModel.osm +0 -10497
  35. data/lib/measures/CalibrationReportsEnhanced/tests/ExampleModel_FuelOil.osm +0 -12740
  36. data/lib/measures/CalibrationReportsEnhanced/tests/USA_CO_Golden-NREL.724666_TMY3.epw +0 -8768
  37. data/lib/measures/CalibrationReportsEnhanced21/LICENSE.md +0 -27
  38. data/lib/measures/CalibrationReportsEnhanced21/README.md +0 -109
  39. data/lib/measures/CalibrationReportsEnhanced21/README.md.erb +0 -42
  40. data/lib/measures/CalibrationReportsEnhanced21/measure.rb +0 -690
  41. data/lib/measures/CalibrationReportsEnhanced21/measure.xml +0 -269
  42. data/lib/measures/CalibrationReportsEnhanced21/resources/report.html.in +0 -380
  43. data/lib/measures/MaalkaMonthlyJSONUtilityData/LICENSE.md +0 -27
  44. data/lib/measures/MaalkaMonthlyJSONUtilityData/README.md +0 -104
  45. data/lib/measures/MaalkaMonthlyJSONUtilityData/README.md.erb +0 -42
  46. data/lib/measures/MaalkaMonthlyJSONUtilityData/measure.rb +0 -304
  47. data/lib/measures/MaalkaMonthlyJSONUtilityData/measure.xml +0 -216
  48. data/openstudio-calibration-measures.gemspec +0 -30
@@ -1,269 +0,0 @@
1
- <measure>
2
- <schema_version>3.0</schema_version>
3
- <name>calibration_reports_enhanced_21</name>
4
- <uid>e6642d40-7366-4647-8724-53a37991d669</uid>
5
- <version_id>45858510-0de6-47ae-98b7-a90ed01654f7</version_id>
6
- <version_modified>20200325T030943Z</version_modified>
7
- <xml_checksum>2C8A3EEF</xml_checksum>
8
- <class_name>CalibrationReportsEnhanced21</class_name>
9
- <display_name>Calibration Reports Enhanced</display_name>
10
- <description>This measure is intended for calibibration of modeled results against user entered utility bill.</description>
11
- <modeler_description>Measure looks at consumption for electricity and natural gas, and demand for electricity. It is inteneded to be used with no more than one gas an electric bills. Each bill can have multiple billing periods. Make sure ot use an AMY matching the utility data time frame.</modeler_description>
12
- <arguments>
13
- <argument>
14
- <name>electric_nmbe_limit</name>
15
- <display_name>Electric NMBE limit (%)</display_name>
16
- <type>Double</type>
17
- <required>true</required>
18
- <model_dependent>false</model_dependent>
19
- <default_value>5</default_value>
20
- </argument>
21
- <argument>
22
- <name>electric_cvrmse_limit</name>
23
- <display_name>Electric CVRMSE limit (%)</display_name>
24
- <type>Double</type>
25
- <required>true</required>
26
- <model_dependent>false</model_dependent>
27
- <default_value>15</default_value>
28
- </argument>
29
- <argument>
30
- <name>gas_nmbe_limit</name>
31
- <display_name>Gas NMBE limit (%)</display_name>
32
- <type>Double</type>
33
- <required>true</required>
34
- <model_dependent>false</model_dependent>
35
- <default_value>5</default_value>
36
- </argument>
37
- <argument>
38
- <name>gas_cvrmse_limit</name>
39
- <display_name>Gas CVRMSE limit (%)</display_name>
40
- <type>Double</type>
41
- <required>true</required>
42
- <model_dependent>false</model_dependent>
43
- <default_value>15</default_value>
44
- </argument>
45
- </arguments>
46
- <outputs>
47
- <output>
48
- <name>electricity_consumption_actual</name>
49
- <display_name>electricity_consumption_actual</display_name>
50
- <short_name>electricity_consumption_actual</short_name>
51
- <type>Double</type>
52
- <model_dependent>false</model_dependent>
53
- </output>
54
- <output>
55
- <name>electricity_consumption_modeled</name>
56
- <display_name>electricity_consumption_modeled</display_name>
57
- <short_name>electricity_consumption_modeled</short_name>
58
- <type>Double</type>
59
- <model_dependent>false</model_dependent>
60
- </output>
61
- <output>
62
- <name>electricity_consumption_cvrmse</name>
63
- <display_name>electricity_consumption_cvrmse</display_name>
64
- <short_name>electricity_consumption_cvrmse</short_name>
65
- <type>Double</type>
66
- <model_dependent>false</model_dependent>
67
- </output>
68
- <output>
69
- <name>electricity_consumption_nmbe</name>
70
- <display_name>electricity_consumption_nmbe</display_name>
71
- <short_name>electricity_consumption_nmbe</short_name>
72
- <type>Double</type>
73
- <model_dependent>false</model_dependent>
74
- </output>
75
- <output>
76
- <name>electricity_sum_of_squares</name>
77
- <display_name>electricity_sum_of_squares</display_name>
78
- <short_name>electricity_sum_of_squares</short_name>
79
- <type>Double</type>
80
- <model_dependent>false</model_dependent>
81
- </output>
82
- <output>
83
- <name>electricity_dof</name>
84
- <display_name>electricity_dof</display_name>
85
- <short_name>electricity_dof</short_name>
86
- <type>Double</type>
87
- <model_dependent>false</model_dependent>
88
- </output>
89
- <output>
90
- <name>electricity_rmse</name>
91
- <display_name>electricity_rmse</display_name>
92
- <short_name>electricity_rmse</short_name>
93
- <type>Double</type>
94
- <model_dependent>false</model_dependent>
95
- </output>
96
- <output>
97
- <name>electricity_peak_demand_nmbe</name>
98
- <display_name>electricity_peak_demand_nmbe</display_name>
99
- <short_name>electricity_peak_demand_nmbe</short_name>
100
- <type>Double</type>
101
- <model_dependent>false</model_dependent>
102
- </output>
103
- <output>
104
- <name>electricity_peak_demand_actual</name>
105
- <display_name>electricity_peak_demand_actual</display_name>
106
- <short_name>electricity_peak_demand_actual</short_name>
107
- <type>Double</type>
108
- <model_dependent>false</model_dependent>
109
- </output>
110
- <output>
111
- <name>electricity_peak_demand_modeled</name>
112
- <display_name>electricity_peak_demand_modeled</display_name>
113
- <short_name>electricity_peak_demand_modeled</short_name>
114
- <type>Double</type>
115
- <model_dependent>false</model_dependent>
116
- </output>
117
- <output>
118
- <name>natural_gas_consumption_actual</name>
119
- <display_name>natural_gas_consumption_actual</display_name>
120
- <short_name>natural_gas_consumption_actual</short_name>
121
- <type>Double</type>
122
- <model_dependent>false</model_dependent>
123
- </output>
124
- <output>
125
- <name>natural_gas_consumption_modeled</name>
126
- <display_name>natural_gas_consumption_modeled</display_name>
127
- <short_name>natural_gas_consumption_modeled</short_name>
128
- <type>Double</type>
129
- <model_dependent>false</model_dependent>
130
- </output>
131
- <output>
132
- <name>natural_gas_consumption_cvrmse</name>
133
- <display_name>natural_gas_consumption_cvrmse</display_name>
134
- <short_name>natural_gas_consumption_cvrmse</short_name>
135
- <type>Double</type>
136
- <model_dependent>false</model_dependent>
137
- </output>
138
- <output>
139
- <name>natural_gas_consumption_nmbe</name>
140
- <display_name>natural_gas_consumption_nmbe</display_name>
141
- <short_name>natural_gas_consumption_nmbe</short_name>
142
- <type>Double</type>
143
- <model_dependent>false</model_dependent>
144
- </output>
145
- <output>
146
- <name>natural_gas_sum_of_squares</name>
147
- <display_name>natural_gas_sum_of_squares</display_name>
148
- <short_name>natural_gas_sum_of_squares</short_name>
149
- <type>Double</type>
150
- <model_dependent>false</model_dependent>
151
- </output>
152
- <output>
153
- <name>natural_gas_dof</name>
154
- <display_name>natural_gas_dof</display_name>
155
- <short_name>natural_gas_dof</short_name>
156
- <type>Double</type>
157
- <model_dependent>false</model_dependent>
158
- </output>
159
- <output>
160
- <name>natural_gas_rmse</name>
161
- <display_name>natural_gas_rmse</display_name>
162
- <short_name>natural_gas_rmse</short_name>
163
- <type>Double</type>
164
- <model_dependent>false</model_dependent>
165
- </output>
166
- <output>
167
- <name>total_sum_of_squares</name>
168
- <display_name>total_sum_of_squares</display_name>
169
- <short_name>total_sum_of_squares</short_name>
170
- <type>Double</type>
171
- <model_dependent>false</model_dependent>
172
- </output>
173
- <output>
174
- <name>total_dof</name>
175
- <display_name>total_dof</display_name>
176
- <short_name>total_dof</short_name>
177
- <type>Double</type>
178
- <model_dependent>false</model_dependent>
179
- </output>
180
- <output>
181
- <name>total_rmse</name>
182
- <display_name>total_rmse</display_name>
183
- <short_name>total_rmse</short_name>
184
- <type>Double</type>
185
- <model_dependent>false</model_dependent>
186
- </output>
187
- <output>
188
- <name>electricity_cvrmse_within_limit</name>
189
- <display_name>electricity_cvrmse_within_limit</display_name>
190
- <short_name>electricity_cvrmse_within_limit</short_name>
191
- <type>Double</type>
192
- <model_dependent>false</model_dependent>
193
- </output>
194
- <output>
195
- <name>electricity_nmbe_within_limit</name>
196
- <display_name>electricity_nmbe_within_limit</display_name>
197
- <short_name>electricity_nmbe_within_limit</short_name>
198
- <type>Double</type>
199
- <model_dependent>false</model_dependent>
200
- </output>
201
- <output>
202
- <name>natural_gas_cvrmse_within_limit</name>
203
- <display_name>natural_gas_cvrmse_within_limit</display_name>
204
- <short_name>natural_gas_cvrmse_within_limit</short_name>
205
- <type>Double</type>
206
- <model_dependent>false</model_dependent>
207
- </output>
208
- <output>
209
- <name>natural_gas_nmbe_within_limit</name>
210
- <display_name>natural_gas_nmbe_within_limit</display_name>
211
- <short_name>natural_gas_nmbe_within_limit</short_name>
212
- <type>Double</type>
213
- <model_dependent>false</model_dependent>
214
- </output>
215
- </outputs>
216
- <provenances/>
217
- <tags>
218
- <tag>Reporting.QAQC</tag>
219
- </tags>
220
- <attributes>
221
- <attribute>
222
- <name>Measure Type</name>
223
- <value>ReportingMeasure</value>
224
- <datatype>string</datatype>
225
- </attribute>
226
- <attribute>
227
- <name>Uses SketchUp API</name>
228
- <value>false</value>
229
- <datatype>boolean</datatype>
230
- </attribute>
231
- </attributes>
232
- <files>
233
- <file>
234
- <filename>report.html.in</filename>
235
- <filetype>in</filetype>
236
- <usage_type>resource</usage_type>
237
- <checksum>22F45739</checksum>
238
- </file>
239
- <file>
240
- <filename>LICENSE.md</filename>
241
- <filetype>md</filetype>
242
- <usage_type>license</usage_type>
243
- <checksum>E0468DD6</checksum>
244
- </file>
245
- <file>
246
- <filename>README.md.erb</filename>
247
- <filetype>erb</filetype>
248
- <usage_type>readmeerb</usage_type>
249
- <checksum>703C9964</checksum>
250
- </file>
251
- <file>
252
- <filename>README.md</filename>
253
- <filetype>md</filetype>
254
- <usage_type>readme</usage_type>
255
- <checksum>6EC9831E</checksum>
256
- </file>
257
- <file>
258
- <version>
259
- <software_program>OpenStudio</software_program>
260
- <identifier>1.11.0</identifier>
261
- <min_compatible>1.11.0</min_compatible>
262
- </version>
263
- <filename>measure.rb</filename>
264
- <filetype>rb</filetype>
265
- <usage_type>script</usage_type>
266
- <checksum>ACDD9C17</checksum>
267
- </file>
268
- </files>
269
- </measure>
@@ -1,380 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Calibration | OpenStudio</title>
6
- <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
7
- <link href="file:///C:/openstudio_git/OpenStudio/openstudiocore/resources/web_assets/bootstrap.min.css" rel="stylesheet">
8
- <style type="text/css">
9
- body {
10
- font: 10px sans-serif;
11
- min-width: 750px;
12
- }
13
- table {
14
- max-width:700px;
15
- }
16
- .axis path, .axis line {
17
- fill: none;
18
- stroke: #000;
19
- shape-rendering: crispEdges;
20
- }
21
- .bar {
22
- fill: steelblue;
23
- }
24
- .x.axis path {
25
- display: none;
26
- }
27
- .d3-tip {
28
- line-height: 1;
29
- font-weight: bold;
30
- padding: 12px;
31
- background: rgba(0, 0, 0, 0.8);
32
- color: #fff;
33
- border-radius: 2px;
34
- }
35
- /* Creates a small triangle extender for the tooltip */
36
- .d3-tip:after {
37
- box-sizing: border-box;
38
- display: inline;
39
- font-size: 10px;
40
- width: 100%;
41
- line-height: 1;
42
- color: rgba(0, 0, 0, 0.8);
43
- content:"\25BC";
44
- position: absolute;
45
- text-align: center;
46
- }
47
- /* Style northward tooltips differently */
48
- .d3-tip.n:after {
49
- margin: -1px 0 0 0;
50
- top: 100%;
51
- left: 0;
52
- }
53
- .chartInfo h6 {
54
- display: inline;
55
- }
56
- </style>
57
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
58
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.3.9/d3.min.js"></script>
59
- <script type="text/javascript" src="file:///C:/openstudio_git/OpenStudio/openstudiocore/resources/web_assets/jquery.min.js"></script>
60
- <script type="text/javascript" src="file:///C:/openstudio_git/OpenStudio/openstudiocore/resources/web_assets/d3.min.js"></script>
61
- <script type="text/javascript">
62
- // http://labratrevenge.com/d3-tip/javascripts/d3.tip.min.js
63
- d3.tip=function(){function t(t){v=m(t),w=v.createSVGPoint(),document.body.appendChild(x)}function e(){return"n"}function n(){return[0,0]}function r(){return" "}function o(){var t=p();return{top:t.n.y-x.offsetHeight,left:t.n.x-x.offsetWidth/2}}function s(){var t=p();return{top:t.s.y,left:t.s.x-x.offsetWidth/2}}function l(){var t=p();return{top:t.e.y-x.offsetHeight/2,left:t.e.x}}function u(){var t=p();return{top:t.w.y-x.offsetHeight/2,left:t.w.x-x.offsetWidth}}function f(){var t=p();return{top:t.nw.y-x.offsetHeight,left:t.nw.x-x.offsetWidth}}function i(){var t=p();return{top:t.ne.y-x.offsetHeight,left:t.ne.x}}function a(){var t=p();return{top:t.sw.y,left:t.sw.x-x.offsetWidth}}function c(){var t=p();return{top:t.se.y,left:t.e.x}}function d(){var t=d3.select(document.createElement("div"));return t.style({position:"absolute",opacity:0,pointerEvents:"none",boxSizing:"border-box"}),t.node()}function m(t){return t=t.node(),"svg"==t.tagName.toLowerCase()?t:t.ownerSVGElement}function p(){var t=d3.event.target,e={},n=t.getScreenCTM(),r=t.getBBox(),o=r.width,s=r.height,l=r.x,u=r.y,f=document.body.scrollTop,i=document.body.scrollLeft;return document.documentElement&&document.documentElement.scrollTop&&(f=document.documentElement.scrollTop,i=document.documentElement.scrollLeft),w.x=l+i,w.y=u+f,e.nw=w.matrixTransform(n),w.x+=o,e.ne=w.matrixTransform(n),w.y+=s,e.se=w.matrixTransform(n),w.x-=o,e.sw=w.matrixTransform(n),w.y-=s/2,e.w=w.matrixTransform(n),w.x+=o,e.e=w.matrixTransform(n),w.x-=o/2,w.y-=s/2,e.n=w.matrixTransform(n),w.y+=s,e.s=w.matrixTransform(n),e}var y=e,g=n,h=r,x=d(),v=null,w=null;t.show=function(){var e,n=h.apply(this,arguments),r=g.apply(this,arguments),o=y.apply(this,arguments),s=d3.select(x),l=0;for(s.html(n).style({opacity:1,pointerEvents:"all"});l--;)s.classed(E[l],!1);return e=T.get(o).apply(this),s.classed(o,!0).style({top:e.top+r[0]+"px",left:e.left+r[1]+"px"}),t},t.hide=function(){return nodel=d3.select(x),nodel.style({opacity:0,pointerEvents:"none"}),t},t.attr=function(e){if(2>arguments.length&&"string"==typeof e)return d3.select(x).attr(e);var n=Array.prototype.slice.call(arguments);return d3.selection.prototype.attr.apply(d3.select(x),n),t},t.style=function(e){if(2>arguments.length&&"string"==typeof e)return d3.select(x).style(e);var n=Array.prototype.slice.call(arguments);return d3.selection.prototype.style.apply(d3.select(x),n),t},t.direction=function(e){return arguments.length?(y=null==e?e:d3.functor(e),t):y},t.offset=function(e){return arguments.length?(g=null==e?e:d3.functor(e),t):g},t.html=function(e){return arguments.length?(h=null==e?e:d3.functor(e),t):h};var T=d3.map({n:o,s:s,e:l,w:u,nw:f,ne:i,sw:a,se:c}),E=T.keys();return t};
64
- </script>
65
- </head>
66
- <body>
67
- <div style="width:250px;display:inline-block;">
68
- <label>Calibration Method</label>
69
- <select id="calibrationMethodSelect">
70
- </select>
71
- </div>
72
- <div style="width:400px;display:inline-block;">
73
- <h6 id="calibrationString"></h6>
74
- </div>
75
- <div id="consumptionString-0" class="chartInfo"></div>
76
- <div id="chart-0"></div>
77
- <div id="table-0" ></div>
78
- <div id="consumptionString-1" class="chartInfo"></div>
79
- <div id="chart-1"></div>
80
- <div id="table-1" ></div>
81
- <div id="consumptionString-2" class="chartInfo"></div>
82
- <div id="chart-2"></div>
83
- <div id="table-2" ></div>
84
- <script type="text/javascript">
85
- function numFormat(n) {
86
- var parts = n.toString().split(".");
87
- return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
88
- }
89
-
90
- <%= energy %>
91
-
92
- $.each(calibrationGuidelines, function (index, value) {
93
- $('#calibrationMethodSelect')
94
- .append($("<option></option>")
95
- .attr("value", index)
96
- .text(value));
97
- });
98
-
99
- $("#calibrationMethodSelect").change(onMethodChange);
100
-
101
- var maxNMBE = 0;
102
- var maxCVRMSE = 0;
103
-
104
- function onMethodChange() {
105
- if ($('#calibrationMethodSelect').val() == "0") {
106
- maxNMBE = ashraeMaxNMBE;
107
- maxCVRMSE = ashraeMaxCVRMSE;
108
- } else {
109
- maxNMBE = fempMaxNMBE;
110
- maxCVRMSE = fempMaxCVRMSE;
111
- }
112
- $('#calibrationString').text("NMBE of " + maxNMBE + "% or less and CV(RMSE) of " + maxCVRMSE + "% relative to monthly data. Must contain all utility data for one year and real weather data. Check the guideline for additional requirements.");
113
-
114
- $('.table').each(function(i) {
115
- $(this).find('tr:last td:not(:first)').each(function(j) {
116
- var value = $(this).text().replace(/%/g, '');
117
- if (value != "&mdash;") {
118
- var num = parseFloat(value);
119
- if (Math.abs(num) > maxNMBE) {
120
- num = "<font color=\"red\">" + num;
121
- }
122
- num = num + "%";
123
- $(this).html(num);
124
- }
125
- });
126
- })
127
-
128
- for (var c in charts) {
129
-
130
- if(consumption[charts[c]]){
131
- cvrmseString = "<h6>CV(RMSE) = </h6>"
132
- num = consumption[charts[c]].cvrsme;
133
- if (Math.abs(num) > maxCVRMSE) {
134
- num = "<font color=\"red\">" + num + "<font color=\"black\">";
135
- }
136
- cvrmseString = cvrmseString + num;
137
-
138
- nmbeString = "<h6>NMBE = </h6>"
139
- num = consumption[charts[c]].nmbe;
140
- if (Math.abs(num) > maxNMBE) {
141
- num = "<font color=\"red\">" + num;
142
- }
143
- nmbeString = nmbeString + num;
144
-
145
- string = "<h4 style=\"margin-bottom:-10px;\">" + charts[c] + " (" + consumption[charts[c]].units + ")</h4>";
146
- if(charts[c] != "Electricity Demand"){
147
- string = string + "<br>" + cvrmseString + "<br>" + nmbeString;
148
- }
149
- $('#consumptionString-' + c).html(string);
150
- }
151
-
152
- }
153
-
154
- }
155
-
156
- onMethodChange();
157
-
158
- function outputTable(name, units, obj, id) {
159
- var $table = $('<table id="' + name.toLowerCase().replace(/ /g, '-') + '">').addClass("table table-striped table-bordered table-condensed");
160
- var headers = '';
161
- for (var i = 1; i <= obj.Start.length; i++) headers += '<th>' + i + '</th>';
162
- $table.append('<thead>').children('thead').append('<tr />').children('tr').append('<th>&nbsp;</th>').append(headers);
163
- var $tbody = $table.append('<tbody />').children('tbody');
164
- var key;
165
- for (key in obj) {
166
- if (obj.hasOwnProperty(key)) {
167
- if (key == "Start" | key == "End" | key == "Actual" | key == "Model" | key == "NMBE") {
168
- var $row = $tbody.append('<tr />').children('tr:last');
169
- $row.append("<td>" + key + "</td>");
170
- for (i = 0; i < obj.Start.length; i++) {
171
- var num = obj[key][i] === 0 ? "&mdash;" : numFormat(obj[key][i]);
172
-
173
- if (num != "&mdash;") {
174
- if (key == "NMBE") {
175
- if (Math.abs(num) > maxNMBE) {
176
- num = "<font color=\"red\">" + num;
177
- }
178
- num = num + "%";
179
- }
180
- }
181
-
182
- $row.append("<td>" + num + "</td>");
183
- }
184
- }
185
- }
186
- }
187
- $table.appendTo('#' + id);
188
- }
189
-
190
- var margin = {
191
- top: 20.5,
192
- right: 20,
193
- bottom: 30,
194
- left: 40.5
195
- },
196
- width = 560 - margin.left - margin.right,
197
- height = 300 - margin.top - margin.bottom;
198
-
199
- var x0 = d3.scale.ordinal()
200
- .rangeRoundBands([0, width], 0.1);
201
-
202
- var x1 = d3.scale.ordinal();
203
-
204
- var y = d3.scale.linear()
205
- .range([height, 0]);
206
-
207
- var color = d3.scale.ordinal()
208
- .range(["#8CC739", "#29AAE7"]);
209
-
210
- var xAxis = d3.svg.axis()
211
- .scale(x0)
212
- .orient("bottom");
213
-
214
- var yAxis = d3.svg.axis()
215
- .scale(y)
216
- .orient("left")
217
- .tickFormat(d3.format(".2s"));
218
-
219
- var tip = d3.tip()
220
- .attr('class', 'd3-tip')
221
- .offset([-10, 0])
222
- .html(function (d) {
223
- return "<strong>" + d3.event.target.__data__.name + ":</strong> <span style='color:red'>" + d3.event.target.__data__.value + "</span>";
224
- });
225
-
226
- var charts = ["Electricity Consumption", "Electricity Demand", "Natural Gas Consumption"];
227
-
228
- for (var c in charts) {
229
-
230
- if(consumption[charts[c]]){
231
-
232
- if (c == 0) {
233
- margin.right = 125;
234
- }
235
-
236
- cvrmseString = "<h6>CV(RMSE) = </h6>"
237
- num = consumption[charts[c]].cvrsme;
238
- if (Math.abs(num) > maxCVRMSE) {
239
- num = "<font color=\"red\">" + num + "<font color=\"black\">";
240
- }
241
- cvrmseString = cvrmseString + num;
242
-
243
- nmbeString = "<h6>NMBE = </h6>"
244
- num = consumption[charts[c]].nmbe;
245
- if (Math.abs(num) > maxNMBE) {
246
- num = "<font color=\"red\">" + num;
247
- }
248
- nmbeString = nmbeString + num;
249
-
250
- string = "<h4 style=\"margin-bottom:-10px;\">" + charts[c] + " (" + consumption[charts[c]].units + ")</h4>";
251
- if(charts[c] != "Electricity Demand"){
252
- string = string + "<br>" + cvrmseString + "<br>" + nmbeString;
253
- }
254
- $('#consumptionString-' + c).html(string);
255
-
256
- var svg = d3.select("#chart-" + c).append("svg")
257
- .attr("width", width + margin.left + margin.right)
258
- .attr("height", height + margin.top + margin.bottom)
259
- .append("g")
260
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
261
- svg.call(tip);
262
-
263
- data = [];
264
- for (var enduse in consumption[charts[c]].data) {
265
- if (enduse == "Actual" | enduse == "Model") {
266
- var enduse_data = consumption[charts[c]].data[enduse];
267
- for (var i = 1; i <= enduse_data.length; i++) {
268
- if (data.length < enduse_data.length) {
269
- var temp = {
270
- "Month": i
271
- };
272
- temp[enduse] = enduse_data[i - 1];
273
- data.push(temp);
274
- } else {
275
- data[i - 1][enduse] = enduse_data[i - 1];
276
- }
277
- }
278
- }
279
- }
280
- var comparison = d3.keys(data[0]).filter(function (key) {
281
- return key !== "Month";
282
- });
283
-
284
- data.forEach(function (d) {
285
- d.consumption = comparison.map(function (name) {
286
- return {
287
- name: name,
288
- value: +d[name]
289
- };
290
- });
291
- });
292
-
293
- x0.domain(data.map(function (d) {
294
- return d.Month;
295
- }));
296
- x1.domain(comparison).rangeRoundBands([0, x0.rangeBand()]);
297
- y.domain([0, d3.max(data, function (d) {
298
- return d3.max(d.consumption, function (d) {
299
- return d.value;
300
- });
301
- })]);
302
-
303
- //data.sort(function(a, b) { return b.total - a.total; });
304
-
305
- svg.append("g")
306
- .attr("class", "x axis")
307
- .attr("transform", "translate(0," + height + ")")
308
- .call(xAxis);
309
-
310
- svg.append("g")
311
- .attr("class", "y axis")
312
- .call(yAxis)
313
- .append("text")
314
- .attr("transform", "rotate(-90)")
315
- .attr("y", -36)
316
- .attr("dy", ".71em")
317
- .style("text-anchor", "end")
318
- .text(consumption[charts[c]].units);
319
-
320
- var month = svg.selectAll(".month")
321
- .data(data)
322
- .enter().append("g")
323
- .attr("class", "g")
324
- .on('mouseover', tip.show)
325
- .on('mouseout', tip.hide)
326
- .attr("transform", function (d) {
327
- return "translate(" + x0(d.Month) + ",0)";
328
- });
329
-
330
- month.selectAll("rect")
331
- .data(function (d) {
332
- return d.consumption;
333
- })
334
- .enter().append("rect")
335
- .attr("width", x1.rangeBand())
336
- .attr("x", function (d) {
337
- return x1(d.name);
338
- })
339
- .attr("y", function (d) {
340
- return y(d.value);
341
- })
342
- .attr("height", function (d) {
343
- return height - y(d.value);
344
- })
345
- .style("fill", function (d) {
346
- return color(d.name);
347
- });
348
-
349
- var legend = svg.selectAll(".legend")
350
- .data(comparison.slice().reverse())
351
- .enter().append("g")
352
- .attr("class", "legend")
353
- .attr("transform", function (d, i) {
354
- return "translate(0," + i * 20 + ")";
355
- });
356
-
357
- legend.append("rect")
358
- .attr("x", width + 105)
359
- .attr("width", 18)
360
- .attr("height", 18)
361
- .style("fill", color);
362
-
363
- legend.append("text")
364
- .attr("x", width + 105 - 3)
365
- .attr("y", 9)
366
- .attr("dy", ".35em")
367
- .style("text-anchor", "end")
368
- .text(function (d) {
369
- return d;
370
- });
371
-
372
- svg.selectAll(".g").attr("stroke", "black");
373
-
374
- outputTable(charts[c], consumption[charts[c]].units, consumption[charts[c]].data, "table-" + c);
375
- }
376
-
377
- }
378
- </script>
379
- </body>
380
- </html>