<commit_before>import FrontendYearFilterableChart from "./frontend-filterable";
import {pluckImm, max} from "../../tools";
import {Map, Set} from "immutable";
import Comparison from "../../comparison";

class ProcurementMethod extends FrontendYearFilterableChart{
  static toCats(data){
    if(!data) return Map();
    return data
        .groupBy(pluckImm('procurementMethodDetails'))
        .map((bidTypes, _id) => Map({
          _id,
          totalTenderAmount: bidTypes.map(pluckImm('totalTenderAmount')).reduce((a, b) => a + b, 0)
        }));
  }

  getCats(data){
    let cats = this.props.cats || Map();
    return cats.merge(this.constructor.toCats(data));
  }

  getData(){
    let raw = super.getData();
    if(!raw) return [];
    let data = this.getCats(raw);

    return [{
      x: data.map(imm => imm.get('_id') || this.__('Unspecified')).toArray(),
      y: data.map(pluckImm('totalTenderAmount')).toArray(),
      type: 'bar',
      marker: {
        color: this.props.styling.charts.traceColors[0]
      }
    }];
  }

  getLayout(){
    return {
      xaxis: {
        title: this.__("Method"),
        type: "category"
      },
      yaxis: {
        title: this.__("Amount")
      }
    }
  }
}

ProcurementMethod.endpoint = 'tenderPriceByVnTypeYear';
ProcurementMethod.getName = __ => __('Procurement method');
ProcurementMethod.UPDATABLE_FIELDS = ['data', 'years', 'cats'];

class ProcurementMethodComparison extends Comparison{
  render(){
    let {compareBy, comparisonData, comparisonCriteriaValues, filters, requestNewComparisonData, years, translations,
      styling} = this.props;
    if(!comparisonCriteriaValues.length) return null;
    let Component = this.getComponent();
    let decoratedFilters = this.constructor.decorateFilters(filters, compareBy, comparisonCriteriaValues);
    let rangeProp, cats;

    if(comparisonData.count() == comparisonCriteriaValues.length + 1){
      let uniformData = comparisonData.map(comparisonDatum =>
          Component.toCats(Component.filterDataByYears(comparisonDatum, years))
      ).reduce(<commit_msg>OCVN-249 OCE Procurement method now uses a parameterizable key for procurementMethod value<commit_after>import FrontendYearFilterableChart from "./frontend-filterable";
import {pluckImm, max} from "../../tools";
import {Map, Set} from "immutable";
import Comparison from "../../comparison";

class ProcurementMethod extends FrontendYearFilterableChart{
  static toCats(data){
    if(!data) return Map();
    return data
        .groupBy(pluckImm(this.PROCUREMENT_METHOD_FIELD))
        .map((bidTypes, _id) => Map({
          _id,
          totalTenderAmount: bidTypes.map(pluckImm('totalTenderAmount')).reduce((a, b) => a + b, 0)
        }));
  }

  getCats(data){
    let cats = this.props.cats || Map();
    return cats.merge(this.constructor.toCats(data));
  }

  getData(){
    let raw = super.getData();
    if(!raw) return [];
    let data = this.getCats(raw);

    return [{
      x: data.map(imm => imm.get('_id') || this.__('Unspecified')).toArray(),
      y: data.map(pluckImm('totalTenderAmount')).toArray(),
      type: 'bar',
      marker: {
        color: this.props.styling.charts.traceColors[0]
      }
    }];
  }

  getLayout(){
    return {
      xaxis: {
        title: this.__("Method"),
        type: "category"
      },
      yaxis: {
        title: this.__("Amount")
      }
    }
  }
}

ProcurementMethod.endpoint = 'tenderPriceByOcdsTypeYear';
ProcurementMethod.getName = __ => __('Procurement method');
ProcurementMethod.UPDATABLE_FIELDS = ['data', 'years', 'cats'];
ProcurementMethod.PROCUREMENT_METHOD_FIELD = 'procurementMethod';

class ProcurementMethodComparison extends Comparison{
  render(){
    let {compareBy, comparisonData, comparisonCriteriaValues, filters, requestNewComparisonData, years, translations,
      styling} = this.props;
    if(!comparisonCriteriaValues.length) return null;
    let Component = this.getComponent();
    let decoratedFilters = this.constructor.decorateFilters(filters, compareBy, comparisonCriteriaValues);
    let rangeProp, cats;

    if(comparisonData.count() == comparisonCriteriaValues.length + 1){
      let uniformData = comparisonData.map(comparisonDatum =>
          Component.toCats(Component.filterDataByYears(comparisonDatum, years))
      ).reduce(
{'fraction_non_alphanumeric': 0.13885025498377376, 'fraction_numerical': 0.002086230876216968, 'mean_word_length': 3.542105263157895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2762588', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1308, 'n_words': 262}