示例#1
0
def db_pair_test():
    print 'create database with capacity 100000 test is started..\n'
    open(os.getcwd() + '/storage/student.txt', 'wb').close()
    db = Table(filename=os.getcwd() + '/storage/student.txt',
               type=student,
               index_attrs=['name'],
               key_sizes=[26])
    # studs = get_shuffled_dataset()

    print('loading dataset')
    pairs = []
    size = 1000
    for i in range(size):
        p = pair(id=i, id1=i, id2=i)
        pairs.append(p)
    i = 0
    for p in pairs:
        with Profiler() as p:
            db.put(p.get_key(), p)
            i += 1
            if i % 50 == 0:
                print('#', i)
    # print(db.get('581200', 1))
    # print(db.trees['name']['Matthew Cervantes'])
    db.save()
示例#2
0
def db_test():
    print 'create database with capacity 100000 test is started..\n'
    open(os.getcwd() + '/storage/student.txt', 'wb').close()
    open(os.getcwd() + '/times.txt', 'wb').close()
    db = Table(filename=os.getcwd() + '/storage/student.txt',
               type=student,
               index_attrs=['name'],
               key_sizes=[26])
    # studs = get_shuffled_dataset()

    print('loading dataset')
    studs = get_shuffled_million()
    i = 0
    for stud in studs[:10000]:
        with Profiler() as p:
            db.put(stud.get_key(), stud)
            i += 1
            if i % 50 == 0:
                print('#', i)
    db.b_index()
    for index in db.index_attrs:
        tree = db.trees[index]
    # print(db.get('581200', 1))
    # print(db.trees['name']['Matthew Cervantes'])
    db.save()
示例#3
0
    def __init__(self, applicationWindow):
        """
		@type applicationWindow: MainApplicationWindow
		"""
        self.applicationWindow = applicationWindow
        self.tableTab = applicationWindow.mainWindow.tableTab
        self.table = Table("", None)
        # Set this to True when programmatically manipulating the columns table
        # to prevent GUI events from causing sync issues with our columns
        self.lockCellChanges = False

        self.previousState = None

        mainWindow = applicationWindow.mainWindow
        mainWindow.addColumnButton.clicked.connect(self.addNewRow)
        mainWindow.removeColumnButton.clicked.connect(
            self.removeCurrentColumnRow)
        mainWindow.moveColumnDownButton.clicked.connect(
            self.moveCurrentColumnDown)
        mainWindow.moveColumnUpButton.clicked.connect(self.moveCurrentColumnUp)
        mainWindow.discardTableButton.clicked.connect(self.discardChanges)
        mainWindow.saveTableButton.clicked.connect(self.saveChanges)
        mainWindow.tableName.textEdited.connect(self.nameEdited)
        mainWindow.tableInfoTable.itemSelectionChanged.connect(
            self.selectedColumnChanged)
示例#4
0
def cursor_test():
    from database.cursor import cursor

    db = Table(type=student, from_dump=True)
    c = cursor(db=db, filename=db.filename)
    # c = select_cursor(db=db,filename=db.filename, on_field='name', greater_than=None, less_than="B")
    # c = project_cursor(db=db,filename=db.filename, fields=['name', 'email'], ordered_on='name')
    c = select_cursor(filename=db.filename,
                      on_field='name',
                      greater_than='G',
                      less_than='K',
                      on_cursor=c)
    while c.has_next():
        print c.next()
示例#5
0
def db_load_test():
    print 'load test is started..\n'
    db = Table(type=student, from_dump=True)
    # print student(db.get('581200', 1)).attrs
    print 'test get student with id = 581200..\n'
    print(student(to_parse=db.get('581200', 1)))
    print 'test neighbours of Matthew Cervantes..\n'
    nbrs = db.neighbours('name', 'Matthew Cervantes', 10)
    for nbr in nbrs:
        print nbr.attrs
    print 'test update Matthew Cervantes to Kamil..\n'
    print(student(to_parse=db.get('581200', 1)).attrs)
    db.update('581200', 1, {'name': 'Kamil'})
    print(student(to_parse=db.get('581200', 1)).attrs)
    print 'test remove Kamil by his id..\n'
    db.remove('581200', 1)
    if db.get('581200', 1) == None:
        print('Kamil is removed!')
示例#6
0
def load_author_names():
    conn = psycopg2.connect(
        "dbname='citadel' user='******' host='localhost' password=''")
    cur = conn.cursor()
    cur.execute("select * from author_names")
    rows = cur.fetchall()
    print("\nShow me the databases:\n")
    from relations.edges import edge
    open(os.getcwd() + '/storage/edge.txt', 'wb').close()
    db = Table(filename=os.getcwd() + '/storage/author_names.txt',
               type=edge,
               index_attrs=['name'],
               key_sizes=[26])
    i = 1
    for row in rows:
        el = author_name(id=row[0], name=row[1])
        db.put(el.get_key(), el)
        i += 1
        if i % 1000 == 0:
            print("i=", i)
    print("storing records is done, b_index started..")
    db.b_index()
    db.save()
    print("database created and saved")
示例#7
0
 def setUp(self):
     self.R = Table()
     self.R1 = Table()
     self.S = Table()
示例#8
0
 def add_to_database(self, types):
     self.db.add_table(Table(type=types, from_dump=True))