<commit_before>import { createSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import { format } from 'd3-format';

// get list data
const getData = state => state.data;
const getSettings = state => state.settings;
const getCurrentLocation = state => state.currentLabel;
const getIndicator = state => state.indicator || null;
const getColors = state => state.colors;
const getSentences = state => state.config && state.config.sentences;

// get lists selected
export const parseData = createSelector(
  [getData, getSettings, getColors],
  (data, settings, colors) => {
    if (isEmpty(data)) return null;
    const { totalArea, totalExtent, extent } = data;
    const secondaryExtent = totalExtent - extent < 0 ? 0 : totalExtent - extent;
    const parsedData = [
      {
        label: 'Primary Forest',
        value: extent,
        color: colors.primaryForest,
        percentage: extent / totalArea * 100
      },
      {
        label: 'Other Tree Cover',
        value: secondaryExtent,
        color: colors.otherCover,
        percentage: secondaryExtent / totalArea * 100
      },
      {
        label: 'Non-Forest',
        value: totalArea - totalExtent,
        color: colors.nonForest,
        percentage: (totalArea - totalExtent) / totalArea * 100
      }
    ];
    return parsedData;
  }
);

export const getSentence = createSelector(
  [parseData, getSettings, getCurrentLocation, getIndicator, getSentences],
  (parsedData, settings, currentLabel, indicator, sentences) => {
    if (!parsedData || !currentLabel) return null;
    const { initial, withIndicator } = sentences;
    const primaryPercentage = parsedData.find(d => d.label === 'Primary Forest')
      .percentage;

    let indicatorLabel = indicator && indicator.label;
    switch (indicator && indicator.value) {
      case 'primary_forest__mining':
        indicatorLabel = 'mining concessions';
        break;
      case 'primary_forest__landmark':
        indicatorLabel = 'indigenous lands';
        break;
      case 'primary_forest__wdpa':
        indicatorLabel = 'protected areas';
        break;
      default:
        indicatorLabel = 'primary forests';
    }

    const params = {
      location: `${currentLabel}'s`,
      indicator: indicatorLabel,<commit_msg>Fix for primary pie<commit_after>import { createSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import { format } from 'd3-format';

// get list data
const getData = state => state.data;
const getSettings = state => state.settings;
const getCurrentLocation = state => state.currentLabel;
const getIndicator = state => state.indicator || null;
const getColors = state => state.colors;
const getSentences = state => state.config && state.config.sentences;

// get lists selected
export const parseData = createSelector(
  [getData, getSettings, getColors],
  (data, settings, colors) => {
    if (isEmpty(data)) return null;
    const { totalArea, totalExtent, extent } = data;
    const secondaryExtent = totalExtent - extent < 0 ? 0 : totalExtent - extent;
    const parsedData = [
      {
        label: 'Primary Forest',
        value: extent,
        color: colors.primaryForest,
        percentage: extent / totalArea * 100
      },
      {
        label: 'Other Tree Cover',
        value: secondaryExtent,
        color: colors.otherCover,
        percentage: secondaryExtent / totalArea * 100
      },
      {
        label: 'Non-Forest',
        value: totalArea - totalExtent,
        color: colors.nonForest,
        percentage: (totalArea - totalExtent) / totalArea * 100
      }
    ];
    return parsedData;
  }
);

export const getSentence = createSelector(
  [parseData, getSettings, getCurrentLocation, getIndicator, getSentences],
  (parsedData, settings, currentLabel, indicator, sentences) => {
    if (!parsedData || !currentLabel) return null;
    const { initial, withIndicator } = sentences;
    const totalExtent = parsedData
      .filter(d => d.label !== 'Non-Forest')
      .map(d => d.value)
      .reduce((sum, d) => sum + d);
    const primaryData = parsedData.find(d => d.label === 'Primary Forest')
      .value;
    const primaryPercentage = primaryData && primaryData / totalExtent * 100;

    let indicatorLabel = indicator && indicator.label;
    switch (indicator && indicator.value) {
      case 'primary_forest__mining':
        indicatorLabel = 'mining concessions';
        break;
      case 'primary_forest__landmark':
        indicatorLabel = 'indigenous lands';
        break;
      case 'primary_forest__wdpa':
        indicatorLabel = 'protected areas';
        break;
      default:
        indicatorLabel = 'primary forests';
    }

    const params = {
      location: `${currentLabel}'s`,
      indicator: indicatorLabel,
{'fraction_non_alphanumeric': 0.10978169605373636, 'fraction_numerical': 0.005667506297229219, 'mean_word_length': 2.9347646573080097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '7324149', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1323, 'n_words': 370}