From 746cc0ce2bc2756cfc4a6836e605514f21e285c5 Mon Sep 17 00:00:00 2001
From: dx-tan <dx.tan@samsung.com>
Date: Tue, 6 Feb 2024 16:31:50 +0700
Subject: [PATCH 1/2] Fix: bypass all doc_type

---
 cope2n-api/fwd_api/celery_worker/internal_task.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/cope2n-api/fwd_api/celery_worker/internal_task.py b/cope2n-api/fwd_api/celery_worker/internal_task.py
index ca8ea38..23abef9 100755
--- a/cope2n-api/fwd_api/celery_worker/internal_task.py
+++ b/cope2n-api/fwd_api/celery_worker/internal_task.py
@@ -117,7 +117,10 @@ def process_csv_feedback(csv_file_path, feedback_id):
                 _predict_result = copy.deepcopy(predict_result_to_ready(sub_rq.predict_result))
                 _feedback_result = copy.deepcopy(sub_rq.feedback_result)
                 _reviewed_result = copy.deepcopy(sub_rq.reviewed_result)
-                image.processing_time = time_cost.get(image.doc_type, [0 for _ in range(image.index_in_request)])[image.index_in_request]
+                try:
+                    image.processing_time = time_cost.get(image.doc_type, [0 for _ in range(image.index_in_request)])[image.index_in_request]
+                except Exception as e:
+                    print(f"[ERROR] image.doc_type: {image.doc_type} - image.index_in_request: {image.index_in_request} - time_cost: {time_cost} - {e}")
                 if not validate_feedback_file(_feedback_result, _predict_result):
                     status[request_id] = "Missalign imei number between feedback and predict"
                     continue

From 341ba5ce931dedeff511aef71c9a30034242b2fb Mon Sep 17 00:00:00 2001
From: dx-tan <dx.tan@samsung.com>
Date: Tue, 6 Feb 2024 16:32:09 +0700
Subject: [PATCH 2/2] Add: onetime runnig files

---
 cope2n-api/scripts/re_feedback.py | 66 +++++++++++++++++++++++++++++++
 cope2n-api/scripts/script.py      |  5 ++-
 2 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 cope2n-api/scripts/re_feedback.py

diff --git a/cope2n-api/scripts/re_feedback.py b/cope2n-api/scripts/re_feedback.py
new file mode 100644
index 0000000..34f82a7
--- /dev/null
+++ b/cope2n-api/scripts/re_feedback.py
@@ -0,0 +1,66 @@
+import os
+import time
+import requests
+from datetime import datetime
+# from tqdm import tqdm
+
+ROOT = "/root/TannedCung/sbt-idp/feedback"
+
+interval = 3
+# Get the proxy URL from the environment variable
+proxy_url = os.getenv('PROXY', "localhost")
+
+# Define the login API URL
+login_url = f'{proxy_url}/api/ctel/login/'
+login_token = None
+
+# Define the login credentials
+login_credentials = {
+    'username': 'sbt',
+    # 'password': '7Eg4AbWIXDnufgn'
+    'password': 'abc'
+}
+
+# Define the command to call the update API
+update_url = f'{proxy_url}/api/ctel/images/feedback_file/'
+
+def login():
+    login_token = None
+    login_response = requests.post(login_url, data=login_credentials)
+    # login_response.raise_for_status()
+    if login_response.status_code == 200:
+        login_token = login_response.json()['token']
+        print("[INFO] relogged in at {}".format(datetime.now()))
+    return login_token
+
+def feedback(login_token, file_path):
+    headers = {'Authorization': login_token}
+    files = {
+        'files': (file_path.split("/")[-1], open(file_path, 'rb'), 'text/csv')
+        }
+    response = requests.post(update_url, headers=headers, files=files)
+
+    if response.status_code == 200:
+        print('[INFO]: File uploaded successfully.')
+    else:
+        print('[ERROR]: File upload failed.')
+
+def search_csv_files(directory):
+    csv_files = []
+    for root, dirs, files in os.walk(directory):
+        for file in files:
+            if file.endswith(".csv"):
+                csv_files.append(os.path.join(root, file))
+    
+    csv_files.sort(key=lambda path: int(os.path.basename(os.path.dirname(path))))
+    return csv_files
+
+def main():
+    login_token = login()
+    list_files = search_csv_files(ROOT)
+    for _file in list_files:
+        feedback(login_token, _file)
+        time.sleep(interval)
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file
diff --git a/cope2n-api/scripts/script.py b/cope2n-api/scripts/script.py
index 713c925..7ff2d96 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 = 60*3
+update_cost = 60*2
 proxy_url = os.getenv('PROXY', "localhost")
 
 # Define the login API URL
@@ -15,7 +15,8 @@ login_token = None
 # Define the login credentials
 login_credentials = {
     'username': 'sbt',
-    'password': '7Eg4AbWIXDnufgn'
+    # 'password': '7Eg4AbWIXDnufgn'
+    'password': 'abc'
 }
 
 # Define the command to call the update API