publiclab/spectral-workbench

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

Summary

Maintainability
D
2 days
Test Coverage

File analyze.js has 283 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//= require graph.js
var ajax_load = "<img src='/images/spinner-small.gif' alt='loading...' />";
spectrum = "";
var legends;
$W = {
Severity: Minor
Found in app/assets/javascripts/analyze.js - About 2 hrs to fix

    Function initialize has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      initialize: function(args) {
        this.spectrum_id = args['spectrum_id']
        this.sample_row = args['sample_row']
        this.calibrated = args['calibrated']
        this.form_authenticity_token = args['form_authenticity_token']
    Severity: Major
    Found in app/assets/javascripts/analyze.js - About 2 hrs to fix

      Function updateLegend has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        updateLegend: function() {
          $W.updateLegendTimeout = null;
      
          var pos = $W.latestPosition;
      
      
      Severity: Minor
      Found in app/assets/javascripts/analyze.js - 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 alert_overexposure has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        alert_overexposure: function() {
          var oe = $W.detect_overexposure()
          if (oe['r'] || oe['g'] || oe['b']) {
            var msg = "Light source is too strong or camera is too sensitive; overexposure in channels: "
            var channels = []
      Severity: Minor
      Found in app/assets/javascripts/analyze.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

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

        notify: function(msg,type,expire) {
          if (expire == null) expire = true
          var id = parseInt(Math.random()*100000)
          $('#alerts').html($('#alerts').html()+"<div id='notify_"+id+"' class='notify'></div>")
          if (type == "warning") $('#notify_'+id).html("<b>Warning:</b> "+msg).addClass('alert warning')
      Severity: Major
      Found in app/assets/javascripts/analyze.js and 1 other location - About 1 day to fix
      app/assets/javascripts/capture.js on lines 727..738

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

      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 (!(e.offsetX || e.offsetY)) {
          offX = e.pageX - $(e.target).offset().left;
          offY = e.pageY - $(e.target).offset().top;
            } else {
          offX = e.offsetX;
      Severity: Major
      Found in app/assets/javascripts/analyze.js and 1 other location - About 4 hrs to fix
      app/assets/javascripts/capture.js on lines 497..503

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

      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

          f.action = "/spectra/calibrate/"+$W.spectrum_id+"?x1="+x1+"&w1="+w1+"&x2="+x2+"&w2="+w2
      Severity: Minor
      Found in app/assets/javascripts/analyze.js and 1 other location - About 50 mins to fix
      app/assets/javascripts/api.js on lines 29..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 51.

      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