コード例 #1
0
        /// <summary>
        /// Calculates the happiness score for the given <see cref="Wish"/>
        /// </summary>
        /// <param name="wish">The <see cref="Wish"/> used to calculate the score</param>
        /// <returns>A number showing how well a <see cref="Wish"/> fits on this <see cref="User"/></returns>
        public int CalculateHappinessScore(Wish wish)
        {
            if (wish is null)
            {
                throw new ArgumentNullException(nameof(wish), "parameter may not be null");
            }

            if (wish.WishUserId == Id)
            {
                return(1000);
            }
            if (wish.WishUserId is null)
            {
                int maxScore = 0;

                //calculate score from organization wish
                int organizationScore = 0;
                if (!(wish.WishOrganizationId is null))
                {
                    maxScore += 950;
                    foreach (UsersOrganizations organizationWork in UsersOrganizations)
                    {
                        if (organizationWork.OrganizationId == wish.WishOrganizationId)
                        {
                            if (wish.WishOrganizationTime is null)
                            {
                                organizationScore = 900;
                            }
                            else
                            {
                                if (organizationWork.WorkYears < wish.WishOrganizationTime)
                                {
                                    organizationScore = 500;
                                }
                                else
                                {
                                    organizationScore = 950;
                                }
                            }
                        }
                    }
                }

                //calculate score from business wishes
                int businessScore = 0;
                if (wish.WishBusinesses.Count != 0)
                {
                    int ownedWishedBusinesses = 0;

                    foreach (WishBusinesses business in wish.WishBusinesses)
                    {
                        if (UsersBusinesses.Any(b => b.BusinessId == business.BusinessId))
                        {
                            ownedWishedBusinesses++;
                        }
                    }
                    businessScore = 500 * ownedWishedBusinesses / wish.WishBusinesses.Count + ownedWishedBusinesses * 75;
                    maxScore     += 500 + ownedWishedBusinesses * 75;
                }

                //calculate score from interest wishes
                int interestScore = 0;
                if (wish.WishInterests.Count != 0)
                {
                    int ownedWishedInterests = 0;

                    foreach (WishInterests interest in wish.WishInterests)
                    {
                        if (UsersInterests.Any(i => i.InterestId == interest.InterestId))
                        {
                            ownedWishedInterests++;
                        }
                    }
                    interestScore = 500 * ownedWishedInterests / wish.WishInterests.Count + ownedWishedInterests * 75;
                    maxScore     += 500 + ownedWishedInterests * 75;
                }

                //Calculate how good the scores are and return
                if (maxScore == 0)
                {
                    return(0);
                }
                return(700 * (organizationScore + businessScore + interestScore) / maxScore);
            }
            return(0);
        }
コード例 #2
0
 /// <summary>
 /// Creates a new <see cref="WishBusinesses"/> object
 /// </summary>
 /// <param name="business">The business in the link</param>
 /// <param name="wish">The wish in the link</param>
 public WishBusinesses(Business business, Wish wish)
 {
     Business = business;
     Wish     = wish;
 }
コード例 #3
0
 /// <summary>
 /// Creates a new <see cref="WishInterests"/> object
 /// </summary>
 /// <param name="interest">the interest in the link</param>
 /// <param name="wish">the wish in the link</param>
 public WishInterests(Interest interest, Wish wish)
 {
     Interest = interest;
     Wish     = wish;
 }