<commit_before>MetricFu.configure
module MetricFu
  class Run
    def initialize
      STDOUT.sync = true
    end
    def run
      add_metrics
      save_reports
      save_graphs
      display_results
    end
    def add_metrics
      MetricFu.metrics.each {|metric|
        mf_debug "** STARTING METRIC #{metric}"
        MetricFu.report.add(metric)
        mf_debug "** ENDING METRIC #{metric}"
      }
    end
    def save_reports
      mf_debug "** SAVING REPORT YAML OUTPUT TO #{MetricFu.base_directory}"
      MetricFu.report.save_output(MetricFu.report.as_yaml,
                                  MetricFu.base_directory,
                                  "report.yml")
      mf_debug "** SAVING REPORT DATA OUTPUT TO #{MetricFu.data_directory}"
      MetricFu.report.save_output(MetricFu.report.as_yaml,
                                  MetricFu.data_directory,
                                  "#{Time.now.strftime("%Y%m%d")}.yml")
      mf_debug "** SAVING TEMPLATIZED REPORT"
      MetricFu.report.save_templatized_report
    end
    def save_graphs
      mf_debug "** PREPARING TO GRAPH"
      MetricFu.graphs.each {|graph|
        mf_debug "** Graphing #{graph} with #{MetricFu.graph_engine}"
        MetricFu.graph.add(graph, MetricFu.graph_engine)
      }
      mf_debug "** GENERATING GRAPH"
      MetricFu.graph.generate
    end
    def display_results
      if MetricFu.report.open_in_browser?
        mf_debug "** OPENING IN BROWSER FROM #{MetricFu.output_directory}"<commit_msg>[#44] BF ensure hotspots runs last<commit_after>MetricFu.configure
module MetricFu
  class Run
    def initialize
      STDOUT.sync = true
    end
    def run
      run_reports
      save_reports
      save_graphs
      display_results
    end

    # ensure :hotspots runs last
    def report_metrics(metrics=MetricFu.metrics)
      hotspots = metrics.delete(:hotspots)
      MetricFu.metrics.push(:hotspots)
    end
    def run_reports
      report_metrics.each {|metric|
        mf_debug "** STARTING METRIC #{metric}"
        MetricFu.report.add(metric)
        mf_debug "** ENDING METRIC #{metric}"
      }
    end
    def save_reports
      mf_debug "** SAVING REPORT YAML OUTPUT TO #{MetricFu.base_directory}"
      MetricFu.report.save_output(MetricFu.report.as_yaml,
                                  MetricFu.base_directory,
                                  "report.yml")
      mf_debug "** SAVING REPORT DATA OUTPUT TO #{MetricFu.data_directory}"
      MetricFu.report.save_output(MetricFu.report.as_yaml,
                                  MetricFu.data_directory,
                                  "#{Time.now.strftime("%Y%m%d")}.yml")
      mf_debug "** SAVING TEMPLATIZED REPORT"
      MetricFu.report.save_templatized_report
    end
    def save_graphs
      mf_debug "** PREPARING TO GRAPH"
      MetricFu.graphs.each {|graph|
        mf_debug "** Graphing #{graph} with #{MetricFu.graph_engine}"
        MetricFu.graph.add(graph, MetricFu.graph_engine)
      }
      mf_debug "** GENERATING GRAPH"
      MetricFu.graph.generate
    end
    def display_results
      if MetricFu.report.open_in_browser?
        mf_debug "** OPENING IN BROWSER FROM #{MetricFu.output_directory}"
{'fraction_non_alphanumeric': 0.08829054477144646, 'fraction_numerical': 0.0006261740763932373, 'mean_word_length': 2.1822709163346614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6757271', 'n_tokens_mistral': 1092, 'n_tokens_neox': 957, 'n_words': 192}