Esempio n. 1
0
 def get_slot_name(self):
     if Utils.checkKeysInDict(self.data, ['response', 'directives']):
         directive = self.data['response']['directives']
         if directive and Utils.checkKeysInDict(
                 directive[0],
             ['slotToElicit']) and directive[0]['slotToElicit']:
             return directive[0]['slotToElicit']
     return None
Esempio n. 2
0
 def get_app_launcher_context(self):
     '''
     获取设备app安装列表
     :return:
     '''
     return Utils.get_dict_data_by_keys(self.data,
                                        ['context', 'AppLauncher'])
Esempio n. 3
0
 def get_location(self):
     if Utils.checkKeysInDict(
             self.data,
         ['context', 'System', 'user', 'userInfo', 'location', 'geo']):
         return self.data['context']['System']['user']['userInfo'][
             'location']['geo']
     return None
Esempio n. 4
0
    def set_opration_tic(self, task_name):

        if self.is_should_disable():
            return
        if task_name:
            self.user_event_list[task_name] = Utils.get_millisecond()
            self.is_event_make_pair[task_name] = False
Esempio n. 5
0
 def get_botid(self):
     if Utils.checkKeysInDict(
             self.data,
         ['context', 'System', 'application', 'applicationId']):
         return self.data['context']['System']['application'][
             'applicationId']
     return None
Esempio n. 6
0
 def get_audio_player_context(self):
     '''
     获取设备音频播放的状态
     :return:
     '''
     return Utils.get_dict_data_by_keys(self.data,
                                        ['context', 'AudioPlayer'])
Esempio n. 7
0
 def get_audio_player_context(self):
     '''
     获取设备音频播放的状态
     :return:
     '''
     if Utils.checkKeysInDict(self.data, ['context', 'AudioPlayer']):
         return self.data['context']['AudioPlayer']
     return None
Esempio n. 8
0
    def getUserInfo(self):
        '''

        :return:
        '''
        if Utils.checkKeysInDict(self.data, ['user_info']):
            return self.data['user_info']
        return None
Esempio n. 9
0
 def get_app_launcher_context(self):
     '''
     获取设备app安装列表
     :return:
     '''
     if Utils.checkKeysInDict(self.data, ['context', 'AppLauncher']):
         return self.data['context']['AppLauncher']
     return None
Esempio n. 10
0
    def __build_upload_data(self):
        sysEvent = {
            'preEventList': {},
            'postEventList': {},
            'eventCostTime': self.event_cost_time,
            'deviceEventCostTime': self.device_event_cost_time
        }

        timestamp = Utils.get_millisecond()

        retData = {
            'serviceData': {
                'sdkType': self.config.get_sdk_type(),
                'sdkVersion': self.config.get_sdk_version(),
                'requestId': self.request.get_request_id(),
                'query': self.request.get_query(),
                'reason': self.request.get_reson(),
                'deviceId': self.request.get_device_id(),
                'requestType': self.request.get_type(),
                'userId': self.request.get_user_id(),
                'intentName': self.request.get_intent_name(),
                'sessionId': self.request.get_session_id(),
                'location': self.request.get_location(),
                'slotToElicit': self.response.get_slot_name(),
                'shouldEndSession': self.response.get_should_end_session(),
                'outputSpeech': self.response.get_output_speech(),
                'reprompt': self.response.get_reprompt(),
                'audioUrl': self.audio_url,
                'appInfo': {
                    'appName': self.app_name,
                    'packageName': self.package_name,
                    'deepLink': self.deep_link
                },
                'requestStartTime': self.request_start_time,
                'requestEndTime': self.request_end_time,
                'timestamp': timestamp,
                'sysEvent': sysEvent,
                'userEvent': self.user_event_list
            }
        }

        orginData = json.dumps(retData)
        logging.info('数据统计原始数据:' + orginData)

        base64Data = str(base64.b64encode(orginData.encode('utf-8')))
        # logging.info('数据统计加密数据:' + base64Data)

        if self.environment == 0:
            pkversion = 'debug'
        else:
            pkversion = 'online'

        return (base64Data, timestamp, pkversion)
Esempio n. 11
0
    def set_opration_toc(self, task_name):

        if self.is_should_disable():
            return
        if task_name:

            if task_name in self.user_event_list:
                old_time = self.user_event_list[task_name]
            else:
                old_time = None
            cost_time = 0

            if old_time:
                curr_time = Utils.get_millisecond()
                cost_time = curr_time - old_time

            self.user_event_list[task_name] = cost_time
            self.is_event_make_pair[task_name] = True
Esempio n. 12
0
 def __init__(self, post_data, private_key=None):
     if not isinstance(post_data, dict):
         post_data = json.loads(post_data)
     self.data = post_data
     self.request_start_time = Utils.get_millisecond()
     self.request_end_time = 0
     self.request = Request(post_data)
     self.audio_url = None
     self.app_name = None
     self.package_name = None
     self.deep_link = None
     self.event_start_time = 0
     self.event_cost_time = 0
     self.device_event_start_time = 0
     self.device_event_cost_time = 0
     self.user_event_list = {}
     self.is_event_make_pair = {}
     self.config = BotMonitorConfig()
     self.private_key = private_key
     self.environment = 0
     self.enabled = False
     self.certificate = None
     self.response = None
Esempio n. 13
0
    def get_reprompt(self):

        return Utils.get_dict_data_by_keys(
            self.data, ['response', 'reprompt', 'outputSpeech'])
Esempio n. 14
0
    def is_dialog_state_completed(self):

        if Utils.checkKeysInDict(self.data, ['request', 'dialogState']):
            return self.data['request']['dialogState'] == 'COMPLETED'
        return False
Esempio n. 15
0
    def get_reson(self):

        return Utils.get_dict_data_by_keys(self.data, ['request', 'reason'])
Esempio n. 16
0
 def getLocation(self):
     return Utils.getDictDataByKeys(
         self.data,
         ['context', 'System', 'user', 'userInfo', 'location', 'geo'])
Esempio n. 17
0
    def getUserId(self):

        return Utils.getDictDataByKeys(self.data,
                                       ['context', 'System', 'user', 'userId'])
Esempio n. 18
0
 def get_bot_id(self):
     return Utils.get_dict_data_by_keys(
         self.data, ['context', 'System', 'application', 'applicationId'])
Esempio n. 19
0
    def get_request_id(self):

        return Utils.get_dict_data_by_keys(self.data, ['request', 'requestId'])
Esempio n. 20
0
    def set_response_data(self, response_data):

        if self.is_should_disable():
            return
        self.request_end_time = Utils.get_millisecond()
        self.response = Response(response_data)
Esempio n. 21
0
    def get_session_id(self):

        return Utils.get_dict_data_by_keys(self.data, ['session', 'sessionId'])
Esempio n. 22
0
    def set_event_start(self):

        if self.is_should_disable():
            return
        self.event_start_time = Utils.get_millisecond()
Esempio n. 23
0
    def get_device_id(self):

        return Utils.get_dict_data_by_keys(
            self.data, ['context', 'System', 'device', 'deviceId'])
Esempio n. 24
0
    def get_user_info(self):
        '''

        :return:
        '''
        return Utils.get_dict_data_by_keys(self.data, ['user_info'])
Esempio n. 25
0
    def set_device_event_end(self):

        if self.is_should_disable():
            return
        self.device_event_cost_time = Utils.get_millisecond(
        ) - self.device_event_start_time
Esempio n. 26
0
 def get_location(self):
     return Utils.get_dict_data_by_keys(
         self.data,
         ['context', 'System', 'user', 'userInfo', 'location', 'geo'])
Esempio n. 27
0
    def get_user_id(self):

        return Utils.get_dict_data_by_keys(
            self.data, ['context', 'System', 'user', 'userId'])
Esempio n. 28
0
 def get_output_speech(self):
     return Utils.get_dict_data_by_keys(self.data,
                                        ['response', 'outputSpeech'])
Esempio n. 29
0
    def get_timestamp(self):

        return Utils.get_dict_data_by_keys(self.data, ['request', 'timestamp'])
Esempio n. 30
0
 def get_should_end_session(self):
     return Utils.get_dict_data_by_keys(self.data,
                                        ['response', 'shouldEndSession'])