-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
72 lines (62 loc) · 1.71 KB
/
cli.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
import pg
import mysql_ex
import mongo
import click
from rich import print
import experiment
@click.group()
def cli():
pass
@cli.command()
def prepare():
"""
Prepare the experiment log, which is stored as an SQLite database.
"""
table = "result"
exists = experiment.table_exists(table)
if exists:
row_count = experiment.get_row_count(table)
if row_count > 0:
print(
f"[bold red]WARNING:[/bold red] table '{table}' contains {row_count} rows"
)
drop = click.confirm(f"Do you want to drop and recreate the table '{table}'?")
if drop:
experiment.initialize()
else:
experiment.initialize()
@cli.command()
@click.argument("dbms", type=str)
def init(dbms: str):
"""
Run script to initialize the experiment schema for the specified DBMS.
"""
print(f"Initializing experiment table for {dbms=}")
if dbms == "pg":
pg.reset_database()
elif dbms == "mysql":
mysql_ex.reset_database()
elif dbms == "mongo":
mongo.reset_database()
else:
raise ValueError(f"Invalid DBMS specified: '{dbms}'")
@cli.command()
@click.option("-i", default=1, help="Number of runs of each experimental setup")
@click.option(
"-n", default=100000, help="Number of records to insert for each experimental run"
)
@click.option(
"-p",
default=1000000,
help="Number of records to preload before each experimental run",
)
def run(i: int, n: int, p: int):
for j in range(i):
experiment.run_experiments(
experiment_size=n,
preload_size=p,
max_iterations=i,
current_iteration=j,
)
if __name__ == "__main__":
cli()