def _prepare_peer_ratings(
    self, ratings: pd.DataFrame, notes: pd.DataFrame, scoredNotes: pd.DataFrame
  ) -> pd.DataFrame:
    """Construct a ratings DF that captures ratings on peer notes.

    Peer notes are defined as different notes that are on the same post.  We consider the
    ratings for the peer note to provide signal for the note being scored (e.g. if another
    note received many "note not needed" ratings, then it is more likely that the post
    itself does not need a note).

    Since each unique {note, peer} pair is a row in the output dataframe, the column name
    for the note being scored remains "noteId" and the note which originally received the
    rating is the "ratedOnNoteId".

    Args:
      ratings: pd.DataFrame containing all ratings used in scoring
      notes: pd.DataFrame relating notes to posts
      scoredNotes: pd.DataFrame specifying which notes are actually being scored
    """
    # Augment ratings with tweetId and classification
    beforeMerge = len(ratings)
    ratings = ratings.merge(notes[[c.noteIdKey, c.tweetIdKey, c.classificationKey]])
    assert len(ratings) == beforeMerge
    ratings = ratings.rename(columns={c.noteIdKey: _RATED_ON_NOTE_ID})
    # Create one copy of each rating for each scored note on the post, excluding
    # ratings that occur on that post itself
    assert len(scoredNotes) == len(scoredNotes[[c.noteIdKey, c.tweetIdKey]].drop_duplicates())
    ratings = ratings.merge(scoredNotes[[c.noteIdKey, c.tweetIdKey]], on=c.tweetIdKey)
    ratings = ratings[
      ratings[c.noteIdKey] != ratings[_RATED_ON_NOTE_ID]
    ]  # throw out ratings that occur on the note itself
    ratings = ratings.drop(columns={c.tweetIdKey})
    return ratings
Construct a ratings DF that captures ratings on peer notes.

    Peer notes are defined as different notes that are on the same post.  We consider the
    ratings for the peer note to provide signal for the note being scored (e.g. if another
    note received many "note not needed" ratings, then it is more likely that the post
    itself does not need a note).

    Since each unique {note, peer} pair is a row in the output dataframe, the column name
    for the note being scored remains "noteId" and the note which originally received the
    rating is the "ratedOnNoteId".

    Args:
      ratings: pd.DataFrame containing all ratings used in scoring
      notes: pd.DataFrame relating notes to posts
      scoredNotes: pd.DataFrame specifying which notes are actually being scored
    
sourcecode/scoring/pflip_plus_model.py