function rerank()

in correlations.js [357:414]


  function rerank(textElem, signature, channel, channel_target, product) {
    textElem.textContent = "";

    return loadChannelsDifferencesData(product)
      .then(() => loadCorrelationData(signature, channel, product))
      .then((data) => {
        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;

        return correlationData
          .filter((socorroElem) => Object.keys(socorroElem.item).length == 1)
          .filter(
            (socorroElem) =>
              getChannelPercentage(channel, socorroElem.item) != 0
          )
          .sort((a, b) => {
            //return getChannelPercentage(channel_target, b.item) / getChannelPercentage(channel, b.item) - getChannelPercentage(channel_target, a.item) / getChannelPercentage(channel, a.item);
            return b.count_group / total_group - a.count_group / total_group;
          })
          .map((elem) => {
            return {
              property: itemToLabel(elem.item),
              in_signature: toPercentage(elem.count_group / total_group),
              in_channel_target: getChannelPercentage(
                channel_target,
                elem.item
              ),
              in_channel: getChannelPercentage(channel, elem.item),
            };
          });
      });
  }