Example #1
0
        static public List <SearchScore> GetSearchScore(UserProfile ownProfile, string searchType, SearchFilter searchFilter, bool IsRefreshTable)
        {
            List <SearchScore> searchScores = new List <SearchScore>();

            //Refresh tables
            if (IsRefreshTable)
            {
                RefreshTables(searchType);
            }

            //loop through table to get score for indivdiual items
            foreach (UserProfile targetProfile in userProfiles)
            {
                //Ignore the following
                if (ownProfile.Id == targetProfile.Id)
                {
                    continue;
                }
                //need to add Mentor / mentee Filter

                //Get the score for each dimension
                double genderScore           = GetGenderScore(genderScores, ownProfile.Gender, targetProfile.Gender, searchType);
                double ageScore              = GetAgeScore(ageScores, ownProfile.Age, targetProfile.Age, searchType);
                double locationScore         = GetLocationScore(locationScores, ownProfile.Latitude, ownProfile.Longtitude, targetProfile.Latitude, targetProfile.Longtitude, searchType);
                double industryScore         = GetIndustryScore(industryScores, ownProfile.Industry, targetProfile.Industry, searchType);
                double organisationTypeScore = GetOrganisationTypeScore(organisationTypeScores, ownProfile.OrganisationType, targetProfile.OrganisationType, searchType);
                double jobLevelScore         = GetJobLevelScore(jobLevelMappings, jobLevelScores, ownProfile.JobLevel, targetProfile.JobLevel, searchType);

                //Calculate TotalScore
                double totalScore = (genderWeight_Final * genderScore
                                     + ageWeight_Final * ageScore
                                     + locationWeight_Final * locationScore
                                     + industryWeight_Final * industryScore
                                     + organisationTypeWeight_Final * organisationTypeScore
                                     + jobLevelWeight_Final * jobLevelScore) / 100;

                searchScores.Add(new SearchScore()
                {
                    OwnUserId             = ownProfile.Id,
                    TargetUserId          = targetProfile.Id,
                    SearchType            = searchType,
                    Distance              = DistanceAlgorithm.DistanceBetweenPlaces(ownProfile.Latitude, ownProfile.Longtitude, targetProfile.Latitude, targetProfile.Longtitude),
                    GenderScore           = genderScore,
                    AgeScore              = ageScore,
                    LocationScore         = locationScore,
                    IndustryScore         = industryScore,
                    OrganisationTypeScore = organisationTypeScore,
                    JobLevelScore         = jobLevelScore,
                    TotalScore            = totalScore
                });
            }

            searchScores = searchScores.OrderByDescending(x => x.TotalScore).ToList();

            return(searchScores);
        }
Example #2
0
        static private double GetLocationScore(List <LocationScore> locationScores, double ownLatitude, double ownLongtitude, double targetLatitude, double targetLongtitude, string searchType)
        {
            int    locationDifference;
            double distance = DistanceAlgorithm.DistanceBetweenPlaces(ownLatitude, ownLongtitude, targetLatitude, targetLongtitude);

            if (distance > 1000)
            {
                locationDifference = 1000;
            }
            else if (distance > 500)
            {
                locationDifference = 500;
            }
            else if (distance > 250)
            {
                locationDifference = 250;
            }
            else if (distance > 100)
            {
                locationDifference = 100;
            }
            else if (distance > 50)
            {
                locationDifference = 50;
            }
            else if (distance > 25)
            {
                locationDifference = 25;
            }
            else
            {
                locationDifference = 0;
            }

            LocationScore locationScore = locationScores.Where(u => u.LocationDistance == locationDifference).FirstOrDefault();

            if (locationScore == null)
            {
                return(0);
            }

            double output = Convert.ToInt64(locationScore.GetType().GetProperty(searchType + "Value").GetValue(locationScore, null));

            return(output);
        }