-
Rosanny Sihombing authoredb0da5bf6
<html>
<head>
<title>ENsource Disaggregation Report</title>
<meta charset="UTF-8">
<!-- Include the CesiumJS JavaScript and CSS files -->
<script src="https://cesium.com/downloads/cesiumjs/releases/1.78/Build/Cesium/Cesium.js"></script>
<link href="https://cesium.com/downloads/cesiumjs/releases/1.78/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
<!-- Terraformer and WKT Parser -->
<script src="https://unpkg.com/terraformer@1.0.7/terraformer.js"></script>
<script src="https://unpkg.com/terraformer-wkt-parser@1.1.2/terraformer-wkt-parser.js"></script>
<!-- proj4js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.2/proj4.min.js" integrity="sha512-dNFx8aqYHHdVRrTfm7fzMSakZd+cD8Bf24ZqvAIh799ORCeyVdzN1w4wiqLtLON7VPkZ1vQmMi+CJRF/b3v/7A==" crossorigin="anonymous"></script>
<style>
h1 {
text-align: center;
color: #002C55;
}
h2 {
text-align: left;
font-size: 25px;
font-weight: "bold";
color: #002C55;
}
h1 span {
color: #549925;
}
table {
border-collapse: collapse;
border: 1px solid #DFDCDC;
border-spacing: 0;
}
th {
background-color: #549925;
color: white;
text-align: left;
padding: 8px;
}
td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #e7f4d9;
}
table th,
table td {
border-top: 1px #efe9e3;
border-right: 0px #efe9e3;
border-bottom: 0px #efe9e3;
border-left: 1px #efe9e3;
}
.button {
float: left;
padding: 6px 9px;
cursor: pointer;
margin-top: 20px;
margin-left: 15px;
border-radius: 5px;
background-color: #549925;
font-size: 12px;
font-weight: bold;
color: #fff;
width: 30px;
}
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
.collapsible {
background-color: #549925;
color: #002C55;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 25px;
font-weight: bold;
}
.active, .collapsible:hover {
background-color: #BAD6A7;
}
.collapsible:after {
content: '\002B'; /* Unicode character for "plus" sign (+) */
color: #002C55;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212"; /* Unicode character for "minus" sign (-) */
}
.content {
padding: 0 18px;
display: none;
overflow: hidden;
}
</style>
</head>
<body>
<h1><span>EN</span>source Disaggregation Report</h1>
<h2 style="float:left; width: 100%;">Run Results</h2>
<form action = "http://127.0.0.1:5000//ensource2/" method = "POST" enctype = "multipart/form-data">
<input type=file name=file required>
<input type=submit value=Run>
</form>
<table style="float:left; width: 49%; margin-right: 10;">
<tr>
<th>Target Demand (kWh)</th>
<td id="target-demand">N/A</td>
</tr>
<tr>
<th>Results Files</th>
<td id="file-name"><a id="jsonResult" href=#></a> | <a id="csvResult" href=#></a></td>
</tr>
<tr>
<th>Segments File</th>
<td id="segments-file-name">N/A</td>
</tr>
<tr>
<th>Available Segments</th>
<td id="available-segments">N/A</td>
</tr>
<tr>
<th>Grid provided</th>
<td id="grid-provided">N/A</td>
</tr>
</table>
<table style="float:left;width: 49%;">
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<tr>
<th>Accumulated demand (kWh)</th>
<td id="accumulated-demand">N/A</td>
</tr>
<tr>
<th>Investment cost (EUR)</th>
<td id="investment-cost">N/A</td>
</tr>
<tr>
<th>Total grid length (m)</th>
<td id="total-length">N/A</td>
</tr>
<tr>
<th>Used segments</th>
<td id="used-segments">N/A</td>
</tr>
<tr>
<th>Grid provided IDs</th>
<td id="grid-provided-ids">{{ givenGridIds }}</td>
</tr>
</table>
<button type="button" class="collapsible">Calculated Grid</button>
<div class="content">
<table id="result-table" border=1 style="width: 99%;">
<tr>
<th> Segment ID </th>
<th> Demand (kWh)</th>
<th> Length (m)</th>
<th> Acc. Demand (kWh)</th>
<th> Acc. Length (m)</th>
<th> Acc. Grid Cost (EUR)</th>
</table>
</div>
<button type="button" class="collapsible">Grid Visualization</button> <!-- span>+</span -->
<div class="content">
<div id="toolbar" style="position: absolute; padding: 25px; z-index: 1;">
<!-- select id="myColor" onchange="doStyling()">
<option value="1">Show/hide grids</option>
<option value="2">Color grids by segment demand (kWh)</option>
<option value="0">Show/hide buildings</option>
</select -->
</div>
<div id="cesiumContainer"></div>
</div>
<script>
//var myViewer
var myWholeGrid
var myGrid
// collapsible
var coll = document.getElementsByClassName("collapsible")
var i
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active")
var content = this.nextElementSibling
if (content.style.display === "block") {
content.style.display = "none"
} else {
content.style.display = "block"
}
})
}
/*
function doStyling() {
let id = document.getElementById("myColor").value
if (id == 0) {
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// show/hide buildings
} else if(id == 1) {
// show/hide grids
} else if(id == 2) {
for (var segment in myGrid.segments) {
let linesReprojected = myGrid.segments[segment].geometryReprojected
for (let i = 0; i < (linesReprojected.length-1); i++) {
myViewer.entities.add({
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([linesReprojected[i][0], linesReprojected[i][1], linesReprojected[i+1][0], linesReprojected[i+1][1]]),
width: 5,
material: Cesium.Color.GREEN,
clampToGround: true,
}
});
}
}
}
} */
function gridCost(total_demand_kWh, total_length_m, a, c1, c2){
const q_s = (total_demand_kWh/(10**6))*3600;
const d_a = 0.0486 * Math.log(q_s / total_length_m) + 0.0007;
grid_investment_cost_EUR = a*(c1 + c2 * d_a) * total_length_m;
return grid_investment_cost_EUR;
}
function displayTable(grid) {
const table = document.getElementById('result-table');
table.children = null;
//element.texContent = JSON.stringify(result);
const tblBody = document.createElement("tbody");
let accDemand = 0;
let accLength = 0;
// creating all cells
const target = document.getElementById('target-demand');
target.textContent = grid.targetDemand;
const segmentsFile = document.getElementById('segments-file-name');
segmentsFile.textContent = grid.segmentsFile;
const availSegments = document.getElementById('available-segments');
availSegments.textContent = grid.availableSegmentsCount;
const gridProvided = document.getElementById('grid-provided');
gridProvided.textContent = grid.givenGridStr;
const accumulatedDemand = document.getElementById('accumulated-demand');
accumulatedDemand.textContent = grid.accumulatedDemand;
const investmentCost = document.getElementById('investment-cost');
investmentCost.textContent = grid.investmentCost.toFixed(3);
const totalLength = document.getElementById('total-length');
totalLength.textContent = grid.totalLength;
const calcGridTitle = document.getElementById('used-segments');
//calcGridTitle.textContent = `${grid.segments.length}`;
calcGridTitle.textContent = grid.segments.length;
for (var segment in grid.segments) {
var row = document.createElement("tr");
const id = document.createElement("td");
let cellText = document.createTextNode(grid.segments[segment].id);
id.appendChild(cellText);
const demand = document.createElement("td");
cellText = document.createTextNode(grid.segments[segment].demand);
demand.appendChild(cellText);
const length = document.createElement("td");
cellText = document.createTextNode(grid.segments[segment].length);
length.appendChild(cellText);
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
var accDemandCell = document.createElement("td");
cellText = document.createTextNode(accDemand += grid.segments[segment].demand);
accDemandCell.appendChild(cellText);
var accLengthCell = document.createElement("td");
cellText = document.createTextNode((accLength += grid.segments[segment].length).toFixed(3));
accLengthCell.appendChild(cellText);
var accCostCell = document.createElement("td");
cellText = document.createTextNode((gridCost(accDemand,accLength, grid.a, grid.c1, grid.c2)).toFixed(3));
accCostCell.appendChild(cellText);
row.appendChild(id);
row.appendChild(demand);
row.appendChild(length);
row.appendChild(accDemandCell);
row.appendChild(accLengthCell);
row.appendChild(accCostCell);
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
if (table.children[1]) table.children[1].replaceWith(tblBody);
else table.appendChild(tblBody);
}
function drawBaseGrid(viewer, wholeGrid) {
// todo: clear entities
for (var segment in wholeGrid) {
// parse a WKT string, converting it into a Terraformer.Primitive
let geojsonLineString = Terraformer.WKT.parse(wholeGrid[segment].geometry)
let coordinates = []
for (let i = 0; i < (geojsonLineString.coordinates.length); i++) {
let projWebCoordinate = reprojectCoordinate(geojsonLineString.coordinates[i])
coordinates.push(projWebCoordinate)
}
// draw grids based on coordinates
for (let i = 0; i < (coordinates.length-1); i++) {
viewer.entities.add({
id: "BaseGrid"+"_Segment-"+wholeGrid[segment].id+"-"+i,
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([coordinates[i][0], coordinates[i][1], coordinates[i+1][0], coordinates[i+1][1]]),
width: 2,
material: Cesium.Color.BLACK,
clampToGround: true,
}
})
}
}
}
function drawGrid(viewer, grid) {
for (var segment in grid.segments) {
// parse a WKT string, converting it into a Terraformer.Primitive
let geojsonLineString = Terraformer.WKT.parse(grid.segments[segment].geometry)
let coordinates = []
for (let i = 0; i < (geojsonLineString.coordinates.length); i++) {
let projWebCoordinate = reprojectCoordinate(geojsonLineString.coordinates[i])
coordinates.push(projWebCoordinate)
}
// draw grids based on coordinates
for (let i = 0; i < (coordinates.length-1); i++) {
viewer.entities.add({
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
id: "Grid"+"_Segment-"+grid.segments[segment].id+"-"+i,
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([coordinates[i][0], coordinates[i][1], coordinates[i+1][0], coordinates[i+1][1]]),
width: 5,
material: Cesium.Color.RED,
clampToGround: true,
},
});
}
}
}
function reprojectCoordinate(coordinate) {
let firstProj = "+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs"; // EPSG:31467
let secondProj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"; // EPSG:4326
// convert the passed coordinate to geographic coordinate
let geoCoordinate = Terraformer.Tools.positionToGeographic(coordinate)
// converts the passed coordinate to web mercator spatial reference.
let webCoordinate = Terraformer.Tools.positionToMercator(geoCoordinate)
// project coordinate to EPSG 4326
let projWebCoordinate = proj4(firstProj, secondProj, webCoordinate)
return projWebCoordinate
}
function init() {
// set links to the result files
let aJson = document.getElementById('jsonResult')
let resultJsonFilename = {{ resultFileJson | tojson }}
aJson.href = "result/"+resultJsonFilename
aJson.textContent = resultJsonFilename
let aCsv = document.getElementById('csvResult')
let resultCsvFilename = {{ resultFileCsv | tojson }}
aCsv.href = "result/"+resultCsvFilename
aCsv.textContent = resultCsvFilename
// load cesiumjs
Cesium.Ion.defaultAccessToken = 'put-your-cesium-token-here'
let viewer = new Cesium.Viewer("cesiumContainer", {
animation: false,
timeline: false,
terrainProvider: Cesium.createWorldTerrain(),
imageryProvider : new Cesium.OpenStreetMapImageryProvider({
url : 'https://a.tile.openstreetmap.org/'})
});
// Add Cesium OSM buildings to the scene
//viewer.scene.primitives.add(Cesium.createOsmBuildings());
//myViewer = viewer
myWholeGrid = JSON.parse({{ wholeGrid | tojson }})
myGrid = JSON.parse({{ grid | tojson }})
displayTable(myGrid)
drawBaseGrid(viewer, myWholeGrid)
drawGrid(viewer, myGrid)
viewer.zoomTo(viewer.entities)
}
init()
</script>
</body>
</html>