<commit_before>import _ from 'lodash'
import Reflux from 'reflux'
import StateMixin from'reflux-state-mixin'
import DatapointActions from 'actions/DatapointActions'

var DatapointStore = Reflux.createStore({

  mixins: [StateMixin.store],

  listenables: DatapointActions,

  datapoints: {
    meta: null,
    raw: null
  },

  getInitialState () {
    return this.datapoints
  },

  // =========================================================================== //
  //                              API CALL HANDLERS                              //
  // =========================================================================== //

  // ============================  Fetch  Datapoints  ========================== //
  onFetchDatapoints () {
    this.setState({ raw: [] })
  },
  onFetchDatapointsCompleted (response) {
    this.setState({
      meta: response.meta,
      raw: response.objects
    })
  },
  onFetchDatapointsFailed (error) {
    this.setState({ error: error })
  }
})

export default DatapointStore<commit_msg>Add melted response to datapoint store<commit_after>import _ from 'lodash'
import Reflux from 'reflux'
import StateMixin from'reflux-state-mixin'
import DatapointActions from 'actions/DatapointActions'

var DatapointStore = Reflux.createStore({

  mixins: [StateMixin.store],

  listenables: DatapointActions,

  datapoints: {
    meta: null,
    melted: null,
    raw: null
  },

  getInitialState () {
    return this.datapoints
  },

  // =========================================================================== //
  //                              API CALL HANDLERS                              //
  // =========================================================================== //

  // ============================  Fetch  Datapoints  ========================== //
  onFetchDatapoints () {
    this.setState({ raw: [] })
  },
  onFetchDatapointsCompleted (response) {
    this.setState({
      meta: response.meta,
      raw: response.objects,
      melted: _(response.objects)
        .flatten()
        .sortBy(_.method('campaign.start_date.getTime'))
        .map(this.melt)
        .flatten()
        .value()
    })
  },

  onFetchDatapointsFailed (error) {
    this.setState({ error: error })
  },

  // =========================================================================== //
  //                                  UTILITIES                                  //
  // =========================================================================== //
  melt (datapoint) {
    var base = _.omit(datapoint, 'indicators')
    return datapoint.indicators.map(indicator => {
      return _.assign({
        computed: indicator.computed,
        indicator: indicator.indicator,
        value: indicator.value
      }, base)
    })
  }
})

export default DatapointStore
{'fraction_non_alphanumeric': 0.29283933024581404, 'fraction_numerical': 0.0, 'mean_word_length': 2.729083665338645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956452', 'n_tokens_mistral': 796, 'n_tokens_neox': 730, 'n_words': 135}