Forráskód Böngészése

AI识别反馈增加识别来源字段

peng 1 éve
szülő
commit
793104c129
2 módosított fájl, 25 hozzáadás és 11 törlés
  1. 18 9
      Controller/FeedBack.py
  2. 7 2
      Service/EquipmentInfoService.py

+ 18 - 9
Controller/FeedBack.py

@@ -1,4 +1,5 @@
 import json
+import threading
 import time
 
 import oss2
@@ -6,7 +7,7 @@ from django.db import transaction
 from django.views.generic.base import View
 
 from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, PUSH_BUCKET, PUSH_INACCURATE_BUCKET
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, LOGGER
 from Model.models import FeedBackModel, StatResModel, PushInaccurateFeedback
 from Object.AWS.AmazonS3Util import AmazonS3Util
 from Object.ResponseObject import ResponseObject
@@ -343,17 +344,26 @@ class FeedBackView(View):
         tag = request_dict.get('tag', '')
         if not all([equipment_info_id, uid, is_st, event_type, event_time, channel]):
             return response.json(444)
+        try:
+            thread = threading.Thread(target=FeedBackView.asyn_push_inaccurate,
+                                      args=(
+                                          equipment_info_id, uid, channel, user_id, event_type, event_time, int(is_st),
+                                          tag,))
+            thread.start()
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, repr(e))
 
-        now_time = int(time.time())
-        is_st = int(is_st)
+    @staticmethod
+    def asyn_push_inaccurate(equipment_info_id, uid, channel, user_id, event_type, event_time, is_st, tag):
         try:
             # 默认查询近七天内数据
-            end_time = int(time.time())
-            start_time = LocalDateTimeUtil.get_before_days_timestamp(end_time, 7)
+            now_time = int(time.time())
+            start_time = LocalDateTimeUtil.get_before_days_timestamp(now_time, 7)
             uid_list = uid.split(',')
             equipment_info_qs, count = EquipmentInfoService. \
-                union_equipment_info(user_id, uid_list, event_type, start_time, end_time, 1, 10)
-            identify_type = 1 if equipment_info_qs[0]['event_tag'] else 0
+                union_equipment_info(user_id, uid_list, event_type, start_time, now_time, 1, 10, event_time)
+            identify_type = 1 if equipment_info_qs[0]['eventTag'] else 0
             s3 = AmazonS3Util(
                 aws_access_key_id=ACCESS_KEY_ID,
                 secret_access_key=SECRET_ACCESS_KEY,
@@ -376,6 +386,5 @@ class FeedBackView(View):
                                                   event_type=event_type, uid=uid, channel=channel,
                                                   add_time=now_time, tag=tag, is_st=is_st, event_time=event_time,
                                                   identify_type=identify_type)
-            return response.json(0)
         except Exception as e:
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            LOGGER.info('asyn_push_inaccurate, errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))

+ 7 - 2
Service/EquipmentInfoService.py

@@ -239,7 +239,7 @@ class EquipmentInfoService:
             return ',' + str(event_type) + ','
 
     @classmethod
-    def union_equipment_info(cls, user_id, uid_list, event_type, start_time, end_time, page, line):
+    def union_equipment_info(cls, user_id, uid_list, event_type, start_time, end_time, page, line, event_time=None):
         """
         联表查询推送数据
         @param user_id:
@@ -249,6 +249,7 @@ class EquipmentInfoService:
         @param end_time:
         @param page:
         @param line:
+        @param event_time:
         @return:
         """
         try:
@@ -275,7 +276,11 @@ class EquipmentInfoService:
                     kwargs['event_tag__regex'] = tags
                 elif tags:
                     kwargs['event_tag__regex'] = tags
-
+            if event_time:
+                kwargs['event_time'] = event_time
+                event_type_kwargs['event_time'] = event_time
+                del kwargs['event_tag__regex']
+                del event_type_kwargs['event_tag']
             if not event_type_list:
                 # 新增tab_val字段记录表的标识:表编号+10
                 equipment_info_1 = EquipmentInfo1.objects.filter(**kwargs).annotate(tab_val=Value('11', output_field=CharField()))