Beispiel #1
0
def f(*args):
    (_, node, cargs) = args
    log = Logger().log

    log.info('{0}: setup +'.format(node))
    with DatabaseConnection() as conn:
        source = nd.Node(node, conn)
        neighbors = [ nd.Node(x, conn) for x in source.neighbors ]
    log.info('{0}: setup -'.format(node))
    
    classes = [ WindowInfluence ] # [ MinuteInfluence, WindowInfluence ]
    
    return [ i(source, neighbors, cargs).run() for i in classes ]
Beispiel #2
0
    def __init__(self, nid, level, cluster, lag=0, db_conn=None, seen=None):
        self.lag = lag
        self.children = set()

        close = not db_conn
        if close:
            db_conn = db.DatabaseConnection().resource

        self.node = nd.Node(nid, db_conn)
        if not seen:
            seen = set()
            seen.add(nid)
        self.__build(level, cluster, db_conn, seen)

        if close:
            db_conn.close()
Beispiel #3
0
def f(*args):
    (index, nid, (window, classify, freq)) = args

    log.info('{0} create'.format(nid))

    node = nd.Node(nid)
    stats = []
    for _ in range(window.prediction):
        stats.append([0 for _ in range(window.target)])

    for i in loop(window):
        args = [i, classify]
        df = pd.rolling_apply(node.readings.speed, len(i), rapply, args=args)
        log.info('{0} {1} {2} {3}'.format(nid, i, df.sum(), df.count()))
        stats[i.prediction][i.target] = df.resample(freq, how=sum)

    return stats
Beispiel #4
0
def f(*args):
    (index, nid, (window, oneday, threshold, agg)) = args

    log.info('{0} create'.format(nid))

    node = nd.Node(nid)
    winlen = nd.winsum(window)

    log.info('{0} apply'.format(nid))

    #
    # determine which windows constitute a traffic event
    #
    df = pd.rolling_apply(node.readings.speed,
                          winlen,
                          g,
                          min_periods=winlen,
                          args=[window, threshold])
    df.dropna(inplace=True)

    #
    # aggregate the results
    #
    log.info('{0} aggregate'.format(nid))

    if df.empty:
        log.error('{0}: No observations'.format(nid))
        return []

    # items = zip(range(oneday), [ [] ] * oneday)
    totals = OrderedDict()
    for i in range(oneday):
        totals[i] = [0]

    for i in df.index:
        key = cp.bucket(i)
        totals[key].append(df.ix[i])

    vals = [agg(x) for x in totals.values()]
    vals.append(nid)  # this is important

    return vals
Beispiel #5
0
    unpaired = []
    paired = set()
    symmetric = (len(ref_seqs) == 2) and (ref_seqs[0] == ref_seqs[1])

    for inter in filter(lambda x: x.wc, interactions):
        pairing.append(pair.Pair(inter.id1, inter.id2, pair.Pair.PTYPE_MUST))
        paired.add(inter.id1)
        paired.add(inter.id2)

    for (chain, ref_seq) in enumerate(ref_seqs):
        for (ndx, c) in enumerate(ref_seq):
            id = len(nodes)

            conds = map(lambda x: x.id1,
                        filter(lambda x: x.id2 == id, interactions))
            nodes.append(node.Node(id, chain, ndx, conds))

            if (id not in paired):
                unpaired.append(id)

    # save a definition file and set the definition input to that file
    model = model.Model(name,
                        version,
                        ref_seqs,
                        data_sources,
                        nodes,
                        None,
                        pairing,
                        unpaired,
                        None,
                        sep_min=4,