From 45d3f618980f3d1899428e2cb8967e41cfc1c9ba Mon Sep 17 00:00:00 2001 From: TannedCung Date: Fri, 14 Jun 2024 18:09:26 +0700 Subject: [PATCH] Fix: minor bugs --- .env_dev | 47 +++++++++++++++++++ cope2n-api/fwd_api/api/accuracy_view.py | 10 ++-- .../celery_worker/process_report_tasks.py | 16 +++---- cope2n-api/fwd_api/utils/accuracy.py | 5 +- cope2n-api/fwd_api/utils/s3.py | 6 ++- 5 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 .env_dev diff --git a/.env_dev b/.env_dev new file mode 100644 index 0000000..2e9062b --- /dev/null +++ b/.env_dev @@ -0,0 +1,47 @@ +MEDIA_ROOT=/app/media +# DATABASE django setup +DB_ENGINE=django.db.backends.postgresql_psycopg2 +DB_SCHEMA=sbt_prod_20240422_1 +DB_USER=postgres +DB_PASSWORD=TannedCung +DB_HOST=db-sbt +DB_PUBLIC_PORT=5432 +DB_INTERNAL_PORT=5432 + +DEBUG=TRUE +CORS_ALLOWED_ORIGINS=* +CTEL_KEY=fTjWnZr4u7x!A%D*G-KaPdRgUkXp2s5v +DB_INTERNAL_KEY=7LYk-iaWTFPqsZHIE5GHuv41S0c_Vlb0ZVc-BnsEZqQ= +ALLOWED_HOSTS='*' +BROKER_URL=amqp://test:test@rabbitmq-manulife-sbt:5672 +BASE_URL=http://be-ctel-sbt:9000 +BASE_UI_URL=http://fe-sbt:9801 +HOST_MEDIA_FOLDER=./media +GID=1000 +UID=198 +SECRET_KEY=999999999999999999999999999999999999999999999999999999999999999999 +RABBITMQ_DEFAULT_USER=test +RABBITMQ_DEFAULT_PASS=test +BASE_PORT=9000 +# S3_HOST=http://minio:9884 +# S3_ACCESS_KEY=TannedCung +# S3_SECRET_KEY=TannedCung +# S3_BUCKET_NAME=ocr-sds +S3_ACCESS_KEY=AKIA3AFPFVWZHYID6NY7 +S3_SECRET_KEY=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 +S3_BUCKET_NAME=ocr-sds + +AUTH_TOKEN_LIFE_TIME=168 +IMAGE_TOKEN_LIFE_TIME=168 +INTERNAL_SDS_KEY=TannedCung +ADMIN_USER_NAME=sbt +ADMIN_PASSWORD=abc +STANDARD_USER_NAME=sbt_standard +STANDARD_PASSWORD=abc + +# Front end env variables +# VITE_PORT=80 +# VITE_PROXY=http://0.0.0.0 +# VITE_API_BASE_URL=http://0.0.0.0:8000 +# PORT=8002 +# PORT=8002 \ No newline at end of file diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index a4543fd..bec5437 100755 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -982,11 +982,11 @@ class AccuracyViewSet(viewsets.ViewSet): "purchase_date": None, "imei_number": [] } - for k, v in file_result.items(): + for k, v in file_result.items(): if k in sample_result.keys(): if not isinstance(sample_result[k], list): sample_result[k] = v - else: + elif v: sample_result[k].append(v) if subscription_request_file.reviewed_result is not None: @@ -994,8 +994,10 @@ class AccuracyViewSet(viewsets.ViewSet): else: subscription_request_file.reviewed_result = sample_result - subscription_request_file.reason = reason - subscription_request_file.counter_measures = solution + if reason: + subscription_request_file.reason = reason + if solution: + subscription_request_file.counter_measures = solution subscription_request_file.is_reviewed = True subscription_request_file.save() is_available = True 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 1d89693..1d3b27e 100755 --- a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py @@ -126,16 +126,12 @@ def create_accuracy_report(report_id, **kwargs): rq_accuracy = {"feedback": [], "reviewed": []} - for _att in _atts: - for t in _att["acc"].keys(): - for cl in _att["acc"][t].keys(): - rq_accuracy[t] += _att["acc"][t][cl] - - # for rpf in _report_files: - # for cl in rpf.feedback_accuracy.keys(): - # rq_accuracy["feedback"] += rpf.feedback_accuracy[cl] - # for cl in rpf.reviewed_accuracy.keys(): - # rq_accuracy["reviewed"] += rpf.reviewed_accuracy[cl] + for rpf in _report_files: + for cl in rpf.feedback_accuracy.keys(): + rq_accuracy["feedback"] += rpf.feedback_accuracy[cl] + for cl in rpf.reviewed_accuracy.keys(): + rq_accuracy["reviewed"] += rpf.reviewed_accuracy[cl] + request.is_required = False if len(rq_accuracy["reviewed"]) > 0: request.raw_accuracy = mean_list(rq_accuracy["reviewed"]) diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index 71a0ace..ef88970 100755 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -351,8 +351,9 @@ class ReportAccumulateByRequest: for key in settings.FIELD: _report["average_accuracy_rate"][key] = _report["average_accuracy_rate"][key]() for accuracy_type in ["feedback_accuracy", "reviewed_accuracy"]: - avg_acc = (avg_acc*count_acc + _report[accuracy_type][key].avg*_report[accuracy_type][key].count) / (_report[accuracy_type][key].count + count_acc) - count_acc += _report[accuracy_type][key].count + if (_report[accuracy_type][key].count + count_acc) > 0: + avg_acc = (avg_acc*count_acc + _report[accuracy_type][key].avg*_report[accuracy_type][key].count) / (_report[accuracy_type][key].count + count_acc) + count_acc += _report[accuracy_type][key].count _report[accuracy_type][key] = _report[accuracy_type][key]() _report["average_accuracy_rate"]["avg"] = avg_acc diff --git a/cope2n-api/fwd_api/utils/s3.py b/cope2n-api/fwd_api/utils/s3.py index c1ee84f..722dde0 100644 --- a/cope2n-api/fwd_api/utils/s3.py +++ b/cope2n-api/fwd_api/utils/s3.py @@ -14,12 +14,16 @@ class MinioS3Client: aws_access_key_id=access_key, aws_secret_access_key=secret_key ) - else: + elif len(secret_key) > 0 and len(access_key) > 0: self.s3_client = boto3.client( 's3', aws_access_key_id=access_key, aws_secret_access_key=secret_key ) + else: + self.s3_client = boto3.client( + 's3') + except Exception as e: print(f"[WARM] Unable to create an s3 client, {e}") self.s3_client = None