"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.sortValues = exports.getUptimeScore = exports.getLatency = exports.getHealthPercentageScore = void 0;
var sortValues = ["none", "asc", "desc"];
exports.sortValues = sortValues;

var getHealthPercentageScore = function getHealthPercentageScore(check) {
  if (check != null) {
    if (check.checkStatuses && check.checkStatuses.length > 0) {
      var positives = 0;
      check.checkStatuses.forEach(function (statusObj) {
        if (statusObj.status) {
          positives += 1;
        }
      });
      return positives / check.checkStatuses.length;
    }

    return -1;
  }

  return -1;
};

exports.getHealthPercentageScore = getHealthPercentageScore;

var getUptimeScore = function getUptimeScore(check) {
  if (check != null) {
    var uptime = check.uptime;
    var score = uptime.passed / (uptime.passed + uptime.failed);

    if (Number.isNaN(score)) {
      return 0;
    }

    return score;
  }

  return -1;
};

exports.getUptimeScore = getUptimeScore;

var getLatency = function getLatency(check) {
  if (check != null) {
    var latency = check.latency;

    if (latency && latency.p95) {
      return latency.p95;
    }

    return Number.POSITIVE_INFINITY;
  }

  return Number.POSITIVE_INFINITY;
};

exports.getLatency = getLatency;