2424
2525from forms .core .forms import from_db
2626
27+
2728def wait_for_postgres (host , port , user , password , dbname , timeout = 15 ):
2829 start_time = time .time ()
2930 while time .time () - start_time < timeout :
@@ -35,10 +36,8 @@ def wait_for_postgres(host, port, user, password, dbname, timeout=15):
3536 time .sleep (1 )
3637 raise Exception ("PostgreSQL did not start within the given timeout" )
3738
38- def start_postgres_container (postgres_user : str ,
39- dbname : str ,
40- password : str ,
41- port : int ) -> Container :
39+
40+ def start_postgres_container (postgres_user : str , dbname : str , password : str , port : int ) -> Container :
4241 docker_client = docker .from_env ()
4342
4443 # Start the PostgreSQL container
@@ -55,23 +54,27 @@ def start_postgres_container(postgres_user: str,
5554 )
5655 except DockerException as e :
5756 raise Exception (f"Failed to start PostgreSQL container: { e } " )
58-
57+
5958 return container
6059
61- def load_table (postgres_user : str ,
62- password : str , dbname : str ,
63- host : str , port : str ,
64- dataset_path : str ,
65- schema_path : str ,
66- test_table : str ):
60+
61+ def load_table (
62+ postgres_user : str ,
63+ password : str ,
64+ dbname : str ,
65+ host : str ,
66+ port : str ,
67+ dataset_path : str ,
68+ schema_path : str ,
69+ test_table : str ,
70+ ):
6771
6872 # Wait for the PostgreSQL service to be ready
69- wait_for_postgres (host = host , port = port , user = postgres_user ,
70- password = password , dbname = dbname )
73+ wait_for_postgres (host = host , port = port , user = postgres_user , password = password , dbname = dbname )
7174
7275 # Load a DataFrame into the database
7376 engine = create_engine (f"postgresql://{ postgres_user } :{ password } @{ host } :{ port } /{ dbname } " )
74- with open (schema_path , 'r' ) as schema_file :
77+ with open (schema_path , "r" ) as schema_file :
7578 schema_sql = schema_file .read ()
7679 with engine .connect () as connection :
7780 connection .execute (schema_sql )
@@ -80,9 +83,17 @@ def load_table(postgres_user: str,
8083 df .to_sql (test_table , engine , if_exists = "append" , index = False )
8184
8285
83- def run (dataset_path , schema_path , table_name , primary_key ,
84- formula_file_path , run : int , pipeline_optimization : bool , output_folder ):
85-
86+ def run (
87+ dataset_path ,
88+ schema_path ,
89+ table_name ,
90+ primary_key ,
91+ formula_file_path ,
92+ run : int ,
93+ pipeline_optimization : bool ,
94+ output_folder ,
95+ ):
96+
8697 host = "localhost"
8798 port = "5432"
8899 postgres_user = "dt"
@@ -109,13 +120,13 @@ def run(dataset_path, schema_path, table_name, primary_key,
109120 )
110121
111122 # Parse the formula file
112- formula_id = ' formula_id'
113- formula_string = ' formula_string'
123+ formula_id = " formula_id"
124+ formula_string = " formula_string"
114125 formulas = pd .read_csv (formula_file_path , header = None , names = [formula_id , formula_string ])
115126
116127 for _ , row in formulas .iterrows ():
117- formula_id = row [' formula_id' ]
118- formula_string = row [' formula_string' ]
128+ formula_id = row [" formula_id" ]
129+ formula_string = row [" formula_string" ]
119130 # Execute the formula string
120131 print (f"Running formula { formula_id } : { formula_string } " )
121132 wb .compute_formula (formula_string )
@@ -127,19 +138,25 @@ def run(dataset_path, schema_path, table_name, primary_key,
127138 # Tear down the PostgreSQL container
128139 container .stop ()
129140 container .remove ()
130-
141+
131142
132143if __name__ == "__main__" :
133144 import argparse
134145
135146 parser = argparse .ArgumentParser (description = "Benchmarking script for FormS" )
136147 parser .add_argument ("--dataset_path" , required = True , help = "Path to the dataset folder" )
137- parser .add_argument ("--schema_path" , required = True , help = "Path to the sql query that creates the table" )
148+ parser .add_argument (
149+ "--schema_path" , required = True , help = "Path to the sql query that creates the table"
150+ )
138151 parser .add_argument ("--table_name" , required = True , help = "Name of the table" )
139152 parser .add_argument ("--primary_key" , required = True , help = "Primary key of the table" )
140153 parser .add_argument ("--formula_file_path" , required = True , help = "Path of the formula file" )
141154 parser .add_argument ("--run" , required = True , type = int , help = "Test run identifier" )
142- parser .add_argument ("--pipeline_optimization" , required = True , help = "False: function-level translation; True: subtree-level translation" )
155+ parser .add_argument (
156+ "--pipeline_optimization" ,
157+ required = True ,
158+ help = "False: function-level translation; True: subtree-level translation" ,
159+ )
143160 parser .add_argument ("--output_folder" , required = True , help = "Path to the output folder" )
144161
145162 args = parser .parse_args ()
@@ -154,5 +171,5 @@ def run(dataset_path, schema_path, table_name, primary_key,
154171 formula_file_path = args .formula_file_path ,
155172 run = args .run ,
156173 pipeline_optimization = pipeline_optimization ,
157- output_folder = args .output_folder
158- )
174+ output_folder = args .output_folder ,
175+ )
0 commit comments