<commit_before>import Chart from "./index";
import {Map, OrderedMap, Set} from "immutable";
import Comparison from "../../comparison";
import backendYearFilterable from "../../backend-year-filterable";

class BidsByItem extends backendYearFilterable(Chart){
  static getName(__){
    return __('Number of bids by item');
  }

  getData(){
    let data = super.getData();
    if(!data) return [];
    let {traceColors, hoverFormatter} = this.props.styling.charts;
    let trace = {
      x: [],
      y: [],
      type: 'bar',
      marker: {
        color: traceColors[0]
      }
    };

    if(hoverFormatter){
      trace.text = [];
      trace.hoverinfo = "text";
    }

    for(let datum of data){
      let name = datum.get('description');
      let totalTenders = datum.get('totalTenders');
      trace.x.push(name);
      trace.y.push(totalTenders);
      if(hoverFormatter) trace.text.push(hoverFormatter(totalTenders));
    }

    return [trace];
  }

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

BidsByItem.endpoint = 'numberOfTendersByItemClassification';
BidsByItem.UPDATABLE_FIELDS = ['data'];

class BidsByItemComparison 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, uniformData;

    if(comparisonData.count() == comparisonCriteriaValues.length + 1){
      let byItems = comparisonData.map(
          data => data.reduce(
              (items, datum) => items.set(datum.get('description'), datum),
              Map()<commit_msg>OCE-108 - added download button for *number of bids by item* excel chart.<commit_after>import Chart from "./index";
import {Map, OrderedMap, Set} from "immutable";
import Comparison from "../../comparison";
import backendYearFilterable from "../../backend-year-filterable";

class BidsByItem extends backendYearFilterable(Chart){
  static getName(__){
    return __('Number of bids by item');
  }

  getData(){
    let data = super.getData();
    if(!data) return [];
    let {traceColors, hoverFormatter} = this.props.styling.charts;
    let trace = {
      x: [],
      y: [],
      type: 'bar',
      marker: {
        color: traceColors[0]
      }
    };

    if(hoverFormatter){
      trace.text = [];
      trace.hoverinfo = "text";
    }

    for(let datum of data){
      let name = datum.get('description');
      let totalTenders = datum.get('totalTenders');
      trace.x.push(name);
      trace.y.push(totalTenders);
      if(hoverFormatter) trace.text.push(hoverFormatter(totalTenders));
    }

    return [trace];
  }

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

BidsByItem.endpoint = 'numberOfTendersByItemClassification';
BidsByItem.excelEP = 'numberOfTendersByItemExcelChart';
BidsByItem.UPDATABLE_FIELDS = ['data'];

class BidsByItemComparison 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, uniformData;

    if(comparisonData.count() == comparisonCriteriaValues.length + 1){
      let byItems = comparisonData.map(
          data => data.reduce(
              (items, datum) => items.set(datum.get('description'), datum),
              Map()
{'fraction_non_alphanumeric': 0.1321608040201005, 'fraction_numerical': 0.0017587939698492463, 'mean_word_length': 3.021212121212121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5208221', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1173, 'n_words': 262}