uccser/cs-field-guide

View on GitHub
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js

Summary

Maintainability
F
3 days
Test Coverage

File data-visualisation.js has 370 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Chart from 'chart.js/auto';

const MIN = 0;      // Numbers for data
const MAX = 9;
const WAIT = 5000;  // Time (milliseconds) to show the chart

Function getFinalResults has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

function getFinalResults() {
  var localSolutions = dataVis.typesAndSolutions; // List of [[type, solution]]
  var localResponses = dataVis.userResponses;     // List of [response]
  var proportionGrid = [0, 0];                    // [correct, out-of]
  var proportionHeatmap = [0, 0];

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

function buildResultsChart() {
  var valueLabels = [CHART_TYPES.GRID, CHART_TYPES.MAP, CHART_TYPES.PIE, CHART_TYPES.BAR];
  var dataPoints = getFinalResults();
  var canvas = $('#data-vis-results-chart');
  if (dataVis.chartResults) {

Function buildPieChart has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function buildPieChart() {
  var valueLabels = [];
  var dataPoints = [];
  for (var i in dataVis.dataFrequencies) {
    if (dataVis.dataFrequencies[i]) {

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

function buildBarChart() {
  var valueLabels = [];
  var dataPoints = [];
  for (var i in dataVis.dataFrequencies) {
    valueLabels.push(i.toString());

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

function getFinalResults() {
  var localSolutions = dataVis.typesAndSolutions; // List of [[type, solution]]
  var localResponses = dataVis.userResponses;     // List of [response]
  var proportionGrid = [0, 0];                    // [correct, out-of]
  var proportionHeatmap = [0, 0];

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

function getFrequencies() {
  // Get the mode(s)
  // Based on parts of https://stackoverflow.com/questions/3783950/get-the-item-that-appears-the-most-times-in-an-array
  var modes = [];
  var frequencies = {};

Function getFrequencies has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

function getFrequencies() {
  // Get the mode(s)
  // Based on parts of https://stackoverflow.com/questions/3783950/get-the-item-that-appears-the-most-times-in-an-array
  var modes = [];
  var frequencies = {};

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

function buildGridChart() {
  var numValues = dataVis.currentDataSet.length;

  // We can afford to have fewer columns with a low number of values
  var numColumns = numValues > (65) ? (8) : (4);

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

Avoid deeply nested control flow statements.
Open

      if (localSolutions[i][1] == localResponses[i]) {
        proportionPie[0]++;
      }

Avoid deeply nested control flow statements.
Open

    } else if (localSolutions[i][0] == CHART_TYPES.BAR) {
      if (localSolutions[i][1] == localResponses[i]) {
        proportionBar[0]++;
      }
      proportionBar[1]++;

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

function showStartScreen() {
  $('#data-vis-guesser').addClass('d-none');
  $('#data-vis-next').addClass('d-none');
  $('#data-vis-restart').addClass('d-none');
  $('#data-vis-game').addClass('d-none');
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 478..487

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

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

function showPerformanceScreen() {
  $('#data-vis-guesser').addClass('d-none');
  $('#data-vis-restart').addClass('d-none');
  $('#data-vis-game').addClass('d-none');
  $('#data-vis-results-chart').addClass('d-none');
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 454..463

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

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

function showResultsScreen() {
  $('#data-vis-next').addClass('d-none');
  $('#data-vis-performance').addClass('d-none');

  $('#data-vis-restart').removeClass('d-none');
csfieldguide/static/interactives/city-trip/js/city-trip.js on lines 253..258

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

function showGuessScreen() {
  $('#data-vis-instructions').addClass('d-none');
  $('#data-vis-game').addClass('d-none');

  $('#data-vis-guesser').removeClass('d-none');
csfieldguide/static/interactives/cfg-parsing-challenge/js/cfg-parsing-challenge.js on lines 379..383
csfieldguide/static/interactives/cfg-parsing-challenge/js/cfg-parsing-challenge.js on lines 383..387

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

    } else if (localSolutions[i][0] == CHART_TYPES.MAP) {
      if (localSolutions[i][1] == localResponses[i]) {
        proportionHeatmap[0]++;
      }
      proportionHeatmap[1]++;
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 336..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 346..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 351..356

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

    } else if (localSolutions[i][0] == CHART_TYPES.PIE) {
      if (localSolutions[i][1] == localResponses[i]) {
        proportionPie[0]++;
      }
      proportionPie[1]++;
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 336..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 341..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 351..356

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

    } else if (localSolutions[i][0] == CHART_TYPES.BAR) {
      if (localSolutions[i][1] == localResponses[i]) {
        proportionBar[0]++;
      }
      proportionBar[1]++;
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 336..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 341..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 346..356

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

    if (localSolutions[i][0] == CHART_TYPES.GRID) {
      if (localSolutions[i][1] == localResponses[i]) {
        proportionGrid[0]++;
      }
      proportionGrid[1]++;
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 341..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 346..356
csfieldguide/static/interactives/data-visualisation/js/data-visualisation.js on lines 351..356

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