예제 #1
0
    def on_completed(self):
        """
    The Event handler when no more Events.
    Subscription completed and finalize the overlaps.

    The overlaps that have same 'count' as the Region dimensionality, replace
    'count' with Region intersection between the two Regions for that edge.
    The overlaps that have 'count' that is less than the Region
    dimensionality, remove the edge.

    Overrides:
      Subscriber.on_completed
    """
        G = self.G
        for a, b, intersect, data in list(G.overlaps):
            # Buffer G.overlaps into a list to prevent 'dictionary changed size
            # during iteration' runtime error.
            if intersect is not None:
                continue

            if 'dimensions' in data:
                dim = data['dimensions']
                assert isinstance(dim, List) and len(dim) == self.dimension
                if all([isinstance(d, Interval) for d in dim]):
                    intersect = Region.from_intervals(dim)
                    intersect['intersect'] = [G.region(a), G.region(b)]
                    G.put_overlap((a, b), intersect=intersect)
                    continue

            # 'dimensions' not in data OR any([d is None for d in dim])
            del G[a, b]
예제 #2
0
 def test_region_from_intervals(self):
     ndimens = 5
     base_interval = Interval(1, 5)
     intervals = [
         Interval(base_interval.lower + d, base_interval.upper + d)
         for d in range(ndimens)
     ]
     region = Region.from_intervals(intervals)
     #print(f'{region}')
     self.assertEqual(region.dimension, ndimens)
     self.assertEqual(region.lower,
                      [base_interval.lower + d for d in range(ndimens)])
     self.assertEqual(region.upper,
                      [base_interval.upper + d for d in range(ndimens)])
     for d, dimension in enumerate(region.dimensions):
         self.assertEqual(dimension, intervals[d])
예제 #3
0
    def test_region_getsetitem(self):
        data = {
            'data': 'value',
            'datalist': ['list', 'of', 'items'],
            'dataprop': 'dataprop'
        }
        intervals = [Interval(0, 10)] * 3
        region = Region.from_intervals(intervals, dataprop=data['dataprop'])

        def check_region(region: Region, intervals: List[Interval]):
            self.assertTrue(
                all([
                    region[i] == interval
                    for i, interval in enumerate(intervals)
                ]))
            self.assertEqual(list(map(lambda i: i.lower, intervals)),
                             region.lower)
            self.assertEqual(list(map(lambda i: i.upper, intervals)),
                             region.upper)

        check_region(region, intervals)
        #print(f'{region}')
        #print(f'{region.data}')
        #print(f'{asdict(region)}')
        intervals = [
            Interval(interval.lower, interval.upper + i)
            for i, interval in enumerate(intervals)
        ]
        for i, interval in enumerate(intervals):
            region[i] = interval
        check_region(region, intervals)

        region['data'] = data['data']
        region['datalist'] = data['datalist']
        #print(f'{region}')
        #print(f'{region.data}')
        #print(f'{asdict(region)}')
        self.assertEqual(data['data'], region['data'])
        self.assertEqual(data['datalist'], region['datalist'])
        self.assertEqual(data['dataprop'], region['dataprop'])
        self.assertDictEqual(data, region.data)