Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcoman/ces demo #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agriculture/.ebextensions/django.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: agriculturecommon.wsgi:application
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
5 changes: 5 additions & 0 deletions agriculture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
2 changes: 2 additions & 0 deletions agriculture/Procfile.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: gunicorn --bind :8000 --workers 3 --threads 2 agriculturecommon.wsgi:application
websocket: daphne -b :: -p 5000 agriculturecommon.asgi:application
4 changes: 2 additions & 2 deletions agriculture/agriculturecommon/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['127.0.0.1', 'django-env5.us-west-2.elasticbeanstalk.com', '172.31.27.57']


# Application definition
Expand Down Expand Up @@ -93,7 +93,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

Expand Down
3 changes: 3 additions & 0 deletions agriculture/agriculturecommon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from django.urls import include, path

urlpatterns = [

# path("index.html", include("app.urls")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be committed.


path("access/", include("login.urls")),

path("", include("agriculturecore.urls")),
Expand Down
6 changes: 4 additions & 2 deletions agriculture/agriculturecore/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ <h6 class="card-title">Weather station</h6>
<td><span class="digi-icon-color fas fa-sun fa-2x"></span></td>
</tr>
<tr>
<td><span id="wind_speed"><i class="fas fa-circle-notch fa-spin"></i></span> km/h</td>
<td><span id="rain_diff"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
<td><span id="wind_speed"><i class="fas fa-circle-notch fa-spin"></i></span> km/h (<span id="wind_direction"><i class="fas fa-circle-notch fa-spin"></i></span>)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either fill this space with the tag contained in the or put the tag right after the to avoid having this blank line.

</td>
<td><span id="rain_acc"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
<td><span id="luminosity"><i class="fas fa-circle-notch fa-spin"></i></span> lux</td>
</tr>
</tbody>
Expand Down
10 changes: 10 additions & 0 deletions agriculture/agriculturecore/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be committed, remove it.

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>
16 changes: 8 additions & 8 deletions agriculture/agriculturecore/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
"agriculture demo."


def farms_map(request):
if is_authenticated(request):
if request.method == "GET":
return TemplateResponse(request, 'map.html')
else:
return redirect_login(request)


def dashboard(request):
if not request_has_params(request):
return redirect("/")
Expand Down Expand Up @@ -74,14 +82,6 @@ def schedule(request):
return redirect_login(request)


def farms_map(request):
if is_authenticated(request):
if request.method == "GET":
return TemplateResponse(request, 'map.html')
else:
return redirect_login(request)


def verify_parameters(request):
"""
Verifies the URL parameters to check if the given farm name and controller
Expand Down
10 changes: 10 additions & 0 deletions agriculture/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file required?

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>
37 changes: 20 additions & 17 deletions agriculture/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
arrow==0.12.1
asgiref==3.2.10
backports.functools-lru-cache==1.6.1
certifi==2018.4.16
channels==3.0.2
chardet==3.0.4
devicecloud==0.5.7
Django==3.1
idna==2.10
python-dateutil==2.7.5
pytz==2020.1
requests==2.20.1
six==1.14.0
sqlparse==0.3.1
urllib3==1.25.10

django-pjax~=1.7
arrow==0.12.1
asgiref==3.2.10
backports.functools-lru-cache==1.6.1
certifi==2018.4.16
channels==3.0.3
chardet==3.0.4
devicecloud==0.5.7
Django==2.2
idna
python-dateutil==2.7.5
pytz==2020.1
requests==2.20.1
six==1.14.0
sqlparse==0.3.1
urllib3
django-pjax~=1.7
supervisor==4.2.2
gunicorn==20.0.4
daphne==3.0.1
channels-redis==3.2.0
24 changes: 12 additions & 12 deletions agriculture/run_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,18 @@ def main():

# If Python version is greater than 3.7, install the corresponding
# Twisted wheel so the channels module can be installed later on.
if sys.platform == "win32" and py_minor_version > 7:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo these changes, these lines should not be commented.

twisted = TWISTED_64 if is_64_bits_python() else TWISTED_32
twisted_path = os.path.join(
FOLDER_WHEELS,
twisted.format(py_major_version, py_minor_version))
print("- Installing Twisted wheel (%s)... " % twisted_path, end="")
sys.stdout.flush()
if run_venv_python(venv_context, ['-m', 'pip', 'install',
twisted_path], debug) != 0:
print_error()
sys.exit(-1)
print_success()
# if sys.platform == "win32" and py_minor_version > 7:
# twisted = TWISTED_64 if is_64_bits_python() else TWISTED_32
# twisted_path = os.path.join(
# FOLDER_WHEELS,
# twisted.format(py_major_version, py_minor_version))
# print("- Installing Twisted wheel (%s)... " % twisted_path, end="")
# sys.stdout.flush()
# if run_venv_python(venv_context, ['-m', 'pip', 'install',
# twisted_path], debug) != 0:
# print_error()
# sys.exit(-1)
# print_success()

# Install the application requirements.
print("- Installing application requirements: ")
Expand Down
Binary file added agriculture/source3.zip
Binary file not shown.
Binary file added agriculture/source4.zip
Binary file not shown.
55 changes: 45 additions & 10 deletions agriculture/static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const INFO_WINDOW_CONTENT_CONTROLLER = "" +
" <span class='digi-icon-color fas fa-wind fa-2x'></span>" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don´t know how to put this comment in source3.zip and source4.zip, so I put it here: Those files should not be committed.

" </div>" +
" <div class='marker-info-value'>" +
" <span id='infow-wind'>@@WIND@@</span> km/h" +
" <span id='infow-wind'>@@WIND@@</span> km/h (" +
" <span id='infow-wind_dir'>@@WIND_DIR@@</span>)" +
" </div>" +
" </div>" +
" <div class='marker-info-element'>" +
Expand All @@ -87,10 +88,11 @@ const CLASS_STATUS_LOADING = "marker-info-value-status-loading";
const CLASS_BUTTON_STATUS_OFF = "marker-info-button-off";

const ID_WIND = "wind_speed";
const ID_WIND_DIR = "wind_direction";
const ID_RADIATION = "radiation";
const ID_LUMINOSITY = "luminosity";
const ID_RAIN = "rain_diff";
const ID_RAIN_ACC = "rain";
const ID_RAIN_ACC = "rain_acc";
const ID_LEVEL = "level";
const ID_VALVE = "valve";
const ID_TEMPERATURE = "temperature";
Expand All @@ -103,7 +105,7 @@ const ID_STATIONS = "stations";
const ID_WEATHER = "weather";
const ID_TANK = "tank";

const REFRESH_INTERVAL = 30000;
const REFRESH_INTERVAL = 15000;

const SUN_GREEN = "<i class='selected-icon-widget fas fa-sun'></i>";
const CLOUD_GREEN = "<i class='selected-icon-widget fas fa-cloud'></i>";
Expand Down Expand Up @@ -133,6 +135,7 @@ var stationMoistures = {};
var stationBatteries = {};
var stationValves = {};
var controllerWind = null;
var controllerWindDir = null;
var controllerRain = null;
var controllerRadiation = null;
var controllerLuminosity = null;
Expand Down Expand Up @@ -508,7 +511,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)
Expand All @@ -517,14 +520,41 @@ function updateWeatherStation(response) {
if (controllerWindInfowElement != null)
controllerWindInfowElement.innerText = weatherStationStatus[ID_WIND];

// Update the wind direction value.
controllerWindDir = weatherStationStatus[ID_WIND_DIR];
dir = "";
if (controllerWindDir = 0)
dir = "N"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not mandatory in JavaScript, but better use ; at the end of each sentence.

if (controllerWindDir = 8)
dir = "NE"
if (controllerWindDir = 16)
dir = "E"
if (controllerWindDir = 24)
dir = "SE"
if (controllerWindDir = 32)
dir = "S"
if (controllerWindDir = 40)
dir = "SW"
if (controllerWindDir = 48)
dir = "W"
if (controllerWindDir = 56)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, this was fixed in a later commit, but just in case, use == to compare in an if block.

dir = "NW"

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 = weatherStationStatus[ID_WIND_DIR];

// Update the rain value.
controllerRain = weatherStationStatus[ID_RAIN];
let controllerRainElement = document.getElementById(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];
controllerRainInfowElement.innerText = weatherStationStatus[ID_RAIN_ACC];

// Update the luminosity value.
controllerLuminosity = weatherStationStatus[ID_LUMINOSITY];
Expand Down Expand Up @@ -656,11 +686,16 @@ 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@@", controllerWindDir);
else
content = content.replace("@@WIND_DIR@@", "-");
// Update the rain value.
if (controllerRain != null)
content = content.replace("@@RAIN@@", controllerRain);
Expand Down Expand Up @@ -919,7 +954,7 @@ function updateCurrentWeather() {
currentWeatherIcon = SUN_GREEN;
currentWeatherStatus = "sunny";

rain = document.getElementById("rain_diff").innerText;
rain = document.getElementById("rain_acc").innerText;
rain = parseInt(rain)
luminosity = document.getElementById("luminosity").innerText;
luminosity = parseInt(luminosity)
Expand Down
10 changes: 6 additions & 4 deletions agriculture/static/js/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ var rainData;
var radiationData;
var luminosityData;
var temperatureData = {};
var temperatureDataG = {};
var moistureData = {};
var valveData = {};

Expand All @@ -128,6 +129,7 @@ function initCharts() {
rainData = null;
radiationData = null;
temperatureData = {};
temperatureDataG = {};
moistureData = {};
valveData = {};

Expand Down Expand Up @@ -175,7 +177,7 @@ function drawAllCharts(refresh=false, showProgress=true) {
// Repeat the task every minute.
setTimeout(function() {
drawAllCharts(true, false);
}, 60000);
}, 15000);
}

// Draws the wind chart.
Expand Down Expand Up @@ -247,12 +249,12 @@ function drawTemperatureChartG(refresh=false, showProgress=false) {
if (showProgress)
$("#temperature-chart-loading").show();
$.post("/ajax/get_temperature", getJsonData(temperatureInterval), function(response) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add fail callback.

temperatureData = response.data;
temperatureDataG = response.data;
drawTemperatureChartG();
$("#temperature-chart-loading").hide();
});
} else {
drawChart("temperature-chart", temperatureData, "Temperature", "ºC", "#FF0000");
drawChart("temperature-chart", temperatureDataG, "Temperature", "ºC", "#FF0000");
}
}

Expand Down Expand Up @@ -350,7 +352,7 @@ function drawChart(id, data, title, units, color=null, data2=null, units2=null,
0: {title: units},
},
vAxis: {
ticks: [{v: 0}, {v: 4}, {v: 8}, {v: 12}, {v: 16}, {v: 20}, {v: 24}, {v: 28} ]
ticks: [{v: 0}, {v: 8}, {v: 16}, {v: 24}, {v: 32}, {v: 40}, {v: 48}, {v: 56} , {v: 64}]
},
legend: { position: 'bottom' }
};
Expand Down