<commit_before>import DataHandler from '../utils/DataHandler';

/**
 * Transform a array of objects into a datum ready
 * to be consumed by nvd3 chars which supports
 * multiple series like linecharts and multibarcharts.
 *
 * Example:
 * {
 *   name:'fieldsToSeries',
 *   fields: [
 *     {name: 'Price', field: 'price', color:'#FF0000'},
 *   ]
 * }
 */
function fieldsToSeries(componentData, dashboardData, handler) {
  if(!componentData.length) return [];
  let series = (handler.fields || []).map( (s) => {
    let serie = {
      key: s.name,
      color: s.color
    };
    serie.values = componentData.map( (row) => {
      return {y: row[s.field], x: row[(this.props.settings.x || x)]};
    });
    return serie;
  });
  console.log(series);
  return series;
}

/**
 * Parse a field as a date.
 * handler = {
 *   field: 'field_name_to_parse',
 *   name: 'parseFieldDate'
 * }
 */
function parseDateField(componentData, dashboardData, handler) {
  return componentData.map((row) => {
    row[handler.field] = Date.parse(row[handler.field]);
    return row;
  });
}

DataHandler.set('fieldsToSeries', fieldsToSeries);
DataHandler.set('parseDateField', parseDateField);<commit_msg>Fix typo<commit_after>import DataHandler from '../utils/DataHandler';

/**
 * Transform a array of objects into a datum ready
 * to be consumed by nvd3 chars which supports
 * multiple series like linecharts and multibarcharts.
 *
 * Example:
 * {
 *   name:'fieldsToSeries',
 *   fields: [
 *     {name: 'Price', field: 'price', color:'#FF0000'},
 *   ]
 * }
 */
function fieldsToSeries(componentData, dashboardData, handler) {
  if(!componentData.length) return [];
  let series = (handler.fields || []).map( (s) => {
    let serie = {
      key: s.name,
      color: s.color
    };
    serie.values = componentData.map( (row) => {
      return {y: row[s.field], x: row[(this.props.settings.x || 'x' )]};
    });
    return serie;
  });
  return series;
}

/**
 * Parse a field as a date.
 * handler = {
 *   field: 'field_name_to_parse',
 *   name: 'parseFieldDate'
 * }
 */
function parseDateField(componentData, dashboardData, handler) {
  return componentData.map((row) => {
    row[handler.field] = Date.parse(row[handler.field]);
    return row;
  });
}

DataHandler.set('fieldsToSeries', fieldsToSeries);
DataHandler.set('parseDateField', parseDateField);
{'fraction_non_alphanumeric': 0.161495962600935, 'fraction_numerical': 0.004249893752656183, 'mean_word_length': 3.5009560229445507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4211821', 'n_tokens_mistral': 774, 'n_tokens_neox': 763, 'n_words': 181}