summaryrefslogtreecommitdiff
path: root/myadmin
diff options
context:
space:
mode:
authorcoderick142017-05-26 17:34:54 +0530
committercoderick142017-05-26 17:34:54 +0530
commitb8e6e8474ba42509445933bf033e4e6c4981eb73 (patch)
tree5952d693eb1007559825b7204c0f406b0b07ba54 /myadmin
parent62e55de6d432edf52e60a2b562e160b74508f256 (diff)
downloadSBHS-2018-Rpi-b8e6e8474ba42509445933bf033e4e6c4981eb73.tar.gz
SBHS-2018-Rpi-b8e6e8474ba42509445933bf033e4e6c4981eb73.tar.bz2
SBHS-2018-Rpi-b8e6e8474ba42509445933bf033e4e6c4981eb73.zip
Add admin monitoring feature
Diffstat (limited to 'myadmin')
-rw-r--r--myadmin/urls.py1
-rw-r--r--myadmin/views.py37
2 files changed, 37 insertions, 1 deletions
diff --git a/myadmin/urls.py b/myadmin/urls.py
index c1831e5..4e929c7 100644
--- a/myadmin/urls.py
+++ b/myadmin/urls.py
@@ -11,6 +11,7 @@ urlpatterns = [
url(r'^admin/resetdevice/?$', views.reset_device, name='admin_reset_device'),
url(r'^admin/setdevice/?$', views.set_device_params, name='admin_set_device'),
url(r'^admin/gettemp/?$', views.get_device_temp, name='admin_get_temp'),
+ url(r'^admin/monitor/?$', views.monitor_experiment, name='admin_monitor'),
url(r'^admin/toggle_allotment_mode/?$', views.toggle_allotment_mode, name='admin_toggle_allotment_mode'),
diff --git a/myadmin/views.py b/myadmin/views.py
index 9e9c314..b4a4f33 100644
--- a/myadmin/views.py
+++ b/myadmin/views.py
@@ -2,7 +2,7 @@ from django.shortcuts import render, redirect
from django.http import Http404,HttpResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
-from sbhs_server.tables.models import Board, Booking, Slot
+from sbhs_server.tables.models import Board, Booking, Slot, Experiment
from sbhs_server import settings,sbhs
import subprocess,json,serial,os, datetime
# Create your views here.
@@ -94,6 +94,41 @@ def testing(req):
return render(req, 'admin/testexp.html', {"boards": boards, "allotment_mode": allotment_mode, "mids": current_mids})
@csrf_exempt
+def monitor_experiment(req):
+ checkadmin(req)
+ try:
+ mid = int(req.POST.get("mid"))
+ except Exception as e:
+ return HttpResponse(json.dumps({"status_code":400, "message":"Invalid parameters"}), content_type="application/json")
+
+ now = datetime.datetime.now()
+ current_slot_id = Slot.objects.filter(start_hour=now.hour,
+ start_minute__lt=now.minute,
+ end_minute__gt=now.minute)
+
+ current_slot_id = -1 if not current_slot_id else current_slot_id[0].id
+
+ try:
+ current_booking = Booking.objects.get(slot_id=current_slot_id,
+ booking_date=datetime.date.today(),
+ account__board__mid=mid)
+ except Exception as e:
+ return HttpResponse(json.dumps({"status_code":400, "message":"Invalid MID"}), content_type="application/json")
+
+ current_booking_id, current_user = current_booking.id, current_booking.account.username
+
+ logfile = Experiment.objects.get(booking_id=current_booking_id).log
+
+ # get last 50 lines from logs
+ stdin,stdout = os.popen2("tail -n 10 "+logfile)
+ stdin.close()
+ logs = stdout.readlines(); stdout.close()
+ logs = "".join(logs)
+
+ data = {"user": current_user, "logs": logs}
+ return HttpResponse(json.dumps({"status_code":200, "message":data}), content_type="application/json")
+
+@csrf_exempt
def reset_device(req):
"""Resets the device to fan = 100 and heat = 0
Takes mid as paramter