<commit_before>import dispatcher from "../dispatcher";
import constants from "./constants";
import {fetchJson, years} from "../../tools";

export default {
  changeTab(slug){
    dispatcher.dispatch(constants.TAB_CHANGED, slug);
  },

  toggleYear(year, selected){
    dispatcher.dispatch(constants.YEAR_TOGGLED, {
      year: year,
      selected: selected
    });
  },

  changeContentWidth(newWidth){
    dispatcher.dispatch(constants.CONTENT_WIDTH_CHANGED, newWidth);
  },

  loadData(){
    Promise.all([
      fetchJson('/api/countBidPlansByYear'),
      fetchJson('/api/countTendersByYear'),
      fetchJson('/api/countAwardsByYear')
    ]).then(([bidplans, tenders, awards]) => dispatcher.dispatch(constants.OVERVIEW_DATA_UPDATED, {
      bidplans: bidplans,
      tenders: tenders,
      awards: awards
    }));

    years().forEach(year => {
      fetchJson(`/api/plannedFundingByLocation/${year}`)
          .then(data => data.filter(location => !!location.coordinates || console.warn('Invalid location!', location)))
          .then(data => dispatcher.dispatch(constants.LOCATION_UPDATED, {year: year, data: data}));

      Promise.all([
        fetchJson(`/api/costEffectivenessTenderAmount/${year}`),
        fetchJson(`/api/costEffectivenessAwardAmount/${year}`)
      ]).then(([tenderResponse, awardResponse]) => {
        var tender = tenderResponse[0].totalTenderAmount;
        var award = awardResponse[0].totalAwardAmount;
        return {
          year: year,
          tender: tender,
          diff: tender - award
        }
      }).then(data => dispatcher.dispatch(constants.COST_EFFECTIVENESS_DATA_UPDATED, {year: year, data: data}));

      fetchJson(`/api/tenderPriceByVnTypeYear/${year}`)
          .then(data => dispatcher.dispatch(constants.BID_TYPE_DATA_UPDATED, {year: year, data: data}))
    });

    fetchJson("/api/tenderBidPeriodPercentiles")
        .then(raw => {
          var parsed = {};
          Object.keys(raw).forEach(key => parsed[key] = raw[key].tenderLengthDays);
          return parsed;
        })
        .then(dispatcher.dispatch.bind(dispatcher, constants.BID_PERIOD_DATA_UPDATED));
  }<commit_msg>OCVN-83 Cleaned up obsolete data fetching code for bid period<commit_after>import dispatcher from "../dispatcher";
import constants from "./constants";
import {fetchJson, years} from "../../tools";

export default {
  changeTab(slug){
    dispatcher.dispatch(constants.TAB_CHANGED, slug);
  },

  toggleYear(year, selected){
    dispatcher.dispatch(constants.YEAR_TOGGLED, {
      year: year,
      selected: selected
    });
  },

  changeContentWidth(newWidth){
    dispatcher.dispatch(constants.CONTENT_WIDTH_CHANGED, newWidth);
  },

  loadData(){
    Promise.all([
      fetchJson('/api/countBidPlansByYear'),
      fetchJson('/api/countTendersByYear'),
      fetchJson('/api/countAwardsByYear')
    ]).then(([bidplans, tenders, awards]) => dispatcher.dispatch(constants.OVERVIEW_DATA_UPDATED, {
      bidplans: bidplans,
      tenders: tenders,
      awards: awards
    }));

    years().forEach(year => {
      fetchJson(`/api/plannedFundingByLocation/${year}`)
          .then(data => data.filter(location => !!location.coordinates || console.warn('Invalid location!', location)))
          .then(data => dispatcher.dispatch(constants.LOCATION_UPDATED, {year: year, data: data}));

      Promise.all([
        fetchJson(`/api/costEffectivenessTenderAmount/${year}`),
        fetchJson(`/api/costEffectivenessAwardAmount/${year}`)
      ]).then(([tenderResponse, awardResponse]) => {
        var tender = tenderResponse[0].totalTenderAmount;
        var award = awardResponse[0].totalAwardAmount;
        return {
          year: year,
          tender: tender,
          diff: tender - award
        }
      }).then(data => dispatcher.dispatch(constants.COST_EFFECTIVENESS_DATA_UPDATED, {year: year, data: data}));

      fetchJson(`/api/tenderPriceByVnTypeYear/${year}`)
          .then(data => dispatcher.dispatch(constants.BID_TYPE_DATA_UPDATED, {year: year, data: data}))
    });
  }
{'fraction_non_alphanumeric': 0.14617283950617285, 'fraction_numerical': 0.0014814814814814814, 'mean_word_length': 3.34656652360515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5598741', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1249, 'n_words': 198}