Exemplo n.º 1
0
    def testConvertToDataTableJSon(self):
        data, _ = utils.InitDataTableInputsWithTimeAxis(freq=1,
                                                        chunk_duration_sec=4,
                                                        chunk_start=4,
                                                        max_samples=10)

        json_data = json.loads(utils.ConvertToDataTableJSon(data, ['seconds']))
        self.assertEqual([{
            'id': 'seconds',
            'label': 'seconds',
            'type': 'number'
        }], json_data['cols'])
        self.assertEqual([{
            'c': [{
                'v': 4
            }]
        }, {
            'c': [{
                'v': 5
            }]
        }, {
            'c': [{
                'v': 6
            }]
        }, {
            'c': [{
                'v': 7
            }]
        }], json_data['rows'])
Exemplo n.º 2
0
def _CreateChunkDataTableJSon(data_source, request, max_samples):
    """Creates a DataTable in JSON format which contains the data specified.

  Data can be specified by a list of minuends and subtrahends of montage
  standards and/or a list of channel keys.
  Args:
    data_source: The DataSource for the waveform data.
    request: A DataRequest proto instance.
    max_samples: The maximum number of samples in one channel response.
  Returns:
    JSON format DataTable loaded with montage data.
  Raises:
    ValueError: The requested channels have multiple frequency types.
  """

    channel_indices = _GetChannelIndicesInChannelDataIdList(
        request.channel_data_ids)
    req_channel_freqs = list(
        set(
            data_source.GetChannelSamplingFrequency(index)
            for index in channel_indices))
    if len(req_channel_freqs) != 1:
        ValueError('The requested channels do not have the same frequency')
    sample_freq = req_channel_freqs[0]

    # Initialize Dygraph data with a time axis of sampling frequency.
    output_data, _ = utils.InitDataTableInputsWithTimeAxis(
        sample_freq, request.chunk_duration_secs, request.chunk_start,
        max_samples)
    columns_order = ['seconds']

    channel_data, channel_names = _CreateChannelData(data_source, request,
                                                     max_samples)
    output_data = _AddDataTableSeries(channel_data, output_data)
    columns_order.extend(channel_names)

    return (utils.ConvertToDataTableJSon(output_data,
                                         columns_order), sample_freq)
Exemplo n.º 3
0
def _CreateChunkDataTableJSon(data_source, request, max_samples):
    """Creates a DataTable in JSON format which contains the data specified.

  Data can be specified by a list of minuends and subtrahends of montage
  standards and/or a list of channel keys.
  Args:
    data_source: The DataSource for the waveform data.
    request: A DataRequest proto instance.
    max_samples: The maximum number of samples in one channel response.
  Returns:
    JSON format DataTable loaded with montage data.
  Raises:
    ValueError: The requested channels have multiple frequency types.
  """

    sample_freq = GetSamplingFrequency(data_source, request.channel_data_ids)

    # Initialize Dygraph data with a time axis of sampling frequency.
    output_data, _ = utils.InitDataTableInputsWithTimeAxis(
        sample_freq, request.chunk_duration_secs, request.chunk_start,
        max_samples)
    columns_order = ['seconds']

    channel_data, channel_names = _CreateChannelData(
        data_source,
        request.channel_data_ids,
        request.low_cut,
        request.high_cut,
        request.notch,
        start=request.chunk_start,
        duration=request.chunk_duration_secs,
        max_samples=max_samples)
    output_data = _AddDataTableSeries(channel_data, output_data)
    columns_order.extend(channel_names)

    return (utils.ConvertToDataTableJSon(output_data,
                                         columns_order), sample_freq)