From e7813fa8d7a74b79d4e0952c15c96a736dbb279e Mon Sep 17 00:00:00 2001 From: m-d-bowerman Date: Mon, 7 Aug 2023 09:34:40 -0700 Subject: [PATCH 1/4] Add All option for local preset runs --- auto_sizing/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_sizing/cli.py b/auto_sizing/cli.py index 66d547c..05f5b38 100644 --- a/auto_sizing/cli.py +++ b/auto_sizing/cli.py @@ -372,7 +372,7 @@ def run( raise Exception("Either provide a config file or run auto sizing presets.") analysis_executor = AnalysisExecutor( - target_slug=target_slug, + target_slug=target_slug if target_slug else All, project_id=project_id, dataset_id=dataset_id, bucket=bucket, From e20db177bae37120d41d38dc198a5c4d0db30d4e Mon Sep 17 00:00:00 2001 From: m-d-bowerman Date: Wed, 9 Aug 2023 09:49:51 -0700 Subject: [PATCH 2/4] Adjust result saving when no bucket is passed --- auto_sizing/size_calculation.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/auto_sizing/size_calculation.py b/auto_sizing/size_calculation.py index 7b3b207..a593722 100644 --- a/auto_sizing/size_calculation.py +++ b/auto_sizing/size_calculation.py @@ -8,6 +8,7 @@ from mozanalysis.experiment import TimeLimits from mozanalysis.frequentist_stats.sample_size import z_or_t_ind_sample_size_calc from mozanalysis.sizing import HistoricalTarget +from numpy import nan, ndarray from pandas import DataFrame import auto_sizing.errors as errors @@ -86,7 +87,7 @@ def calculate_metrics( ) ) - df = self.bigquerycontext.run_query(metrics_sql, metrics_table_name).to_dataframe() + df = self.bigquerycontext.run_query(metrics_sql, metrics_table_name, replace_tables=True).to_dataframe() delete_bq_table( self.bigquerycontext.fully_qualify_table_name(targets_table_name), self.project ) @@ -106,8 +107,10 @@ def calculate_sample_sizes( metrics_results = { key: { "number_of_clients_targeted": res[key]["number_of_clients_targeted"], - "sample_size_per_branch": res[key]["sample_size_per_branch"], - "population_percent_per_branch": res[key]["population_percent_per_branch"], + "sample_size_per_branch": + nan if type(res[key]["sample_size_per_branch"]) == ndarray else res[key]["sample_size_per_branch"], + "population_percent_per_branch": + nan if type(res[key]["population_percent_per_branch"]) == ndarray else res[key]["population_percent_per_branch"], } for key in res.keys() } @@ -124,7 +127,7 @@ def publish_results(self, result_dict: Dict[str, Any], current_date: str) -> Non path.write_text(json.dumps(result_dict)) print(f"Results saved at {path}") - else: + elif self.bucket: export_sample_size_json( self.project, self.bucket, @@ -132,6 +135,10 @@ def publish_results(self, result_dict: Dict[str, Any], current_date: str) -> Non json.dumps(result_dict), current_date, ) + + path = Path(__file__).parent / f"{self.config.target_slug}.json" + path.write_text(json.dumps(result_dict)) + print(f"Results saved at {path}") def run(self, current_date: datetime) -> None: time_limits = self._validate_requested_timelimits(current_date) From 99c9c508a7e15ebd0e6c54430627a7fa634c57f3 Mon Sep 17 00:00:00 2001 From: m-d-bowerman Date: Wed, 9 Aug 2023 10:15:21 -0700 Subject: [PATCH 3/4] formatting --- auto_sizing/size_calculation.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/auto_sizing/size_calculation.py b/auto_sizing/size_calculation.py index a593722..a8e5824 100644 --- a/auto_sizing/size_calculation.py +++ b/auto_sizing/size_calculation.py @@ -87,7 +87,9 @@ def calculate_metrics( ) ) - df = self.bigquerycontext.run_query(metrics_sql, metrics_table_name, replace_tables=True).to_dataframe() + df = self.bigquerycontext.run_query( + metrics_sql, metrics_table_name, replace_tables=True + ).to_dataframe() delete_bq_table( self.bigquerycontext.fully_qualify_table_name(targets_table_name), self.project ) @@ -107,10 +109,12 @@ def calculate_sample_sizes( metrics_results = { key: { "number_of_clients_targeted": res[key]["number_of_clients_targeted"], - "sample_size_per_branch": - nan if type(res[key]["sample_size_per_branch"]) == ndarray else res[key]["sample_size_per_branch"], - "population_percent_per_branch": - nan if type(res[key]["population_percent_per_branch"]) == ndarray else res[key]["population_percent_per_branch"], + "sample_size_per_branch": nan + if type(res[key]["sample_size_per_branch"]) == ndarray + else res[key]["sample_size_per_branch"], + "population_percent_per_branch": nan + if type(res[key]["population_percent_per_branch"]) == ndarray + else res[key]["population_percent_per_branch"], } for key in res.keys() } @@ -135,7 +139,7 @@ def publish_results(self, result_dict: Dict[str, Any], current_date: str) -> Non json.dumps(result_dict), current_date, ) - + path = Path(__file__).parent / f"{self.config.target_slug}.json" path.write_text(json.dumps(result_dict)) print(f"Results saved at {path}") From 7dcc330b00dbf7e1e8106a9736fbbc7533f3a746 Mon Sep 17 00:00:00 2001 From: m-d-bowerman Date: Wed, 9 Aug 2023 10:29:51 -0700 Subject: [PATCH 4/4] flake8 fixes --- auto_sizing/size_calculation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto_sizing/size_calculation.py b/auto_sizing/size_calculation.py index a8e5824..7414243 100644 --- a/auto_sizing/size_calculation.py +++ b/auto_sizing/size_calculation.py @@ -110,10 +110,10 @@ def calculate_sample_sizes( key: { "number_of_clients_targeted": res[key]["number_of_clients_targeted"], "sample_size_per_branch": nan - if type(res[key]["sample_size_per_branch"]) == ndarray + if isinstance(res[key]["sample_size_per_branch"], ndarray) else res[key]["sample_size_per_branch"], "population_percent_per_branch": nan - if type(res[key]["population_percent_per_branch"]) == ndarray + if type(res[key]["population_percent_per_branch"], ndarray) else res[key]["population_percent_per_branch"], } for key in res.keys()