From a9ae6549573cdfaf698998dc815dd1e47b9486aa Mon Sep 17 00:00:00 2001
From: phanphan <lh.phan@samsung.com>
Date: Thu, 6 Jun 2024 11:05:05 +0700
Subject: [PATCH 1/6] improve some ui

---
 cope2n-fe/package.json                    |  1 +
 cope2n-fe/src/pages/reviews2/FileCard.tsx | 40 +++++++++++++---------
 cope2n-fe/src/pages/reviews2/api.ts       |  2 +-
 cope2n-fe/src/pages/reviews2/index.tsx    | 41 ++++++++++++++---------
 4 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/cope2n-fe/package.json b/cope2n-fe/package.json
index 9cfce13..06c2cfc 100644
--- a/cope2n-fe/package.json
+++ b/cope2n-fe/package.json
@@ -41,6 +41,7 @@
     "history": "^5.3.0",
     "lodash-es": "^4.17.21",
     "mousetrap": "^1.6.5",
+    "openseadragon": "^4.1.1",
     "pdfjs-dist": "^3.11.174",
     "process": "^0.11.10",
     "react": "^18.3.1",
diff --git a/cope2n-fe/src/pages/reviews2/FileCard.tsx b/cope2n-fe/src/pages/reviews2/FileCard.tsx
index 7156e9d..79efa76 100644
--- a/cope2n-fe/src/pages/reviews2/FileCard.tsx
+++ b/cope2n-fe/src/pages/reviews2/FileCard.tsx
@@ -8,10 +8,9 @@ import { Button, Tag } from 'antd';
 const FileCard = ({ file, isSelected, onClick }) => {
   const fileName = file['File Name'];
   const extensionType = fileName.split('.').pop();
-  let status = true;
-  if (file['Is Required'] && !file['Is Reviewed']) {
-    status = false;
-  }
+  const isRequired = file['Is Required'];
+  const isReviewd = file['Is Reviewed'];
+
   return (
     <div
       style={{
@@ -52,20 +51,29 @@ const FileCard = ({ file, isSelected, onClick }) => {
           >
             {fileName
               ? fileName.substring(0, 25).replace('temp_', '')
-              : fileName}
-            {' '}({extensionType})
+              : fileName}{' '}
+            ({extensionType})
           </span>
         </div>
-        <Tag
-          color={status ? 'success' : 'warning'}
-          icon={
-            status ? <CheckCircleOutlined /> : <ExclamationCircleOutlined />
-          }
-          style={{ display: 'inline-block', fontWeight: 'bold' }}
-          // bordered={false}
-        >
-          {status ? 'Good' : 'Warning'}{' '}
-        </Tag>
+        <div style={{display: 'flex', justifyContent: 'space-between', alignItems:'center'}}>
+          <Tag
+            color={isRequired ? 'warning' : ''}
+            style={{ display: 'inline-block', fontWeight: 'bold' , textTransform: 'capitalize' }}
+            // bordered={false}
+          >
+            Required: {isRequired.toString()}
+          </Tag>
+
+
+          <Tag
+            color={isReviewd ? 'success' : 'warning'}
+            style={{ display: 'inline-block', fontWeight: 'bold', textTransform: 'capitalize' }}
+            // bordered={false}
+          >
+            Reviewed: {isReviewd.toString()}
+          </Tag>
+
+        </div>
       </div>
       <Button
         style={{
diff --git a/cope2n-fe/src/pages/reviews2/api.ts b/cope2n-fe/src/pages/reviews2/api.ts
index 998dd20..29123f8 100644
--- a/cope2n-fe/src/pages/reviews2/api.ts
+++ b/cope2n-fe/src/pages/reviews2/api.ts
@@ -56,7 +56,7 @@ export const updateRevisedData = async (requestID: any) => {
     console.log(error);
     throw error;
   });
-  if (result.status != 200) {
+  if (!result.ok) {
     throw new Error('Could not update revised data');
   }
 };
diff --git a/cope2n-fe/src/pages/reviews2/index.tsx b/cope2n-fe/src/pages/reviews2/index.tsx
index 4601dbf..cd03908 100644
--- a/cope2n-fe/src/pages/reviews2/index.tsx
+++ b/cope2n-fe/src/pages/reviews2/index.tsx
@@ -53,6 +53,8 @@ import {
 } from './const';
 import FileCard from './FileCard';
 import RecentRequest from './RecentRequest';
+import './style.css';
+
 const ReviewPage = () => {
   const [loading, setLoading] = useState(false);
   const [fullscreen, setFullscreen] = useState(false);
@@ -137,13 +139,19 @@ const ReviewPage = () => {
       SOURCE_OBJECT_NAMES.forEach((name) => {
         tempData[k][name] = fileContent[name][k];
       });
-      if (
-        (isEmpty(tempData[k][REVIEWED_RESULT]) ||
-          (tempData[k][REVIEWED_RESULT].length == 1 &&
-            isEmpty(tempData[k][REVIEWED_RESULT][0]))) &&
-        !isEmpty(tempData[k][PREDICTED_RESULT])
-      ) {
-        tempData[k][REVIEWED_RESULT] = tempData[k][PREDICTED_RESULT];
+      if (!isEmpty(tempData[k][PREDICTED_RESULT])) {
+        let isEmptyResult = false;
+        if (isEmpty(tempData[k][REVIEWED_RESULT])) {
+          isEmptyResult = true;
+        }
+        if (tempData[k][REVIEWED_RESULT].length > 0) {
+          isEmptyResult = tempData[k][REVIEWED_RESULT].every((r: any) =>
+            isEmpty(r),
+          );
+        }
+        if (isEmptyResult) {
+          tempData[k][REVIEWED_RESULT] = tempData[k][PREDICTED_RESULT];
+        }
       }
     });
 
@@ -277,8 +285,8 @@ const ReviewPage = () => {
     );
     if (isConfirmed) {
       try {
-        addRecentRequest(currentRequest?.RequestID);
         await updateRevisedData(currentRequest?.RequestID);
+        addRecentRequest(currentRequest?.RequestID);
         setCurrentRequest({
           ...currentRequest,
           ['Is Reviewed']: true,
@@ -327,6 +335,8 @@ const ReviewPage = () => {
   // use left/right keys to navigate
   useHotkeys('left', gotoPreviousRequest);
   useHotkeys('right', gotoNextRequest);
+  useHotkeys('u', submitRevisedData);
+  useHotkeys('c', handleConfirmReview);
 
   const fileExtension = selectedFileName
     ? selectedFileName.split('.').pop()
@@ -527,13 +537,12 @@ const ReviewPage = () => {
                 overflowX: 'visible',
               }}
             >
-              <Spin spinning={imageLoading}>
+              <Spin spinning={imageLoading} wrapperClassName='image-spin'>
                 <img
                   style={{
-                    maxHeight: '100%',
-                    maxWidth: '100%',
-                    height: 'auto',
-                    width: 'auto',
+                    height: '100%',
+                    width: '100%',
+                    objectFit: 'contain',
                     cursor: 'zoom-in',
                   }}
                   src={selectedFileData}
@@ -666,7 +675,7 @@ const ReviewPage = () => {
               style={{ minWidth: '120px' }}
               onClick={handleConfirmReview}
             >
-              Confirm request
+              (C) Confirm request
             </Button>
           </div>
         </div>
@@ -721,7 +730,7 @@ const ReviewPage = () => {
                 }
               } catch (error) {}
               return (
-                <div style={{ margin: '0 0 8px' }}>
+                <div style={{ margin: '0 0 8px' }} className='file-input-group'>
                   <div
                     style={{
                       display: 'flex',
@@ -828,7 +837,7 @@ const ReviewPage = () => {
               }}
               onClick={submitRevisedData}
             >
-              Update File
+              (U) Update File
             </Button>
           </div>
         </div>

From edf8966fccfde1ea829a3b1fef1bc373d62c0d4d Mon Sep 17 00:00:00 2001
From: phanphan <lh.phan@samsung.com>
Date: Thu, 6 Jun 2024 11:08:18 +0700
Subject: [PATCH 2/6] improve some ui

---
 cope2n-fe/package.json | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cope2n-fe/package.json b/cope2n-fe/package.json
index 06c2cfc..9cfce13 100644
--- a/cope2n-fe/package.json
+++ b/cope2n-fe/package.json
@@ -41,7 +41,6 @@
     "history": "^5.3.0",
     "lodash-es": "^4.17.21",
     "mousetrap": "^1.6.5",
-    "openseadragon": "^4.1.1",
     "pdfjs-dist": "^3.11.174",
     "process": "^0.11.10",
     "react": "^18.3.1",

From 4c075aea699daa00975a7e504839d5a28547670c Mon Sep 17 00:00:00 2001
From: TannedCung <dx.tan@samsung.com>
Date: Thu, 6 Jun 2024 13:15:42 +0700
Subject: [PATCH 3/6] Fix: empty accuracy requests

---
 cope2n-api/fwd_api/utils/accuracy.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py
index ceced56..66bea04 100755
--- a/cope2n-api/fwd_api/utils/accuracy.py
+++ b/cope2n-api/fwd_api/utils/accuracy.py
@@ -847,7 +847,6 @@ def calculate_a_request(report, request):
         rv_avg_acc = avg_dict(att["acc"]["reviewed"])
 
         image.is_required = fb_avg_acc < settings.BAD_THRESHOLD
-        image.is_reviewed = rv_avg_acc > 0
 
         if image.processing_time < 0:
             continue

From 44c34f95f5d6b66edcae0545710e5cbe12851e8e Mon Sep 17 00:00:00 2001
From: phanphan <lh.phan@samsung.com>
Date: Thu, 6 Jun 2024 13:56:05 +0700
Subject: [PATCH 4/6] fix some bugs

---
 cope2n-fe/src/pages/reviews2/index.tsx | 45 +++++++++++++++++---------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/cope2n-fe/src/pages/reviews2/index.tsx b/cope2n-fe/src/pages/reviews2/index.tsx
index cd03908..9b19d8f 100644
--- a/cope2n-fe/src/pages/reviews2/index.tsx
+++ b/cope2n-fe/src/pages/reviews2/index.tsx
@@ -126,11 +126,11 @@ const ReviewPage = () => {
     }
   }, []);
 
-  useEffect(() => {
-    if (reason) {
-      setSolution(counter_measure_map[reason]);
-    }
-  }, [reason]);
+  // useEffect(() => {
+  //   if (reason) {
+  //     setSolution(counter_measure_map[reason]);
+  //   }
+  // }, [reason]);
 
   const updateSelectedFileDataSource = (fileContent) => {
     let tempData = {};
@@ -144,13 +144,14 @@ const ReviewPage = () => {
         if (isEmpty(tempData[k][REVIEWED_RESULT])) {
           isEmptyResult = true;
         }
-        if (tempData[k][REVIEWED_RESULT].length > 0) {
+        if (Array.isArray(tempData[k][REVIEWED_RESULT]) && tempData[k][REVIEWED_RESULT].length > 0) {
           isEmptyResult = tempData[k][REVIEWED_RESULT].every((r: any) =>
             isEmpty(r),
           );
         }
         if (isEmptyResult) {
           tempData[k][REVIEWED_RESULT] = tempData[k][PREDICTED_RESULT];
+         
         }
       }
     });
@@ -174,16 +175,20 @@ const ReviewPage = () => {
 
     if (!reason) {
       setReason(null);
+      setOtherReason(null);
     } else if (REASON_BAD_QUALITY.some((r) => r.value === reason)) {
       setReason(reason);
+      setOtherReason(null);
     } else {
       setReason('other');
       setOtherReason(reason);
     }
     if (!solution) {
       setSolution(null);
+      setOtherSolution(null);
     } else if (SOLUTION_BAD_QUALITY.some((r) => r.value === solution)) {
       setSolution(solution);
+      setOtherSolution(null);
     } else {
       setSolution('other');
       setOtherSolution(solution);
@@ -198,7 +203,6 @@ const ReviewPage = () => {
       setImageLoading(false);
     }
   };
-
   const loadCurrentRequest = (requestIndex) => {
     setLoading(true);
     setImageLoading(true);
@@ -306,11 +310,18 @@ const ReviewPage = () => {
     let request_file_result = {};
     SOURCE_KEYS.forEach((k) => {
       request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT];
+      if(Array.isArray(selectedFileDataSource[k][REVIEWED_RESULT])){
+        request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT].toString();
+      }else{
+        request_file_result[k] = selectedFileDataSource[k][REVIEWED_RESULT];
+      }
+
+
     });
     let data = {
       request_file_result,
-      reason: reason ? reason : otherReason,
-      solution: solution ? solution : otherSolution,
+      reason: reason !== 'other' ? reason : otherReason,
+      solution: solution !== 'other' ? solution : otherSolution,
     };
     try {
       await updateRevisedDataByFile(currentRequest?.RequestID, fileId, data);
@@ -344,10 +355,10 @@ const ReviewPage = () => {
 
   const [lightBox, setLightBox] = useState(false);
 
-  const updateRevised = (fieldName) => {
+  const updateRevisedByFeedback = (fieldName) => {
     setSelectedFileDataSource((prevData) => {
       prevData[fieldName][REVIEWED_RESULT] =
-        prevData[fieldName][FEEDBACK_RESULT];
+      prevData[fieldName][FEEDBACK_RESULT];
       return {
         ...prevData,
       };
@@ -675,7 +686,7 @@ const ReviewPage = () => {
               style={{ minWidth: '120px' }}
               onClick={handleConfirmReview}
             >
-              (C) Confirm request
+            Confirm request
             </Button>
           </div>
         </div>
@@ -746,7 +757,7 @@ const ReviewPage = () => {
                       ghost
                       icon={<CopyOutlined />}
                       size='small'
-                      onClick={() => updateRevised(data)}
+                      onClick={() => updateRevisedByFeedback(data)}
                     />
                   </div>
                   <Input
@@ -785,7 +796,11 @@ const ReviewPage = () => {
                 placeholder='Select a reason'
                 style={{ width: 170, flexBasis: '50%', height: '32px' }}
                 options={REASON_BAD_QUALITY}
-                onChange={setReason}
+                onChange={(value) => {
+                  let newReason = value;
+                  setReason(newReason);
+                  setSolution(counter_measure_map[newReason]);
+                }}
                 value={reason}
               />
               {reason === 'other' && (
@@ -837,7 +852,7 @@ const ReviewPage = () => {
               }}
               onClick={submitRevisedData}
             >
-              (U) Update File
+              Update File
             </Button>
           </div>
         </div>

From 25245aa770af1eecad61e5342e1b301cd7e8d13c Mon Sep 17 00:00:00 2001
From: TannedCung <dx.tan@samsung.com>
Date: Thu, 6 Jun 2024 14:08:10 +0700
Subject: [PATCH 5/6] Fix: logging file name for AI service

---
 cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py b/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
index 3a4bed3..c004dd0 100755
--- a/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
+++ b/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
@@ -4,6 +4,7 @@ import urllib
 import random
 import numpy as np
 from pathlib import Path
+import urllib.parse
 import uuid
 from copy import deepcopy
 import sys, os
@@ -33,10 +34,13 @@ def sbt_predict(image_url, engine, metadata={}) -> None:
     img = cv2.imdecode(arr, -1)
     
     save_dir = "./tmp_results"
+    parsed_url = urllib.parse.urlparse(image_url)
+    query_params = urllib.parse.parse_qs(parsed_url.query)
+    file_name = query_params['file_name'][0]
     os.makedirs(save_dir, exist_ok=True)
     # image_path = os.path.join(save_dir, f"{image_url}.jpg")
     os.makedirs(save_dir, exist_ok = True)
-    tmp_image_path = os.path.join(save_dir, f"{uuid.uuid4()}.jpg")
+    tmp_image_path = os.path.join(save_dir, file_name)
     cv2.imwrite(tmp_image_path, img)   
     extra_params = {'sub': metadata.get("subsidiary", None)} # example of 'AU' 
     outputs = process_img(img=tmp_image_path, 

From e4b3d1079f2fdfb20e82ea80ab7dd88d89961084 Mon Sep 17 00:00:00 2001
From: TannedCung <dx.tan@samsung.com>
Date: Thu, 6 Jun 2024 14:10:38 +0700
Subject: [PATCH 6/6] Add: Try for filename exrtaction

---
 cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py b/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
index c004dd0..a59a653 100755
--- a/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
+++ b/cope2n-ai-fi/api/sdsap_sbt/prediction_sbt.py
@@ -34,9 +34,14 @@ def sbt_predict(image_url, engine, metadata={}) -> None:
     img = cv2.imdecode(arr, -1)
     
     save_dir = "./tmp_results"
-    parsed_url = urllib.parse.urlparse(image_url)
-    query_params = urllib.parse.parse_qs(parsed_url.query)
-    file_name = query_params['file_name'][0]
+    try:
+
+        parsed_url = urllib.parse.urlparse(image_url)
+        query_params = urllib.parse.parse_qs(parsed_url.query)
+        file_name = query_params['file_name'][0]
+    except Exception as e:
+        print(f"[ERROR]: Error extracting file name from url: {image_url}")
+        file_name = f"{uuid.uuid4()}.jpg"
     os.makedirs(save_dir, exist_ok=True)
     # image_path = os.path.join(save_dir, f"{image_url}.jpg")
     os.makedirs(save_dir, exist_ok = True)