def test_chop_on_key_not_in_db(): gen_demo_data() db = connect("DELETEME.dbdb") assert db.chop(6.1) == [(6, u'six'), (1, u'one'), (3, u'three'), (4, u'four')] db.close() purge_demo_data()
def test_commit_necessary(): gen_demo_data() db = connect("DELETEME.dbdb") db.set(10, "nonsense") # this fails db.close() db = connect("DELETEME.dbdb") assert db.get(10) == "ten" db.close() db = connect("DELETEME.dbdb") db.set(10, "nonsense") # this works db.commit() db.close() db = connect("DELETEME.dbdb") assert db.get(10) == "nonsense" db.close() purge_demo_data()
def add_ts_to_vpdb(data_tuple): """ Worker function called by add_ts_to_vpdbs above. This process is repeated on each vantage point. """ file, fsm, s_ts, ts_fn, db_dir = data_tuple vp_ts = load_ts(file[:-5], fsm) dist_to_vp = kernel_dist(standardize(vp_ts), s_ts) # print("Adding " + ts_fn + " to " + (db_dir + file)) db = connect(db_dir + file) db.set(dist_to_vp, ts_fn) db.commit() db.close()
def save_vp_dbs(vp_tuple): """ Creates unbalanced binary tree databases and saves them to disk""" vp, timeseries_dict, DB_DIR = vp_tuple sorted_ds = calc_distances(vp, timeseries_dict) # ts_datafile_51 -> vp_dbs/ts_datafile_51.dbdb db_filepath = DB_DIR + vp + ".dbdb" db = connect(db_filepath) for dist_to_vp, ts_fn in sorted_ds: db.set(dist_to_vp, ts_fn) db.commit() db.close()
def gen_demo_data(): # initialize database db = connect("DELETEME.dbdb") db.close() # fill database input_data = [ (1, "one"), (3, "three"), (4, "four"), (6, "six"), (7, "seven"), (8, "eight"), (10, "ten"), (10, "ten"), (13, "thirteen"), (14, "fourteen"), ] db = connect("DELETEME.dbdb") for key, val in input_data: db.set(key, val) # db._print_tree() # USE THIS TO VISUALIZE TREE db.commit() db.close()
def test_balance_successful(): gen_demo_data() # check balance # note that in the absence of balancing every node will be entered to the right db = connect("DELETEME.dbdb") assert db.get_left(6) == (3, "three") assert db.get_right(6) == (8, "eight") assert db.get_left(3) == (1, "one") assert db.get_right(3) == (4, "four") assert db.get_left(8) == (7, "seven") assert db.get_right(8) == (13, "thirteen") assert db.get_left(13) == (10, "ten") assert db.get_right(13) == (14, "fourteen") db.close() purge_demo_data()
def find_lc_candidates(vp_t, db_dir, lc_dir): """ Identifies light curves in selected vantage db that are up to 2x the distance that the time series is from the vantage point Returns tuple with list of light curve candidates and file storage manager object """ fsm = FileStorageManager(lc_dir) vp_fn, dist_to_vp = vp_t db = connect(db_dir + vp_fn + ".dbdb") lc_candidates = db.chop(2 * dist_to_vp) db.close() return (lc_candidates, fsm)
def test_get_min(): gen_demo_data() db = connect("DELETEME.dbdb") assert db.get_min() == "one" db.close() purge_demo_data()