From af581060fcb22ea5aa664e11f942e3fb108ed182 Mon Sep 17 00:00:00 2001 From: dk-15 Date: Fri, 26 May 2017 00:01:35 +0530 Subject: Add new_cron_job.sh for django 1.11 and include log_generator in maintenance management --- date.txt | 2 +- maintenance/__init__.py | 0 maintenance/admin.py | 6 +++++ maintenance/apps.py | 8 +++++++ maintenance/management/__init__.py | 0 maintenance/management/commands/__init__.py | 1 + maintenance/management/commands/log_generator.py | 20 +++++++++++++++++ maintenance/migrations/__init__.py | 0 maintenance/models.py | 6 +++++ maintenance/tests.py | 6 +++++ maintenance/views.py | 6 +++++ map_machine_ids.txt | 28 ------------------------ new_cron_job.sh | 24 ++++++++++++++++++++ sbhs_server/sbhs.py | 2 +- sbhs_server/settings.py | 7 ++++-- 15 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 maintenance/__init__.py create mode 100644 maintenance/admin.py create mode 100644 maintenance/apps.py create mode 100644 maintenance/management/__init__.py create mode 100644 maintenance/management/commands/__init__.py create mode 100644 maintenance/management/commands/log_generator.py create mode 100644 maintenance/migrations/__init__.py create mode 100644 maintenance/models.py create mode 100644 maintenance/tests.py create mode 100644 maintenance/views.py create mode 100644 new_cron_job.sh diff --git a/date.txt b/date.txt index 2312a90..0ac25fc 100644 --- a/date.txt +++ b/date.txt @@ -1 +1 @@ -Wed Jan 4 10:58:02 IST 2017 +Fri May 26 00:00:46 IST 2017 diff --git a/maintenance/__init__.py b/maintenance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/maintenance/admin.py b/maintenance/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/maintenance/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/maintenance/apps.py b/maintenance/apps.py new file mode 100644 index 0000000..4262aa8 --- /dev/null +++ b/maintenance/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class MaintenanceConfig(AppConfig): + name = 'maintenance' diff --git a/maintenance/management/__init__.py b/maintenance/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/maintenance/management/commands/__init__.py b/maintenance/management/commands/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/maintenance/management/commands/__init__.py @@ -0,0 +1 @@ + diff --git a/maintenance/management/commands/log_generator.py b/maintenance/management/commands/log_generator.py new file mode 100644 index 0000000..95c03d0 --- /dev/null +++ b/maintenance/management/commands/log_generator.py @@ -0,0 +1,20 @@ +#Dev/KoDe :) + +import csv +import datetime +import os +import sys +from django.core.management.base import BaseCommand, CommandError + +class Command(BaseCommand): + args = '' + help = 'Creates Log' + + def handle(self, *args, **options): + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sbhs_server.settings") # To make a Django Environment. + + from sbhs_server.tables.models import Board + board_details = Board.objects.values_list("online", flat=True) + board = str([x for x in board_details]) + with open('new.csv', "a") as newcsv: + newcsv.write("{0} {1} \n".format(datetime.datetime.now(), board.replace(",", "").replace("[", "").replace("]",""))) diff --git a/maintenance/migrations/__init__.py b/maintenance/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/maintenance/models.py b/maintenance/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/maintenance/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/maintenance/tests.py b/maintenance/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/maintenance/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/maintenance/views.py b/maintenance/views.py new file mode 100644 index 0000000..e784a0b --- /dev/null +++ b/maintenance/views.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. diff --git a/map_machine_ids.txt b/map_machine_ids.txt index 7b66f9f..d586cb4 100644 --- a/map_machine_ids.txt +++ b/map_machine_ids.txt @@ -1,29 +1 @@ -32=/dev/ttyUSB2 -25=/dev/ttyUSB1 52=/dev/ttyUSB0 -15=/dev/ttyUSB30 -16=/dev/ttyUSB36 -14=/dev/ttyUSB31 -11=/dev/ttyUSB41 -1=/dev/ttyUSB40 -8=/dev/ttyUSB39 -7=/dev/ttyUSB38 -2=/dev/ttyUSB32 -13=/dev/ttyUSB37 -10=/dev/ttyUSB35 -12=/dev/ttyUSB34 -9=/dev/ttyUSB33 -20=/dev/ttyUSB28 -17=/dev/ttyUSB26 -28=/dev/ttyUSB25 -24=/dev/ttyUSB24 -22=/dev/ttyUSB23 -18=/dev/ttyUSB22 -30=/dev/ttyUSB20 -29=/dev/ttyUSB18 -3=/dev/ttyUSB13 -6=/dev/ttyUSB12 -31=/dev/ttyUSB7 -19=/dev/ttyUSB6 -23=/dev/ttyUSB5 -5=/dev/ttyUSB3 diff --git a/new_cron_job.sh b/new_cron_job.sh new file mode 100644 index 0000000..f757e20 --- /dev/null +++ b/new_cron_job.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Django 1.11 compatible + + +find $(pwd) -iname \*.pyc -exec rm -rfv {} \; #to delete all .pyc files + +DIR="$( cd "$( dirname "$0" )" && pwd )" +cd $DIR +killall streamer +source ../bin/activate +#source ./bin/activate +python sbhs_server/scan_machines.py +#python offline_reconnect.py +python manage.py makemigrations +python manage.py migrate +python manage.py initialize_machines +python manage.py generate_checksum +touch index.wsgi +python manage.py log_generator + +#python log_generator.py +date > date.txt +sleep 2 \ No newline at end of file diff --git a/sbhs_server/sbhs.py b/sbhs_server/sbhs.py index c9620e9..f7873cb 100644 --- a/sbhs_server/sbhs.py +++ b/sbhs_server/sbhs.py @@ -1,7 +1,7 @@ import serial import os from time import localtime, strftime, sleep -import sbhs_server.credentials as credentials +import credentials MAP_FILE = credentials.MAP_FILE #LOG_FILE = '../log/sbhserr.log' diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py index b7ec8b7..1b6091f 100644 --- a/sbhs_server/settings.py +++ b/sbhs_server/settings.py @@ -72,6 +72,7 @@ INSTALLED_APPS = ( 'slot', 'sbhs_server.tables', 'webcam', + 'maintenance', ) MIDDLEWARE = ( @@ -236,8 +237,10 @@ WEBCAM_STATIC_DIR = 'img/webcam/' if not is_production: SBHS_ADMINS = ( - ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"), - ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"), + # ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"), + # ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"), + ('Debakanta Kar' , '0123456789' , 'kar.bubu.15@gmail.com'), + ('Deep Bhattacharyya' , '9876543210' , 'cr7.rick@gmail.com') ) else: from sbhs_server.sbhs_admin_config import SBHS_ADMINS -- cgit From 909763c658b4fff1f7a1697669aa381197f3daee Mon Sep 17 00:00:00 2001 From: dk-15 Date: Fri, 26 May 2017 03:06:14 +0530 Subject: Add features and fix bugs - Fix sorting bug in bookings - Prevent admin access during ongoing experiment - Fix trashable bug in slot deletion - Show only online machines in test boards --- myadmin/views.py | 21 ++++++++++++++++----- slot/views.py | 2 +- templates/admin/testexp.html | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/myadmin/views.py b/myadmin/views.py index a15770b..9e9c314 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -2,9 +2,9 @@ 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 +from sbhs_server.tables.models import Board, Booking, Slot from sbhs_server import settings,sbhs -import subprocess,json,serial,os +import subprocess,json,serial,os, datetime # Create your views here. def checkadmin(req): @@ -27,7 +27,7 @@ def toggle_allotment_mode(req): @login_required(redirect_field_name=None) def booking_index(req): checkadmin(req) - bookings = Booking.objects.order_by('-booking_date').select_related()[:50] + bookings = Booking.objects.order_by('-booking_date','-slot_id').filter(trashed_at__isnull=True).select_related()[:50] return render(req, 'admin/booking_index.html', {"bookings": bookings}) @login_required(redirect_field_name=None) @@ -78,9 +78,20 @@ def profile(req, mid): @login_required(redirect_field_name=None) def testing(req): checkadmin(req) - boards = Board.objects.order_by('online').all() + 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 + + current_bookings = Booking.objects.filter(slot_id=current_slot_id, + booking_date=datetime.date.today()).select_related() + current_mids = list([-1]) if not current_bookings else [current_booking.account.board.mid for current_booking in current_bookings] + + boards = Board.objects.filter(online=1) allotment_mode = "Random" if Board.can_do_random_allotment() else "Workshop" - return render(req, 'admin/testexp.html', {"boards": boards, "allotment_mode": allotment_mode}) + return render(req, 'admin/testexp.html', {"boards": boards, "allotment_mode": allotment_mode, "mids": current_mids}) @csrf_exempt def reset_device(req): diff --git a/slot/views.py b/slot/views.py index b137f93..5d22ac2 100644 --- a/slot/views.py +++ b/slot/views.py @@ -54,7 +54,7 @@ def create(req): @login_required(redirect_field_name=None) def index(req): - bookings = req.user.booking_set.select_related("slot").order_by("booking_date") + bookings = req.user.booking_set.select_related("slot").filter(trashed_at__isnull=True).order_by("booking_date") return render(req, "slot/index.html", {"bookings": reversed(bookings), "now_time": datetime.datetime.now()}) diff --git a/templates/admin/testexp.html b/templates/admin/testexp.html index 880f081..39291fa 100644 --- a/templates/admin/testexp.html +++ b/templates/admin/testexp.html @@ -2,6 +2,18 @@ {% load staticfiles %} {% block content %} +
{% include "account/sub_nav.html" %} @@ -15,6 +27,7 @@ Board MID Status + Occupied @@ -22,12 +35,13 @@ {{ b.mid }} {% if b.online %}Online{% else %}Offline{% endif %} + {% if b.mid in mids %}Ongoing{% else %}Vacant{% endif %} {% endfor %}
-
+

@@ -48,18 +62,29 @@
+
+ chal raha hain bhai +
+
-