def test_load_del(self): db = PersistentDB(schema, 'pk', dbname='testdb', overwrite=True) n_add = 50 mus = np.random.uniform(low=0.0, high=1.0, size=n_add) sigs = np.random.uniform(low=0.05, high=0.4, size=n_add) jits = np.random.uniform(low=0.05, high=0.2, size=n_add) saveinfo = {} for i, m, s, j in zip(range(n_add), mus, sigs, jits): new_ts = tsmaker(m, s, j) db.insert_ts("ts-{}".format(i), tsmaker(m, s, j)) db.upsert_meta("ts-{}".format(i), { 'mean': new_ts.mean(), 'std': new_ts.std() }) saveinfo["ts-{}".format(i)] = new_ts.mean() db.add_vp("ts-4") db.add_vp() db.delete_ts("ts-4") pks, fields = db.select(meta={'vp': True}, fields=None) self.assertEqual(len(pks), 1) newdb = PersistentDB(schema, 'pk', dbname='testdb', load=True) pks, fields = db.select(meta={}, fields=['mean']) self.assertEqual(len(pks), n_add - 1) self.assertTrue("ts-4" not in pks) for i in range(0, n_add - 1): self.assertEqual(fields[i]['mean'], saveinfo[pks[i]])
def test_load_del(self): db = PersistentDB(schema, 'pk', dbname='testdb', overwrite=True) n_add = 50 mus = np.random.uniform(low=0.0, high=1.0, size=n_add) sigs = np.random.uniform(low=0.05, high=0.4, size=n_add) jits = np.random.uniform(low=0.05, high=0.2, size=n_add) saveinfo = {} for i, m, s, j in zip(range(n_add), mus, sigs, jits): new_ts = tsmaker(m, s, j) db.insert_ts("ts-{}".format(i), tsmaker(m, s, j)) db.upsert_meta("ts-{}".format(i), {'mean':new_ts.mean(), 'std':new_ts.std()}) saveinfo["ts-{}".format(i)] = new_ts.mean() db.add_vp("ts-4") db.add_vp() db.delete_ts("ts-4") pks, fields = db.select(meta={'vp':True}, fields=None) self.assertEqual(len(pks),1) newdb = PersistentDB(schema, 'pk', dbname='testdb', load=True) pks, fields = db.select(meta={}, fields=['mean']) self.assertEqual(len(pks), n_add-1) self.assertTrue("ts-4" not in pks) for i in range(0,n_add-1): self.assertEqual(fields[i]['mean'], saveinfo[pks[i]])
def test_simsearch(self): db = PersistentDB(schema, 'pk', dbname='testdb', overwrite=True) n_add = 50 mus = np.random.uniform(low=0.0, high=1.0, size=n_add) sigs = np.random.uniform(low=0.05, high=0.4, size=n_add) jits = np.random.uniform(low=0.05, high=0.2, size=n_add) for i, m, s, j in zip(range(n_add), mus, sigs, jits): db.insert_ts("ts-{}".format(i), tsmaker(m, s, j)) m = np.random.uniform(low=0.0, high=1.0) s = np.random.uniform(low=0.05, high=0.4) j = np.random.uniform(low=0.05, high=0.2) query = tsmaker(m, s, j) with self.assertRaises(ValueError): # No similarity search w/o vantage points closest = db.simsearch(query) for i in range(5): db.add_vp() closest = db.simsearch(query)
def test_simsearch(self): db = PersistentDB(schema, 'pk', dbname='testdb', overwrite=True) n_add = 50 mus = np.random.uniform(low=0.0, high=1.0, size=n_add) sigs = np.random.uniform(low=0.05, high=0.4, size=n_add) jits = np.random.uniform(low=0.05, high=0.2, size=n_add) for i, m, s, j in zip(range(n_add), mus, sigs, jits): db.insert_ts("ts-{}".format(i), tsmaker(m, s, j)) m = np.random.uniform(low=0.0, high=1.0) s = np.random.uniform(low=0.05, high=0.4) j = np.random.uniform(low=0.05, high=0.2) query = tsmaker(m, s, j) with self.assertRaises( ValueError): # No similarity search w/o vantage points closest = db.simsearch(query) for i in range(5): db.add_vp() closest = db.simsearch(query)