<commit_before>#TODO: rename to ChartDataPacket
#TODO: find a fitting place for this file maybe in module
class Chart
  @@chart_index = 0
  @@header = false
  attr :chart_id
  attr :width
  attr :data

  def initialize(type,data,option=nil,width = nil)
    @@chart_index = @@chart_index + 1
    chart_data = self.class.dataAdapter(type,data,option);
    unless width.nil?
      @width = width
    end
    @data = chart_data
    @chart_id = @@chart_index
  end

  def get_id_str()
    "chart_container_" + @chart_id.to_s
  end

  def self.include_header?()
    !@@header
  end

  def self.set_header()
    @@header = true
  end

  def self.dataAdapter(type,data,optionalConf)
    template = data_template[type];
    if (type == :pie) then
      data[:type] = 'pie';
      template[:series] = [data]
    else
      template[:series] = data
    end
    if optionalConf.nil? then
      template[:title][:text] = ""
      template.delete(:subtitle)
      template.delete(:yAxis)
      template.delete(:xAxis)
    else
      if template[:subtitle].nil? then
        template[:subtitle]={}
      end
      if optionalConf[:title].nil? then
        template[:title][:text] = ""
      else
        template[:title][:text] = optionalConf[:title]
      end
      if optionalConf[:subtitle].nil? then
        template.delete(:subtitle)
      else
        template[:subtitle][:text]=optionalConf[:subtitle]
      end

      if optionalConf[:y_axis].nil? then
        template.delete(:yAxis)
      else
        template[:yAxis][:title][:text]=optionalConf[:y_axis]
      end

      if optionalConf[:x_axis].nil? then
        template[:xAxis].delete(:title)
      else
        template[:xAxis][:title][:text] = optionalConf[:x_axis]
      end

      if optionalConf[:x_axis_categories].nil? then
        template[:xAxis].delete(:categories)
      else
        template[:xAxis][:categories]=optionalConf[:x_axis_categories]
      end
    end
    template
  end


  def self.data_template()
    {
      :pie => {
        :chart => {
          :plotBackgroundColor => nil,
          :plotBorderWidth => nil,
          :plotShadow => false
        },
        :title => {
          :text => 'Title'
        },
        :subtitle => {
          :text => 'Title'
        },
        :xAxis => {},
        :yAxis => {},<commit_msg>refactored self.data_adapter<commit_after>#TODO: rename to ChartDataPacket
#TODO: find a fitting place for this file maybe in module
class Chart
  @@chart_index = 0
  @@header = false
  attr :chart_id
  attr :width
  attr :data

  def initialize(type,data,option=nil,width = nil)
    @@chart_index = @@chart_index + 1
    chart_data = self.class.dataAdapter(type,data,option);
    unless width.nil?
      @width = width
    end
    @data = chart_data
    @chart_id = @@chart_index
  end

  def get_id_str()
    "chart_container_" + @chart_id.to_s
  end

  def self.include_header?()
    !@@header
  end

  def self.set_header()
    @@header = true
  end

  def self.set_Template_Optional_Params(template)
    template[:title][:text] = ""
    template.delete(:subtitle)
    template.delete(:yAxis)
    template.delete(:xAxis)
    template
  end

  def self.dataAdapter(type,data,optionalConf)
    template = data_template[type];
    if (type == :pie) then
      data[:type] = 'pie';
      template[:series] = [data]
    else
      template[:series] = data
    end
    if optionalConf.nil? then
      template = self.class.set_Template_optional_Params(template)
    else
      if optionalConf[:title].nil? then
        template[:title][:text] = ""
      else
        template[:title][:text] = optionalConf[:title]
      end
    template=self.class.validate_optional_conf(optionalConf,template)
    end
    template
  end

  def self.validate_optional_conf(optionalConf,template)
    if optionalConf[:subtitle].nil? then
      template.delete(:subtitle)
    else
      template[:subtitle]={}
      template[:subtitle][:text]=optionalConf[:subtitle]
    end

    if optionalConf[:y_axis].nil? then
      template.delete(:yAxis)
    else
      template[:yAxis][:title][:text]=optionalConf[:y_axis]
    end

    if optionalConf[:x_axis].nil? then
      template[:xAxis].delete(:title)
    else
      template[:xAxis][:title][:text] = optionalConf[:x_axis]
    end

    if optionalConf[:x_axis_categories].nil? then
      template[:xAxis].delete(:categories)
    else
      template[:xAxis][:categories]=optionalConf[:x_axis_categories]
    end
    template
  end

  def self.data_template()
    {
      :pie => {
        :chart => {
          :plotBackgroundColor => nil,
          :plotBorderWidth => nil,
          :plotShadow => false
        },
        :title => {
          :text => 'Title'
        },
        :subtitle => {
          :text => 'Title'
        },
        :xAxis => {},
        :yAxis => {},
{'fraction_non_alphanumeric': 0.12887133652047392, 'fraction_numerical': 0.0008314279775514446, 'mean_word_length': 2.577695167286245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6497746', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1483, 'n_words': 300}