Exemple #1
0
    def _getGaps(self, WEName, trList):

        fullHazardInv = self._getWEInventory(WEName)
        gaps = []

        for timeRange in trList:
        
            # Convert Java TimeRange to Python for comparisons
            if not isinstance(timeRange, TimeRange):
                timeRange = TimeRange(timeRange)
                
            hazInv = []
            for h in fullHazardInv:
                if timeRange.overlaps(h):
                    hazInv.append(h)
    
            # check for empty inventory
            if len(hazInv) == 0:   # no grids at all
                gaps.append(timeRange)
                continue
    
            # see if we have a gap at the beginning
            if timeRange.startTime() < hazInv[0].startTime():
                tr = TimeRange(timeRange.startTime(),
                               hazInv[0].startTime())
                gaps.append(tr)
    
            # Find any gaps in the middle of the inventory
            for i in range(len(hazInv) - 1):
                if hazInv[i].endTime() != hazInv[i+1].startTime():
                    gapTR = TimeRange(hazInv[i].endTime(),
                                      hazInv[i+1].startTime())
                    gaps.append(gapTR)
    
            # see if we have a gap at the end of the inventory
            if timeRange.endTime() > hazInv[-1].endTime():
                tr = TimeRange(hazInv[-1].endTime(),
                               timeRange.endTime())
                gaps.append(tr)

        return gaps
Exemple #2
0
    def _getGaps(self, WEName, trList):

        fullHazardInv = self._getWEInventory(WEName)
        gaps = []

        for timeRange in trList:
        
            # Convert Java TimeRange to Python for comparisons
            if not isinstance(timeRange, TimeRange):
                timeRange = TimeRange(timeRange)
                
            hazInv = []
            for h in fullHazardInv:
                if timeRange.overlaps(h):
                    hazInv.append(h)
    
            # check for empty inventory
            if len(hazInv) == 0:   # no grids at all
                gaps.append(timeRange)
                continue
    
            # see if we have a gap at the beginning
            if timeRange.startTime() < hazInv[0].startTime():
                tr = TimeRange(timeRange.startTime(),
                               hazInv[0].startTime())
                gaps.append(tr)
    
            # Find any gaps in the middle of the inventory
            for i in range(len(hazInv) - 1):
                if hazInv[i].endTime() != hazInv[i+1].startTime():
                    gapTR = TimeRange(hazInv[i].endTime(),
                                      hazInv[i+1].startTime())
                    gaps.append(gapTR)
    
            # see if we have a gap at the end of the inventory
            if timeRange.endTime() > hazInv[-1].endTime():
                tr = TimeRange(hazInv[-1].endTime(),
                               timeRange.endTime())
                gaps.append(tr)

        return gaps