BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

Method group_by_half_hour has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def group_by_half_hour(school_data_array)
    by_half_hour = Hash.new do |h1, day_type|
      h1[day_type] = Hash.new do |h2, month|
        h2[month] = Hash.new do |h3, half_hour|
          h3[half_hour] = []
Severity: Minor
Found in app/services/calculate_average_school.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

Function setupAnalysisControls has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function setupAnalysisControls(chartContainer, chartConfig){
  var controls = $(chartContainer).parent().find('.analysis-controls');
  if(controls.length){
    controls.find('.move_back').on('click', function(event){
      event.preventDefault();
Severity: Minor
Found in app/assets/javascripts/analysis.js - About 1 hr to fix

    Method for_schools has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.for_schools(schools)
        query = <<-SQL.squish
          SELECT a.school_id, a.id, cv.alert_type_rating_id, vars.average_one_year_saving_£, vars.one_year_saving_co2, vars.one_year_saving_kwh
          FROM management_priorities mp
          INNER JOIN alert_type_rating_content_versions cv ON mp.alert_type_rating_content_version_id = cv.id
    Severity: Minor
    Found in app/models/management_priority.rb - About 1 hr to fix

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

            def create
              @school_group.meter_attributes.create!(
                attribute_type: params[:attribute][:type],
                reason: params[:attribute][:reason],
                input_data: params[:attribute][:root],
      app/controllers/admin/schools/school_attributes_controller.rb on lines 18..29

      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 49.

      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

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

            def create
              @school.meter_attributes.create!(
                attribute_type: params[:attribute][:type],
                reason: params[:attribute][:reason],
                input_data: params[:attribute][:root],
      app/controllers/admin/school_groups/meter_attributes_controller.rb on lines 16..27

      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 49.

      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

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

        def school_data_source_report
          to, data_source_id = params.values_at(:to, :data_source_id)
          @data_source = DataSource.find(data_source_id)
          title = "#{t('common.application')}-#{@data_source.name}-meters-#{Time.zone.now.iso8601}".parameterize
          attachments[(title + '.csv')] = { mime_type: 'text/csv', content: @data_source.to_csv }
      Severity: Major
      Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
      app/mailers/admin_mailer.rb on lines 14..20

      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 49.

      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

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

        def school_procurement_route_report
          to, procurement_route_id = params.values_at(:to, :procurement_route_id)
          @procurement_route = ProcurementRoute.find(procurement_route_id)
          title = "#{t('common.application')}-#{@procurement_route.organisation_name}-meters-#{Time.zone.now.iso8601}".parameterize
          attachments[(title + '.csv')] = { mime_type: 'text/csv', content: @procurement_route.to_csv }
      Severity: Major
      Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
      app/mailers/admin_mailer.rb on lines 5..11

      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 49.

      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

      Method school_params has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def school_params
            params.require(:school).permit(
              :indicated_has_solar_panels,
              :indicated_has_storage_heaters,
              :has_swimming_pool,
      Severity: Minor
      Found in app/controllers/schools/your_school_estates_controller.rb - About 1 hr to fix

        Method resource_data has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def resource_data(name, slug, project_id, categories, priority)
              {
                "data": {
                  "attributes": {
                    "accept_translations": true,
        Severity: Minor
        Found in lib/transifex/client.rb - About 1 hr to fix

          Function initChart has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function initChart(chartDiv) {
          
              var supply = $(chartDiv).find("input[name='supply']").val();
              var period = $(chartDiv).find("input[name='period']").val();
          
          
          Severity: Minor
          Found in app/assets/javascripts/usage_charts.js - About 1 hr to fix

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

              module System
                class MissingElectricityData
                  def self.front_end_template_variables
                    {}
                  end
            Severity: Major
            Found in app/services/alerts/system/missing_electricity_data.rb and 1 other location - About 1 hr to fix
            app/services/alerts/system/missing_gas_data.rb on lines 2..28

            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

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

              module System
                class MissingGasData
                  def self.front_end_template_variables
                    {}
                  end
            Severity: Major
            Found in app/services/alerts/system/missing_gas_data.rb and 1 other location - About 1 hr to fix
            app/services/alerts/system/missing_electricity_data.rb on lines 2..28

            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

            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

            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/helpers/application_helper.rb and 1 other location - About 1 hr to fix
            app/models/chart_data_values.rb on lines 468..475

            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

            Method with_neighbour_updates has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def with_neighbour_updates(calendar_event, attributes)
                managing_state(calendar_event) do |pre_save, post_save|
                  calendar_event.attributes = attributes
                  reset_parent(calendar_event)
                  if calendar_event.calendar_event_type.term_time || calendar_event.calendar_event_type.holiday
            Severity: Minor
            Found in app/services/holiday_factory.rb - About 55 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 check_operations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def check_operations(chart_config)
                allowed_operations = {}
                OPERATIONS.each do |operation_type|
                  manipulator = ChartManagerTimescaleManipulation.factory(operation_type, chart_config, @aggregated_school)
                  allowed_operations[operation_type] = if manipulator.chart_suitable_for_timescale_manipulation?
            Severity: Minor
            Found in app/models/chart_data.rb - About 55 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 country has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def country
                  scotland_postcodes = %w[AB DD DG EH FK G HS IV KA KW KY ML PA PH TD ZE]
                  wales_postcodes    = %w[CF CH GL HR LD LL NP SA SY]
                  postcode_prefix = @school.postcode.upcase[/^[[:alpha:]]+/]
            
            
            Severity: Minor
            Found in app/services/schools/country_lookup.rb - About 55 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 export has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def export
                  CSV.generate(headers: true) do |csv|
                    csv << headers
                    @total_savings.each do |alert_type_rating, _savings| # rubocop:disable Style/HashEachMethods - not a hash
                      next unless @alert_type_rating_ids.map(&:to_i).include?(alert_type_rating.id)
            Severity: Minor
            Found in app/services/school_groups/schools_priority_action_csv_generator.rb - About 55 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

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

                  missing_array = (first_reading.reading_date.to_date..Time.zone.today).collect do |day|
                    if ! reading_summary.key?(day)
                      [day, 'No readings']
                    elsif reading_summary.key?(day) && reading_summary[day] < 48
                      [day, 'Partial readings']
            Severity: Minor
            Found in app/controllers/data_feeds/generic_controller.rb and 1 other location - About 55 mins to fix
            app/controllers/data_feeds_controller.rb on lines 37..44

            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 45.

            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

            Method process_area has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def process_area(area)
                  gsp_area_id = gsp_area_id(area)
                  solar_pv_data, _missing_date_times, _whole_day_substitutes = @solar_pv_tuos_interface.historic_solar_pv_data(
                    gsp_area_id,
                    area.latitude,
            Severity: Minor
            Found in lib/data_feeds/solar_pv_tuos_loader.rb - About 55 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

            Severity
            Category
            Status
            Source
            Language