Skip to content

Instantly share code, notes, and snippets.

@hadinh1306
Created August 6, 2023 22:03
Show Gist options
  • Select an option

  • Save hadinh1306/018a3938401b2aca62b81589f92227e2 to your computer and use it in GitHub Desktop.

Select an option

Save hadinh1306/018a3938401b2aca62b81589f92227e2 to your computer and use it in GitHub Desktop.
import pandas as pd
MEANINGFUL_COLLABORATION_DAYS = 15
def _rank_collaborators(df, keep_meaningful_collaborations=True):
df_copy = df.copy()
if keep_meaningful_collaborations:
meaningful_collaborations_mask = df_copy["collaboration_days"] >= MEANINGFUL_COLLABORATION_DAYS
df_copy = df_copy.loc[meaningful_collaborations_mask]
# Rank collaborator higher if they have more collaboration days
df_copy.loc[:, "reviewer_ranking"] = df_copy.groupby("employee")["collaboration_days"].rank(ascending=False)
# Rank employee higher if they have more collaboration days with reviewers
df_copy.loc[:, "reviewe_ranking"] = df_copy.groupby("collaborator_employee")["collaboration_days"].rank(ascending=False)
# Rank reviewer-reviewee pairs higher if they rank higher in each other's list
df_copy.loc[:, "sum_ranking"] = df_copy.loc[:, "reviewer_ranking"] + df_copy.loc[:, "reviewe_ranking"]
df_copy.loc[:, "overall_ranking"] = df_copy["sum_ranking"].rank()
df_copy = df_copy.sort_values(by="overall_ranking")
return df_copy
ranked_team_df = _rank_collaborators(team_df)
ranked_cross_team_df = _rank_collaborators(cross_team_df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment