Use flowcell model information to estimate how long it will take to run the flowcell.
[htsworkflow.git] / htsworkflow / frontend / experiments / experiments.py
old mode 100755 (executable)
new mode 100644 (file)
index 3cdbc7b..fef68ed
@@ -9,10 +9,12 @@ import os
 import re
 
 from django.contrib.auth.decorators import login_required
+from django.views.decorators.csrf import csrf_exempt
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.mail import send_mail, mail_admins
 from django.http import HttpResponse, Http404
 from django.conf import settings
+from django.utils import timezone
 
 from htsworkflow.frontend.auth import require_api_key
 from htsworkflow.frontend.experiments.models import \
@@ -78,6 +80,7 @@ def flowcell_information(flowcell_id):
 
     return info
 
+@csrf_exempt
 def flowcell_json(request, fc_id):
     """
     Return a JSON blob containing enough information to generate a config file.
@@ -117,6 +120,7 @@ def lanes_for(username=None):
                         'affiliations': affiliations_list})
     return result
 
+@csrf_exempt
 def lanes_for_json(request, username):
     """
     Format lanes for a user
@@ -176,7 +180,7 @@ def updStatus(request):
       rec.run_status = UpdatedStatus
 
       #if there's a message update that too
-      mytimestamp = datetime.now().__str__()
+      mytimestamp = timezone.now().__str__()
       mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
       if request.REQUEST.has_key('msg'):
         rec.run_note += ", "+request.REQUEST['msg']+" ("+mytimestamp+")"
@@ -304,16 +308,11 @@ def estimateFlowcellDuration(flowcell):
     Attempt to estimate how long it will take to run a flowcell
 
     """
-    # (3600 seconds * 1.5 hours per cycle )
-    sequencing_seconds_per_cycle= 3600 * 1.5
-    # 800 is a rough guess
-    pipeline_seconds_per_cycle = 800
-
     cycles = flowcell.read_length
     if flowcell.paired_end:
         cycles *= 2
-    sequencing_time = timedelta(0, cycles * sequencing_seconds_per_cycle)
-    analysis_time = timedelta(0, cycles * pipeline_seconds_per_cycle)
+    sequencing_time = timedelta(0, cycles * flowcell.flowcell_model.per_cycle_time)
+    analysis_time = timedelta(0, flowcell.flowcell_model.fixed_time)
     estimate_mid = sequencing_time + analysis_time
 
     return estimate_mid
@@ -322,7 +321,7 @@ def estimateFlowcellTimeRemaining(flowcell):
     estimate_mid = estimateFlowcellDuration(flowcell)
 
     # offset for how long we've been running
-    running_time = datetime.now() - flowcell.run_date
+    running_time = timezone.now() - flowcell.run_date
     estimate_mid -= running_time
 
     return estimate_mid