public async Task <bool> UpdateSimilarityScores(Guid userId) { var oldScores = await _context.SimilarityScores.Where(x => x.FromUserId == userId).ToListAsync(); var features = (await _featureApplication.GetFeatures()).Where(x => x.IsCalculated).ToList(); var columns = features.Count; var users = await GetUsersToCalculate(userId); int rows = users.Count; double[,] usersMatrix = new double[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { var vm = users[i].FeatureViewModels .Where(x => x.FeatureId == features[j].Id) .FirstOrDefault(); if (vm == null) { usersMatrix[i, j] = -1; } else { if (!vm.IsCalculated) { usersMatrix[i, j] = 0; continue; } usersMatrix[i, j] = vm.Rate * vm.weight; } } } SimilarityMatrix m = new SimilarityMatrix { Row = rows, Column = columns, Matrix = usersMatrix }; List <double> kq = new List <double>(); kq = m.SimilarityCalculate(); users.RemoveAt(0); var similarityScores = new List <SimilarityScore>(); for (int i = 1; i < kq.Count; i++) { users[i - 1].Point = kq[i]; var score = new SimilarityScore() { FromUserId = userId, ToUserId = users[i - 1].UserId, Score = kq[i] }; similarityScores.Add(score); } try { _context.SimilarityScores.AddRange(similarityScores); _context.SimilarityScores.RemoveRange(oldScores); await _context.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <IActionResult> GetFeatures() { var Gender = new List <string>(); List <EGender> Genders = Enum.GetValues(typeof(EGender)) .Cast <EGender>() .ToList(); foreach (var item in Genders) { Gender.Add(item.ToString()); } var FindPeople = new List <string>(); List <EGender> findPeople = Enum.GetValues(typeof(EGender)) .Cast <EGender>() .ToList(); foreach (var item in findPeople) { FindPeople.Add(item.ToString()); } var Job = new List <string>(); List <EJob> Jobs = Enum.GetValues(typeof(EJob)) .Cast <EJob>() .ToList(); foreach (var item in Jobs) { Job.Add(item.ToString()); } var Location = new List <string>(); List <ELocation> Locations = Enum.GetValues(typeof(ELocation)) .Cast <ELocation>() .ToList(); foreach (var item in Locations) { Location.Add(item.ToString()); } //var TypeAccount = new List<string>(); //List<ETypeAccount> TypeAccounts = Enum.GetValues(typeof(ETypeAccount)) // .Cast<ETypeAccount>() // .ToList(); //foreach (var item in TypeAccounts) //{ // TypeAccount.Add(item.ToString()); //} //var UserStatus = new List<string>(); //List<EUserStatus> UserStatuses = Enum.GetValues(typeof(EUserStatus)) // .Cast<EUserStatus>() // .ToList(); //foreach (var item in UserStatuses) //{ // UserStatus.Add(item.ToString()); //} var AgeGroup = new List <string>(); List <EAgeGroup> ageGroups = Enum.GetValues(typeof(EAgeGroup)) .Cast <EAgeGroup>() .ToList(); foreach (var item in ageGroups) { AgeGroup.Add(item.ToString()); } var features = await _featureApplication.GetFeatures(); var response = new { //AtmosphereLike, //Body, //Character, //DrinkBeer, //Education, //FavoriteMovie, Gender, FindPeople, Job, //LifeStyle, Location, //Marriage, //MostValuable, //Religion, //Smoking, //LikeTechnology, //LikePet, //PlaySport, //Travel, //Game, //Shopping, AgeGroup, features }; return(Ok(response)); }
public async Task <IActionResult> GetFeatures() { var Gender = new List <string>(); List <EGender> Genders = Enum.GetValues(typeof(EGender)) .Cast <EGender>() .ToList(); foreach (var item in Genders) { Gender.Add(item.ToString()); } var FindPeople = new List <string>(); List <EGender> findPeople = Enum.GetValues(typeof(EGender)) .Cast <EGender>() .ToList(); foreach (var item in findPeople) { FindPeople.Add(item.ToString()); } var Job = new List <string>(); List <EJob> Jobs = Enum.GetValues(typeof(EJob)) .Cast <EJob>() .ToList(); foreach (var item in Jobs) { Job.Add(item.ToString()); } var Location = new List <string>(); List <ELocation> Locations = Enum.GetValues(typeof(ELocation)) .Cast <ELocation>() .ToList(); foreach (var item in Locations) { Location.Add(item.ToString()); } //var TypeAccount = new List<string>(); //List<ETypeAccount> TypeAccounts = Enum.GetValues(typeof(ETypeAccount)) // .Cast<ETypeAccount>() // .ToList(); //foreach (var item in TypeAccounts) //{ // TypeAccount.Add(item.ToString()); //} //var UserStatus = new List<string>(); //List<EUserStatus> UserStatuses = Enum.GetValues(typeof(EUserStatus)) // .Cast<EUserStatus>() // .ToList(); //foreach (var item in UserStatuses) //{ // UserStatus.Add(item.ToString()); //} var AgeGroup = new List <string>(); List <EAgeGroup> ageGroups = Enum.GetValues(typeof(EAgeGroup)) .Cast <EAgeGroup>() .ToList(); foreach (var item in ageGroups) { AgeGroup.Add(item.ToString()); } var features = await _featureApplication.GetFeatures(); var response = new { Gender, FindPeople, Job, Location, AgeGroup, features }; return(Ok(response)); }
public async Task <IActionResult> GetFeatures() { var features = await _featureApplication.GetFeatures(); return(Ok(features)); }