BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

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

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

    def show
      area_id = params[:area_id]
      ordered_readings = @data_class.where(area_id: area_id).order(reading_date: :asc)

      @first_read = ordered_readings.first
Severity: Major
Found in app/controllers/data_feeds/generic_controller.rb and 1 other location - About 1 hr to fix
app/controllers/data_feeds/weather_observations_controller.rb on lines 9..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 68.

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 show
      weather_station_id = params[:weather_station_id]
      ordered_readings = @data_class.where(weather_station_id: weather_station_id).order(reading_date: :asc)

      @first_read = ordered_readings.first
app/controllers/data_feeds/generic_controller.rb on lines 9..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 68.

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 processAnalysisChartAjax has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function processAnalysisChartAjax(chartId, chartConfig, highchartsChart) {
  var chartType = chartConfig.type;
  var yAxisUnits = chartConfig.y_axis_units;
  var mpanMprn = chartConfig.mpan_mprn;
  var seriesBreakdown = chartConfig.series_breakdown;
Severity: Minor
Found in app/assets/javascripts/analysis.js - About 1 hr to fix

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

          def export
            service = CategoriseSchools.new(schools: @schools)
            CSV.generate(headers: true) do |csv|
              csv << headers
              service.categorise_schools.each do |fuel_type, advice_pages|
      Severity: Minor
      Found in app/services/school_groups/comparisons_csv_generator.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 processAnnotations has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function processAnnotations(loaded_annotations, chart){
        var xAxis = chart.xAxis[0];
        var xAxisCategories = xAxis.categories;
      
        var annotations = loaded_annotations.map(function(annotation){
      Severity: Minor
      Found in app/assets/javascripts/analysis.js - About 1 hr to fix

        Method csv_headers has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def csv_headers
                [
                  'School group',
                  'School name',
                  'School type',
        Severity: Minor
        Found in app/services/schools/funder_allocation_report_service.rb - About 1 hr to fix

          Method perform has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def perform
                transifex_load = TransifexLoad.create!(status: :running)
                begin
                  log('Synchronising Activity Types')
                  synchronise_resources(transifex_load, ActivityType.tx_resources)
          Severity: Minor
          Found in app/services/transifex/loader.rb - About 1 hr to fix

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

              class ResourceFilesController < AdminController
                load_and_authorize_resource
            
                def index
                  @resource_files = ResourceFile.order(:title)
            Severity: Major
            Found in app/controllers/admin/resource_files_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/admin/partners_controller.rb on lines 2..42

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

            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

              class PartnersController < AdminController
                load_and_authorize_resource
            
                def index
                  @partners = Partner.order(:position)
            Severity: Major
            Found in app/controllers/admin/partners_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/admin/resource_files_controller.rb on lines 2..42

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

            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

                $(".case-studies-download-links a").click(function() {
                  gtag('event', 'download-link', {
                    'event_label': 'Download',
                    'event_category': 'case-study',
                    'value': $(this).parents(".case-studies-download-links").data("event-value")
            Severity: Major
            Found in app/assets/javascripts/gtag.js and 1 other location - About 1 hr to fix
            app/assets/javascripts/gtag.js on lines 22..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 65.

            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

                $(".programme-type-download-links a").click(function() {
                  gtag('event', 'download-link', {
                    'event_label': 'Download',
                    'event_category': 'programme-type',
                    'value': $(this).parents(".programme-type-download-links").data("event-value")
            Severity: Major
            Found in app/assets/javascripts/gtag.js and 1 other location - About 1 hr to fix
            app/assets/javascripts/gtag.js on lines 38..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 65.

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

                def export
                  CSV.generate(headers: true) do |csv|
                    csv << headers
                    @scored_schools.with_points.schools_with_positions.each do |position, schools|
                      schools.each do |school|
            Severity: Minor
            Found in app/services/school_groups/current_scores_csv_generator.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 create_chart has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def create_chart(results, metric_to_translation_key, multiplier, y_axis_label,
                                 column_heading_keys: 'analytics.benchmarking.configuration.column_headings',
                                 y_axis_keys: 'chart_configuration.y_axis_label_name')
                  chart_data = {}
                  schools = []
            Severity: Minor
            Found in app/controllers/comparisons/base_controller.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 extract_readings has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def extract_readings(readings)
                  data = {}
                  readings.each do |reading|
                    datetime = DateTime.parse(reading['from'])
                    carbon = reading['intensity']['actual']
            Severity: Minor
            Found in lib/data_feeds/u_k_grid_carbon_intensity_feed.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 processAnalysisOperations has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function processAnalysisOperations(chartConfig, chart, operations, drilldownAvailable, parentTimescaleDescription){
              var chartContainer = $(chart.renderTo);
              var controls = $(chartContainer).parent().find('.analysis-controls');
              var anyOperations = false;
              if(controls.length){
            Severity: Minor
            Found in app/assets/javascripts/analysis.js - About 1 hr to fix

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

                def school_params
                  params.require(:school).permit(
                    :name,
                    :activation_date,
                    :school_type,
              Severity: Minor
              Found in app/controllers/schools_controller.rb - About 1 hr to fix

                Function chart has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const chart = ( function() {
                
                  var chartId = 'transport_surveys_pie';
                  var colors = ["#5cb85c", "#ff3a5b", "#fff9b2", "#ffac21", "#3bc0f0"];
                
                
                Severity: Minor
                Found in app/javascript/transport_surveys/charts.js - About 1 hr to fix

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

                    if(status === 'Accepted') {
                      accept.style.display = 'none';
                      reject.style.display = 'inline';
                      accept_msg.style.display = 'block';
                      reject_msg.style.display = 'none';
                  Severity: Major
                  Found in app/assets/javascripts/cookie_banner.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/cookie_banner.js on lines 80..85

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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language