forked from TonicAI/condenser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (49 loc) · 1.98 KB
/
main.py
File metadata and controls
69 lines (49 loc) · 1.98 KB
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
from subset import Subset
from database_creator import DatabaseCreator
from db_connect import DbConnect
from config_reader import ConfigReader
from subset_result_norm import SubsetResultNorm
from scipy.optimize import bisect
from result_tabulator import SubsetResultFunc
source_dbc = DbConnect('.source_db_connection_info')
destination_dbc = DbConnect('.destination_db_connection_info')
temp_schema = 'subset'
schema = 'public'
def func(percent, lower_limit, lower_limit_norm, upper_limit, upper_limit_norm):
if percent == lower_limit:
return lower_limit_norm
if percent == upper_limit:
return upper_limit_norm
return func_base(percent)
def func_base(percent):
database = DatabaseCreator(source_dbc, destination_dbc, temp_schema, False)
database.teardown()
database.create()
database.validate_database_create()
s = Subset(source_dbc, destination_dbc, percent, temp_schema)
s.run_downward()
database.add_constraints()
database.validate_constraints()
norm = SubsetResultNorm(source_dbc, destination_dbc, 'public').norm()
print(percent, norm)
return norm
def compute_fast_limits():
desired_result = ConfigReader().get_desired_result()['percent']
upper_limit_guess = desired_result
last_result = desired_result
lower_limit_guess = 0
result = func_base(upper_limit_guess)
while result > 0:
lower_limit_guess = upper_limit_guess
upper_limit_guess *= 2
last_result = result
result = func_base(upper_limit_guess)
return (lower_limit_guess, last_result, upper_limit_guess, result)
if __name__ == '__main__':
lower_limit, lower_limit_norm, upper_limit, upper_limit_norm = compute_fast_limits()
max_tries = ConfigReader().get_max_tries()
try:
bisect(func, lower_limit, upper_limit, maxiter=max_tries, args=(lower_limit, lower_limit_norm, upper_limit, upper_limit_norm))
except:
pass
SubsetResultFunc(source_dbc, destination_dbc, schema).tabulate()