<commit_before>-#######################################################################
-# Ruby helper functions, used in the HAML below
-#######################################################################

:ruby
  require 'sass'

  # General chart options
  # See http://www.chartjs.org/docs/#chart-configuration-creating-a-chart-with-options
  optionsLine = {
    animation: false,
    title:     {display: false},
    legend:    {position: 'bottom'},
    scales:    {xAxes: [{display: false}]},
    fill:      false,
  }

  # In CoffeeScript, this gets merged with the above options
  optionsLineSimple = {
    legend: {display: false},
    scales: {xAxes: [{display: false}], yAxes: [{display: false}]},
    fill:   true,
  }

  # Helper to easily do SASS from within Ruby
  def sass(cmd)
    Sass::Script::Parser.parse(cmd, 0, 0).perform(Sass::Environment.new).to_s
  end

  # Defined colors
  # (specifically chosen for colorblind contrast)
  color = {
    red:     '#d91515',
    blue:    '#0097ff',
    green:   '#00720d',
    orange:  '#ffa143',
    purple:  '#d71ecd',
    pink:    '#ff00e8',
    teal:    '#088',
    grey:    '#aaa',
  }

  # Extend color with light and dark variants
  # (:darkblue, :lightblue, :extradarkblue, :extralightblue, etc.)
  color = color.inject({}) do |h, (k, v)|
    h[k] = v
    h["dark#{k.to_s}".to_sym]       = sass("darken(#{v}, 10)")
    h["light#{k.to_s}".to_sym]      = sass("lighten(#{v}, 15)")
    h["extradark#{k.to_s}".to_sym]  = sass("mix(#{v}, black, 70)")
    h["extralight#{k.to_s}".to_sym] = sass("mix(#{v}, white, 50)")
    h
  end

  # Generate options for a line graphs
  def chartLine(label, color, info, simple = false)
    opt = {
      data: info,
      fill: false,
      # Override the backgroundColor, since we've set things to not fill
      # and it'd be nice to pass the original color back to the legend
      # as this list is processed, and only a few things escape to the
      # legendTemplate
      backgroundColor: sass("#{color}"),
      borderColor: sass("mix(#{color}, #fff, 40)"),
      label: label,
      originalColor: sass("#{color}"),
      pointBackgroundColor: sass("mix(#{color}, #fff, 70)"),
      pointBorderColor: "transparent",
      pointHoverBackgroundColor: sass("mix(#{color}, #000, 100)"),
      pointHoverBorderColor: sass("mix(#{color}, #000, 100)"),
      pointRadius: 1.5,
      pointHitRadius: 12,
    }

    # Inherit from above and provide some overrides for simple mode
    # (used for contributor growth)
    if simple
      opt.merge({
        fill: true,
        borderWidth: 1,
        pointRadius: 0,
        pointHitRadius: 0,
      })
    else
      opt
    end
  end

  # Generate options for a pie piece
  def chartPie(label, color, info)
    {
      value: info,
      color: sass(color),
      highlight: sass("mix(#{color}, #fff, 75)"),
      label: label
    }
  end

  # Return only last X months (default = 12),
  # minus the current month (which is incomplete in the data)
  def lastMonths(info, months = 12)
    info.last(months + 1).take(months)
  end

-#######################################################################
-# CoffeeScript, to generate the in-page JS
-#######################################################################

- content_for :tail do
  :coffee
    ###
    # Typical options
    ###
    @optionsLine = #{optionsLine.to_json}
    @optionsLineSimple = $.extend true, {}, optionsLine, #{optionsLineSimple.to_json}

    ###
    # Format a string as a sentence
    ###
    @sentence = (string) ->
      string.replace /^(.)/g, (letter) -> letter.toUpperCase()

    ###
    # Given dates, return the duration
    ###
    @getDuration = (dates) ->
      dates.length + ' months'

    ###
    # Common chart creation code, to prevent duplication
    ###
    @chart = (name, type, data, opts = @optionsLine) ->
      canvasElement = $(name).get(0).getContext('2d')

      result = new Chart(canvasElement, {
        type:    type.toLowerCase(),
        data:    data,
        options: opts
      })

      if data.heading
        # For projects that have data for other than 12 months,
        # figure out duration of time and make a string
        if data.labels.length != 12
          duration = ' (' + @getDuration(data.labels) + ')'

        # Prepend (optional) heading
        $(name).before('<h4>' + data.heading + (duration ? '') + '</h4>')

      return chart

-#######################################################################
-# HAML to build the dashboard
-#######################################################################

- if data[:dashboard]

  .dashboard

    -#----------------------------------------------------------
    -# Intro text
    -#----------------------------------------------------------

    #intro
      %h1 #{data.dashboard.index_page.title}
<commit_msg>fix dashboard data's presence check<commit_after>-#######################################################################
-# Ruby helper functions, used in the HAML below
-#######################################################################

:ruby
  require 'sass'

  # General chart options
  # See http://www.chartjs.org/docs/#chart-configuration-creating-a-chart-with-options
  optionsLine = {
    animation: false,
    title:     {display: false},
    legend:    {position: 'bottom'},
    scales:    {xAxes: [{display: false}]},
    fill:      false,
  }

  # In CoffeeScript, this gets merged with the above options
  optionsLineSimple = {
    legend: {display: false},
    scales: {xAxes: [{display: false}], yAxes: [{display: false}]},
    fill:   true,
  }

  # Helper to easily do SASS from within Ruby
  def sass(cmd)
    Sass::Script::Parser.parse(cmd, 0, 0).perform(Sass::Environment.new).to_s
  end

  # Defined colors
  # (specifically chosen for colorblind contrast)
  color = {
    red:     '#d91515',
    blue:    '#0097ff',
    green:   '#00720d',
    orange:  '#ffa143',
    purple:  '#d71ecd',
    pink:    '#ff00e8',
    teal:    '#088',
    grey:    '#aaa',
  }

  # Extend color with light and dark variants
  # (:darkblue, :lightblue, :extradarkblue, :extralightblue, etc.)
  color = color.inject({}) do |h, (k, v)|
    h[k] = v
    h["dark#{k.to_s}".to_sym]       = sass("darken(#{v}, 10)")
    h["light#{k.to_s}".to_sym]      = sass("lighten(#{v}, 15)")
    h["extradark#{k.to_s}".to_sym]  = sass("mix(#{v}, black, 70)")
    h["extralight#{k.to_s}".to_sym] = sass("mix(#{v}, white, 50)")
    h
  end

  # Generate options for a line graphs
  def chartLine(label, color, info, simple = false)
    opt = {
      data: info,
      fill: false,
      # Override the backgroundColor, since we've set things to not fill
      # and it'd be nice to pass the original color back to the legend
      # as this list is processed, and only a few things escape to the
      # legendTemplate
      backgroundColor: sass("#{color}"),
      borderColor: sass("mix(#{color}, #fff, 40)"),
      label: label,
      originalColor: sass("#{color}"),
      pointBackgroundColor: sass("mix(#{color}, #fff, 70)"),
      pointBorderColor: "transparent",
      pointHoverBackgroundColor: sass("mix(#{color}, #000, 100)"),
      pointHoverBorderColor: sass("mix(#{color}, #000, 100)"),
      pointRadius: 1.5,
      pointHitRadius: 12,
    }

    # Inherit from above and provide some overrides for simple mode
    # (used for contributor growth)
    if simple
      opt.merge({
        fill: true,
        borderWidth: 1,
        pointRadius: 0,
        pointHitRadius: 0,
      })
    else
      opt
    end
  end

  # Generate options for a pie piece
  def chartPie(label, color, info)
    {
      value: info,
      color: sass(color),
      highlight: sass("mix(#{color}, #fff, 75)"),
      label: label
    }
  end

  # Return only last X months (default = 12),
  # minus the current month (which is incomplete in the data)
  def lastMonths(info, months = 12)
    info.last(months + 1).take(months)
  end

-#######################################################################
-# CoffeeScript, to generate the in-page JS
-#######################################################################

- content_for :tail do
  :coffee
    ###
    # Typical options
    ###
    @optionsLine = #{optionsLine.to_json}
    @optionsLineSimple = $.extend true, {}, optionsLine, #{optionsLineSimple.to_json}

    ###
    # Format a string as a sentence
    ###
    @sentence = (string) ->
      string.replace /^(.)/g, (letter) -> letter.toUpperCase()

    ###
    # Given dates, return the duration
    ###
    @getDuration = (dates) ->
      dates.length + ' months'

    ###
    # Common chart creation code, to prevent duplication
    ###
    @chart = (name, type, data, opts = @optionsLine) ->
      canvasElement = $(name).get(0).getContext('2d')

      result = new Chart(canvasElement, {
        type:    type.toLowerCase(),
        data:    data,
        options: opts
      })

      if data.heading
        # For projects that have data for other than 12 months,
        # figure out duration of time and make a string
        if data.labels.length != 12
          duration = ' (' + @getDuration(data.labels) + ')'

        # Prepend (optional) heading
        $(name).before('<h4>' + data.heading + (duration ? '') + '</h4>')

      return chart

-#######################################################################
-# HAML to build the dashboard
-#######################################################################

- if data[:dashboard] and data.dashboard[:projects]

  .dashboard

    -#----------------------------------------------------------
    -# Intro text
    -#----------------------------------------------------------

    #intro
      %h1 #{data.dashboard.index_page.title}

{'fraction_non_alphanumeric': 0.2404220446629789, 'fraction_numerical': 0.01516082769924196, 'mean_word_length': 2.651084517576664, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7527364', 'n_tokens_mistral': 3087, 'n_tokens_neox': 2905, 'n_words': 798}