ActivEarth.Server.Service.Competition.ChallengeManager.GetProgress C# (CSharp) Method

GetProgress() public static method

Gets the progress made by a user in the challenge as a percentage (0-100).
public static GetProgress ( int challengeId, int userId ) : int
challengeId int The challenge to evaluate progress for.
userId int The user to evaluate.
return int
        public static int GetProgress(int challengeId, int userId)
        {
            Challenge challenge = ChallengeDAO.GetChallengeFromChallengeId(challengeId);

            float initial = ChallengeDAO.GetInitializationValue(challengeId, userId);
            UserStatistic current = UserStatisticDAO.GetStatisticFromUserIdAndStatType(userId, challenge.StatisticBinding);

            if (initial >= 0 && current != null)
            {
                return Math.Min((int)(100 * (current.Value - initial) / challenge.Requirement), 100);
            }
            else
            {
                return 0;
            }
        }