|
@@ -15,16 +15,19 @@
|
|
|
import json
|
|
|
import time
|
|
|
|
|
|
+import boto3
|
|
|
import oss2
|
|
|
from django.db import transaction
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
-from Model.models import FeedBackModel, StatResModel
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
|
|
|
+from Model.models import FeedBackModel, StatResModel, EquipmentInfoMonday, EquipmentInfoTuesday, EquipmentInfoWednesday, \
|
|
|
+ EquipmentInfoThursday, EquipmentInfoFriday, EquipmentInfoSaturday, EquipmentInfoSunday, PushInaccurateFeedback
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService
|
|
|
+from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
|
|
|
|
|
|
class FeedBackView(View):
|
|
@@ -304,7 +307,98 @@ class FeedBackView(View):
|
|
|
|
|
|
@staticmethod
|
|
|
def ai_recognition(user_id, request_dict, response):
|
|
|
- equipment_info_id = request_dict.get('equipment_info_id', None)
|
|
|
- if not equipment_info_id:
|
|
|
+ equipment_info_id = request_dict.get('equipmentInfoId', None)
|
|
|
+ region_id = request_dict.get('regionId', None)
|
|
|
+ if not all([equipment_info_id, region_id]):
|
|
|
return response.json(444)
|
|
|
- return response.json(0)
|
|
|
+ region_id = int(region_id)
|
|
|
+ week = int(equipment_info_id[0])
|
|
|
+ equipment_info_id = equipment_info_id[1:]
|
|
|
+ now_time = int(time.time())
|
|
|
+ try:
|
|
|
+ if region_id == 1: # 国内
|
|
|
+ s3 = AmazonS3Util(
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
+ secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
+ region_name='cn-northwest-1'
|
|
|
+ )
|
|
|
+ else: # 国外
|
|
|
+ s3 = AmazonS3Util(
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
+ secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
+ region_name='us-east-1'
|
|
|
+ )
|
|
|
+ if week == 1:
|
|
|
+ equipment_info_qs = EquipmentInfoMonday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+ elif week == 2:
|
|
|
+ equipment_info_qs = EquipmentInfoMonday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+
|
|
|
+ elif week == 3:
|
|
|
+ equipment_info_qs = EquipmentInfoWednesday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+
|
|
|
+ elif week == 4:
|
|
|
+ equipment_info_qs = EquipmentInfoThursday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+
|
|
|
+ elif week == 5:
|
|
|
+ equipment_info_qs = EquipmentInfoFriday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+
|
|
|
+ elif week == 6:
|
|
|
+ equipment_info_qs = EquipmentInfoSaturday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+
|
|
|
+ else:
|
|
|
+ equipment_info_qs = EquipmentInfoSunday.objects.filter(id=equipment_info_id).values('device_uid',
|
|
|
+ 'channel',
|
|
|
+ 'event_time',
|
|
|
+ 'event_type',
|
|
|
+ 'is_st')
|
|
|
+ if not equipment_info_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ equipment_info = equipment_info_qs.first()
|
|
|
+ uid = equipment_info['device_uid']
|
|
|
+ channel = equipment_info['channel']
|
|
|
+ event_time = equipment_info['event_time']
|
|
|
+ event_type = equipment_info['event_type']
|
|
|
+ is_st = equipment_info['is_st']
|
|
|
+ if is_st != 3:
|
|
|
+ file_path = '{uid}/{channel}/{event_time}.jpeg'.format(uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ event_time=event_time)
|
|
|
+ s3.copy_obj('push', 'push-inaccurate', file_path)
|
|
|
+ else:
|
|
|
+ for index in range(3):
|
|
|
+ file_path = '{uid}/{channel}/{event_time}_{index}.jpeg'.format(uid=uid,
|
|
|
+ channel=channel,
|
|
|
+ event_time=event_time,
|
|
|
+ index=index)
|
|
|
+ s3.copy_obj('push', 'push-inaccurate', file_path)
|
|
|
+ PushInaccurateFeedback.objects.create(equipment_info_id=equipment_info_id,
|
|
|
+ user_id=user_id, event_type=event_type,
|
|
|
+ uid=uid, channel=channel, add_time=now_time,
|
|
|
+ is_st=is_st)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|