Ejemplo n.º 1
0
 def getDueDate(self):
     """Used to populate getDueDate index and metadata.
     This calculates the difference between the time the analysis processing
     started and the maximum turnaround time. If the analysis has no
     turnaround time set or is not yet ready for proces, returns None
     """
     tat = self.getMaxTimeAllowed()
     if not tat:
         return None
     start = self.getStartProcessDate()
     if not start:
         return None
     return dt2DT(DT2dt(start) + timedelta(minutes=api.to_minutes(**tat)))
Ejemplo n.º 2
0
 def getEarliness(self):
     """The remaining time in minutes for this analysis to be completed.
     Returns zero if the analysis is neither 'ready to process' nor a
     turnaround time is set.
         earliness = duration - max_turnaround_time
     The analysis is late if the earliness is negative
     :return: the remaining time in minutes before the analysis reaches TAT
     :rtype: int
     """
     maxtime = self.getMaxTimeAllowed()
     if not maxtime:
         # No Turnaround time is set for this analysis
         return 0
     return api.to_minutes(**maxtime) - self.getDuration()
Ejemplo n.º 3
0
    def getDueDate(self):
        """Used to populate getDueDate index and metadata.
        This calculates the difference between the time the analysis processing
        started and the maximum turnaround time. If the analysis has no
        turnaround time set or is not yet ready for proces, returns None
        """
        tat = self.getMaxTimeAllowed()
        if not tat:
            return None
        start = self.getStartProcessDate()
        if not start:
            return None

        # delta time when the first analysis is considered as late
        delta = timedelta(minutes=api.to_minutes(**tat))

        # calculated due date
        end = dt2DT(DT2dt(start) + delta)

        # delta is within one day, return immediately
        if delta.days == 0:
            return end

        # get the laboratory workdays
        setup = api.get_setup()
        workdays = setup.getWorkdays()

        # every day is a workday, no need for calculation
        if workdays == tuple(map(str, range(7))):
            return end

        # reset the due date to the received date, and add only for configured
        # workdays another day
        due_date = end - delta.days

        days = 0
        while days < delta.days:
            # add one day to the new due date
            due_date += 1
            # skip if the weekday is a non working day
            if str(due_date.asdatetime().weekday()) not in workdays:
                continue
            days += 1

        return due_date