in osci/postprocess/osci_change_report/osci_change_report.py [0:0]
def get_osci_ranking_change_report(old_report: pd.DataFrame, new_report: pd.DataFrame,
company_field: str,
active_contributors_field: str, active_contributors_change_field: str,
total_community_field: str, total_community_change_field: str,
rank_field: str, rank_change_field: str) -> pd.DataFrame:
"""Get difference between two OSCI Ranking (for two days or months or years, etc)
:param old_report: OSCI ranking
:param new_report: OSCI ranking
:param company_field: company column name
:param active_contributors_field: active contributors column name
:param active_contributors_change_field: active contributors change column name
:param total_community_field: total community column name
:param total_community_change_field: total community change column name
:param rank_field: ranking index column name
:param rank_change_field: ranking index change column name
:return: OSCI ranking change report
"""
old_suffix = '_old'
df = old_report.merge(new_report,
on=company_field,
how='outer',
suffixes=(old_suffix, '')
).dropna(subset=[f'{rank_field}'])
col_pairs = (
(rank_field, rank_change_field),
(active_contributors_field, active_contributors_change_field),
(total_community_field, total_community_change_field),
)
for col, change_col in col_pairs:
df[change_col] = df[col] - df[f'{col}{old_suffix}']
df = df[[
rank_field, rank_change_field,
company_field,
active_contributors_field, active_contributors_change_field,
total_community_field, total_community_change_field,
]].sort_values(by=rank_field)
df[rank_field] = df[rank_field].astype(int)
return df.set_index(rank_field)