Przeglądaj źródła

add catching meeting info logic

highing666 4 lat temu
rodzic
commit
1545ef9a86

+ 4 - 4
app/api/routers/bluetooth.py

@@ -5,18 +5,18 @@ from typing import List
 from fastapi import APIRouter, Depends, HTTPException, Query
 from loguru import logger
 
+from app.controllers.location.ble.space import get_space_location
 from app.models.domain.bluetooth import BluetoothUserResponse
-from app.schemas.bluetooth import BluetoothCreate, IBeaconBase
+from app.schemas.bluetooth import IBeaconBase
 
 router = APIRouter()
 
 
 @router.post('/user/{user_id}', response_model=BluetoothUserResponse)
 async def create_bluetooth_info(user_id: str, bluetooth_info: List[IBeaconBase]):
-    valid_data = []
-    logger.debug(valid_data)
     info_list = [item.dict() for item in bluetooth_info]
     logger.info(f'{user_id}: {info_list}')
-    response = {'Result': 'success'}
+    sp_id = await get_space_location('Pj1101080259', bluetooth_info)
+    response = {'Result': sp_id}
 
     return response

+ 15 - 0
app/api/routers/nlp.py

@@ -0,0 +1,15 @@
+from fastapi import APIRouter, Query
+
+from app.controllers.nlp.meeting import get_caught_result
+from app.models.domain.nlp import MeetingInfoResponse
+
+router = APIRouter()
+
+
+@router.get('/meeting/info', response_model=MeetingInfoResponse)
+async def catch_meeting_info(sentence: str = Query(..., max_length=50)):
+    await get_caught_result(sentence)
+
+    return {
+        'Message': 'success'
+    }

+ 33 - 0
app/controllers/nlp/meeting.py

@@ -0,0 +1,33 @@
+import json
+
+from typing import List
+
+from loguru import logger
+from tencentcloud.nlp.v20190408 import nlp_client, models
+
+from app.services.tencent_nlp import get_tencent_nlp_client
+
+
+class MeetingInfoCatcher:
+
+    def __init__(self, client: nlp_client.NlpClient, sentence: str):
+        super(MeetingInfoCatcher, self).__init__()
+        self.client = client
+        self.sentence = sentence
+
+    def run(self):
+        req = models.LexicalAnalysisRequest()
+        params = {
+            'Text': self.sentence
+        }
+        req.from_json_string(json.dumps(params))
+
+        resp = self.client.LexicalAnalysis(req)
+        logger.debug(resp)
+
+
+@logger.catch()
+async def get_caught_result(sentence: str):
+    client = get_tencent_nlp_client()
+    catcher = MeetingInfoCatcher(client, sentence)
+    catcher.run()

+ 4 - 0
app/core/config.py

@@ -14,6 +14,10 @@ class Settings(BaseSettings):
     TRANSFER_HOST: AnyHttpUrl
     WEATHER_HOST: AnyHttpUrl
 
+    TENCENT_NLP_ENDPOINT: str
+    TENCENT_SECRET_ID_V1: str
+    TENCENT_SECRET_KEY_V1: str
+
     PROJECT_DIR: DirectoryPath
     LOGS_DIR: DirectoryPath
 

+ 23 - 0
app/models/domain/nlp.py

@@ -0,0 +1,23 @@
+from enum import Enum
+from typing import List, Optional
+
+from pydantic import BaseModel
+
+
+class RoomSize(str, Enum):
+    small = 'small'
+    medium = 'medium'
+    large = 'large'
+
+
+class NLPResponseBase(BaseModel):
+    Message: str
+
+
+class MeetingInfoResponse(NLPResponseBase):
+    AcceptableStartTime: Optional[str]
+    AcceptableEndTime: Optional[str]
+    MeetingTimeDelta: Optional[int]
+    MeetingRoomSize: Optional[RoomSize]
+    Topic: Optional[str]
+    Participants: Optional[List[str]]

+ 0 - 14
app/schemas/bluetooth.py

@@ -5,20 +5,6 @@ from typing import Optional
 from pydantic import BaseModel
 
 
-class BluetoothBase(BaseModel):
-    name: Optional[str] = None
-    deviceName: Optional[str] = None
-    deviceId: Optional[str] = None
-    localName: Optional[str] = None
-    RSSI: Optional[float] = None
-    advertisData: Optional[str] = None
-    manufacturerData: Optional[str] = None
-
-
-class BluetoothCreate(BluetoothBase):
-    pass
-
-
 class IBeaconBase(BaseModel):
     minor: Optional[int] = None
     major: Optional[int] = None

+ 25 - 0
app/services/tencent_nlp.py

@@ -0,0 +1,25 @@
+from loguru import logger
+
+from tencentcloud.common import credential
+from tencentcloud.common.profile.client_profile import ClientProfile
+from tencentcloud.common.profile.http_profile import HttpProfile
+from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
+from tencentcloud.nlp.v20190408 import nlp_client
+
+from app.core.config import settings
+
+
+def get_tencent_nlp_client() -> nlp_client.NlpClient:
+    try:
+        cred = credential.Credential(settings.TENCENT_SECRET_ID_V1, settings.TENCENT_SECRET_KEY_V1)
+        http_profile = HttpProfile()
+        http_profile.reqMethod = 'GET'
+        http_profile.endpoint = settings.TENCENT_NLP_ENDPOINT
+
+        client_profile = ClientProfile()
+        client_profile.httpProfile = http_profile
+        client = nlp_client.NlpClient(cred, 'ap-guangzhou', client_profile)
+
+        return client
+    except TencentCloudSDKException as e:
+        logger.error(e)