Gapminder/vizabi

View on GitHub
src/base/datastorage.js

Summary

Maintainability
F
5 days
Test Coverage

File datastorage.js has 621 lines of code (exceeds 250 allowed). Consider refactoring.
Open


import * as utils from "base/utils";
import Class from "base/class";

function _getQueryId(query, path, lastModified, readerName) {
Severity: Major
Found in src/base/datastorage.js - About 1 day to fix

    Function framesQueue has 118 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      framesQueue(framesArray, whatId) {
        const _context = this;
        return new function() {
          this.defaultCallbacks = [];
          this.callbacks = {};
    Severity: Major
    Found in src/base/datastorage.js - About 4 hrs to fix

      Function queryQueue has 118 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        queryQueue(readerObject, queryMergeId) {
          const _context = this;
          const _parsersCompare = function(readerParsers, queryParcers) {
            return Object.keys(queryParcers).filter(p => queryParcers[p] !== readerParsers[p]).length == 0 &&
            (Object.keys(readerParsers).length == 0 || Object.keys(queryParcers).length != 0);
      Severity: Major
      Found in src/base/datastorage.js - About 4 hrs to fix

        Function _getFrames has 96 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _getFrames(dataId, whatId, framesArray, keys, indicatorsDB) {
            const _this = this;
            if (!_this._collection[dataId]["frames"][whatId]) {
              _this._collection[dataId]["frames"][whatId] = {};
            }
        Severity: Major
        Found in src/base/datastorage.js - About 3 hrs to fix

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

                const buildFrame = function(frameName, keys, dataId, callback) {
                  const frame = {};
                  if (query.from !== "datapoints") {
                    // we populate the regular set with a single value (unpack properties into constant time series)
                    const dataset = _this._collection[dataId].data;
          Severity: Major
          Found in src/base/datastorage.js - About 2 hrs to fix

            Function reader has 61 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  this.reader = function(query, parsers, defer) {
                    const _queue = this;
                    // && !(_queue.readerObject.compatibility || {}).aggregateValues
                    const _query = query.grouping ? utils.clone(query, null, ["grouping"]) : query;
                    return new function() {
            Severity: Major
            Found in src/base/datastorage.js - About 2 hrs to fix

              Function aggregateData has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                aggregateData(dataId, query, readerObject, conceptProps) {
                  if (Object.keys(query.grouping).every(key => query.grouping[key]["grouping"] === 1)) {
                    return Promise.resolve(dataId);
                  }
              
              
              Severity: Major
              Found in src/base/datastorage.js - About 2 hrs to fix

                Function _getLimits has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                  _getLimits(dataId, attr) {
                
                    const items = this._collection[dataId].data;
                    // get only column attr and only rows with number or date
                    const filtered = items.reduce((filtered, d) => {
                Severity: Minor
                Found in src/base/datastorage.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 forceFrame has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      this.forceFrame = function(frameName, cb) {
                        const objIndexOf = function(obj, need) {
                          const search = need.toString();
                          let index = -1;
                          for (let i = 0, len = obj.length; i < len; i++) {
                Severity: Minor
                Found in src/base/datastorage.js - About 1 hr to fix

                  Function getData has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    getData(dataId, what, whatId, args) {
                      // if they want data, return the data
                      if (!what || what == "data") {
                        return this._collection[dataId]["data"];
                      }
                  Severity: Minor
                  Found in src/base/datastorage.js - About 1 hr to fix

                    Function _getLimits has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      _getLimits(dataId, attr) {
                    
                        const items = this._collection[dataId].data;
                        // get only column attr and only rows with number or date
                        const filtered = items.reduce((filtered, d) => {
                    Severity: Minor
                    Found in src/base/datastorage.js - About 1 hr to fix

                      Function aggregateData has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                        aggregateData(dataId, query, readerObject, conceptProps) {
                          if (Object.keys(query.grouping).every(key => query.grouping[key]["grouping"] === 1)) {
                            return Promise.resolve(dataId);
                          }
                      
                      
                      Severity: Minor
                      Found in src/base/datastorage.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

                      Avoid deeply nested control flow statements.
                      Open

                                      if (items && items.length > 0) {
                                        next = null;
                                        frame[column][key] = utils.interpolatePoint(items, use, column, next, TIME, frameName, method);
                                      }
                      Severity: Major
                      Found in src/base/datastorage.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                        if (items === null) {
                                          const givenFrames = Object.keys(nested[nestedKey]);
                                          items = new Array(givenFrames.length);
                                          itemsIndex = 0;
                        
                        
                        Severity: Major
                        Found in src/base/datastorage.js - About 45 mins to fix

                          Function getData has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                            getData(dataId, what, whatId, args) {
                              // if they want data, return the data
                              if (!what || what == "data") {
                                return this._collection[dataId]["data"];
                              }
                          Severity: Minor
                          Found in src/base/datastorage.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

                          Avoid too many return statements within this function.
                          Open

                              return this._collection[dataId][what][id];
                          Severity: Major
                          Found in src/base/datastorage.js - About 30 mins to fix

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

                                const filtered = items.reduce((filtered, d) => {
                            
                                  // check for dates
                                  const f = (utils.isDate(d[attr])) ? d[attr] : parseFloat(d[attr]);
                            
                            
                            Severity: Major
                            Found in src/base/datastorage.js and 1 other location - About 3 hrs to fix
                            src/models/hook.js on lines 592..604

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

                            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

                                      if (query.select.value.filter(x => reader.query.select.value.indexOf(x) == -1).length == 0 &&
                            Severity: Major
                            Found in src/base/datastorage.js and 1 other location - About 1 hr to fix
                            src/base/datastorage.js on lines 109..109

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

                            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

                                      if ((!query.select.value || query.select.value.filter(x => reader.query.select.value.indexOf(x) == -1).length == 0)
                            Severity: Major
                            Found in src/base/datastorage.js and 1 other location - About 1 hr to fix
                            src/base/datastorage.js on lines 75..75

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

                            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