def get_data_for_interval(limit, offset, start, end, resolution, out): params = dict(limit=limit, offset=offset) with get_connection() as conn: with conn.cursor() as cursor: cursor.execute(_QUERY, params) res = cursor.fetchall() x = np.asarray(res) if x.size == 0: raise EndOfData("no data in this range") # normalize to indices max_start_time = x[-1, 1] x[:, 1] = np.maximum(x[:, 1], start) x[:, 2] = np.minimum(x[:, 2], end) x[:, 1] -= start x[:, 2] -= start x[:, 1:] /= float(resolution) try: add_means_to_array(x, out) except ValueError: print(x[:, 1].min(), x[:, 2].min()) print(x[:, 1].max(), x[:, 2].max()) raise return max_start_time, len(x)
# execute special commands name = "task_usage" logger.info("creating index on table {}".format(name)) cmd = "CREATE INDEX ON {} (start_time, end_time);".format(name) c.execute(cmd) if __name__ == "__main__": from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument("-y", "--disclaimer_accepted", action="store_true", default=False, help="I have read the disclaimer") args = parser.parse_args() print(disclaimer) conn = get_connection() try: if not args.disclaimer_accepted: print("re-run with -y if your input is sanitized.") else: run(conn) except: raise else: conn.commit() finally: conn.close()