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 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()
i : a counter to be appended to the file name where it is stored Returns ------- None. ''' path = "ts-{}.txt".format(i) datafile_id = open(path, 'wb') data = np.array([ts._times, ts._values]) data = data.T np.savetxt(datafile_id, data, fmt=['%.3f','%8f']) datafile_id.close() # Get distance from vantage points from DB, and if its not there then proceed db = redblackDB.connect("distanceFromVantagePoints.dbdb") db_vantagepoints = redblackDB.connect("vantagePoints.dbdb") db_data = redblackDB.connect("timeseriesdata.dbdb") distances_from_vantage_points = [] v=[] x=[] try: #try to read the file containing the dictionary of vantagepoint_id:vantagepoint_timeseries #try to check if there are 20 redblack trees. One of these will be read in the later part oft he code. #db_data.get('hello') #raise KeyError file=open('vantagepointids.txt')
#print("I'mhere",ts_obj) return ts_obj def encodeVantagePoints(decoded): """""" def decodeVantagePoints(encoded): """""" # Get distance from vantage points from DB, and if its not there then proceed # os.remove('distanceFromVantagePoints.dbdb') db = redblackDB.connect("distanceFromVantagePoints.dbdb") db_vantagepoints = redblackDB.connect("vantagePoints.dbdb") db_data = redblackDB.connect("timeseriesdata.dbdb") db_known_ts = redblackDB.connect(sys.argv[1]) dbKey = 'encodedDistance' dbKey_vantagepoint = 'vantagePoints' dbKey_data = 'timeseriesdata' dbKey_known_ts = 'newtimeseries' distances_from_vantage_points = [] # Check if it is in DB try: #print("getting distances from storage") encodedDistances = db.get(dbKey) distances_from_vantage_points = decodeVantageDistances(encodedDistances)
def test_get_min(): gen_demo_data() db = connect("DELETEME.dbdb") assert db.get_min() == "one" db.close() purge_demo_data()