"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _reduxRecord = _interopRequireDefault(require("./reduxRecord"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var QuizAnalysis =
/*#__PURE__*/
function (_ReduxRecord) {
  (0, _inherits2.default)(QuizAnalysis, _ReduxRecord);

  function QuizAnalysis() {
    (0, _classCallCheck2.default)(this, QuizAnalysis);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(QuizAnalysis).apply(this, arguments));
  }

  (0, _createClass2.default)(QuizAnalysis, [{
    key: "isLoaded",
    value: function isLoaded() {
      return this.quizId !== '0';
    }
  }, {
    key: "isPresent",
    value: function isPresent() {
      return !this.notFound;
    }
  }, {
    key: "scoreInfo",
    value: function scoreInfo() {
      return this.quizAnalysis.get('scoreInfo', {});
    }
  }, {
    key: "pointsPossible",
    value: function pointsPossible() {
      return this.scoreInfo().get('pointsPossible') || 0;
    }
  }, {
    key: "scoreCount",
    value: function scoreCount() {
      return this.scoreInfo().get('scoreCount') || 0;
    }
  }, {
    key: "formatRatio",
    value: function formatRatio(ratio) {
      return isFinite(ratio) ? _formatMessage.default.number(ratio, 'percent') : '--';
    }
  }, {
    key: "meanElapsedTime",
    value: function meanElapsedTime() {
      var scoreCount = this.scoreCount();
      if (scoreCount === 0) return 0;
      var elapsedTimeSum = this.scoreInfo().get('elapsedTimeSum') || 0;
      return Math.round(elapsedTimeSum / scoreCount);
    }
  }, {
    key: "meanScore",
    value: function meanScore() {
      var scoreSum = this.scoreInfo().get('scoreSum') || 0;
      return this.formatRatio(scoreSum / this.scoreCount() / this.pointsPossible());
    }
  }, {
    key: "highScore",
    value: function highScore() {
      var scoreMax = this.scoreInfo().get('scoreMax') || 0;
      return this.formatRatio(scoreMax / this.pointsPossible());
    }
  }, {
    key: "lowScore",
    value: function lowScore() {
      var scoreMin = this.scoreInfo().get('scoreMin') || 0;
      return this.formatRatio(scoreMin / this.pointsPossible());
    }
  }, {
    key: "standardDeviation",
    value: function standardDeviation() {
      var stdDeviation = this.scoreInfo().get('scoreStddevPop');
      return isFinite(stdDeviation) ? _formatMessage.default.number(stdDeviation) : null;
    }
  }, {
    key: "centileDistribution",
    value: function centileDistribution() {
      return this.quizAnalysis.get('centile').toArray();
    }
  }, {
    key: "decileDistribution",
    value: function decileDistribution() {
      return this.quizAnalysis.get('decile').toArray();
    }
  }, {
    key: "cronbachsAlpha",
    value: function cronbachsAlpha() {
      var alpha = this.quizAnalysis.get('cronbachsAlpha');
      return isFinite(alpha) ? _formatMessage.default.number(alpha) : null;
    }
  }]);
  return QuizAnalysis;
}((0, _reduxRecord.default)({
  quizId: '0',
  quizAnalysis: null,
  batchTimestamp: null,
  notFound: false
}));

exports.default = QuizAnalysis;