def create_template_prep(self, exp): # handle Template Prep stage self.name = exp.plan.planDisplayedName self.date = exp.chefStartTime self.last_updated = exp.chefLastUpdate self.instrumentName = exp.chefInstrumentName # if run aborted only last update date is available if not self.date: self.date = self.last_updated if exp.plan.planStatus == "voided": self.state = ERROR self.error_string = exp.chefStatus elif exp.chefProgress < 100: self.state = IN_PROGRESS self.progress_string = "%d%%" % exp.chefProgress self.status_string = exp.chefStatus estimated_end_time = utils.convert_seconds_to_datetime_string( exp.chefLastUpdate, exp.chefRemainingSeconds) if estimated_end_time: self.status_string += ( " Until " + estimated_end_time.strftime("%I:%M%p").lower()) else: self.state = DONE self.update_application_and_samples(exp.plan)
def create_library_prep(self, sampleSet): # handle Library Prep stage self.name = sampleSet.displayedName self.date = sampleSet.libraryPrepInstrumentData.startTime self.last_updated = sampleSet.libraryPrepInstrumentData.lastUpdate self.instrumentName = sampleSet.libraryPrepInstrumentData.instrumentName if not self.date: self.date = self.last_updated if sampleSet.status == "voided": self.state = ERROR self.error_string = sampleSet.libraryPrepInstrumentData.instrumentStatus elif sampleSet.libraryPrepInstrumentData.progress < 100: self.state = IN_PROGRESS self.progress_string = "%d%%" % sampleSet.libraryPrepInstrumentData.progress self.status_string = sampleSet.libraryPrepInstrumentData.instrumentStatus estimated_end_time = utils.convert_seconds_to_datetime_string( sampleSet.libraryPrepInstrumentData.lastUpdate, sampleSet.libraryPrepInstrumentData.remainingSeconds, ) if estimated_end_time: self.status_string += ( " Until " + estimated_end_time.strftime("%I:%M %p").lower()) else: self.state = DONE # application icon for Chef library prep - don't show, it's visually distinct from run type icons # self.runType = sampleSet.libraryPrepType # self.applicationCategoryDisplayedName = sampleSet.get_libraryPrepType_display() # samples sampleSetItems = sampleSet.samples.order_by( "dnabarcode__id_str").values_list("sample__displayedName", "dnabarcode__id_str") samples = {} if len(sampleSetItems) == 1 and not sampleSetItems[0][1]: self.sampleDisplayedName = sampleSetItems[0][0] elif len(sampleSetItems) > 0: for sampleName, barcode in sampleSetItems: if sampleName not in samples: samples[sampleName] = { "sampleName": sampleName, "barcodes": barcode or "", } elif barcode: samples[sampleName]["barcodes"] += " " + barcode self.barcodedSamples = sorted( list(samples.values()), key=lambda x: (x["barcodes"], x["sampleName"].lower()), )
def create_library_prep(self, sampleSet): # handle Library Prep stage self.name = sampleSet.displayedName self.date = sampleSet.libraryPrepInstrumentData.startTime self.last_updated = sampleSet.libraryPrepInstrumentData.lastUpdate self.instrumentName = sampleSet.libraryPrepInstrumentData.instrumentName if not self.date: self.date = self.last_updated if sampleSet.status == "voided": self.state = ERROR self.error_string = sampleSet.libraryPrepInstrumentData.instrumentStatus elif sampleSet.libraryPrepInstrumentData.progress < 100: self.state = IN_PROGRESS self.progress_string = "%d%%" % sampleSet.libraryPrepInstrumentData.progress self.status_string = sampleSet.libraryPrepInstrumentData.instrumentStatus estimated_end_time = utils.convert_seconds_to_datetime_string(sampleSet.libraryPrepInstrumentData.lastUpdate, sampleSet.libraryPrepInstrumentData.remainingSeconds) if estimated_end_time: self.status_string += ' Until ' + estimated_end_time.strftime('%I:%M %p').lower() else: self.state = DONE # application icon for Chef library prep - don't show, it's visually distinct from run type icons #self.runType = sampleSet.libraryPrepType #self.applicationCategoryDisplayedName = sampleSet.get_libraryPrepType_display() # samples sampleSetItems = sampleSet.samples.order_by('dnabarcode__id_str').values_list('sample__displayedName', 'dnabarcode__id_str') samples = {} if len(sampleSetItems) == 1 and not sampleSetItems[0][1]: self.sampleDisplayedName = sampleSetItems[0][0] elif len(sampleSetItems) > 0: for sampleName, barcode in sampleSetItems: if sampleName not in samples: samples[sampleName] = { "sampleName": sampleName, "barcodes": barcode or "" } elif barcode: samples[sampleName]["barcodes"] += " " + barcode self.barcodedSamples = sorted( samples.values(), key=lambda x:(x['barcodes'],x['sampleName'].lower()) )
def create_template_prep(self, exp): # handle Template Prep stage self.name = exp.plan.planDisplayedName self.date = exp.chefStartTime self.last_updated = exp.chefLastUpdate self.instrumentName = exp.chefInstrumentName # if run aborted only last update date is available if not self.date: self.date = self.last_updated if exp.plan.planStatus == "voided": self.state = ERROR self.error_string = exp.chefStatus elif exp.chefProgress < 100: self.state = IN_PROGRESS self.progress_string = "%d%%" % exp.chefProgress self.status_string = exp.chefStatus estimated_end_time = utils.convert_seconds_to_datetime_string(exp.chefLastUpdate, exp.chefRemainingSeconds) if estimated_end_time: self.status_string += ' Until ' + estimated_end_time.strftime('%I:%M%p').lower() else: self.state = DONE self.update_application_and_samples(exp.plan)
def chef(request): querydict = request.GET days = get_int(querydict, "days", 7) size = get_int(querydict, "size", 10) page = get_int(querydict, "page", 1) days_ago = datetime.datetime.now() - datetime.timedelta(days=days) # monitoring page should show Chef plans that are currently in progress or have recently finished Chef processing, # regardless if they are being or have been sequenced plans = models.PlannedExperiment.objects.filter( experiment__chefLastUpdate__gte=days_ago) sampleSets = models.SampleSet.objects.filter( libraryPrepInstrumentData__lastUpdate__gte=days_ago) libprep_done = [] chef_table = [] # planned runs may have both Template and Library prep data for plan in plans: data = { "planName": plan.planDisplayedName, "sampleSetName": ", ".join( plan.sampleSets.order_by("displayedName").values_list( "displayedName", flat=True)), "last_updated": plan.experiment.chefLastUpdate, "instrumentName": plan.experiment.chefInstrumentName, "template_prep_progress": plan.experiment.chefProgress, "template_prep_status": plan.experiment.chefStatus, "template_prep_operation_mode": plan.experiment.chefOperationMode, "template_prep_remaining_time": utils.convert_seconds_to_hhmmss_string( plan.experiment.chefRemainingSeconds), "template_prep_estimated_end_time": utils.convert_seconds_to_datetime_string( plan.experiment.chefLastUpdate, plan.experiment.chefRemainingSeconds), } samplesets_w_libprep = plan.sampleSets.filter( libraryPrepInstrumentData__isnull=False) if samplesets_w_libprep: libprep_done.extend( list(samplesets_w_libprep.values_list("pk", flat=True))) data.update({ "lib_prep_progress": samplesets_w_libprep[0].libraryPrepInstrumentData.progress, "lib_prep_status": samplesets_w_libprep[0].libraryPrepInstrumentData. instrumentStatus, }) chef_table.append(data) # add sample sets with Library prep only for sampleSet in sampleSets: if sampleSet.pk not in libprep_done: chef_table.append({ "planName": "", "sampleSetName": sampleSet.displayedName, "sample_prep_type": "Library Prep", # TODO: i18n - not used by UI "last_updated": sampleSet.libraryPrepInstrumentData.lastUpdate, "instrumentName": sampleSet.libraryPrepInstrumentData.instrumentName, "lib_prep_progress": sampleSet.libraryPrepInstrumentData.progress, "lib_prep_status": sampleSet.libraryPrepInstrumentData.instrumentStatus, "operation_mode": sampleSet.libraryPrepInstrumentData.operationMode, "remaining_time": utils.convert_seconds_to_hhmmss_string( sampleSet.libraryPrepInstrumentData.remainingSeconds), "estimated_end_time": utils.convert_seconds_to_datetime_string( sampleSet.libraryPrepInstrumentData.lastUpdate, sampleSet.libraryPrepInstrumentData.remainingSeconds, ), }) chef_table = sorted(chef_table, key=lambda plan: plan["last_updated"], reverse=True) chef_pager = Paginator(chef_table, size, 0) try: chef_page = chef_pager.page(page) except InvalidPage: chef_page = chef_pager.page(1) context = {"plans": chef_page} return render(request, "rundb/monitor/chef.html", context)
def chef(request): querydict = request.GET days = get_int(querydict, "days", 7) size = get_int(querydict, "size", 10) page = get_int(querydict, "page", 1) days_ago = datetime.datetime.now() - datetime.timedelta(days=days) # monitoring page should show Chef plans that are currently in progress or have recently finished Chef processing, # regardless if they are being or have been sequenced plans = models.PlannedExperiment.objects.filter(experiment__chefLastUpdate__gte=days_ago) sampleSets = models.SampleSet.objects.filter(libraryPrepInstrumentData__lastUpdate__gte=days_ago) libprep_done = [] chef_table = [] # planned runs may have both Template and Library prep data for plan in plans: data = { 'planName': plan.planDisplayedName, 'sampleSetName': ', '.join(plan.sampleSets.order_by('displayedName').values_list('displayedName', flat=True)), 'last_updated' : plan.experiment.chefLastUpdate, 'instrumentName': plan.experiment.chefInstrumentName, 'template_prep_progress': plan.experiment.chefProgress, 'template_prep_status': plan.experiment.chefStatus, 'template_prep_operation_mode': plan.experiment.chefOperationMode, 'template_prep_remaining_time': utils.convert_seconds_to_hhmmss_string(plan.experiment.chefRemainingSeconds), 'template_prep_estimated_end_time': utils.convert_seconds_to_datetime_string(plan.experiment.chefLastUpdate, plan.experiment.chefRemainingSeconds) } samplesets_w_libprep = plan.sampleSets.filter(libraryPrepInstrumentData__isnull=False) if samplesets_w_libprep: libprep_done.extend(list(samplesets_w_libprep.values_list('pk', flat=True))) data.update({ 'lib_prep_progress': samplesets_w_libprep[0].libraryPrepInstrumentData.progress, 'lib_prep_status': samplesets_w_libprep[0].libraryPrepInstrumentData.instrumentStatus }) chef_table.append(data) # add sample sets with Library prep only for sampleSet in sampleSets: if sampleSet.pk not in libprep_done: chef_table.append({ 'planName': '', 'sampleSetName': sampleSet.displayedName, 'sample_prep_type': 'Library Prep', 'last_updated' : sampleSet.libraryPrepInstrumentData.lastUpdate, 'instrumentName': sampleSet.libraryPrepInstrumentData.instrumentName, 'lib_prep_progress': sampleSet.libraryPrepInstrumentData.progress, 'lib_prep_status': sampleSet.libraryPrepInstrumentData.instrumentStatus, 'operation_mode': sampleSet.libraryPrepInstrumentData.operationMode, 'remaining_time': utils.convert_seconds_to_hhmmss_string(sampleSet.libraryPrepInstrumentData.remainingSeconds), 'estimated_end_time': utils.convert_seconds_to_datetime_string(sampleSet.libraryPrepInstrumentData.lastUpdate, sampleSet.libraryPrepInstrumentData.remainingSeconds) }) chef_table = sorted(chef_table, key=lambda plan: plan['last_updated'], reverse=True) chef_pager = Paginator(chef_table, size, 0) try: chef_page = chef_pager.page(page) except InvalidPage: chef_page = chef_pager.page(1) context = { "plans": chef_page } return render(request, "rundb/monitor/chef.html", context)