function text()

in correlations.js [461:564]


  function text(textElem, signature, channel, product, show_ci = false) {
    loadCorrelationData(signature, channel, product).then((data) => {
      textElem.textContent = "";

      if (!(product in data)) {
        textElem.textContent =
          "No correlation data was generated for the '" +
          product +
          "' product.";
        return;
      }

      if (
        !(signature in data[product][channel]["signatures"]) ||
        !data[product][channel]["signatures"][signature]["results"]
      ) {
        textElem.textContent =
          'No correlation data was generated for the signature "' +
          signature +
          '" on the ' +
          channel +
          " channel, for the '" +
          product +
          "' product.";
        return;
      }

      let correlationData =
        data[product][channel]["signatures"][signature]["results"];

      let total_reference = data[product][channel].total;
      let total_group = data[product][channel]["signatures"][signature].total;

      textElem.textContent = sortCorrelationData(
        correlationData,
        total_reference,
        total_group
      ).reduce((prev, cur) => {
        let support_group = toPercentage(cur.count_group / total_group);
        let support_reference = toPercentage(
          cur.count_reference / total_reference
        );
        let support_diff = toPercentage(
          Math.abs(
            cur.count_group / total_group -
              cur.count_reference / total_reference
          )
        );

        let ci = confidenceInterval(
          cur.count_group,
          total_group,
          cur.count_reference,
          total_reference
        );

        let support_diff_incertezza = toPercentage(
          Math.abs(
            Math.abs(ci[0]) -
              Math.abs(
                cur.count_group / total_group -
                  cur.count_reference / total_reference
              )
          )
        );

        let res =
          prev +
          "(" +
          support_group +
          "% in signature vs " +
          support_reference +
          "% overall, difference " +
          support_diff +
          "±" +
          support_diff_incertezza +
          "%) " +
          itemToLabel(cur.item);

        if (cur.prior) {
          let support_group_given_prior = toPercentage(
            cur.prior.count_group / cur.prior.total_group
          );
          let support_reference_given_prior = toPercentage(
            cur.prior.count_reference / cur.prior.total_reference
          );
          res +=
            " [" +
            support_group_given_prior +
            "% vs " +
            support_reference_given_prior +
            "% if " +
            itemToLabel(cur.prior.item) +
            "]";
        }

        return res + "\n";
      }, "");

      textElem.textContent +=
        "\n\nTop Words: " +
        data[product][channel]["signatures"][signature]["top_words"].join(", ");
    });
  }