diff --git a/.gitignore b/.gitignore index ff76763..16da799 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,8 @@ media # Backup files # *.bak -# If you are using PyCharm # +# If you are using PyCharm # +.idea/* */.idea/* *.iws /out/ @@ -103,3 +104,4 @@ GitHub.sublime-settings !.vscode/launch.json !.vscode/extensions.json .history + diff --git a/agriculture/.configured b/agriculture/.configured new file mode 100644 index 0000000..e69de29 diff --git a/agriculture/.ebextensions/django.config b/agriculture/.ebextensions/django.config new file mode 100644 index 0000000..87bc1e7 --- /dev/null +++ b/agriculture/.ebextensions/django.config @@ -0,0 +1,5 @@ +option_settings: + aws:elasticbeanstalk:container:python: + WSGIPath: agriculturecommon.wsgi:application + aws:elasticbeanstalk:environment:proxy:staticfiles: + /static: static \ No newline at end of file diff --git a/agriculture/.gitignore b/agriculture/.gitignore new file mode 100644 index 0000000..fe4c0e0 --- /dev/null +++ b/agriculture/.gitignore @@ -0,0 +1,5 @@ + +# Elastic Beanstalk Files +.elasticbeanstalk/* +!.elasticbeanstalk/*.cfg.yml +!.elasticbeanstalk/*.global.yml diff --git a/agriculture/agriculturecommon/settings.py b/agriculture/agriculturecommon/settings.py index 3ff11f0..95dc2bc 100644 --- a/agriculture/agriculturecommon/settings.py +++ b/agriculture/agriculturecommon/settings.py @@ -39,7 +39,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Application definition @@ -93,7 +93,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } diff --git a/agriculture/agriculturecommon/templates/base.html b/agriculture/agriculturecommon/templates/base.html index cc19d2b..a30e8e4 100644 --- a/agriculture/agriculturecommon/templates/base.html +++ b/agriculture/agriculturecommon/templates/base.html @@ -20,7 +20,8 @@ diff --git a/agriculture/agriculturecommon/urls.py b/agriculture/agriculturecommon/urls.py index ee424cc..204d18e 100644 --- a/agriculture/agriculturecommon/urls.py +++ b/agriculture/agriculturecommon/urls.py @@ -31,6 +31,7 @@ from django.urls import include, path urlpatterns = [ + path("access/", include("login.urls")), path("", include("agriculturecore.urls")), diff --git a/agriculture/agriculturecore/drm_requests.py b/agriculture/agriculturecore/drm_requests.py index c6f68f1..80896e1 100644 --- a/agriculture/agriculturecore/drm_requests.py +++ b/agriculture/agriculturecore/drm_requests.py @@ -53,22 +53,25 @@ DO_CMD_XBEE_DISCOVER = "" DO_CMD_XBEE_SETTING = "" -ID_WIND = "wind" +ID_WIND = "wind_speed" +ID_WIND_DIR = "wind_direction" ID_RADIATION = "radiation" -ID_RAIN = "rain" +ID_RAIN_ACC = "rain_acc" +ID_RAIN = "rain_diff" ID_LEVEL = "level" ID_VALVE = "valve" ID_TEMPERATURE = "temperature" +ID_PRESSURE = "pressure" +ID_LUMINOSITY = "luminosity" ID_BATTERY = "battery" ID_MOISTURE = "moisture" ID_CONTROLLERS = "controllers" +ID_ERROR = "error" ID_STATIONS = "stations" ID_WEATHER = "weather" ID_TANK = "tank" -ID_ERROR = "error" - REGEX_DEV_REQUEST_RESPONSE = ".*(.*)<\\/device_request>.*" REGEX_DO_CMD_RESPONSE = ".*]*>(.*)<\\/do_command>.*" @@ -150,10 +153,8 @@ def check_ajax_request(request): """ Checks whether the given AJAX request is valid and the user is authenticated. - Args: request (:class:`.WSGIRequest`): The HTTP request. - Returns: `None` if the request is valid, or a `JsonResponse` with the error if it is not. @@ -629,10 +630,18 @@ def get_general_farm_status(request, device_id, stations): # Weather station. if stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_WIND): status[ID_WEATHER][ID_WIND] = data + elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_WIND_DIR): + status[ID_WEATHER][ID_WIND_DIR] = data + elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LUMINOSITY): + status[ID_WEATHER][ID_LUMINOSITY] = data + elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN_ACC): + status[ID_WEATHER][ID_RAIN_ACC] = data elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN): status[ID_WEATHER][ID_RAIN] = data elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RADIATION): status[ID_WEATHER][ID_RADIATION] = data + elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_TEMPERATURE): + status[ID_WEATHER][ID_TEMPERATURE] = data # Water tank. elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LEVEL): status[ID_TANK][ID_LEVEL] = data diff --git a/agriculture/agriculturecore/templates/dashboard.html b/agriculture/agriculturecore/templates/dashboard.html index fed186c..cef1348 100644 --- a/agriculture/agriculturecore/templates/dashboard.html +++ b/agriculture/agriculturecore/templates/dashboard.html @@ -88,9 +88,9 @@
Weather station
- km/h - L/m² - W/m² + km/h () + L/m² + lux diff --git a/agriculture/agriculturecore/templates/history.html b/agriculture/agriculturecore/templates/history.html index 40f295e..df6f33f 100644 --- a/agriculture/agriculturecore/templates/history.html +++ b/agriculture/agriculturecore/templates/history.html @@ -10,10 +10,10 @@
Historic data: Irrigation controller
-
+
- Wind speed + Wind
@@ -36,7 +36,7 @@
Historic data: Irrigation controller
-
+
Rain @@ -62,32 +62,58 @@
Historic data: Irrigation controller
-
+
- Solar radiation + Luminosity
-
-
+
+
Loading...
+
+
+ + Temperature +
+
+
+
+ Loading... +
+
+
+ + + + +
+
@@ -113,9 +139,14 @@
Historic data: Irrigation controller
drawRainChart(true, true); }); - $("input[type=radio][name=radiation-interval]").change(function() { - radiationInterval = this.value; - drawRadiationChart(true, true); + $("input[type=radio][name=luminosity-interval]").change(function() { + luminosityInterval = this.value; + drawLuminosityChart(true, true); + }); + + $("input[type=radio][name=temperature-interval]").change(function() { + temperatureInterval = this.value; + drawTemperatureChartG(true, true); }); }); @@ -124,4 +155,5 @@
Historic data: Irrigation controller
drawAllCharts(); }); + {% endblock %} \ No newline at end of file diff --git a/agriculture/agriculturecore/templates/sidebar.html b/agriculture/agriculturecore/templates/sidebar.html index 28d72f7..49b2b85 100644 --- a/agriculture/agriculturecore/templates/sidebar.html +++ b/agriculture/agriculturecore/templates/sidebar.html @@ -20,22 +20,7 @@ " + "
" + @@ -79,16 +80,19 @@ const INFO_WINDOW_CONTENT_CONTROLLER = "" + " " + "
" + "
" + - " @@RADIATION@@ W/m²" + + " @@LUMINOSITY@@ lux" + "
" + "
" + "
"; const CLASS_STATUS_LOADING = "marker-info-value-status-loading"; const CLASS_BUTTON_STATUS_OFF = "marker-info-button-off"; -const ID_WIND = "wind"; +const ID_WIND = "wind_speed"; +const ID_WIND_DIR = "wind_direction"; const ID_RADIATION = "radiation"; -const ID_RAIN = "rain"; +const ID_LUMINOSITY = "luminosity"; +const ID_RAIN = "rain_diff"; +const ID_RAIN_ACC = "rain_acc"; const ID_LEVEL = "level"; const ID_VALVE = "valve"; const ID_TEMPERATURE = "temperature"; @@ -101,7 +105,7 @@ const ID_STATIONS = "stations"; const ID_WEATHER = "weather"; const ID_TANK = "tank"; -const REFRESH_INTERVAL = 30000; +const REFRESH_INTERVAL = 10000; const SUN_GREEN = ""; const CLOUD_GREEN = ""; @@ -131,8 +135,12 @@ var stationMoistures = {}; var stationBatteries = {}; var stationValves = {}; var controllerWind = null; +var controllerWindDir = null; var controllerRain = null; +var controllerRainDiff = null; var controllerRadiation = null; +var controllerLuminosity = null; +var controllerTemperature = null; var tankValve; var waterLevel; @@ -146,7 +154,6 @@ var currentWeatherIcon; var currentWeatherStatus; var avgTemp = 23.0; // Define initial value for the temperature so if no stations are registered the weather forecast can be displayed. - var bounds; var markersZIndex = 0; @@ -275,13 +282,13 @@ function processFarmStatusResponse(response, first) { updateCurrentWeather(); }); drawDevices(response); - updateWeatherWidget(); } updateStationsStatus(response); updateStationCounters(response); updateWeatherStation(response); updateWaterTank(response); updateCurrentWeather(); + updateWeatherWidget(); // Hide the station loading. loadingStationsStatus = false; @@ -507,7 +514,7 @@ function updateWeatherStation(response) { let weatherStationStatus = response[ID_STATUS][ID_WEATHER]; - // Update the wind value. + // Update the wind speed value. controllerWind = weatherStationStatus[ID_WIND]; let controllerWindElement = document.getElementById(ID_WIND); if (controllerWindElement != null) @@ -516,25 +523,64 @@ function updateWeatherStation(response) { if (controllerWindInfowElement != null) controllerWindInfowElement.innerText = weatherStationStatus[ID_WIND]; + // Update the wind direction value. + controllerWindDir = weatherStationStatus[ID_WIND_DIR]; + dir = getControllerWindDirString(controllerWindDir); + + let controllerWindDirElement = document.getElementById(ID_WIND_DIR); + if (controllerWindDirElement != null) + controllerWindDirElement.innerText = dir; + let controllerWindDirInfowElement = document.getElementById("infow-wind_dir"); + if (controllerWindDirInfowElement != null) + controllerWindDirInfowElement.innerText = dir; + // Update the rain value. - controllerRain = weatherStationStatus[ID_RAIN]; - let controllerRainElement = document.getElementById(ID_RAIN); + controllerRainDiff = weatherStationStatus[ID_RAIN]; + controllerRain = weatherStationStatus[ID_RAIN_ACC]; + let controllerRainElement = document.getElementById(ID_RAIN_ACC); if (controllerRainElement != null) - controllerRainElement.innerText = weatherStationStatus[ID_RAIN]; + controllerRainElement.innerText = weatherStationStatus[ID_RAIN_ACC]; let controllerRainInfowElement = document.getElementById("infow-rain"); if (controllerRainInfowElement != null) - controllerRainInfowElement.innerText = weatherStationStatus[ID_RAIN]; - - // Update the radiation value. - controllerRadiation = weatherStationStatus[ID_RADIATION]; - let controllerRadiationElement = document.getElementById(ID_RADIATION); - if (controllerRadiationElement != null) - controllerRadiationElement.innerText = weatherStationStatus[ID_RADIATION]; - let controllerRadiationInfowElement = document.getElementById("infow-radiation"); - if (controllerRadiationInfowElement != null) - controllerRadiationInfowElement.innerText = weatherStationStatus[ID_RADIATION]; + controllerRainInfowElement.innerText = weatherStationStatus[ID_RAIN_ACC]; + + // Update the luminosity value. + controllerLuminosity = weatherStationStatus[ID_LUMINOSITY]; + let controllerLuminosityElement = document.getElementById(ID_LUMINOSITY); + if (controllerLuminosityElement != null) + controllerLuminosityElement.innerText = weatherStationStatus[ID_LUMINOSITY]; + let controllerLuminosityInfowElement = document.getElementById("infow-luminosity"); + if (controllerLuminosityInfowElement != null) + controllerLuminosityInfowElement.innerText = weatherStationStatus[ID_LUMINOSITY]; + + // Update the temperature value. + controllerTemperature = weatherStationStatus[ID_TEMPERATURE]; + avgTemp = weatherStationStatus[ID_TEMPERATURE]; + let controllerTemperatureElement = document.getElementById("current-temp"); + if (controllerTemperatureElement != null) + controllerTemperatureElement.innerText = weatherStationStatus[ID_TEMPERATURE]; +} + +function getControllerWindDirString (controllerWindDir){ + if (controllerWindDir == 0) + return "N"; + else if (controllerWindDir == 8) + return "NE"; + else if (controllerWindDir == 16) + return "E"; + else if (controllerWindDir == 24) + return "SE"; + else if (controllerWindDir == 32) + return "S"; + else if (controllerWindDir == 40) + return "SW"; + else if (controllerWindDir == 48) + return "W"; + else if (controllerWindDir == 56) + return "NW"; } + // Updates the water tank information based on the given response. function updateWaterTank(response) { if (response[ID_STATUS] == null || response[ID_STATUS][ID_TANK] == null) @@ -648,22 +694,26 @@ function getStationInfoWindowContent(stationID) { function getControllerInfoWindowContent() { // Clone the content template. let content = INFO_WINDOW_CONTENT_CONTROLLER; - // Update the wind value. + // Update the wind speed value. if (controllerWind != null) content = content.replace("@@WIND@@", controllerWind); else content = content.replace("@@WIND@@", "-"); + // Update the wind direction value. + if (controllerWindDir != null) + content = content.replace("@@WIND_DIR@@", getControllerWindDirString(controllerWindDir)); + else + content = content.replace("@@WIND_DIR@@", "-"); // Update the rain value. if (controllerRain != null) content = content.replace("@@RAIN@@", controllerRain); else content = content.replace("@@RAIN@@", "-"); - // Update the radiation value. - if (controllerRadiation != null) - content = content.replace("@@RADIATION@@", controllerRadiation); + // Update the luminosity value. + if (controllerLuminosity != null) + content = content.replace("@@LUMINOSITY@@", controllerLuminosity); else - content = content.replace("@@RADIATION@@", "-"); - + content = content.replace("@@LUMINOSITY@@", "-"); return content; } @@ -911,16 +961,20 @@ function updateWeatherWidget() { // Updates the current weather data (icon, temperature and status). function updateCurrentWeather() { - // Calculate average temperature. - calculateAvgTemp(); - // Identify the current weather icon to use. currentWeatherIcon = SUN_GREEN; currentWeatherStatus = "sunny"; - if ($("#weather-rainy-logo").hasClass("selected-icon-widget")) { + + rain = controllerRainDiff + rain = parseInt(rain) + luminosity = document.getElementById("luminosity").innerText; + luminosity = parseInt(luminosity) + + if(rain != 0){ currentWeatherIcon = RAIN_GREEN; currentWeatherStatus = "rainy"; - } else if ($("#weather-cloudy-logo").hasClass("selected-icon-widget")) { + } + else if(rain == 0 && luminosity < 4000){ currentWeatherIcon = CLOUD_GREEN; currentWeatherStatus = "cloudy"; } @@ -930,11 +984,6 @@ function updateCurrentWeather() { if (currentWeather != null) currentWeather.innerHTML = currentWeatherIcon; - // Update current temperature. - let currentTemp = document.getElementById("current-temp"); - if (currentTemp != null) - currentTemp.innerText = avgTemp; - // Update current weather status. let currentStatus = document.getElementById("current-status"); if (currentStatus != null) diff --git a/agriculture/static/js/history.js b/agriculture/static/js/history.js index af80d8b..42e50a2 100644 --- a/agriculture/static/js/history.js +++ b/agriculture/static/js/history.js @@ -108,13 +108,16 @@ const STATION_CHART_HTML = "" + var windData; var rainData; var radiationData; +var luminosityData; var temperatureData = {}; +var temperatureDataG = {}; var moistureData = {}; var valveData = {}; var windInterval; var rainInterval; var radiationInterval; +var luminosityInterval; var temperatureInterval = {}; var moistureInterval = {}; var valveInterval = {}; @@ -126,12 +129,14 @@ function initCharts() { rainData = null; radiationData = null; temperatureData = {}; + temperatureDataG = {}; moistureData = {}; valveData = {}; windInterval = null; rainInterval = null; radiationInterval = null; + luminosityInterval = null; temperatureInterval = {}; moistureInterval = {}; valveInterval = {}; @@ -160,7 +165,8 @@ function drawAllCharts(refresh=false, showProgress=true) { drawWindChart(refresh, showProgress); drawRainChart(refresh, showProgress); - drawRadiationChart(refresh, showProgress); + drawLuminosityChart(refresh, showProgress); + drawTemperatureChartG(refresh, showProgress); for (macAddr in temperatureData) { drawTemperatureChart(macAddr, refresh, showProgress); @@ -181,13 +187,16 @@ function drawWindChart(refresh=false, showProgress=false) { $("#wind-chart-loading").show(); $.post("/ajax/get_wind", getJsonData(windInterval), function(response) { windData = response.data; - drawWindChart(); - $("#wind-chart-loading").hide(); + $.post("/ajax/get_wind_dir", getJsonData(windInterval), function(response2) { + windDirectionData = response2.data; + drawWindChart(); + $("#wind-chart-loading").hide(); + }); }).fail(function(response) { processErrorResponse(response); }); } else { - drawChart("wind-chart", windData, "Wind", "km/h", "#4F4F4F"); + drawChart("wind-chart", windData, "Wind speed", "km/h", "#4F4F4F", windDirectionData, "Direction", "Direction", "#3CE222"); } } @@ -196,7 +205,7 @@ function drawRainChart(refresh=false, showProgress=false) { if (refresh) { if (showProgress) $("#rain-chart-loading").show(); - $.post("/ajax/get_rain", getJsonData(rainInterval), function(response) { + $.post("/ajax/get_rain_acc", getJsonData(rainInterval), function(response) { rainData = response.data; drawRainChart(); $("#rain-chart-loading").hide(); @@ -204,7 +213,24 @@ function drawRainChart(refresh=false, showProgress=false) { processErrorResponse(response); }); } else { - drawChart("rain-chart", rainData, "Rain", "mm", "#3399FF"); + drawChart("rain-chart", rainData, "Rain", "L/m²", "#3399FF"); + } +} + +// Draws the luminosity chart. +function drawLuminosityChart(refresh=false, showProgress=false) { + if (refresh) { + if (showProgress) + $("#luminosity-chart-loading").show(); + $.post("/ajax/get_luminosity", getJsonData(luminosityInterval), function(response) { + luminosityData = response.data; + drawLuminosityChart(); + $("#luminosity-chart-loading").hide(); + }).fail(function(response) { + processErrorResponse(response); + }); + } else { + drawChart("luminosity-chart", luminosityData, "Luminosity", "Lux", "#FFD500"); } } @@ -221,11 +247,28 @@ function drawRadiationChart(refresh=false, showProgress=false) { processErrorResponse(response); }); } else { - drawChart("radiation-chart", radiationData, "Radiation", "W/m2", "#FFD500"); + drawChart("radiation-chart", radiationData, "Radiation", "W/m²", "#FFD500"); } } -// Draws the temperature chart. +// Draws the temperature chart of gateway. +function drawTemperatureChartG(refresh=false, showProgress=false) { + if (refresh) { + if (showProgress) + $("#temperature-chart-loading").show(); + $.post("/ajax/get_temperature", getJsonData(temperatureInterval), function(response) { + temperatureDataG = response.data; + drawTemperatureChartG(); + $("#temperature-chart-loading").hide(); + }).fail(function(response) { + processErrorResponse(response); + }); + } else { + drawChart("temperature-chart", temperatureDataG, "Temperature", "ºC", "#FF0000"); + } +} + +// Draws the temperature chart of xbees. function drawTemperatureChart(macAddr, refresh=false, showProgress=false) { if (refresh) { if (showProgress) @@ -277,13 +320,16 @@ function drawValveChart(macAddr, refresh=false, showProgress=false) { } // Draws the chart with the given data. -function drawChart(id, data, title, units, color=null) { - if (!isHistoryShowing()) +function drawChart(id, data, title, units, color=null, data2=null, units2=null, title2=null, color2=null) { + if (!isHistoryShowing() || id === undefined) return; var dataTable = new google.visualization.DataTable(); - dataTable.addColumn("date", ""); - dataTable.addColumn("number", ""); + dataTable.addColumn('date', ''); + dataTable.addColumn("number", title); + if (data2 != null){ + dataTable.addColumn("number", title2); + } if (data.length == 0) { $("#" + id).empty(); @@ -291,41 +337,77 @@ function drawChart(id, data, title, units, color=null) { return; } - dataTable.addRows(data.length); + var maximumLength = data.length; + if (data2 != null && data2.length > maximumLength) { + maximumLength = data2.length; + } + + dataTable.addRows(maximumLength); $.each(data, function(k, v) { - dataTable.setCell(k, 0, new Date(v["timestamp"])); - dataTable.setCell(k, 1, v["data"]); + dataTable.setCell(k, 0, new Date(v["timestamp"])); + dataTable.setCell(k, 1, v["data"]); }); - var options = { - backgroundColor: "transparent", - series: { - 0: { - axis: "Data", - color: color, - visibleInLegend: false - } - }, - axes: { - y: { - Data: { - label: units - } - } - }, - legend: { - position: "none" - }, - vAxis: { - viewWindow: { - min: 0 - } - } - }; + if(data2 != null){ + $.each(data2, function(k, v) { + dataTable.setCell(k, 2, v["data"]); + }); + } + + var options = null; + + if(data2 == null && id == "rain-chart"){ + options = { + backgroundColor: "transparent", + series: { + 0: { targetAxisIndex: 0, color: color}, + }, + vAxes: { + // Adds titles to each axis. + 0: {title: units, ticks: [{v: 0}, {v: 8}, {v: 16}, {v: 24}, {v: 32}, {v: 40}, {v: 48}, {v: 56} , {v: 64}]} + }, + + legend: { position: 'bottom' }, + tooltip: { ignoreBounds: true, isHtml: true, trigger: 'both' } + }; + } + else if(data2 == null && id != "rain-chart"){ + options = { + backgroundColor: "transparent", + series: { + 0: {targetAxisIndex: 0, color: color} + }, + vAxes: { + // Adds titles to each axis. + 0: {title: units, viewWindow: {min: 0}} + }, + + legend: { position: 'bottom' }, + tooltip: { ignoreBounds: true, isHtml: true, trigger: 'both' } + }; + } + else if(data2 != null){ + options = { + backgroundColor: "transparent", + + series: { + 0: {targetAxisIndex: 0, color: color}, + 1: {targetAxisIndex: 1, color: color2} + }, + vAxes: { + // Adds titles to each axis. + 0: {title: units, minValue: 0, ticks: [{v: 0}, {v: 8}, {v: 16}, {v: 24}, {v: 32}, {v: 40}, {v: 48}, {v: 56}]}, + 1: {title: units2, minValue: 0, ticks: [{v: 0, f: 'N'}, {v: 8, f: 'NE'}, {v: 16, f: 'E'}, {v: 24, f: 'SE'}, {v: 32, f: 'S'}, {v: 40, f: 'SW'}, {v: 48, f: 'W'}, {v: 56, f: 'NW'}]} + }, + + legend: { position: 'bottom' }, + tooltip: { ignoreBounds: true, isHtml: true, trigger: 'both' } + }; + } - var chart = new google.charts.Line(document.getElementById(id)); - chart.draw(dataTable, google.charts.Line.convertOptions(options)); + var chart = new google.visualization.LineChart(document.getElementById(id)); + chart.draw(dataTable, options); } // Draws the charts of the irrigation stations. diff --git a/agriculture/static/js/widgets.js b/agriculture/static/js/widgets.js index e898402..3509692 100644 --- a/agriculture/static/js/widgets.js +++ b/agriculture/static/js/widgets.js @@ -18,32 +18,6 @@ var currentTime; var currentTimeFactor; var timeWorker; -// Sets the new weather condition. -function setWeatherCondition(e) { - e.preventDefault(); - - var selected = $(this).attr("value"); - selectWeatherIcon(selected); - - $.post("/ajax/set_condition", getJsonData(selected)).fail(function(response) { - // If the operation fails, get the real condition. - getWeatherCondition(); - }).fail(function(response) { - processErrorResponse(response); - }); -} - -// Gets the current weather condition. -function getWeatherCondition() { - var data = getJsonData(); - - $.post("/ajax/get_condition", getJsonData(), function(response) { - var resp = response["data"]; - selectWeatherIcon(resp); - }).fail(function(response) { - processErrorResponse(response); - }); -} // Sets the new time factor. function setTimeFactor(e) { @@ -93,22 +67,6 @@ function getCurrentTime() { }); } -// Marks the weather icon with the given value as selected. -function selectWeatherIcon(value) { - unselectWeatherIcons(); - if (value == document.getElementById("weather-sunny").value) - $("#weather-sunny-logo").addClass("selected-icon-widget"); - else if (value == document.getElementById("weather-cloudy").value) - $("#weather-cloudy-logo").addClass("selected-icon-widget"); - else if (value == document.getElementById("weather-rainy").value) - $("#weather-rainy-logo").addClass("selected-icon-widget"); -} - -// Unselects all the weather icons. -function unselectWeatherIcons() { - $(".weather-icon").removeClass("selected-icon-widget"); -} - // Marks the time icon with the given value as selected. function selectTimeIcon(value) { unselectTimeIcons();