BathHacked/energy-sparks

View on GitHub
app/assets/javascripts/analysis.js

Summary

Maintainability
D
2 days
Test Coverage

File analysis.js has 332 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

function updateDynamicTitles(titleWrapper, chartData) {
  var titleH3 = titleWrapper.find('h3');
  var titleH5 = titleWrapper.find('h5');
Severity: Minor
Found in app/assets/javascripts/analysis.js - About 4 hrs to fix

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

      Function processAnalysisChartAjax has 40 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

        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

          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

            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

              Function processAnalysisOperations has a Cognitive Complexity of 8 (exceeds 5 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 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

              Function processAnalysisOperations has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function processAnalysisOperations(chartConfig, chart, operations, drilldownAvailable, parentTimescaleDescription){
              Severity: Minor
              Found in app/assets/javascripts/analysis.js - About 35 mins to fix

                Function processAnnotations has a Cognitive Complexity of 7 (exceeds 5 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 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

                Function processAnalysisChartAjax has a Cognitive Complexity of 6 (exceeds 5 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 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

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

                  if (chartData.subtitle_start_date) {
                    var startDateElement = $(subTitleElement).find('.start-date');
                    startDateElement.text(chartData.subtitle_start_date);
                  }
                Severity: Minor
                Found in app/assets/javascripts/analysis.js and 1 other location - About 30 mins to fix
                app/assets/javascripts/analysis.js on lines 22..25

                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

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

                  if (chartData.subtitle_end_date) {
                    var endDateElement = $(subTitleElement).find('.end-date');
                    endDateElement.text(chartData.subtitle_end_date);
                  }
                Severity: Minor
                Found in app/assets/javascripts/analysis.js and 1 other location - About 30 mins to fix
                app/assets/javascripts/analysis.js on lines 18..21

                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

                There are no issues that match your filters.

                Category
                Status