Пример #1
0
def data_parse(cblock_str):
    '''Compute the FHR MHR TOCO mother_mv 
    from C block'''
    mm = '10024d4d1003'                 # MM block
    event = 0
    FHR = []
    MHR = []
    TOCO = 0
    mother_mv = []
    data_one_sec = []
    init_An24.run_check(cblock_str)
    if(len(cblock_str) == CBLOCK_STR_LEN):
        

        FHR_split = [10, 14, 18, 22, 26]
        MHR_split = [42, 46, 50, 54, 58]
        TOCO_split = [58, 60, 62, 64, 66]

        FHR_section = [
                cblock_str[FHR_split[0]:FHR_split[1]],
                cblock_str[FHR_split[1]:FHR_split[2]],
                cblock_str[FHR_split[2]:FHR_split[3]],
                cblock_str[FHR_split[3]:FHR_split[4]]
                ]
        MHR_section = [
                cblock_str[MHR_split[0]:MHR_split[1]],
                cblock_str[MHR_split[1]:MHR_split[2]],
                cblock_str[MHR_split[2]:MHR_split[3]],
                cblock_str[MHR_split[3]:MHR_split[4]]
                ]
        TOCO_section = [
                cblock_str[TOCO_split[0]:TOCO_split[1]],
                cblock_str[TOCO_split[1]:TOCO_split[2]],
                cblock_str[TOCO_split[2]:TOCO_split[3]],
                cblock_str[TOCO_split[3]:TOCO_split[4]]
                ]
                        
        FHR_section = [int_16(f) for f in FHR_section]
        MHR_section = [int_16(m) for m in MHR_section]
        TOCO_section = [int_16(t) for t in TOCO_section]
        ''' :
        for fh_s in xrange(0,4):
            FHR[fh_s] = round(int(FHR_section[fh_s]&
                                0x7FF) *HEART_RATE_RESOLUTION, 2)
        for mh_s in xrange(0,4):
            MHR[mh_s] = round(int(MHR[mh_s]&
                                0x7ff) * HEART_RATE_RESOLUTION, 2)
            mother_mv[mh_s] = int((MHR[mh_s]&0x1800) >> 11)

        '''
        for fh_s in FHR_section:
            fh = round(int(fh_s & 0x7FF) * HEART_RATE_RESOLUTION, 2)
            FHR.append(fh)

        for mh_s in MHR_section:
            mh =round(int(mh_s&0x7ff) * HEART_RATE_RESOLUTION, 2)
            m_mv = int((mh_s&0x1800) >> 11)
            mother_mv.append(m_mv)
            MHR.append(mh)
        
        for to_s in TOCO_section:
            TOCO = int(int(to_s) * TOTO_RESOLUTION)
        
        
        '''
        print 'FHR:', FHR
        print 'MHR:', MHR
        print 'TOCO:', TOCO
        print 'mother_mv:', mother_mv
        '''

    elif len(cblock_str) == NBLOCK_STR_LEN:
         FHR = [0, 0, 0, 0]
         MHR = [0, 0, 0, 0]
         mother_mv = [0, 0, 0, 0]
         '''Compute the SNR from N block'''
         if cblock_str[14:16] == NBLOCK_SNR_TAG:
             global SNR
             fetal_signal = int(cblock_str[16:24], 16)
             noise = int_16(cblock_str[24:32])          #int(cblock_str[24:32], 16)
             SNR_func = lambda x, y : round(x / float(y), 4)
             SNR = SNR_func(fetal_signal,
                           noise)

             #print 'SNR:', SNR
         else:
             pass

    elif cblock_str == mm:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

        event = 1
        log('-!-!-!-!-event-!-!-!-!-', event)
         

    else:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

    data_one_sec.append([FHR[0], MHR[0], TOCO, mother_mv[0], SNR, event])
    data_one_sec.append([FHR[1], MHR[1], TOCO, mother_mv[1], SNR, event])
    data_one_sec.append([FHR[2], MHR[2], TOCO, mother_mv[2], SNR, event])
    data_one_sec.append([FHR[3], MHR[3], TOCO, mother_mv[3], SNR, event])
    log('data_one_sec:', data_one_sec)
    #return FHR, MHR, TOCO, mother_mv, SNR, event
    return data_one_sec
Пример #2
0
def data_parse(cblock_str):
    '''Compute the FHR MHR TOCO mother_mv 
    from C block'''
    mm = '10024d4d1003'  # MM block
    event = 0
    FHR = []
    MHR = []
    TOCO = 0
    mother_mv = []
    data_one_sec = []
    init_An24.run_check(cblock_str)
    if (len(cblock_str) == CBLOCK_STR_LEN):

        FHR_split = [10, 14, 18, 22, 26]
        MHR_split = [42, 46, 50, 54, 58]
        TOCO_split = [58, 60, 62, 64, 66]

        FHR_section = [
            cblock_str[FHR_split[0]:FHR_split[1]],
            cblock_str[FHR_split[1]:FHR_split[2]],
            cblock_str[FHR_split[2]:FHR_split[3]],
            cblock_str[FHR_split[3]:FHR_split[4]]
        ]
        MHR_section = [
            cblock_str[MHR_split[0]:MHR_split[1]],
            cblock_str[MHR_split[1]:MHR_split[2]],
            cblock_str[MHR_split[2]:MHR_split[3]],
            cblock_str[MHR_split[3]:MHR_split[4]]
        ]
        TOCO_section = [
            cblock_str[TOCO_split[0]:TOCO_split[1]],
            cblock_str[TOCO_split[1]:TOCO_split[2]],
            cblock_str[TOCO_split[2]:TOCO_split[3]],
            cblock_str[TOCO_split[3]:TOCO_split[4]]
        ]

        FHR_section = [int_16(f) for f in FHR_section]
        MHR_section = [int_16(m) for m in MHR_section]
        TOCO_section = [int_16(t) for t in TOCO_section]
        ''' :
        for fh_s in xrange(0,4):
            FHR[fh_s] = round(int(FHR_section[fh_s]&
                                0x7FF) *HEART_RATE_RESOLUTION, 2)
        for mh_s in xrange(0,4):
            MHR[mh_s] = round(int(MHR[mh_s]&
                                0x7ff) * HEART_RATE_RESOLUTION, 2)
            mother_mv[mh_s] = int((MHR[mh_s]&0x1800) >> 11)

        '''
        for fh_s in FHR_section:
            fh = round(int(fh_s & 0x7FF) * HEART_RATE_RESOLUTION, 2)
            FHR.append(fh)

        for mh_s in MHR_section:
            mh = round(int(mh_s & 0x7ff) * HEART_RATE_RESOLUTION, 2)
            m_mv = int((mh_s & 0x1800) >> 11)
            mother_mv.append(m_mv)
            MHR.append(mh)

        for to_s in TOCO_section:
            TOCO = int(int(to_s) * TOTO_RESOLUTION)
        '''
        print 'FHR:', FHR
        print 'MHR:', MHR
        print 'TOCO:', TOCO
        print 'mother_mv:', mother_mv
        '''

    elif len(cblock_str) == NBLOCK_STR_LEN:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        '''Compute the SNR from N block'''
        if cblock_str[14:16] == NBLOCK_SNR_TAG:
            global SNR
            fetal_signal = int(cblock_str[16:24], 16)
            noise = int_16(cblock_str[24:32])  #int(cblock_str[24:32], 16)
            SNR_func = lambda x, y: round(x / float(y), 4)
            SNR = SNR_func(fetal_signal, noise)

            #print 'SNR:', SNR
        else:
            pass

    elif cblock_str == mm:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

        event = 1
        log('-!-!-!-!-event-!-!-!-!-', event)

    else:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

    data_one_sec.append([FHR[0], MHR[0], TOCO, mother_mv[0], SNR, event])
    data_one_sec.append([FHR[1], MHR[1], TOCO, mother_mv[1], SNR, event])
    data_one_sec.append([FHR[2], MHR[2], TOCO, mother_mv[2], SNR, event])
    data_one_sec.append([FHR[3], MHR[3], TOCO, mother_mv[3], SNR, event])
    #return FHR, MHR, TOCO, mother_mv, SNR, event
    return data_one_sec
Пример #3
0
def data_parse(cblock_str, run_chk, low_battry):
    '''Compute the FHR MHR TOCO mother_mv 
    from C block'''
    mm = '10024d4d1003'                 # MM block
    low_battry = '10024e3032414eB1003'  #low battry
    event = 0
    FHR = []
    MHR = []
    TOCO = 0
    mother_mv = []
    data_one_sec = []
    #init_An24.run_check(cblock_str)
    if(len(cblock_str) == CBLOCK_STR_LEN):
        

        FHR_split = [10, 14, 18, 22, 26]
        MHR_split = [42, 46, 50, 54, 58]
        TOCO_split = [58, 60, 62, 64, 66]

        FHR_section = [
                cblock_str[FHR_split[0]:FHR_split[1]],
                cblock_str[FHR_split[1]:FHR_split[2]],
                cblock_str[FHR_split[2]:FHR_split[3]],
                cblock_str[FHR_split[3]:FHR_split[4]]
                ]
        MHR_section = [
                cblock_str[MHR_split[0]:MHR_split[1]],
                cblock_str[MHR_split[1]:MHR_split[2]],
                cblock_str[MHR_split[2]:MHR_split[3]],
                cblock_str[MHR_split[3]:MHR_split[4]]
                ]
        TOCO_section = [
                cblock_str[TOCO_split[0]:TOCO_split[1]],
                cblock_str[TOCO_split[1]:TOCO_split[2]],
                cblock_str[TOCO_split[2]:TOCO_split[3]],
                cblock_str[TOCO_split[3]:TOCO_split[4]]
                ]
                        
        FHR_section = [int_16(f) for f in FHR_section]
        MHR_section = [int_16(m) for m in MHR_section]
        TOCO_section = [int_16(t) for t in TOCO_section]
        ''' :
        for fh_s in xrange(0,4):
            FHR[fh_s] = round(int(FHR_section[fh_s]&
                                0x7FF) *HEART_RATE_RESOLUTION, 2)
        for mh_s in xrange(0,4):
            MHR[mh_s] = round(int(MHR[mh_s]&
                                0x7ff) * HEART_RATE_RESOLUTION, 2)
            mother_mv[mh_s] = int((MHR[mh_s]&0x1800) >> 11)

        '''
        for fh_s in FHR_section:
            fh = round(int(fh_s & 0x7FF) * HEART_RATE_RESOLUTION, 2)
            FHR.append(fh)

        for mh_s in MHR_section:
            mh =round(int(mh_s&0x7ff) * HEART_RATE_RESOLUTION, 2)
            m_mv = int((mh_s&0x1800) >> 11)
            mother_mv.append(m_mv)
            MHR.append(mh)
        
        for to_s in TOCO_section:
            TOCO = int(int(to_s) * TOTO_RESOLUTION)
        
        
        '''
        print 'FHR:', FHR
        print 'MHR:', MHR
        print 'TOCO:', TOCO
        print 'mother_mv:', mother_mv
        '''

    elif len(cblock_str) == NBLOCK_STR_LEN:
         FHR = [0, 0, 0, 0]
         MHR = [0, 0, 0, 0]
         mother_mv = [0, 0, 0, 0]
         '''Compute the SNR from N block'''
         if cblock_str[14:16] == NBLOCK_SNR_TAG:
             global SNR
             fetal_signal = int(cblock_str[16:24], 16)
             noise = int_16(cblock_str[24:32])          #int(cblock_str[24:32], 16)
             SNR_func = lambda x, y : round(x / float(y), 4)
             SNR = SNR_func(fetal_signal,
                           noise)

             #print 'SNR:', SNR
         else:
             pass
    elif len(cblock_str) == ELECTRODE_STR_LEN:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        run_chk = init_An24.run_check(cblock_str, run_chk)

    elif cblock_str == mm:          #event
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

        event = 1
        log('-!-!-!-!-event-!-!-!-!-', event)
         
    elif cblock_str == low_battry:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        #init_An24.LOW_BATTRY = True
        low_battry[0] = True

    else:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

    data_one_sec.append([FHR[0], MHR[0], TOCO, mother_mv[0], SNR, event])
    data_one_sec.append([FHR[1], MHR[1], TOCO, mother_mv[1], SNR, event])
    data_one_sec.append([FHR[2], MHR[2], TOCO, mother_mv[2], SNR, event])
    data_one_sec.append([FHR[3], MHR[3], TOCO, mother_mv[3], SNR, event])
    print '------------------------------'
    log('data_one_sec:', data_one_sec)
    print '------------------------------'
    
    if FHR != [0, 0, 0, 0]:                             #rest run_chk
        run_chk[0] = 0
        run_chk[1] = 0
        run_chk[2] = 0
        run_chk[3] = 0
        run_chk[4] = 0
        
    log('run_chk', run_chk)
    #return FHR, MHR, TOCO, mother_mv, SNR, event
    #upload_data(data_one_sec)
    updata = ','.join(str(v) for v in FHR)
    print 'updata:', updata
    #upload_data(updata)
    return data_one_sec
Пример #4
0
def data_parse(cblock_str, run_chk, low_battry):
    '''Compute the FHR MHR TOCO mother_mv 
    from C block'''
    mm = '10024d4d1003'  # MM block
    low_battry = '10024e3032414eB1003'  #low battry
    event = 0
    FHR = []
    MHR = []
    TOCO = 0
    mother_mv = []
    data_one_sec = []
    #init_An24.run_check(cblock_str)
    if (len(cblock_str) == CBLOCK_STR_LEN):

        FHR_split = [10, 14, 18, 22, 26]
        MHR_split = [42, 46, 50, 54, 58]
        TOCO_split = [58, 60, 62, 64, 66]

        FHR_section = [
            cblock_str[FHR_split[0]:FHR_split[1]],
            cblock_str[FHR_split[1]:FHR_split[2]],
            cblock_str[FHR_split[2]:FHR_split[3]],
            cblock_str[FHR_split[3]:FHR_split[4]]
        ]
        MHR_section = [
            cblock_str[MHR_split[0]:MHR_split[1]],
            cblock_str[MHR_split[1]:MHR_split[2]],
            cblock_str[MHR_split[2]:MHR_split[3]],
            cblock_str[MHR_split[3]:MHR_split[4]]
        ]
        TOCO_section = [
            cblock_str[TOCO_split[0]:TOCO_split[1]],
            cblock_str[TOCO_split[1]:TOCO_split[2]],
            cblock_str[TOCO_split[2]:TOCO_split[3]],
            cblock_str[TOCO_split[3]:TOCO_split[4]]
        ]

        FHR_section = [int_16(f) for f in FHR_section]
        MHR_section = [int_16(m) for m in MHR_section]
        TOCO_section = [int_16(t) for t in TOCO_section]
        ''' :
        for fh_s in xrange(0,4):
            FHR[fh_s] = round(int(FHR_section[fh_s]&
                                0x7FF) *HEART_RATE_RESOLUTION, 2)
        for mh_s in xrange(0,4):
            MHR[mh_s] = round(int(MHR[mh_s]&
                                0x7ff) * HEART_RATE_RESOLUTION, 2)
            mother_mv[mh_s] = int((MHR[mh_s]&0x1800) >> 11)

        '''
        for fh_s in FHR_section:
            fh = round(int(fh_s & 0x7FF) * HEART_RATE_RESOLUTION, 2)
            FHR.append(fh)

        for mh_s in MHR_section:
            mh = round(int(mh_s & 0x7ff) * HEART_RATE_RESOLUTION, 2)
            m_mv = int((mh_s & 0x1800) >> 11)
            mother_mv.append(m_mv)
            MHR.append(mh)

        for to_s in TOCO_section:
            TOCO = int(int(to_s) * TOTO_RESOLUTION)
        '''
        print 'FHR:', FHR
        print 'MHR:', MHR
        print 'TOCO:', TOCO
        print 'mother_mv:', mother_mv
        '''

    elif len(cblock_str) == NBLOCK_STR_LEN:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        '''Compute the SNR from N block'''
        if cblock_str[14:16] == NBLOCK_SNR_TAG:
            global SNR
            fetal_signal = int(cblock_str[16:24], 16)
            noise = int_16(cblock_str[24:32])  #int(cblock_str[24:32], 16)
            SNR_func = lambda x, y: round(x / float(y), 4)
            SNR = SNR_func(fetal_signal, noise)

            #print 'SNR:', SNR
        else:
            pass
    elif len(cblock_str) == ELECTRODE_STR_LEN:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        run_chk = init_An24.run_check(cblock_str, run_chk)

    elif cblock_str == mm:  #event
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

        event = 1
        log('-!-!-!-!-event-!-!-!-!-', event)

    elif cblock_str == low_battry:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]
        #init_An24.LOW_BATTRY = True
        low_battry[0] = True

    else:
        FHR = [0, 0, 0, 0]
        MHR = [0, 0, 0, 0]
        mother_mv = [0, 0, 0, 0]

    data_one_sec.append([FHR[0], MHR[0], TOCO, mother_mv[0], SNR, event])
    data_one_sec.append([FHR[1], MHR[1], TOCO, mother_mv[1], SNR, event])
    data_one_sec.append([FHR[2], MHR[2], TOCO, mother_mv[2], SNR, event])
    data_one_sec.append([FHR[3], MHR[3], TOCO, mother_mv[3], SNR, event])
    print '------------------------------'
    log('data_one_sec:', data_one_sec)
    print '------------------------------'

    if FHR != [0, 0, 0, 0]:  #rest run_chk
        run_chk[0] = 0
        run_chk[1] = 0
        run_chk[2] = 0
        run_chk[3] = 0
        run_chk[4] = 0

    log('run_chk', run_chk)
    #return FHR, MHR, TOCO, mother_mv, SNR, event
    #upload_data(data_one_sec)
    updata = ','.join(str(v) for v in FHR)
    print 'updata:', updata
    #upload_data(updata)
    return data_one_sec