summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2018-11-01 17:35:00 +0530
committerCruiseDevice2018-11-01 17:35:00 +0530
commit4050ec641b8cc4fef8d8a757c27bde0802b5c3e9 (patch)
tree68698c8b3da1a0b2a4a6540f667792192601e802
parent0bb3e3efd22a5a0f48c88720f6142bc3f49bc349 (diff)
downloadsbhs_server-4050ec641b8cc4fef8d8a757c27bde0802b5c3e9.tar.gz
sbhs_server-4050ec641b8cc4fef8d8a757c27bde0802b5c3e9.tar.bz2
sbhs_server-4050ec641b8cc4fef8d8a757c27bde0802b5c3e9.zip
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.
-rw-r--r--README.rst62
-rw-r--r--sbhs/models.py18
-rw-r--r--sbhs/templates/base.html27
-rw-r--r--sbhs/templates/dashboard/all_images.html18
-rw-r--r--sbhs/templates/dashboard/show_all_boards.html2
-rw-r--r--sbhs/templates/webcam/show_video.html54
-rw-r--r--sbhs/urls.py5
-rw-r--r--sbhs/views.py34
-rw-r--r--sbhs_server/settings.py11
9 files changed, 207 insertions, 24 deletions
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 %}
</head>
<body>
+
<div id = "header">
{% block nav %}
@@ -35,7 +36,7 @@
{% if user.is_authenticated %}
<li id="book-slot-nav"><a href="{% url 'slot_new' %}">Book slot</a></li>
<li id="download-log-nav"><a href="{% url 'experiment_logs' %}">Download log files</a></li>
- <li id="video-nav"><a href="">Show video</a></li>
+ <li id="video-nav"><a href="{% url 'show_video' %}">Show video</a></li>
{% if user.profile.is_moderator %}
<li id="admin-nav"><a href="{% url 'moderator_dashboard' %}">Moderator Dashboard</a></li>
{% endif %}
@@ -58,7 +59,7 @@
<div class="dropdown-menu">
<ul class="nav">
<li><a class="dropdown-item" href="{% url 'password_change'%}">Change Password</a></li>
- <li><a>Request machine change</a></li>
+ <li><a data-toggle="modal" data-target="#myModal">Request Machine Change</a></li>
<li><a href="{% url 'account_logout' %}">Logout</a></li>
</ul>
</div>
@@ -91,7 +92,6 @@
</div>
</div>
-
<div class="footer" id = "footer">
{% block footer %}
@@ -138,6 +138,25 @@
</div>
</div>
-
+{% if user.is_authenticated %}
+ <!-- Modal -->
+ <div class="modal fade" id="myModal" role="dialog">
+ <div class="modal-dialog">
+ <!-- Modal content-->
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal">&times;</button>
+ <h3>Machine change</h3>
+ </div>
+ <div class="modal-body">
+ <p>Please send an email to <strong>rupakrokade@iitb.ac.in</strong> stating the reasons why machine change is required.</p>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+ </div>
+ </div>
+ </div>
+ </div>
+{% endif %}
</body>
</html>
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 %}
- <div>
- <h4>All Images</h4>
+ <div class = "container">
+ <div class = "row">
+ {% for b in boards %}
+ <div class="span4" style="text-align: center; outline: 1px solid black">
+ <img src="{% static b.image_link %}" alt="{{ b.mid }}" style="width:90%;">
+ <br>
+ Board MID: {{ b.mid }}
+ </div>
+ {% endfor %}
</div>
+ </div>
+<script type="text/javascript">
+ var timer = setInterval(function(){
+ location.reload();
+ }, 25000);
+</script>
{% 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 @@
<td>{{board.mid}}</td>
<td><span style="cursor: pointer;" class = "label label-{% if board.online %}success{% else %}danger{% endif %}">{% if board.online %}Online{% else %}Offline{% endif %}</span></td>
<td><span style="cursor: pointer;" class = "label label-{% if board.online %}success{% else %}danger{% endif %}">{% if board.online %}On{% else %}Off{% endif %}</span></td>
- <td><a href = "">View Image</a></td>
+ <td><a href = "{% url 'show_video_to_moderator' board.mid %}">View Image</a></td>
<td><a href = "{% url 'profile' board.mid %}">View Profile</a></td>
<td><a href = "{% url 'download_log' board.mid %}" target="_blank">Download</a></td>
</tr>
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 %}
+ <script type="{% static 'js/jquery-ui.js' %}"></script>
+ <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
+ {% endblock %}
+ <br>
+ <div>
+ <div>
+ <script type="text/javascript">
+ document.getElementById("video-nav").classList.add("active");
+ </script>
+ <div class = "">
+ <h3>SBHS live feed: Machine ID {{mid}}</h3>
+ <div class = "offeset4" style="text-align:center;">
+ </div>
+ <img src="{% static image_link %}" id="videoImage" alt="SBHS live feed" class = "offeset4">
+ <div class = "offeset4" style="text-align:center">
+ <a href="#" onclick = "image_reloader()" id = "image_reloader" class = "btn btn-primary btn-large">Refresh Image.</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ <script type="text/javascript">
+ {% if request.user.profile.is_moderator %}
+ setInterval(function(){
+ var refresh = new Image();
+ refresh.src = "{% url 'reload_image' mid %}";
+ document.getElementById("videoImage").src = "{% static image_link %}" + new Date().getTime();
+ }, 2000);
+ {% else %}
+ window.image_reloader = function(){
+ var button = document.getElementById("image_reloader");
+
+ if (!button.disabled){
+ button.setAttribute("disabled", true);
+ var refresh = new Image();
+ refresh.src = "{% url 'reload_image' mid %}";
+ document.getElementById("videoImage").src = "{% static image_link %}" + new Date.getTime();
+ setTimeout(function(){
+ button.removeAttribute("disabled");
+ }, 3000);
+ }
+ }
+ (function(){
+ image_reloader();
+ })();
+ {% endif %}
+ </script>
+{% 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<mid>\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/'
+