From 00a2ffa98974443031905201639c222d8a92e20a Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 23 Feb 2024 15:50:52 +0700 Subject: [PATCH] Fix: SEAO --- cope2n-api/fwd/settings.py | 4 +++- cope2n-api/fwd_api/api/accuracy_view.py | 2 +- cope2n-api/fwd_api/celery_worker/process_report_tasks.py | 4 +--- cope2n-api/fwd_api/utils/accuracy.py | 2 +- cope2n-api/fwd_api/utils/report.py | 1 + cope2n-api/fwd_api/utils/subsidiary.py | 6 +++--- cope2n-api/scripts/script.py | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cope2n-api/fwd/settings.py b/cope2n-api/fwd/settings.py index 39860be..cc8a106 100755 --- a/cope2n-api/fwd/settings.py +++ b/cope2n-api/fwd/settings.py @@ -234,9 +234,11 @@ SUBS = { "TSE": "TH", "SEIN": "ID", "ALL": "all", # all_detail - "ALL_SUMARY": "ALL_SUMARY" + "SEAO": "seao" } +SUB_FOR_BILLING = ["all", "seao"] + CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index e68cb4f..7e7dec1 100644 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -510,7 +510,7 @@ class AccuracyViewSet(viewsets.ViewSet): key = f"{sub}_{duration}" try: this_overview = json.loads(redis_client.get_specific_cache(settings.OVERVIEW_REPORT_ROOT, key)).get("data", []) - if sub != "ALL_SUMARY": + if sub != "seao": this_overview = [d for d in this_overview if d.get("subs") != "+"] else: for item in this_overview: diff --git a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py index 0e1e710..1a514ae 100644 --- a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py @@ -180,7 +180,7 @@ def make_a_report_2(report_id, query_set): if query_set["include_test"]: base_query = ~base_query if isinstance(query_set["subsidiary"], str): - if query_set["subsidiary"] and query_set["subsidiary"].lower().replace(" ", "")!="all": + if query_set["subsidiary"] and query_set["subsidiary"].lower().replace(" ", "") not in settings.SUB_FOR_BILLING: base_query &= Q(redemption_id__startswith=query_set["subsidiary"]) if isinstance(query_set["is_reviewed"], str): if query_set["is_reviewed"] == "reviewed": @@ -304,8 +304,6 @@ def make_a_report_2(report_id, query_set): for x_key in report_fine_data[i][key].keys(): report_fine_data[i][key][x_key] = report_fine_data[i][key][x_key]*100 data_workbook = dict2xlsx(report_fine_data, _type='report') - if query_set["subsidiary"] == "ALL": - query_set["subsidiary"] = "ALL_SUMARY" overview_filename = query_set["subsidiary"] + "_" + query_set["report_overview_duration"] + ".xlsx" local_workbook = save_workbook_file(overview_filename, report, data_workbook, settings.OVERVIEW_REPORT_ROOT) s3_key=save_report_to_S3(report.report_id, local_workbook) diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index 136cd5d..03b3632 100644 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -584,7 +584,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True) def count_transactions(start_date, end_date, subsidiary="all"): base_query = Q(created_at__range=(start_date, end_date)) base_query &= Q(is_test_request=False) - if subsidiary and subsidiary.lower().replace(" ", "")!="all": + if subsidiary and subsidiary.lower().replace(" ", "") not in settings.SUB_FOR_BILLING: base_query &= Q(redemption_id__startswith=subsidiary) transaction_att = {} diff --git a/cope2n-api/fwd_api/utils/report.py b/cope2n-api/fwd_api/utils/report.py index fcc2a37..b1e4462 100644 --- a/cope2n-api/fwd_api/utils/report.py +++ b/cope2n-api/fwd_api/utils/report.py @@ -1,5 +1,6 @@ CAT_VALUES = { "ALL": "ZZZZZZZZ", + "SEAO": "ZZ" } def aggregate_overview(overview_list): overview_list = sorted(overview_list, key=lambda x: x["extraction_date"] + CAT_VALUES.get(x["subs"], x["subs"]), reverse=True) diff --git a/cope2n-api/fwd_api/utils/subsidiary.py b/cope2n-api/fwd_api/utils/subsidiary.py index d10c879..78a8b55 100644 --- a/cope2n-api/fwd_api/utils/subsidiary.py +++ b/cope2n-api/fwd_api/utils/subsidiary.py @@ -2,10 +2,10 @@ from fwd.settings import SUBS def map_subsidiary_long_to_short(long_sub): short_sub = SUBS.get(long_sub.upper(), "all") - return short_sub.upper() + return short_sub def map_subsidiary_short_to_long(short_sub): for k, v in SUBS.items(): - if v == short_sub.upper(): + if v == short_sub.upper() or v == short_sub: return k - return "ALL" \ No newline at end of file + return "SEAO" \ No newline at end of file diff --git a/cope2n-api/scripts/script.py b/cope2n-api/scripts/script.py index a906a44..8f0c599 100644 --- a/cope2n-api/scripts/script.py +++ b/cope2n-api/scripts/script.py @@ -5,7 +5,7 @@ from datetime import datetime # Get the proxy URL from the environment variable interval = 60*60*1 # 1 minute -update_cost = int(60*1.5) +update_cost = int(60*2) proxy_url = os.getenv('PROXY', "localhost") # Define the login API URL @@ -29,7 +29,7 @@ update_data = { "report_overview_duration" -def update_report(login_token, report_overview_duration=["30d", "7d"], subsidiary=["all", "SEAU", "SESP", "SME", "SEPCO", "TSE", "SEIN"]): +def update_report(login_token, report_overview_duration=["30d", "7d"], subsidiary=["SEAO", "SEAU", "SESP", "SME", "SEPCO", "TSE", "SEIN"]): headers = {'Authorization': login_token} for dur in report_overview_duration: for sub in subsidiary: