Fix: SEAO

This commit is contained in:
dx-tan 2024-02-23 15:50:52 +07:00
parent c605b51863
commit 00a2ffa989
7 changed files with 12 additions and 11 deletions

View File

@ -234,9 +234,11 @@ SUBS = {
"TSE": "TH", "TSE": "TH",
"SEIN": "ID", "SEIN": "ID",
"ALL": "all", # all_detail "ALL": "all", # all_detail
"ALL_SUMARY": "ALL_SUMARY" "SEAO": "seao"
} }
SUB_FOR_BILLING = ["all", "seao"]
CACHES = { CACHES = {
'default': { 'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache', 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',

View File

@ -510,7 +510,7 @@ class AccuracyViewSet(viewsets.ViewSet):
key = f"{sub}_{duration}" key = f"{sub}_{duration}"
try: try:
this_overview = json.loads(redis_client.get_specific_cache(settings.OVERVIEW_REPORT_ROOT, key)).get("data", []) 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") != "+"] this_overview = [d for d in this_overview if d.get("subs") != "+"]
else: else:
for item in this_overview: for item in this_overview:

View File

@ -180,7 +180,7 @@ def make_a_report_2(report_id, query_set):
if query_set["include_test"]: if query_set["include_test"]:
base_query = ~base_query base_query = ~base_query
if isinstance(query_set["subsidiary"], str): 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"]) base_query &= Q(redemption_id__startswith=query_set["subsidiary"])
if isinstance(query_set["is_reviewed"], str): if isinstance(query_set["is_reviewed"], str):
if query_set["is_reviewed"] == "reviewed": 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(): 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 report_fine_data[i][key][x_key] = report_fine_data[i][key][x_key]*100
data_workbook = dict2xlsx(report_fine_data, _type='report') 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" 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) 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) s3_key=save_report_to_S3(report.report_id, local_workbook)

View File

@ -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"): def count_transactions(start_date, end_date, subsidiary="all"):
base_query = Q(created_at__range=(start_date, end_date)) base_query = Q(created_at__range=(start_date, end_date))
base_query &= Q(is_test_request=False) 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) base_query &= Q(redemption_id__startswith=subsidiary)
transaction_att = {} transaction_att = {}

View File

@ -1,5 +1,6 @@
CAT_VALUES = { CAT_VALUES = {
"ALL": "ZZZZZZZZ", "ALL": "ZZZZZZZZ",
"SEAO": "ZZ"
} }
def aggregate_overview(overview_list): 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) overview_list = sorted(overview_list, key=lambda x: x["extraction_date"] + CAT_VALUES.get(x["subs"], x["subs"]), reverse=True)

View File

@ -2,10 +2,10 @@ from fwd.settings import SUBS
def map_subsidiary_long_to_short(long_sub): def map_subsidiary_long_to_short(long_sub):
short_sub = SUBS.get(long_sub.upper(), "all") short_sub = SUBS.get(long_sub.upper(), "all")
return short_sub.upper() return short_sub
def map_subsidiary_short_to_long(short_sub): def map_subsidiary_short_to_long(short_sub):
for k, v in SUBS.items(): for k, v in SUBS.items():
if v == short_sub.upper(): if v == short_sub.upper() or v == short_sub:
return k return k
return "ALL" return "SEAO"

View File

@ -5,7 +5,7 @@ from datetime import datetime
# Get the proxy URL from the environment variable # Get the proxy URL from the environment variable
interval = 60*60*1 # 1 minute interval = 60*60*1 # 1 minute
update_cost = int(60*1.5) update_cost = int(60*2)
proxy_url = os.getenv('PROXY', "localhost") proxy_url = os.getenv('PROXY', "localhost")
# Define the login API URL # Define the login API URL
@ -29,7 +29,7 @@ update_data = {
"report_overview_duration" "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} headers = {'Authorization': login_token}
for dur in report_overview_duration: for dur in report_overview_duration:
for sub in subsidiary: for sub in subsidiary: