From 4050ec641b8cc4fef8d8a757c27bde0802b5c3e9 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 1 Nov 2018 17:35:00 +0530 Subject: Update documentation in README and Add webcam features in SBHS - Admin can view all SBHS live feeds. - User can view their allocated live feed. - Request machine change modal fix in base.html. --- README.rst | 62 +++++++++++++++++++++++---- sbhs/models.py | 18 +++++--- sbhs/templates/base.html | 27 ++++++++++-- sbhs/templates/dashboard/all_images.html | 18 +++++++- sbhs/templates/dashboard/show_all_boards.html | 2 +- sbhs/templates/webcam/show_video.html | 54 +++++++++++++++++++++++ sbhs/urls.py | 5 +++ sbhs/views.py | 34 ++++++++++++++- sbhs_server/settings.py | 11 ++++- 9 files changed, 207 insertions(+), 24 deletions(-) create mode 100644 sbhs/templates/webcam/show_video.html diff --git a/README.rst b/README.rst index 2e84876..8d686a7 100644 --- a/README.rst +++ b/README.rst @@ -4,20 +4,64 @@ SINGLE BOARD HEATER SYSTEM INSTALLATION GUIDE ~~~~~~~~~~~~~~~~~~ -1. Clone from github server - https://github.com/CruiseDevice/sbhs_server +1. Clone from the SBHS Github server :: + https://github.com/CruiseDevice/sbhs_server + 2. Create a virtual environment, using command `virtualenv` and activate - the virtualenv. We recommend using Python 3.:: - virtualenv myenv -p python3 - source myenv/bin/activate + the virtualenv. We recommend using Python 3:: +virtualenv myenv -p python3 +source myenv/bin/activate 3. Install necessary packages from requirements.txt using command:: pip install -r requirements.txt -4. Make first migrations by using the commands :: - python manage..py makemigrations - python manage..py migrate -5. Please fill in the necessary information in the file + +4. Add ``'crispy_forms'`` to INSTALLED_APPS in ``settings.py`` + +5. Make first migrations by using the commands :: + python manage.py makemigrations + python manage.py migrate + +6. Create superuser by using the command :: + python manage.py createsuperuser + + Enter the admin ``username`` and ``email`` you want, then enter the admin + ``password``. + +7. Create moderator group by using command :: + python manage.py create_moderator + +8. Please fill in the necessary information in the file ``sbhs_server/credentials.py``. -6. In ``sbhs_server/settings.py``, fill in the following details - + +9. In ``sbhs_server/settings.py``, fill in the following details - + a. If SBHS devices are connected to a cluster of Raspberry Pis or other similar machines, enter the raspberry pi IPs in the variable ``RASP_PI_IP``. + + b. If the SBHS devices are connected directly to the main server through + USB, Keep ``RASP_PI_IP`` empty and the server will detect devices + automatically. + +10. Run the server by using the command :: + python manage.py runserver + +11. Once the server is running successfully, go to the URL ``http://localhost:8000/account/enter/`` + + To create a normal user, just fill the registration form and submit. You can + the login with the created normal user. + + To create a moderator :: + * First create a normal user by filling the registration form and submitting + it + * Then go to django admin by entering URL ``http://localhost:8000/admin`` + * Login into admin my using credentials you entered while creating admin + in ``step ?`` + * Go to the ``profile`` section and click on the user you just created. + * Tick is_moderator checkbox and click on save. + * Exit the admin by loggin out of it. + + Now you have created a moderator account. With moderator account you can + view state of all the SBHS connected, all the logs of the all the users, + all the slots booked by the users, and also the profile of each SBHS. + diff --git a/sbhs/models.py b/sbhs/models.py index 2cdbb90..506ba14 100644 --- a/sbhs/models.py +++ b/sbhs/models.py @@ -66,6 +66,13 @@ class Board(models.Model): self.userboard_set.all().count() ) + def image_link(self): + """ + Function to show the image obtained from webcam + """ + return settings.WEBCAM_STATIC_DIR + "image" + '0' + str(self.mid) \ + + ".jpeg" + class Profile(models.Model): """ Profile model to store user details. @@ -167,12 +174,11 @@ class UserBoard(models.Model): def __str__(self): return '{0}: {1}'.format(self.user.username, self.board.mid) -class Webcam(): - - def __init__(self): - pass +class Webcam(object): - def load_image(className,mid): + @staticmethod + def load_image(mid): command = "timeout 2s streamer -q -f jpeg -c /dev/video" + '0'+str(mid) - command += " -o " + settings.WEBCAM_DIR + "image" + '0'+str(mid) + ".jpeg" + command += " -o " + settings.WEBCAM_DIR + "image" + '0'+str(mid) \ + + ".jpeg" os.system(command) \ No newline at end of file diff --git a/sbhs/templates/base.html b/sbhs/templates/base.html index 099488b..65f05b9 100644 --- a/sbhs/templates/base.html +++ b/sbhs/templates/base.html @@ -20,6 +20,7 @@ {% endblock %} + - - +{% if user.is_authenticated %} + + +{% endif %} diff --git a/sbhs/templates/dashboard/all_images.html b/sbhs/templates/dashboard/all_images.html index 102a93b..5a7b74e 100644 --- a/sbhs/templates/dashboard/all_images.html +++ b/sbhs/templates/dashboard/all_images.html @@ -1,9 +1,23 @@ {% extends 'dashboard/dashboard_index.html' %} +{% load staticfiles %} {% block title %} All Images {% endblock %} {% block main %} -
-

All Images

+
+
+ {% for b in boards %} +
+ {{ b.mid }} +
+ Board MID: {{ b.mid }} +
+ {% endfor %}
+
+ {% endblock %} \ No newline at end of file diff --git a/sbhs/templates/dashboard/show_all_boards.html b/sbhs/templates/dashboard/show_all_boards.html index e247ffe..6ede6d8 100644 --- a/sbhs/templates/dashboard/show_all_boards.html +++ b/sbhs/templates/dashboard/show_all_boards.html @@ -27,7 +27,7 @@ {{board.mid}} {% if board.online %}Online{% else %}Offline{% endif %} {% if board.online %}On{% else %}Off{% endif %} - View Image + View Image View Profile Download diff --git a/sbhs/templates/webcam/show_video.html b/sbhs/templates/webcam/show_video.html new file mode 100644 index 0000000..1f372d7 --- /dev/null +++ b/sbhs/templates/webcam/show_video.html @@ -0,0 +1,54 @@ +{% extends "account/home.html" %} +{% load staticfiles %} +{% block title %} + Show video +{% endblock %} +{% block content %} + {% block headerfiles %} + + + {% endblock %} +
+
+
+ +
+

SBHS live feed: Machine ID {{mid}}

+
+
+ SBHS live feed + +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/sbhs/urls.py b/sbhs/urls.py index 001572e..b4df2a6 100644 --- a/sbhs/urls.py +++ b/sbhs/urls.py @@ -92,4 +92,9 @@ urlpatterns = [ name='download_file'), url(r'^moderator/updatemid/$', views.update_mid, name='update_mid'), + url(r'^moderator/webcam/(?P\d+)/$',views.show_video_to_moderator, + name='show_video_to_moderator'), + ####################### Webcam Url ######################### + url(r'^show_video/$',views.show_video,name='show_video'), + url(r'^reload_image/(.*)/$',views.reload,name='reload_image'), ] diff --git a/sbhs/views.py b/sbhs/views.py index 3b6db2f..f486cfb 100644 --- a/sbhs/views.py +++ b/sbhs/views.py @@ -739,9 +739,14 @@ def all_bookings(request): @login_required def all_images(request): user = request.user + context = {} if not is_moderator(user): raise Http404("You are not allowed to see this page.") else: + boards = Board.objects.filter(online=True) + for board in boards: + Webcam.load_image(board.mid) + context["boards"] = boards return render(request,'dashboard/all_images.html') @@ -891,5 +896,32 @@ def reload(request, mid): Webcam.load_image(mid) return HttpResponse("") +@login_required def show_video(request): - board = request.user + """ + Show the video of the SBHS. + """ + user = request.user + context = {} + board = UserBoard.objects.filter(user=user).order_by("id").last() + image_link = board.board.image_link() + mid = str(board.board.mid) + context["image_link"] = image_link + context["mid"] = mid + return render(request, 'webcam/show_video.html',context) + +@login_required +def show_video_to_moderator(request,mid): + """ + Shows the video of all the SBHSs to the moderator. + """ + user = request.user + context = {} + if not is_moderator(user): + raise Http404("You are not allowed to view this page.") + else: + board = Board.objects.get(mid=mid) + image_link = board.image_link() + context["image_link"] = image_link + context["mid"] = mid + return render(request, 'webcam/show_video.html',context) diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py index a3545dc..d3d4b8d 100644 --- a/sbhs_server/settings.py +++ b/sbhs_server/settings.py @@ -194,5 +194,14 @@ EXPERIMENT_LOGS_DIR = os.path.join(BASE_DIR, 'experiments') SBHS_GLOBAL_LOG_DIR = os.path.join(BASE_DIR, 'log') # Path for sbhs global log directory on Django server. + # Advance slot booking LIMIT for a day. -LIMIT = 2 \ No newline at end of file +LIMIT = 2 + +WEBCAM_DIR = os.path.join(STATIC_ROOT, 'img/webcam/') if IS_DEVELOPMENT \ + else os.path.join( + BASE_DIR, + 'static/img/webcam/' + ) +WEBCAM_STATIC_DIR = 'img/webcam/' + -- cgit