'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _reduxRecord = require('./reduxRecord');

var _reduxRecord2 = _interopRequireDefault(_reduxRecord);

var _formatMessage = require('../format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var QuizAnalysis = function (_ReduxRecord) {
  (0, _inherits3.default)(QuizAnalysis, _ReduxRecord);

  function QuizAnalysis() {
    (0, _classCallCheck3.default)(this, QuizAnalysis);
    return (0, _possibleConstructorReturn3.default)(this, (QuizAnalysis.__proto__ || Object.getPrototypeOf(QuizAnalysis)).apply(this, arguments));
  }

  (0, _createClass3.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) ? _formatMessage2.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) ? _formatMessage2.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) ? _formatMessage2.default.number(alpha) : null;
    }
  }]);
  return QuizAnalysis;
}((0, _reduxRecord2.default)({
  quizId: '0',
  quizAnalysis: null,
  batchTimestamp: null,
  notFound: false
}));

exports.default = QuizAnalysis;