Пример #1
0
def test_db_get():
    dbName = "/tmp/test2.dbdb"
    if os.path.exists(dbName):
        os.remove(dbName)
    db = lab10.connect(dbName)
    db.set("rahul", "aged")
    db.set("pavlos", "aged")
    db.set("kobe", "stillyoung")
    db.commit()
    db.close()
    db = lab10.connect("/tmp/test2.dbdb")
    assert db.get("rahul") == "aged"
    db.commit()
    db.close()
Пример #2
0
def test_db_get_error():
    dbName = "/tmp/test2.dbdb"
    if os.path.exists(dbName):
        os.remove(dbName)
    db = lab10.connect(dbName)
    db.set(4.4, "ts484.dat")
    with raises(KeyError):
        db.get(3.9)
    db.commit()
    db.close()
Пример #3
0
def test_db_get_All_LTE():
    dbName = "/tmp/test2.dbdb"
    if os.path.exists(dbName):
        os.remove(dbName)
    db = lab10.connect(dbName)
    db.set(4.4, "ts484.dat")
    db.set(0.0, "ts3.dat")  #vantagePT
    db.set(1.3, "ts82.dat")
    db.set(2.9, "ts84.dat")
    db.set(2.3, "ts382.dat")
    db.set(2.1, "ts52.dat")
    db.set(1.8, "ts49.dat")
    db.set(1.1, "ts77.dat")
    db.set(5.3, "ts583.dat")
    keys, vals = db.get_All_LTE(2.9)
    assert keys == [0.0, 1.3, 2.9, 2.3, 2.1, 1.8, 1.1]
    db.commit()
    db.close()
Пример #4
0
'''

if __name__ == "__main__":
    # Load in the TS to Evaluate
    filename = sys.argv[1]
    x = np.loadtxt(filename, delimiter=' ')
    origTs = ts.TimeSeries(x[:,1],x[:,0])
    time = np.arange(0.0, 1.0, 0.01)
    testTs = origTs.interpolate(time)

    # Find the Nearest vantagePt
    minDist = float('inf')
    for j in range(20):
        dbName = "tsdb/db"+str(j)+".dbdb"
        db = lab10.connect(dbName)
        vantagePtFile = db.get(0)
        x = np.loadtxt(vantagePtFile, delimiter=' ')
        comparePt = ts.TimeSeries(x[:,1],x[:,0])
        dist = 2*(1-ss.kernel_corr(comparePt,testTs))
        if dist < minDist:
            minDist = dist
            minDbName = dbName
            minVantagePtFile = vantagePtFile

    #Connect to DB Referencing the Nearest vantagePT
    db = lab10.connect(minDbName)
    keys, filenames = db.get_All_LTE(float(2)*minDist)
    nFiles = len(filenames)

    #Dictionary Key File, Val = Distance to testTs
Пример #5
0
    dbList = []

    #Create TS Referencing
    #The 20 randomally selected vantagePtFiles
    for j in range(20):
        fileName = 'tsdata/ts' + str(indexes[j]) + '.dat'
        dbName = "tsdb/db" + str(j) + ".dbdb"
        x = np.loadtxt(fileName, delimiter=' ')
        vantagePt = ts.TimeSeries(x[:, 1], x[:, 0])
        vantagePtList.append(vantagePt)
        ##Remove DB if it has previously been created
        if os.path.exists(dbName):
            os.remove(dbName)

        # Connect to Databses
        db = lab10.connect(dbName)
        dbList.append(db)

    #For all 20 Databases
    #Loop through 1000 TimeSeries
    #Add Key = Distance(vantagePt, comparePt)
    #Value = comparePT's fileName
    for i in range(1000):
        fileName = 'tsdata/ts' + str(i) + '.dat'
        x = np.loadtxt(fileName, delimiter=' ')
        comparePt = ts.TimeSeries(x[:, 1], x[:, 0])

        # Add Key,Value for ComparePt for all 20 Databases
        for j in range(20):
            dist = 2 * (1 - ss.kernel_corr(vantagePtList[j], comparePt))
            dbList[j].set(dist, fileName)