I just tried it and it worked without problems, everything was fine, although in two tests I did, in one it appeared to me at 79% completed for my next rank, and in the second it appeared to me at 87%, which would make sense if there had been changes in my account, or I had received merits recently but that is not the case, I recommend you carefully review how you are managing those percentages, for the rest, thanks for the initiative!
Thank you boss for the feedback and observation as well. I have fixed that issue it was coming from the formula used and i have made the correction so the system should now handle the percentage calculation accurately.
You should consider the activity in percentage, since this is an important factor to calculate the real progress, since maybe you have 300 merits for example and 150 of activity, therefore both figures must be considered for the calculation of progress, I don't know if you already do it, but in Python it would be something like this:
def calculate_real_progress(merit, activity):
ranks = [
{"name": "Full Member", "min": 100, "max": 250},
{"name": "Senior Member", "min": 250, "max": 500},
{"name": "Hero Member", "min": 500, "max": 1000},
{"name": "Legendary Member","min": 1000, "max": float("inf")}
]
for i in range(len(ranks) - 1):
current = ranks[i]
next_rank = ranks[i + 1]
if merit < next_rank["min"] or activity < next_rank["min"]:
span = next_rank["min"] - current["min"]
merit_pct = ((merit - current["min"]) / span) * 100
activity_pct = ((activity - current["min"]) / span) * 100
merit_pct = max(0, min(100, merit_pct))
activity_pct = max(0, min(100, activity_pct))
real_pct = (merit_pct + activity_pct) / 2
missing_pct = 100 - real_pct
return {
"current_rank": current["name"],
"next_rank": next_rank["name"],
"merit_pct": round(merit_pct, 2),
"activity_pct": round(activity_pct, 2),
"real_pct": round(real_pct, 2),
"missing_pct": round(missing_pct, 2)
}
return {
"current_rank": "Legendary Member",
"next_rank": "—",
"merit_pct": 100.0,
"activity_pct": 100.0,
"real_pct": 100.0,
"missing_pct": 0.0
}
result = calculate_real_progress(merit=375, activity=375)
print(f"Current rank: {result['current_rank']}")
print(f"Next rank: {result['next_rank']}")
print(f"Merit %: {result['merit_pct']}%")
print(f"Activity %: {result['activity_pct']}%")
print(f"Real %: {result['real_pct']}%")
print(f"Missing %: {result['missing_pct']}%")