-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbs.py
74 lines (55 loc) · 2.31 KB
/
dbs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sqlalchemy as al
import datetime
# choose engine and location of the database
engine = al.create_engine('sqlite:///history.db', echo=True)
meta = al.MetaData()
connection = engine.connect()
# creates two tables
sorting = al.Table('sorting algs', meta,
al.Column('time', al.DateTime, primary_key=True,
default=datetime.datetime.now),
al.Column('algorithm', al.String),
al.Column('list size', al.Integer),
al.Column('swaps', al.String),
al.Column('comparisons', al.String))
path_finding = al.Table('path finding', meta,
al.Column('time', al.DateTime, primary_key=True,
default=datetime.datetime.now),
al.Column('algorithm', al.String),
al.Column('maze size', al.Integer),
al.Column('cell scanned', al.Integer))
meta.create_all(engine)
# function to insert into the sorting table
def sort_entry(alg, list_size, swaps, comparison):
connection.execute(sorting.insert(), [
{'algorithm': alg, 'list size': list_size, 'swaps': swaps, 'comparisons': comparison},
])
# function to insert into the maze table
def maze_entry(alg, maze_size, cells):
connection.execute(path_finding.insert(), [
{'algorithm': alg, 'maze size': maze_size, 'cell scanned': cells},
])
# gets all entries from the sorting table
def get_sort():
all_entries = sorting.select()
result = connection.execute(all_entries)
return result
# gets all entries from the maze table
def get_path():
all_entries = path_finding.select()
result = connection.execute(all_entries)
return result
# deletes all entries in maze table
def clear_path():
connection.execute(path_finding.delete())
# deletes all entries in sort table
def clear_sort():
connection.execute(sorting.delete())
# select maze algorithm
def filter_maze(alg):
result = connection.execute(path_finding.select(whereclause=(path_finding.c.algorithm == alg)))
return result
# select sorting algorithm
def filter_sort(alg):
result = connection.execute(sorting.select(whereclause=(sorting.c.algorithm == alg)))
return result