def _get_visible_note_counts(
  scoredNotes: pd.DataFrame,
  lastNNotes: int = -1,
  countNMRNotesLast: bool = False,
  sinceLastEarnOut: bool = False,
):
  """
  Given scored notes from the algorithm, this function aggregates the note status by note author.

  Args:
      scoredNotes: Notes scored from MF + contributor stats
      lastNNotes: Only count the last n notes
      countNMRNotesLast: Count the NMR notes last. Only affects lastNNNotes counts.
      sinceLastEarnOut: Only count notes since the last time the contributor earned out
  Returns:
      pd.DataFrame: noteCounts The visible note counts
  """
  sort_by = [c.finalRatingStatusKey, c.noteIdKey] if countNMRNotesLast else c.noteIdKey
  key_function = _sort_nmr_status_last if countNMRNotesLast else None
  if not sinceLastEarnOut:
    aggNotes = scoredNotes
  else:
    aggNotes = scoredNotes.loc[
      scoredNotes[c.createdAtMillisKey] > scoredNotes[c.timestampOfLastEarnOut]
    ].copy()

  groupAuthorCounts = (
    aggNotes.sort_values(sort_by, ascending=False, key=key_function)
    .groupby(c.noteAuthorParticipantIdKey)
    .agg(
      {
        c.currentlyRatedHelpfulBoolKey: _sum_first_n(lastNNotes),
        c.currentlyRatedNotHelpfulBoolKey: _sum_first_n(lastNNotes),
        c.awaitingMoreRatingsBoolKey: _sum_first_n(lastNNotes),
        c.numRatingsKey: _sum_first_n(lastNNotes),
      }
    )
    if lastNNotes > 0
    else aggNotes.groupby(c.noteAuthorParticipantIdKey).sum(numeric_only=True)
  )
  authorCounts = pd.DataFrame(
    groupAuthorCounts[
      [
        c.currentlyRatedHelpfulBoolKey,
        c.currentlyRatedNotHelpfulBoolKey,
        c.awaitingMoreRatingsBoolKey,
        c.numRatingsKey,
      ]
    ]
  )
  authorCounts[c.notesCurrentlyRatedHelpful] = authorCounts[c.currentlyRatedHelpfulBoolKey]
  authorCounts[c.notesCurrentlyRatedNotHelpful] = authorCounts[c.currentlyRatedNotHelpfulBoolKey]
  authorCounts[c.notesAwaitingMoreRatings] = authorCounts[c.awaitingMoreRatingsBoolKey]
  authorCounts[c.aggregateRatingReceivedTotal] = authorCounts[c.numRatingsKey]
  authorCounts.fillna(
    inplace=True,
    value={
      c.notesCurrentlyRatedHelpful: 0,
      c.notesCurrentlyRatedNotHelpful: 0,
      c.notesAwaitingMoreRatings: 0,
    },
  )
  return authorCounts

  Given scored notes from the algorithm, this function aggregates the note status by note author.

  Args:
      scoredNotes: Notes scored from MF + contributor stats
      lastNNotes: Only count the last n notes
      countNMRNotesLast: Count the NMR notes last. Only affects lastNNNotes counts.
      sinceLastEarnOut: Only count notes since the last time the contributor earned out
  Returns:
      pd.DataFrame: noteCounts The visible note counts
  
sourcecode/scoring/contributor_state.py