<commit_before>import { createSelector, createStructuredSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import uniqBy from 'lodash/uniqBy';
import sumBy from 'lodash/sumBy';
import { sortByKey } from 'utils/data';
import { formatNumber } from 'utils/format';
import { format } from 'd3-format';

// get list data
const getLoss = state => state.data && state.data.lossByRegion;
const getExtent = state => state.data && state.data.extent;
const getSettings = state => state.settings;
const getIndicator = state => state.indicator;
const getLocationsMeta = state => state.childData;
const getLocationName = state => state.locationLabel;
const getColors = state => state.colors;
const getSentences = state => state.sentences;

export const mapData = createSelector(
  [getLoss, getExtent, getSettings, getLocationsMeta],
  (data, extent, settings, meta) => {
    if (isEmpty(data) || isEmpty(meta)) return null;
    const { startYear, endYear } = settings;

    const mappedData = data.map(d => {
      const region = meta[d.id];
      const loss =
        sumBy(
          d.loss.filter(l => l.year >= startYear && l.year <= endYear),
          'area'
        ) || 0;
      const locationExtentById = extent.filter(l => l.id === d.id);
      const locationExtent =
        locationExtentById &&
        !!locationExtentById.length &&
        locationExtentById[0].extent;
      const percentage =
        loss && locationExtent ? loss / locationExtent * 100 : 0;
      const normalPercentage = percentage > 100 ? 100 : percentage;

      return {
        label: (region && region.label) || '',
        loss,<commit_msg>add location path to located widget list<commit_after>import { createSelector, createStructuredSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import uniqBy from 'lodash/uniqBy';
import sumBy from 'lodash/sumBy';
import { sortByKey } from 'utils/data';
import { formatNumber } from 'utils/format';
import { format } from 'd3-format';

// get list data
const getLoss = state => state.data && state.data.lossByRegion;
const getExtent = state => state.data && state.data.extent;
const getSettings = state => state.settings;
const getIndicator = state => state.indicator;
const getLocationsMeta = state => state.childData;
const getLocationName = state => state.locationLabel;
const getColors = state => state.colors;
const getSentences = state => state.sentences;

export const mapData = createSelector(
  [getLoss, getExtent, getSettings, getLocationsMeta],
  (data, extent, settings, meta) => {
    if (isEmpty(data) || isEmpty(meta)) return null;
    const { startYear, endYear } = settings;

    const mappedData = data.map(d => {
      const region = meta[d.id];
      const loss =
        sumBy(
          d.loss.filter(l => l.year >= startYear && l.year <= endYear),
          'area'
        ) || 0;
      const locationExtentById = extent.filter(l => l.id === d.id);
      const locationExtent =
        locationExtentById &&
        !!locationExtentById.length &&
        locationExtentById[0].extent;
      const percentage =
        loss && locationExtent ? loss / locationExtent * 100 : 0;
      const normalPercentage = percentage > 100 ? 100 : percentage;

      return {
        label: (region && region.label) || '',
        loss,
        path: region.path,
{'fraction_non_alphanumeric': 0.12311860325105359, 'fraction_numerical': 0.007826610475617099, 'mean_word_length': 3.3268229166666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '5109966', 'n_tokens_mistral': 995, 'n_tokens_neox': 962, 'n_words': 271}