Ver código fonte

更新card_list返回格式

AnlaAnla 3 semanas atrás
pai
commit
167299ddf8

+ 5 - 0
.idea/CardScoreDataServer.iml

@@ -5,4 +5,9 @@
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
+  <component name="PackageRequirementsSettings">
+    <option name="versionSpecifier" value="不指定版本" />
+    <option name="removeUnused" value="true" />
+    <option name="modifyBaseFiles" value="true" />
+  </component>
 </module>

+ 4 - 4
.idea/dataSources.xml

@@ -8,11 +8,11 @@
       <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
       <working-dir>$ProjectFileDir$</working-dir>
     </data-source>
-    <data-source source="LOCAL" name="服务器1" uuid="d455fdf3-b4f3-466c-b306-d62db890c85e">
-      <driver-ref>mariadb</driver-ref>
+    <data-source source="LOCAL" name="服务器2" uuid="048007ce-612b-4dfc-a03a-4093e6ad84ef">
+      <driver-ref>mysql.8</driver-ref>
       <synchronize>true</synchronize>
-      <jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
-      <jdbc-url>jdbc:mariadb://192.168.31.243:3306</jdbc-url>
+      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
+      <jdbc-url>jdbc:mysql://192.168.77.78:3306</jdbc-url>
       <working-dir>$ProjectFileDir$</working-dir>
     </data-source>
   </component>

+ 7 - 0
.idea/deployment.xml

@@ -16,6 +16,13 @@
           </mappings>
         </serverdata>
       </paths>
+      <paths name="martin@192.168.77.78">
+        <serverdata>
+          <mappings>
+            <mapping deploy="/home/martin/_ML/RemoteProject/CardScoreDataServer" local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
     </serverData>
   </component>
 </project>

+ 7 - 7
Test/img_score_and_insert.py

@@ -11,18 +11,18 @@ from datetime import datetime
 # INFERENCE_SERVICE_URL = "http://127.0.0.1:7744"
 # STORAGE_SERVICE_URL = "http://127.0.0.1:7745"
 
-INFERENCE_SERVICE_URL = "http://192.168.31.243:7744"
-STORAGE_SERVICE_URL = "http://192.168.31.243:7745"
+INFERENCE_SERVICE_URL = "http://192.168.77.78:7744"
+STORAGE_SERVICE_URL = "http://192.168.77.78:7745"
 
 # 2. 要处理的卡片信息
 formate_time = datetime.now().strftime("%Y-%m-%d_%H:%M")
 CARD_NAME = f"卡 {formate_time}"
 
 # 3. 四张卡片图片的本地路径
-front_face_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\7_front_coaxial_1_0.jpg"
-front_edge_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\7_front_ring_0_1.jpg"
-back_face_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\7_back_coaxial_1_0.jpg"
-back_edge_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\7_back_ring_0_1.jpg"
+front_face_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\45_front_coaxial_1_0.jpg"
+front_edge_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\45_front_ring_0_1.jpg"
+back_face_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\45_back_coaxial_1_0.jpg"
+back_edge_img_path = r"C:\Code\ML\Image\Card\_250915_many_capture_img\_250915_1643_no_reflect_hand_defect\45_back_ring_0_1.jpg"
 IMAGE_PATHS = [
     front_edge_img_path,
     front_face_img_path,
@@ -233,4 +233,4 @@ if __name__ == "__main__":
         # 在 Windows 上使用 ProactorEventLoop 可能会更稳定
         if os.name == 'nt':
             asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
-        asyncio.run(main())
+        asyncio.run(main())

+ 1 - 0
Test/test01.py

@@ -1,4 +1,5 @@
 import requests
+import torch
 
 
 def send(url):

+ 3 - 1
app/api/cards.py

@@ -101,7 +101,9 @@ def list_cards_detailed(  # MODIFIED
         cards_with_images = crud_card.get_card_list_with_images(
             db_conn, card_name, card_type, sort_by, sort_order, skip, limit
         )
-        return [CardListDetailResponse.model_validate(c) for c in cards_with_images]
+        card_list = [CardListDetailResponse.model_validate(c) for c in cards_with_images]
+        logger.info(card_list)
+        return card_list
     except Exception as e:
         logger.error(f"查询卡牌列表失败: {e}")
         raise HTTPException(status_code=500, detail="获取数据列表失败。")

+ 15 - 1
app/crud/crud_card.py

@@ -132,6 +132,20 @@ def get_card_list_with_images(
 
         # 4. 将图片附加到对应的卡牌上
         for card in cards:
-            card['images'] = images_by_card_id.get(card['id'], [])
+            # 初始化新的字典字段
+            card['image_path_list'] = {}
+            card['detection_image_path'] = {}
+            card['modified_image_path'] = {}
+
+            # 获取与当前卡牌关联的所有图片记录
+            related_images = images_by_card_id.get(card['id'], [])
+
+            # 遍历图片记录,用 image_type 作为 key 来填充三个字典
+            for image_data in related_images:
+                image_type = image_data['image_type']  # e.g., 'front_face'
+                if image_type:  # 确保 image_type 不为空
+                    card['image_path_list'][image_type] = image_data.get('image_path')
+                    card['detection_image_path'][image_type] = image_data.get('detection_image_path')
+                    card['modified_image_path'][image_type] = image_data.get('modified_image_path')
 
         return cards

+ 4 - 2
app/main.py

@@ -14,11 +14,13 @@ from .core.logger import setup_logging, get_logger
 setup_logging()
 logger = get_logger(__name__)
 
+settings.set_config()
+os.makedirs(settings.DATA_DIR, exist_ok=True)
+
 @asynccontextmanager
 async def lifespan(main_app: FastAPI):
     print("--- 应用启动 ---")
-    settings.set_config()
-    os.makedirs(settings.DATA_DIR, exist_ok=True)
+
     init_database()
     load_database_pool()
     yield

+ 3 - 1
app/utils/scheme.py

@@ -142,7 +142,9 @@ class CardListDetailResponse(BaseModel):
     is_edited: bool
     created_at: datetime
     updated_at: datetime
-    images: List[CardImageInListResponse] = []
+    image_path_list: Dict[str, Optional[str]] = {}
+    detection_image_path: Dict[str, Optional[str]] = {}
+    modified_image_path: Dict[str, Optional[str]] = {}
 
     class Config:
         from_attributes = True

+ 7 - 0
requirements.txt

@@ -0,0 +1,7 @@
+fastapi
+mysql-connector-python
+requests
+pydantic
+aiohttp
+aiofiles
+uvicorn