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

class BidSelectionMethod 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'
    }];
  }

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

BidSelectionMethod.endpoint = 'tenderPriceByVnTypeYear';
BidSelectionMethod.getName = __ => __('Bid selection method');
BidSelectionMethod.UPDATABLE_FIELDS = ['data', 'years', 'cats'];

class BidSelectionMethodComparison extends Comparison{
  render(){
    let {compareBy, comparisonData, comparisonCriteriaValues, filters, requestNewComparisonData, years, translations} = 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(
          (a, b) => a.mergeWith(
              (a, b) => a.get('totalTenderAmount') > b.get('totalTenderAmount') ? a : b
              , b)
      );

      let maxValue = uniformData.map(pluckImm('totalTenderAmount')).reduce(max, 0);

      rangeProp = {
        yAxisRange: [0, maxValue]
      };

      cats = uniformData.map(uniformDatum => uniformDatum.set('totalTenderAmount', undefined))
    } else {
      cats = Map();
      rangeProp = {};
    }

    return this.wrap(decoratedFilters.map((comparisonFilters, index) => <div className="col-md-6" key={index}>
          <Component
              filters={comparisonFilters}
              requestNewData={(_, data) => requestNewComparisonData([index], data)}
              data={comparisonData.get(index)}
              years={years}
              title={this.getTitle(index)}
              cats={cats}
              translations={translations}
              {...rangeProp}
          />
        </div>
    ));
  }
}


BidSelectionMethod.compareWith = BidSelectionMethodComparison;

export default BidSelectionMethod;<commit_msg>OCVN-199 Updated bid period chart and custom bid period comparison to use new styling functionality<commit_after>import FrontendYearFilterableChart from "../../oce/visualizations/charts/frontend-filterable";
import {pluckImm, max} from "../../oce/tools";
import {Map, Set} from "immutable";
import Comparison from "../../oce/comparison";

class BidSelectionMethod 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")
      }
    }
  }
}

BidSelectionMethod.endpoint = 'tenderPriceByVnTypeYear';
BidSelectionMethod.getName = __ => __('Bid selection method');
BidSelectionMethod.UPDATABLE_FIELDS = ['data', 'years', 'cats'];

class BidSelectionMethodComparison 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(
          (a, b) => a.mergeWith(
              (a, b) => a.get('totalTenderAmount') > b.get('totalTenderAmount') ? a : b
              , b)
      );

      let maxValue = uniformData.map(pluckImm('totalTenderAmount')).reduce(max, 0);

      rangeProp = {
        yAxisRange: [0, maxValue]
      };

      cats = uniformData.map(uniformDatum => uniformDatum.set('totalTenderAmount', undefined))
    } else {
      cats = Map();
      rangeProp = {};
    }

    return this.wrap(decoratedFilters.map((comparisonFilters, index) => <div className="col-md-6" key={index}>
          <Component
              filters={comparisonFilters}
              requestNewData={(_, data) => requestNewComparisonData([index], data)}
              data={comparisonData.get(index)}
              years={years}
              title={this.getTitle(index)}
              cats={cats}
              translations={translations}
              styling={styling}
              {...rangeProp}
          />
        </div>
    ));
  }
}


BidSelectionMethod.compareWith = BidSelectionMethodComparison;

export default BidSelectionMethod;
{'fraction_non_alphanumeric': 0.14036697247706423, 'fraction_numerical': 0.0027522935779816515, 'mean_word_length': 2.8363636363636364, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1683916', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1933, 'n_words': 368}