Exemple #1
0
def merge_split_overlap_IntervalTree(p_acts, r_acts):
    tree = IntervalTree()
    from result_analyse.visualisation import plotJoinTree
    PACT = column_index(p_acts, 'Activity')
    PSTIME = column_index(p_acts, 'StartTime')
    PETIME = column_index(p_acts, 'EndTime')

    for row in p_acts.values:
        if (row[PACT] == 0):
            continue
        start = row[PSTIME]
        end = row[PETIME]
        startv = start.value
        endv = end.value
        if (startv == endv):
            startv = startv - 1
        #tree[start:end]={'P':{'Activitiy':act.Activity,'Type':'P','Data':act}]
        d = Data('P-act')
        d.P = {'Activity': row[PACT], 'StartTime': start, 'EndTime': end}
        d.R = None
        tree[startv:endv] = d

    RACT = column_index(r_acts, 'Activity')
    RSTIME = column_index(r_acts, 'StartTime')
    RETIME = column_index(r_acts, 'EndTime')

    for row in r_acts.values:
        if (row[RACT] == 0):
            continue
        start = row[RSTIME]
        end = row[RETIME]
        startv = start.value
        endv = end.value
        if (startv == endv):
            startv = startv - 1
        #tree[start:end]=[{'Activitiy':act.Activity,'Type':'R','Data':act}]
        d = Data('R-act')
        d.P = None
        d.R = {'Activity': row[RACT], 'StartTime': start, 'EndTime': end}
        tree[startv:endv] = d
    # cmTreePlot(tree)
    tree.split_overlaps()

    # cmTreePlot(tree)
    def data_reducer(x, y):
        res = Data('merge')
        res.R = x.R
        res.P = x.P
        if not (y.P is None):
            if (res.P is None) or y.P['EndTime'] < res.P['EndTime']:
                res.P = y.P
        if not (y.R is None):
            if (res.R is None) or y.R['EndTime'] < res.R['EndTime']:
                res.R = y.R
        return res

    tree.merge_equals(data_reducer=data_reducer)

    return tree
Exemple #2
0
 def data_reducer(x, y):
     res = Data('merge')
     res.R = x.R
     res.P = x.P
     if not (y.P is None):
         if (res.P is None) or y.P['EndTime'] < res.P['EndTime']:
             res.P = y.P
     if not (y.R is None):
         if (res.R is None) or y.R['EndTime'] < res.R['EndTime']:
             res.R = y.R
     return res
def merge_split_overlap_IntervalTree(p_acts, r_acts):
    tree = IntervalTree()

    for act in p_acts:
        if (act['Activity'] == 0):
            continue
        start = act['StartTime'].value
        end = act['EndTime'].value
        if (start == end):
            start = start - 1
        #tree[start:end]={'P':{'Activitiy':act.Activity,'Type':'P','Data':act}]
        d = Data('P-act')
        d.P = act
        d.R = None
        tree[start:end] = d  #{'P':act,'PActivitiy':act.Activity}

    for act in r_acts:
        start = act['StartTime'].value
        end = act['EndTime'].value
        if (start == end):
            start = start - 1
        #tree[start:end]=[{'Activitiy':act.Activity,'Type':'R','Data':act}]
        d = Data('P-act')
        d.P = None
        d.R = act
        tree[start:end] = d  #{'R':act,'RActivitiy':act.Activity}

    tree.split_overlaps()

    def data_reducer(x, y):
        res = x
        if not (y.P is None):
            if (res.P is None) or y.P['EndTime'] < res.P['EndTime']:
                res.P = y.P
        if not (y.R is None):
            if (res.R is None) or y.R['EndTime'] < res.R['EndTime']:
                res.R = y.R
        return res

    tree.merge_equals(data_reducer=data_reducer)

    return tree