Skip to content
This repository was archived by the owner on Oct 7, 2019. It is now read-only.

Commit 67d2f6a

Browse files
committed
implemented call to calculator API
replaced hardcoded variables and equation with request to calculator API, which exposes all parameters and returns response with all intermediate values
1 parent 85b9524 commit 67d2f6a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

project/static/js/geoprocessing.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ var analyzeGPResults = function(elevProfileResult,watershedResult) {
148148
var firstZ = coords[0][2];
149149
var lastZ = coords[coords.length - 1][2];
150150
// save the difference
151-
var head = lastZ - firstZ;
152-
// check result. It must be a positive number
151+
var head = Math.abs(lastZ - firstZ);
152+
153153

154154
$('#msg-text').append('<h3><small>Head:</small>&nbsp;' + _round(head,2) + '&nbsp;<small>meters</small></h3>');
155155

156-
156+
/*
157157
// calculate power
158158
var Qavail = (area * 1.6);
159159
//where x is a range from 0.1 to 0.5 with default value of 0.3 (edited)
@@ -164,7 +164,31 @@ var analyzeGPResults = function(elevProfileResult,watershedResult) {
164164
var e = 0.7;
165165
var p = Quseable * head * (0.084) * e;
166166
var power = _round(p, 2);
167-
167+
*/
168+
var envflow = 0, efficiency = 0;
169+
calcRequestURL = Flask.url_for("api", {
170+
"area": area, "head": head, "envflow": envflow, "efficiency": efficiency
171+
});
172+
173+
$.get({
174+
url: calcRequestURL,
175+
success: function(data) {
176+
if (head < 0) {
177+
$('#msg-status').html(makeAlert("The head calculation returned a negative value. Make sure the line was drawn downstream&rarr;upstream.", 'warning'));
178+
} else {
179+
//$('#msg-status').html(makeAlert(null,'success'));
180+
$('#msg-status').hide();
181+
}
182+
183+
$('#msg-text').append('<h2><small>Power:</small>&nbsp;' + data.result.power + '&nbsp;<small>kW/year</small></h2>');
184+
$('#msg-status-power').html(makeAlert("Power Generation Est.: Complete", 'success'));
185+
$('#analyze-button-item').html(clearButton);
186+
$('#msg-text').show();
187+
}
188+
});
189+
190+
/*
191+
//check result. It must be a positive number
168192
if (head < 0) {
169193
$('#msg-status').html(makeAlert("The head calculation returned a negative value. Make sure the line was drawn downstream&rarr;upstream.", 'warning'));
170194
} else {
@@ -176,4 +200,5 @@ var analyzeGPResults = function(elevProfileResult,watershedResult) {
176200
$('#msg-status-power').html(makeAlert("Power Generation Est.: Complete", 'success'));
177201
$('#analyze-button-item').html(clearButton);
178202
$('#msg-text').show();
203+
*/
179204
};

project/templates/pages/map.html

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ <h3 class="modal-title">Bard Micro-Hydropower Calculator</h3>
7878
<script src="https://cdn.jsdelivr.net/leaflet.esri.webmap/0.4.0/esri-leaflet-webmap.js"></script>
7979

8080
<!--APPLICATION-->
81+
{{ JSGlue.include() }}
8182
<script>
8283
// ArcGIS token passed from Flask to javascript (rendered by Jinja2)
8384
var arcgis_token = {{ arcgis_token|tojson }};

0 commit comments

Comments
 (0)