function getComparison()

in compare-betas.js [78:196]


function getComparison() {
  if (!getOption("beta1") || !getOption("beta2")) {
    return;
  }

  let version1 = getOption("beta1");
  let version2 = getOption("beta2");
  let build_id1 = "";
  let build_id2 = "";
  if (version1.includes(" - ")) {
    let vals = version1.split(" - ");
    version1 = vals[0];
    build_id1 = vals[1];
  }
  if (version2.includes(" - ")) {
    let vals = version2.split(" - ");
    version2 = vals[0];
    build_id2 = vals[1];
  }

  fetch(
    "https://product-details.mozilla.org/1.0/firefox_history_development_releases.json"
  )
    .then((response) => response.json())
    .then((release_history) => {
      let date1 = dateToStr(
        getReleaseDate(version1, build_id1, release_history)
      );
      let date2 = dateToStr(
        getReleaseDate(version2, build_id2, release_history)
      );

      let url = new URL(location.href);
      url.search =
        "?product=" +
        getOption("product") +
        "&beta1=" +
        getOption("beta1") +
        "&beta2=" +
        getOption("beta2");
      history.replaceState({}, document.title, url.href);

      let signatureNumberElem = document.getElementById("signatureNumber");
      let signatureNumber = Number(signatureNumberElem.value);
      if (!signatureNumber || isNaN(signatureNumber)) {
        signatureNumber = 20;
      }

      document.getElementById("frame").src =
        "scomp.html?limit=" +
        signatureNumber +
        "&common=product%3D" +
        getOption("product") +
        "&p1=version%3D" +
        version1 +
        (build_id1 ? "%26build_id=" + build_id1 : "") +
        "%26date%3D%3E" +
        date1 +
        "&p2=version%3D" +
        version2 +
        (build_id2 ? "%26build_id=" + build_id2 : "") +
        "%26date%3D%3E" +
        date2;

      let total1, total2;
      Promise.all([
        fetch(
          "https://crash-stats.mozilla.org/api/SuperSearch/?product=" +
            getOption("product") +
            "&version=" +
            version1 +
            (build_id1 ? "&build_id=" + build_id1 : "") +
            "&_results_number=0&_facets_size=0" +
            "&date=>%3D" +
            date1
        )
          .then((response) => response.json())
          .then((results) => (total1 = results["total"] || 0)),
        fetch(
          "https://crash-stats.mozilla.org/api/SuperSearch/?product=" +
            getOption("product") +
            "&version=" +
            version2 +
            (build_id2 ? "&build_id=" + build_id2 : "") +
            "&_results_number=0&_facets_size=0" +
            "&date=>%3D" +
            date2
        )
          .then((response) => response.json())
          .then((results) => (total2 = results["total"] || 0)),
      ]).then(() => {
        let warning = "";
        if (total1 < total2 * 0.2) {
          warning =
            "WARNING: Number of crash reports for " +
            getOption("beta1") +
            " (" +
            total1 +
            ") are way lower than for " +
            getOption("beta2") +
            " (" +
            total2 +
            "); the comparison might be skewed.";
        } else if (total2 < total1 * 0.2) {
          warning =
            "WARNING: Number of crash reports for " +
            getOption("beta2") +
            " (" +
            total2 +
            ") are way lower than for " +
            getOption("beta1") +
            " (" +
            total1 +
            "); the comparison might be skewed.";
        }
        document.getElementById("warning").textContent = warning;
      });
    });
}