Skip to content

Commit 6c88f65

Browse files
committed
Merge branch 'vcoman/ces_demo' of github.com:digidotcom/xbee-iot-web-apps into vcoman/ces_demo
2 parents cdb8ce0 + 96697d5 commit 6c88f65

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

agriculture/.configured

Whitespace-only changes.

agriculture/agriculturecore/templates/sidebar.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<img id="simulation-logo" class="banner-icon" src="{% static 'images/simulation.png' %}">
2121
</button>
2222
<div class="dropdown-menu shadow-sm simulation-controls-container" aria-labelledby="simulationMenuButton">
23-
<p>Simulation controls</p>
23+
<p>Simulation control</p>
2424
<!-- <div class="card">-->
2525
<!-- <p class="widget-title">Weather condition</p>-->
2626
<!-- <p class="widget-desc">Control the weather condition of the farm. You can change it to see different temperature and moisture values.</p>-->
@@ -188,14 +188,14 @@
188188
});
189189

190190
// Add 'click' callbacks to the weather and time buttons.
191-
$(".weather-button").click(setWeatherCondition);
191+
// $(".weather-button").click(setWeatherCondition);
192192
$(".time-button").click(setTimeFactor);
193193

194194
// Check the farm connection status.
195195
checkFarmConnectionStatus();
196196

197-
// Get the weather condition and time factor from the irrigation controller.
198-
getWeatherCondition();
197+
// Get the time factor from the irrigation controller.
198+
// getWeatherCondition();
199199
getTimeFactor();
200200

201201
// Check farm connectivity in 5 secs.
@@ -243,9 +243,7 @@
243243
if (data["redirect"])
244244
window.location.replace(data["redirect"]);
245245
}
246-
).fail(function(response) {
247-
processErrorResponse(response);
248-
});
246+
);
249247
}
250248
</script>
251249
{% endblock %}

agriculture/agriculturecore/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
path('ajax/get_wind', views.get_wind, name="get_wind"),
3838
path('ajax/get_wind_dir', views.get_wind_dir, name="get_wind_dir"),
3939
path('ajax/get_luminosity', views.get_luminosity, name="get_luminosity"),
40+
path('ajax/get_rain_acc', views.get_rain_acc, name="get_rain_acc"),
4041
path('ajax/get_rain', views.get_rain, name="get_rain"),
4142
path('ajax/get_radiation', views.get_radiation, name="get_radiation"),
4243
path('ajax/get_temperature', views.get_temperature, name="get_temperature"),

agriculture/agriculturecore/views.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,23 @@ def get_luminosity(request):
516516
return get_data_points(request, ID_LUMINOSITY)
517517

518518

519-
def get_rain(request):
519+
def get_rain_acc(request):
520520
"""
521521
Returns the rain data of the main controller.
522522
523+
Args:
524+
request (:class:`.WSGIRequest`): the AJAX request.
525+
526+
Returns:
527+
A JSON with the list of data points or the error.
528+
"""
529+
return get_data_points(request, ID_RAIN_ACC)
530+
531+
532+
def get_rain(request):
533+
"""
534+
Returns the rain accumulated data of the main controller.
535+
523536
Args:
524537
request (:class:`.WSGIRequest`): the AJAX request.
525538

agriculture/static/js/history.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const STATION_CHART_HTML = "" +
108108
var windData;
109109
var rainData;
110110
var radiationData;
111+
var luminosityData;
111112
var temperatureData = {};
112113
var moistureData = {};
113114
var valveData = {};
@@ -163,7 +164,7 @@ function drawAllCharts(refresh=false, showProgress=true) {
163164
drawWindChart(refresh, showProgress);
164165
drawRainChart(refresh, showProgress);
165166
drawLuminosityChart(refresh, showProgress);
166-
drawTemperatureChart(refresh, showProgress);
167+
drawTemperatureChartG(refresh, showProgress);
167168

168169
for (macAddr in temperatureData) {
169170
drawTemperatureChart(macAddr, refresh, showProgress);
@@ -200,13 +201,13 @@ function drawRainChart(refresh=false, showProgress=false) {
200201
if (refresh) {
201202
if (showProgress)
202203
$("#rain-chart-loading").show();
203-
$.post("/ajax/get_rain", getJsonData(rainInterval), function(response) {
204+
$.post("/ajax/get_rain_acc", getJsonData(rainInterval), function(response) {
204205
rainData = response.data;
205206
drawRainChart();
206207
$("#rain-chart-loading").hide();
207208
});
208209
} else {
209-
drawChart("rain-chart", rainData, "Rain", "mm", "#3399FF");
210+
drawChart("rain-chart", rainData, "Rain", "L/m²", "#3399FF");
210211
}
211212
}
212213

@@ -236,25 +237,40 @@ function drawRadiationChart(refresh=false, showProgress=false) {
236237
$("#radiation-chart-loading").hide();
237238
});
238239
} else {
239-
drawChart("radiation-chart", radiationData, "Radiation", "W/m2", "#FFD500");
240+
drawChart("radiation-chart", radiationData, "Radiation", "W/", "#FFD500");
240241
}
241242
}
242243

243-
// Draws the temperature chart.
244-
function drawTemperatureChart(refresh=false, showProgress=false) {
244+
// Draws the temperature chart of gateway.
245+
function drawTemperatureChartG(refresh=false, showProgress=false) {
245246
if (refresh) {
246247
if (showProgress)
247248
$("#temperature-chart-loading").show();
248249
$.post("/ajax/get_temperature", getJsonData(temperatureInterval), function(response) {
249250
temperatureData = response.data;
250-
drawTemperatureChart();
251+
drawTemperatureChartG();
251252
$("#temperature-chart-loading").hide();
252253
});
253254
} else {
254255
drawChart("temperature-chart", temperatureData, "Temperature", "ºC", "#FF0000");
255256
}
256257
}
257258

259+
// Draws the temperature chart of xbees.
260+
function drawTemperatureChart(macAddr, refresh=false, showProgress=false) {
261+
if (refresh) {
262+
if (showProgress)
263+
$("#temperature-" + macAddr + "-chart-loading").show();
264+
$.post("/ajax/get_temperature", getJsonData(temperatureInterval[macAddr], macAddr), function(response) {
265+
temperatureData[macAddr] = response.data;
266+
drawTemperatureChart(macAddr);
267+
$("#temperature-" + macAddr + "-chart-loading").hide();
268+
});
269+
} else {
270+
drawChart("temperature-" + macAddr + "-chart", temperatureData[macAddr], "Temperature", "ºC", "#FF0000");
271+
}
272+
}
273+
258274
// Draws the moisture chart.
259275
function drawMoistureChart(macAddr, refresh=false, showProgress=false) {
260276
if (refresh) {
@@ -285,12 +301,6 @@ function drawValveChart(macAddr, refresh=false, showProgress=false) {
285301
}
286302
}
287303

288-
//google.charts.load('current', {
289-
// callback: drawChart,
290-
// packages: ['scatterChart', 'lineChart']
291-
//});
292-
293-
294304
// Draws the chart with the given data.
295305
function drawChart(id, data, title, units, color=null, data2=null, units2=null, title2=null, color2=null) {
296306
if (!isHistoryShowing() || id === undefined)
@@ -340,12 +350,7 @@ function drawChart(id, data, title, units, color=null, data2=null, units2=null,
340350
0: {title: units},
341351
},
342352
vAxis: {
343-
// viewWindow: {
344-
// min: 0,
345-
// max: 50
346-
// }
347-
//ticks: [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
348-
ticks: [{v: 0}, {v: 8}, {v: 16}, {v: 24}, {v: 32}, {v: 40}, {v: 48}, {v: 56} ]
353+
ticks: [{v: 0}, {v: 4}, {v: 8}, {v: 12}, {v: 16}, {v: 20}, {v: 24}, {v: 28} ]
349354
},
350355
legend: { position: 'bottom' }
351356
};

0 commit comments

Comments
 (0)