BathHacked/energy-sparks

View on GitHub
app/models/chart_data_values.rb

Summary

Maintainability
D
2 days
Test Coverage
C
72%

File chart_data_values.rb has 498 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

class ChartDataValues
  attr_reader :anaylsis_type, :title, :subtitle, :chart1_type, :chart1_subtype,
              :y_axis_label, :x_axis_label, :x_axis_categories, :x_max_value, :x_min_value,
              :advice_header, :advice_footer, :y2_axis_label, :y2_point_format, :y2_max, :x_axis_ranges, :annotations,
              :transformations, :allowed_operations, :drilldown_available, :parent_timescale_description,
Severity: Minor
Found in app/models/chart_data_values.rb - About 7 hrs to fix

    Class ChartDataValues has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ChartDataValues
      attr_reader :anaylsis_type, :title, :subtitle, :chart1_type, :chart1_subtype,
                  :y_axis_label, :x_axis_label, :x_axis_categories, :x_max_value, :x_min_value,
                  :advice_header, :advice_footer, :y2_axis_label, :y2_point_format, :y2_max, :x_axis_ranges, :annotations,
                  :transformations, :allowed_operations, :drilldown_available, :parent_timescale_description,
    Severity: Major
    Found in app/models/chart_data_values.rb - About 7 hrs to fix

      Method process has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def process
          return self if @chart.nil?
          @x_data_hash = reverse_x_data_if_required
      
          @series_data = []
      Severity: Minor
      Found in app/models/chart_data_values.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method column_or_bar has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def column_or_bar
          @series_data = @x_data_hash.each_with_index.map do |(data_type, data), index|
            data_type = tidy_label(data_type)
            colour = work_out_best_colour(data_type)
      
      
      Severity: Minor
      Found in app/models/chart_data_values.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method series_translation_key_lookup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def series_translation_key_lookup
          @series_translation_key_lookup ||= {
            Series::DegreeDays::DEGREEDAYS => Series::DegreeDays::DEGREEDAYS_I18N_KEY,
            Series::Temperature::TEMPERATURE => Series::Temperature::TEMPERATURE_I18N_KEY,
            Series::DayType::SCHOOLDAYCLOSED => Series::DayType::SCHOOLDAYCLOSED_I18N_KEY,
      Severity: Minor
      Found in app/models/chart_data_values.rb - About 1 hr to fix

        Method initialize has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def initialize(chart, chart_type, transformations: [], allowed_operations: {}, drilldown_available: false, parent_timescale_description: nil, y1_axis_choices: [])
            if chart
              @chart_type         = chart_type
              @chart              = chart
              @title              = chart[:title]
        Severity: Minor
        Found in app/models/chart_data_values.rb - About 1 hr to fix

          Method as_chart_json has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.as_chart_json(output)
              [
                :title,
                :subtitle,
                :chart1_type,
          Severity: Minor
          Found in app/models/chart_data_values.rb - About 1 hr to fix

            Method teachers_chart_colour has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Wontfix

              def teachers_chart_colour(index)
                if @chart_type.match?(/_gas_/)
                  index.zero? ? Colours.chart_gas_dark : Colours.chart_gas_light
                elsif @chart_type.match?(/_storage_/)
                  index.zero? ? Colours.chart_storage_dark : Colours.chart_storage_light
            Severity: Minor
            Found in app/models/chart_data_values.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method benchmark_colour has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def benchmark_colour(data_type, category)
                # this has multiple fuel types
                if [:benchmark, :benchmark_one_year].include?(@chart_type)
                  return colours_for_multiple_fuel_type_benchmark(data_type, category)
                end
            Severity: Minor
            Found in app/models/chart_data_values.rb - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method translated_series_item_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def translated_series_item_for(series_key_as_string)
                series_key_as_string = series_key_as_string.to_s
                return I18n.t('analytics.series_data_manager.series_name.baseload') if series_key_as_string.casecmp('baseload').zero?
                return I18n.t('advice_pages.benchmarks.benchmark_school') if series_key_as_string == 'benchmark'
                return I18n.t('advice_pages.benchmarks.exemplar_school') if series_key_as_string == 'exemplar'
            Severity: Minor
            Found in app/models/chart_data_values.rb - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method colours_for_multiple_fuel_type_benchmark has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def colours_for_multiple_fuel_type_benchmark(data_type, category)
                case data_type
                when translated_series_item_for('Gas')
                  if benchmark_school_category?(category)
                    Colours.chart_gas_middle
            Severity: Minor
            Found in app/models/chart_data_values.rb - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Avoid too many return statements within this method.
            Open

                return series_key_as_string unless i18n_key
            Severity: Major
            Found in app/models/chart_data_values.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return translate_bill_component_series(series_key_as_string) if I18n.t('advice_pages.tables.labels.bill_components').keys.map(&:to_s).include?(series_key_as_string)
              Severity: Major
              Found in app/models/chart_data_values.rb - About 30 mins to fix

                Method series_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def series_data
                    return @series_data unless @series_data.is_a? Array
                
                    # Temporary TOFIX TODO as analytics should not return negative values
                    @series_data.map do |series|
                Severity: Minor
                Found in app/models/chart_data_values.rb - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method label_point_and_max_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def label_point_and_max_for(y2_data_title)
                    if y2_is_temperature?(y2_data_title)
                      ['°C', '{point.y:.2f} °C',]
                    elsif y2_is_degree_days?(y2_data_title)
                      [
                Severity: Minor
                Found in app/models/chart_data_values.rb - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                  def sort_out_dates_when_tidying_labels(current_label)
                    date_to_and_from = current_label.scan(/\d+|[A-Za-z]+/).drop(1).each_slice(4).to_a
                
                    if date_to_and_from.size > 1 && date_to_and_from[0][3] != date_to_and_from[1][3]
                      date_to_and_from[0].delete_at(0)
                Severity: Major
                Found in app/models/chart_data_values.rb and 1 other location - About 1 hr to fix
                app/helpers/application_helper.rb on lines 240..247

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 48.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status