def set_score_percentile(org_grouped_by_type): """This function computes the score percentile of each organization within its own group, and store it into the database. For organization whose credit score is unavailable, its percentile will be Null. The computation will only be done among organization will valid score. """ dbclient = DBClient() for orgs_queue in org_grouped_by_type.values(): total_count = len(orgs_queue) index = 1 while len(orgs_queue) != 0: score, electronic_id = heappop(orgs_queue) percentile = round(float(index) / total_count, 2) index += 1 dbclient.update_score_percentile(percentile, electronic_id)