def score_notes(
    self, noteStats: pd.DataFrame, currentLabels: pd.DataFrame, statusColumn: str
  ) -> Tuple[pd.DataFrame, pd.DataFrame]:
    """Returns notes on track for CRH with high levels of any tag to receive NMR status."""
    # Prune noteStats to exclude CRNH notes.  CRNH will have stronger downstream effects, so
    # we don't want to over-write that status.
    candidateNotes = currentLabels[currentLabels[statusColumn] != c.currentlyRatedNotHelpful][
      [c.noteIdKey]
    ]
    noteStats = noteStats.merge(candidateNotes, on=c.noteIdKey, how="inner")
    logger.info(f"Candidate notes prior to tag filtering: {len(noteStats)}")

    # Identify impacted notes.
    impactedNotes = pd.DataFrame.from_dict(
      {
        c.noteIdKey: pd.Series([], dtype=np.int64),
        c.activeFilterTagsKey: pd.Series([], dtype=object),
      }
    )
    logger.info("Checking note tags:")
    for tag in c.notHelpfulTagsTSVOrder:
      adjustedColumn = f"{tag}{c.adjustedSuffix}"
      adjustedRatioColumn = f"{adjustedColumn}{c.ratioSuffix}"
      logger.info(tag)
      if tag == c.notHelpfulHardToUnderstandKey:
        logger.info(f"outlier filtering disabled for tag: {tag}")
        continue
      tagFilteredNotes = noteStats[
        # Adjusted total must pass minimum threhsold set across all tags.
        (noteStats[adjustedColumn] > self._minAdjustedTotal)
        # Adjusted ratio must exceed percentile based total for this specific tag.
        & (noteStats[adjustedRatioColumn] > self._tagFilterThresholds[adjustedRatioColumn])
      ][c.noteIdKey]
      impactedNotes = pd.concat(
        [impactedNotes, pd.DataFrame({c.noteIdKey: tagFilteredNotes, c.activeFilterTagsKey: tag})],
        unsafeAllowed=[c.defaultIndexKey, c.activeFilterTagsKey],
      )
    # log and consolidate imapcted notes
    logger.info(f"Total {{note, tag}} pairs where tag filter logic triggered: {len(impactedNotes)}")
    impactedNotes = impactedNotes.groupby(c.noteIdKey).aggregate(list).reset_index()
    impactedNotes[c.activeFilterTagsKey] = [
      ",".join(tags) for tags in impactedNotes[c.activeFilterTagsKey]
    ]
    logger.info(f"Total unique notes impacted by tag filtering: {len(impactedNotes)}")
    noteStatusUpdates = impactedNotes[[c.noteIdKey]].drop_duplicates()
    noteStatusUpdates[statusColumn] = self._status
    return (noteStatusUpdates, impactedNotes)
Returns notes on track for CRH with high levels of any tag to receive NMR status.
sourcecode/scoring/scoring_rules.py