Example #1
0
    def get_download_query():
        '''Responds to a data download query by sending a query to the appropriate
        black box and then saving the data to a temporary file for download.
        '''
        robot_id = request.args.get('robot_id', '', type=str)
        black_box_id = BBUtils.get_bb_id(robot_id)
        variable_list = request.args.get('variables').split(',')
        start_query_time = request.args.get('start_timestamp')
        end_query_time = request.args.get('end_timestamp')

        query_msg = DataUtils.get_bb_query_msg(session['uid'].hex,
                                               black_box_id,
                                               variable_list,
                                               start_query_time,
                                               end_query_time)
        query_result = zyre_communicator.get_query_data(query_msg)

        message = ''
        try:
            with open(query_result_file_path, 'w') as download_file:
                json.dump(query_result, download_file)
            return jsonify(success=True)
        except Exception as exc:
            print('[get_download_query_robot_data] %s' % str(exc))
            message = 'Data could not be retrieved'
            return jsonify(message=message)
Example #2
0
    def send_query(self, start_time, end_time, variables):
        """
        create and send a query message to black box query interface through
        pyre shout.

        :start_time: float
        :end_time: float
        :variables: list of strings
        :returns: None

        """
        msg_sender_id = str(uuid.uuid4())
        data_query_msg = DataUtils.get_bb_query_msg(msg_sender_id,
                                                    self.black_box_id,
                                                    variables, start_time,
                                                    end_time)
        return self.get_black_box_data(data_query_msg)
Example #3
0
    def send_diagnostic_data(session_id, black_box_id, diagnostic_vars):
        end_query_time = int(time.time())
        start_query_time = end_query_time - 10

        query_msg = DataUtils.get_bb_query_msg(session_id, black_box_id,
                                               diagnostic_vars,
                                               start_query_time,
                                               end_query_time)
        query_result = zyre_communicator.get_query_data(query_msg)

        try:
            variables, data = DataUtils.parse_bb_data_msg(query_result)
            vel_vars, vel_data = get_variable_data('velocity', variables, data)
            socketio.emit('vel_data',
                          json.dumps({
                              'variables': vel_vars,
                              'data': vel_data
                          }),
                          namespace='/experiments')

            accel_vars, accel_data = get_variable_data('accel', variables,
                                                       data)
            socketio.emit('accel_data',
                          json.dumps({
                              'variables': accel_vars,
                              'data': accel_data
                          }),
                          namespace='/experiments')

            gyro_vars, gyro_data = get_variable_data('gyro', variables, data)
            socketio.emit('gyro_data',
                          json.dumps({
                              'variables': gyro_vars,
                              'data': gyro_data
                          }),
                          namespace='/experiments')
        except Exception as exc:
            print('[send_diagnostic_data] {0} does not seem to be responding'.
                  format(black_box_id))
            print(str(exc))

        global data_thread
        data_thread = None
Example #4
0
    def test_get_bb_query_msg(self):
        query_msg = DataUtils.get_bb_query_msg(
            sender_id='some_unique_id',
            bb_id='black_box_101',
            variable_list=['variable_name'],
            start_query_time=5.0,
            end_query_time=6.0)

        self.assertIsInstance(query_msg, dict)
        self.assertIn('header', query_msg)
        self.assertIsInstance(query_msg['header'], dict)
        self.assertIn('type', query_msg['header'])
        self.assertEqual('DATA-QUERY', query_msg['header']['type'])
        self.assertIn('timestamp', query_msg['header'])
        self.assertIn('payload', query_msg)
        self.assertIsInstance(query_msg['payload'], dict)
        self.assertEqual('some_unique_id', query_msg['payload'].get('senderId', None))
        self.assertEqual('black_box_101', query_msg['payload'].get('blackBoxId', None))
        self.assertListEqual(['variable_name'], query_msg['payload'].get('variables', None))
        self.assertEqual(5.0, query_msg['payload'].get('startTime', None))
        self.assertEqual(6.0, query_msg['payload'].get('endTime', None))
Example #5
0
    def get_robot_data():
        robot_id = request.args.get('robot_id', '', type=str)
        black_box_id = BBUtils.get_bb_id(robot_id)
        variable_list = request.args.get('variables').split(',')
        start_query_time = request.args.get('start_timestamp')
        end_query_time = request.args.get('end_timestamp')

        query_msg = DataUtils.get_bb_query_msg(session['uid'].hex,
                                               black_box_id,
                                               variable_list,
                                               start_query_time,
                                               end_query_time)
        query_result = zyre_communicator.get_query_data(query_msg)

        variables = list()
        data = list()
        message = ''
        try:
            variables, data = DataUtils.parse_bb_data_msg(query_result)
        except Exception as exc:
            print('[get_robot_data] %s' % str(exc))
            message = 'Data could not be retrieved'
        return jsonify(variables=variables, data=data, message=message)