def get_timestamps(src, sql, tol_hrs): with src.session_ctx() as sess: result = sess.execute(sql) ts = array([make_timef(ri[0]) for ri in result.fetchall()]) idxs = bin_timestamps(ts, tol_hrs=tol_hrs) return ts, idxs
def run(self, state): unks = getattr(state, self.analysis_kind) key = attrgetter('timestamp') unks = sorted(unks, key=key) tol_hrs = 1 ts = array([ai.timestamp for ai in unks]) idxs = bin_timestamps(ts, tol_hrs) if idxs: unks = array(unks) for i, ais in enumerate(array_split(unks, idxs + 1)): for ai in ais: ai.group_id = i else: for ai in unks: ai.group_id = 0
def run(self, state): unks = getattr(state, self.analysis_kind) key = lambda x: x.timestamp unks = sorted(unks, key=key) tol_hrs = 1 # tol = 60 * 60 * tol_hrs ts = array([ai.timestamp for ai in unks]) # dts = ediff1d(ts) # idxs = where(dts > tol)[0] idxs = bin_timestamps(ts, tol_hrs) if idxs: unks = array(unks) for i, ais in enumerate(array_split(unks, idxs + 1)): for ai in ais: ai.group_id = i else: for ai in unks: ai.group_id = 0