All files / engine/Source/Scene I3SStatistics.js

100% Statements 27/27
100% Branches 8/8
100% Functions 6/6
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95                          7x   7x 7x 7x     1x                 1x                       1x                       2x 2x 2x 1x 2x     2x                   1x 7x 7x           1x 4x 4x 3x 5x 5x 2x 1x   1x              
import defined from "../Core/defined.js";
import I3SDataProvider from "./I3SDataProvider.js";
import Resource from "../Core/Resource.js";
 
/**
 * This class implements an I3S statistics for Building Scene Layer.
 * <p>
 * Do not construct this directly, instead access statistics through {@link I3SDataProvider}.
 * </p>
 * @alias I3SStatistics
 * @internalConstructor
 */
function I3SStatistics(dataProvider, uri) {
  this._dataProvider = dataProvider;
 
  this._resource = new Resource({ url: uri });
  this._resource.setQueryParameters(dataProvider.resource.queryParameters);
  this._resource.appendForwardSlash();
}
 
Object.defineProperties(I3SStatistics.prototype, {
  /**
   * Gets the resource for the statistics
   * @memberof I3SStatistics.prototype
   * @type {Resource}
   * @readonly
   */
  resource: {
    get: function () {
      return this._resource;
    },
  },
 
  /**
   * Gets the I3S data for this object.
   * @memberof I3SStatistics.prototype
   * @type {object}
   * @readonly
   */
  data: {
    get: function () {
      return this._data;
    },
  },
 
  /**
   * Gets the collection of attribute names.
   * @memberof I3SStatistics.prototype
   * @type {string[]}
   * @readonly
   */
  names: {
    get: function () {
      const names = [];
      const summary = this._data.summary;
      if (defined(summary)) {
        for (let i = 0; i < summary.length; ++i) {
          names.push(summary[i].fieldName);
        }
      }
      return names;
    },
  },
});
 
/**
 * Loads the content.
 * @returns {Promise<object>} A promise that is resolved when the data of the I3S statistics is loaded
 * @private
 */
I3SStatistics.prototype.load = async function () {
  this._data = await I3SDataProvider.loadJson(this._resource);
  return this._data;
};
 
/**
 * @private
 */
I3SStatistics.prototype._getValues = function (attributeName) {
  const summary = this._data.summary;
  if (defined(summary)) {
    for (let i = 0; i < summary.length; ++i) {
      const attribute = summary[i];
      if (attribute.fieldName === attributeName) {
        if (defined(attribute.mostFrequentValues)) {
          return [...attribute.mostFrequentValues];
        }
        return [];
      }
    }
  }
};
 
export default I3SStatistics;