BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

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

    all_defaults = [
      { meter_type: :electricity, avg: 'equivalence_1.measure_html', title: 'equivalence_1.equivalence', img: 'kettle' },
      { meter_type: :electricity, avg: 'equivalence_2.measure_html', title: 'equivalence_2.equivalence', img: 'onshore_wind_turbine' },
      { meter_type: :gas, avg: 'equivalence_3.measure_html', title: 'equivalence_3.equivalence', img: 'tree' },
      { meter_type: :gas, avg: 'equivalence_4.measure_html', title: 'equivalence_4.equivalence', img: 'meal' },
Severity: Major
Found in app/components/dashboard_equivalences_component.rb and 1 other location - About 2 hrs to fix
app/controllers/pupils/public_displays_controller.rb on lines 137..152

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

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

      all_defaults = [
        { meter_type: :electricity, avg: 'equivalence_1.measure_html', title: 'equivalence_1.equivalence', img: 'kettle' },
        { meter_type: :electricity, avg: 'equivalence_2.measure_html', title: 'equivalence_2.equivalence', img: 'onshore_wind_turbine' },
        { meter_type: :gas, avg: 'equivalence_3.measure_html', title: 'equivalence_3.equivalence', img: 'tree' },
        { meter_type: :gas, avg: 'equivalence_4.measure_html', title: 'equivalence_4.equivalence', img: 'meal' },
Severity: Major
Found in app/controllers/pupils/public_displays_controller.rb and 1 other location - About 2 hrs to fix
app/components/dashboard_equivalences_component.rb on lines 109..124

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

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

Function chartSuccess has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function chartSuccess(chartConfig, chartData, chart) {

  var $chartDiv = $(chart.renderTo);
  var chartType = chartData.chart1_type;
  var seriesData = chartData.series_data;
Severity: Major
Found in app/assets/javascripts/analysis.js - About 2 hrs to fix

    Function fireRequestForJson has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function fireRequestForJson(mapDiv) {
    
      var dataUrl = '/map.json';
      var schoolGroupId = mapDiv.data('schoolGroupId');
    
    
    Severity: Major
    Found in app/assets/javascripts/map.js - About 2 hrs to fix

      Method value_for has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def value_for(recent_usage, formatted: true)
          return nil unless recent_usage
          case params['metric']
          when 'usage' then formatted ? recent_usage.usage : recent_usage.usage_text
          when 'co2' then formatted ? recent_usage.co2 : recent_usage.co2_text
      Severity: Minor
      Found in app/helpers/school_groups_helper.rb - About 2 hrs 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

      Class SummaryTableData has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class SummaryTableData
          def initialize(template_data)
            @template_data = template_data
          end
      
      
      Severity: Minor
      Found in app/classes/tables/summary_table_data.rb - About 2 hrs to fix

        Method report has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def report
              report = {}
              fuel_type_report = {
                enough_data: false,
                recent_data: 'N/A',
        Severity: Minor
        Found in app/services/targets/school_group_targets_testing_service.rb - About 2 hrs 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 chartSuccess has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        function chartSuccess(chartConfig, chartData, chart) {
        
          var $chartDiv = $(chart.renderTo);
          var chartType = chartData.chart1_type;
          var seriesData = chartData.series_data;
        Severity: Minor
        Found in app/assets/javascripts/analysis.js - About 2 hrs 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 convert_to_date_to_x48_yield_hash has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def convert_to_date_to_x48_yield_hash(start_date, end_date, datetime_to_yield_hash)
              date_to_halfhour_yields_x48 = {}
              missing_date_times = []
              too_little_data_on_day = []
              interpolator = setup_interpolation(datetime_to_yield_hash)
        Severity: Minor
        Found in lib/data_feeds/pv_live_service.rb - About 2 hrs 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 csv has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def csv
              CSV.generate(headers: true) do |csv|
                csv << self.class.csv_headers
        
                school_ids = School.active.pluck(:id) + School.archived.pluck(:id)
        Severity: Major
        Found in app/services/schools/funder_allocation_report_service.rb - About 2 hrs to fix

          Method report has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def report
                report = {}
                fuel_type_report = {
                  enough_data: false,
                  recent_data: 'N/A',
          Severity: Major
          Found in app/services/targets/school_group_targets_testing_service.rb - About 2 hrs to fix

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

                $(".activity-type-download-links a").click(function() {
                  gtag('event', 'download-link', {
                    'event_label': $(this).text(),
                    'event_category': 'activity-type',
                    'value': $(this).parents(".activity-type-download-links").data("event-value")
            Severity: Major
            Found in app/assets/javascripts/gtag.js and 2 other locations - About 2 hrs to fix
            app/assets/javascripts/gtag.js on lines 14..20
            app/assets/javascripts/gtag.js on lines 30..36

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

            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 3 locations. Consider refactoring.
            Open

                $(".resource-download-links a").click(function() {
                  gtag('event', 'download-link', {
                    'event_label': $(this).text(),
                    'event_category': 'resource',
                    'value': $(this).parents(".resource-download-links").data("event-value")
            Severity: Major
            Found in app/assets/javascripts/gtag.js and 2 other locations - About 2 hrs to fix
            app/assets/javascripts/gtag.js on lines 6..12
            app/assets/javascripts/gtag.js 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 76.

            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 3 locations. Consider refactoring.
            Open

                $(".intervention-type-download-links a").click(function() {
                  gtag('event', 'download-link', {
                    'event_label': $(this).text(),
                    'event_category': 'intervention-type',
                    'value': $(this).parents(".intervention-type-download-links").data("event-value")
            Severity: Major
            Found in app/assets/javascripts/gtag.js and 2 other locations - About 2 hrs to fix
            app/assets/javascripts/gtag.js on lines 6..12
            app/assets/javascripts/gtag.js on lines 30..36

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

            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

            Function carbon has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const carbon = ( function() {
            
              var local = {
                neutral: '',
                equivalences: '',
            Severity: Minor
            Found in app/javascript/transport_surveys/carbon.js - About 1 hr 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 remove_users! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                def remove_users!
                  raise SchoolRemover::Error.new('Cannot remove users while school is still visible') if @school.visible?
              
                  @school.transaction do
                    @school.users.each do |user|
              Severity: Minor
              Found in app/services/school_remover.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

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

                module AlertTypes
                  class InterventionTypesController < AdminController
                    def show
                      @alert_type = AlertType.find(params[:alert_type_id])
                      @rating = @alert_type.ratings.find(params[:rating_id])
              app/controllers/admin/alert_types/activity_types_controller.rb on lines 2..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 72.

              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 AlertTypes
                  class ActivityTypesController < AdminController
                    def show
                      @alert_type = AlertType.find(params[:alert_type_id])
                      @rating = @alert_type.ratings.find(params[:rating_id])
              app/controllers/admin/alert_types/intervention_types_controller.rb on lines 2..22

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

              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 based_on_energy_use has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def based_on_energy_use(limit = NUMBER_OF_SUGGESTIONS)
                    alerts = alerts_by_fuel_type
                    fuel_types = alerts.keys
              
                    suggestions = []
              Severity: Minor
              Found in app/services/recommendations/base.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

              Severity
              Category
              Status
              Source
              Language