diff options
Diffstat (limited to 'experiment/views.py')
-rw-r--r-- | experiment/views.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/experiment/views.py b/experiment/views.py index 3575094..c2424a1 100644 --- a/experiment/views.py +++ b/experiment/views.py @@ -10,10 +10,18 @@ from sbhs_server import settings # Create your views here. # def check_connection(req): + """ Checks if the connection exists or not. + Input: req:request object. + Output: HttpResponse object. + """ return HttpResponse("TESTOK") @csrf_exempt def initial_login(req): + """ Logs in an user for conducting the experiment on the specified board. + Input: req:request object. + Output: HttpResponse object. + """ username = req.POST.get("username") rpi_ip = '' try: @@ -28,6 +36,13 @@ def initial_login(req): # @login_required(redirect_field_name=None) @csrf_exempt def experiment(req): + """ Manages an ongoing experiment. + Alert the user when: + The slot has ended. + The slot wasn't booked. + Input: req:request object. + Output: HttpResponse object. + """ try: server_start_ts = int(time.time() * 1000) from sbhs_server.settings import boards @@ -86,6 +101,10 @@ def experiment(req): @csrf_exempt def reset(req): + """ Resets an experiment. + Input: req:request object. + Output: HttpResponse object. + """ try: from sbhs_server.settings import boards user = req.user @@ -110,10 +129,18 @@ def reset(req): return HttpResponse("") def client_version(req): + """ Input: req:request object. + Output: HttpResponse object. + """ return HttpResponse("3") @login_required(redirect_field_name=None) + def logs(req): + """ Renders experimental log files to the user interface. + Input: req:request object. + Output: HttpResponse object. + """ bookings = Booking.objects.only("id").filter(account__id=req.user.id) deleted_bookings = Booking.trash.only("id").filter(account__id=req.user.id) bookings = list(bookings) + list(deleted_bookings) @@ -125,6 +152,10 @@ def logs(req): @login_required(redirect_field_name=None) def download_log(req, experiment_id, fn): + """ Downloads the experimental log file. + Input: req: request object, experiment_id: experimental id, fn: filename. + Output: HttpResponse object + """ try: experiment_data = Experiment.objects.select_related("booking", "booking__account").get(id=experiment_id) assert req.user.id == experiment_data.booking.account.id @@ -136,6 +167,9 @@ def download_log(req, experiment_id, fn): return HttpResponse("Requested log file doesn't exist.") def log_data(sbhs, mid, experiment_id, heat=None, fan=None, temp=None): + """ Update the experimental log file. + Input: sbhs:board object, mid: machine-id of the SBHS, experiment_id: experimental id, heat: heater value, fan: fan value, temp: temperature. + """ if heat is None: heat = sbhs.getHeat() if fan is None: @@ -151,6 +185,10 @@ def log_data(sbhs, mid, experiment_id, heat=None, fan=None, temp=None): experiment_loghandler.write(data) def validate_log_file(req): + """ Validates the experimental log file. + Input: req: request object. + Output: HttpResponse object. + """ import hashlib data = req.POST.get("data") data = data.strip().split("\n") |