Exemplo n.º 1
0
    def test_intersection(self):
        inter1 = Interval(0, 10)
        inter2 = Interval(15, 20)

        inter = inter1.intersection(inter2)
        assert inter.empty
        assert inter.start == 0

        inter = inter2.intersection(inter1)
        assert inter.empty
        assert inter.start == 0

        inter2 = Interval(5, 15)

        inter = inter2.intersection(inter1)
        assert inter.start == 5
        assert inter.end == 10

        inter = inter1.intersection(inter2)
        assert inter.start == 5
        assert inter.end == 10

        inter2 = Interval(10, 15)
        inter = inter1.intersection(inter2)
        assert inter.empty

        inter = inter2.intersection(inter1)
        assert inter.empty

        inter2 = Interval(-1, 0)
        inter = inter1.intersection(inter2)
        assert inter.empty

        inter = inter2.intersection(inter1)
        assert inter.empty
Exemplo n.º 2
0
def eval_vflut(anns, _):
    """Evaluates the ventricular flutter presence"""
    lth, uth, dth = ms2sp(
        (4 * 60 + 45) * 1000), ms2sp(5 * 60 * 1000), ms2sp(3500)
    #We remove separations between consecutive flutter fragments
    i = 0
    while i < len(anns):
        if anns[i].code is ECGCodes.VFOFF:
            onset = next((j for j in range(i, len(anns))
                          if anns[j].code is ECGCodes.VFON), None)
            if onset is not None and anns[i].time == anns[onset].time:
                anns.pop(onset)
                anns.pop(i)
                i -= 1
        i += 1
    vflim = (a for a in anns if a.code in (ECGCodes.VFON, ECGCodes.VFOFF))
    vfluts = []
    while True:
        try:
            beg = next(vflim)
            end = next(vflim)
            vfluts.append(Iv(beg.time, end.time))
        except StopIteration:
            break
    #If the record shows many flutter fragments, we simply check some flutter
    #waves in the last 15 seconds.
    if sum(fl.length for fl in vfluts) > ms2sp(20000):
        vfw = [
            a.time for a in anns
            if a.code is ECGCodes.FLWAV and lth <= a.time <= uth
        ]
        return len(vfw) > 5
    interv = Iv(lth, uth)
    return any([interv.intersection(vflut).length > dth for vflut in vfluts])