Exemplo n.º 1
0
        public async Task <TokenInfo> GetToken(GenericUser user)
        {
            var refreshToken = new RefreshTempUser()
            {
                PhoneNumber = user.PhoneNumber
            };
            var resValidate = await Post <SimpleSuccess>($"{Constants.V1Prefix}/{Constants.TokenEndpoint}/refresh", refreshToken);

            if (resValidate.Result == null || resValidate.Result.Success == false)
            {
                throw new Exception(resValidate.Meta.Message);
            }
            var checkToken = new TokenCheck()
            {
                PhoneNumber = user.PhoneNumber,
                Token       = FakeToken
            };

            var resRefreshToken = await Post <TokenInfo>($"{Constants.V1Prefix}/{Constants.TokenEndpoint}/validate", checkToken);

            if (resRefreshToken.Result == null)
            {
                throw new Exception(resValidate.Meta.Message);
            }
            return(resRefreshToken.Result);
        }
Exemplo n.º 2
0
        public GenericUser GetUser(String userName)
        {
            GenericUser user = null;

            m_connection.Open();

            SqlCommand command = m_connection.CreateCommand();

            command.CommandText = "SELECT * FROM users WHERE user_name=@UserName";
            IDbDataParameter parameter = command.CreateParameter();

            parameter.ParameterName = "@UserName";
            parameter.Value         = userName;
            command.Parameters.Add(parameter);
            SqlDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                if (dataReader.GetString(dataReader.GetOrdinal("user_name")).Equals(userName))
                {
                    UInt32 uid = dataReader.GetUInt32(dataReader.GetOrdinal("user_id"));
                    user = new GenericUser(uid, userName);
                }
            }

            dataReader.Close();

            return(user);
        }
Exemplo n.º 3
0
        private DataModel CreateModel()
        {
            List <Item> items = new List <Item>(NUM_ITEMS);

            for (int i = 0; i < NUM_ITEMS; i++)
            {
                items.Add(new GenericItem <String>(i.ToString()));
            }

            List <User> users = new List <User>(NUM_USERS);

            for (int i = 0; i < NUM_USERS; i++)
            {
                int numPrefs            = (int)(random.NextDouble() * NUM_PREFS) + 1;
                List <Preference> prefs = new List <Preference>(numPrefs);
                for (int j = 0; j < numPrefs; j++)
                {
                    prefs.Add(new GenericPreference(null, items[random.Next(NUM_ITEMS)], random.NextDouble()));
                }
                GenericUser <String> user = new GenericUser <String>(i.ToString(), prefs);
                users.Add(user);
            }

            return(new GenericDataModel(users));
        }
Exemplo n.º 4
0
 public TempUser(GenericUser user)
 {
     PhoneNumber = user.PhoneNumber;
     Email       = user.Email;
     Token       = user.Token;
     Id          = user.Id;
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Uses <see cref="CustomerId" /> to try and return the customer. Will return null if not found
        /// </summary>
        /// <remarks>
        ///     NOTE: Does not include any other embedded properties such as history, reviews, or  payment.
        ///     To get all of those properties, see <see cref="GetWithAllData" />
        /// </remarks>
        /// <param name="context">A Database context to use for retieval</param>
        /// <returns>A customer if there is one with the provided id, otherwise null</returns>
        public GenericUser GetUser(BusinessDbContext context)
        {
            if (_user != null)
            {
                return(_user);
            }

            return(_user = Includes(context.Users).FirstOrDefault(t => t.Id == new Guid(CustomerId)));
        }
Exemplo n.º 6
0
		public void TestUserRescorer() 
		{
			Rescorer<User> rescorer = NullRescorer<User>.Instance;
			Assert.IsNotNull(rescorer);
			User user = new GenericUser<String>("test", new List<Preference>());
			Assert.AreEqual(1.0, rescorer.Rescore(user, 1.0));
			Assert.AreEqual(1.0, rescorer.Rescore(null, 1.0));
			Assert.AreEqual(0.0, rescorer.Rescore(user, 0.0));
			Assert.IsTrue(Double.IsNaN(rescorer.Rescore(user, Double.NaN)));
		}
Exemplo n.º 7
0
        public void testNoCorrelation2()
        {
            Preference           pref1     = new GenericPreference(null, new GenericItem <String>("1"), 1.0);
            GenericUser <String> user1     = new GenericUser <String>("test1", ScalarToList <Preference>(pref1));
            Preference           pref2     = new GenericPreference(null, new GenericItem <String>("2"), 1.0);
            GenericUser <String> user2     = new GenericUser <String>("test2", ScalarToList <Preference>(pref2));
            DataModel            dataModel = GetDataModel(user1, user2);
            double correlation             = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);

            Assert.IsTrue(Double.IsNaN(correlation));
        }
Exemplo n.º 8
0
        public void TestUserRescorer()
        {
            Rescorer <User> rescorer = NullRescorer <User> .Instance;

            Assert.IsNotNull(rescorer);
            User user = new GenericUser <String>("test", new List <Preference>());

            Assert.AreEqual(1.0, rescorer.Rescore(user, 1.0));
            Assert.AreEqual(1.0, rescorer.Rescore(null, 1.0));
            Assert.AreEqual(0.0, rescorer.Rescore(user, 0.0));
            Assert.IsTrue(Double.IsNaN(rescorer.Rescore(user, Double.NaN)));
        }
Exemplo n.º 9
0
        public async Task <Results <bool> > CreateAccount(GenericUserContract account)
        {
            var newAccount = new GenericUser
            {
                Email     = account.Email,
                FirstName = account.FirstName,
                LastName  = account.LastName,
                UserName  = account.Email,
            };
            var result = await _userManager.CreateAsync(newAccount, account.Password);

            return(LinqExtensions.CreateSuccessResponse <bool>(result.Succeeded));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> SignIn([FromBody] GenericUserContract account)
        {
            GenericUser accountData = await _accountFacade.SignIn(account);

            var response = LinqExtensions.CreateErrorResponse <RefreshTokenContract>("Unauthorized");

            if (accountData != null)
            {
                var token        = _jwtTokenService.GenerateToken(accountData.Email, accountData.Id.ToString());
                var refreshToken = _jwtTokenService.GenerateRefreshToken();
                var tokenData    = new RefreshTokenContract {
                    RefreshToken = refreshToken, Token = token
                };
                response = LinqExtensions.CreateSuccessResponse(tokenData);
            }
            return(Ok(response));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Helper to allow use to init an address from a <see cref="AddressWithLatLng"/>
        /// </summary>
        /// <param name="addre"></param>
        /// <param name="user"></param>
        public Address(AddressWithLatLng addre, GenericUser user)
        {
            if (addre == null)
            {
                throw new ArgumentNullException(nameof(addre));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            User             = user;
            Number           = addre.Number;
            Street           = addre.Street;
            State            = addre.State;
            Zip              = addre.Zip;
            City             = addre.City;
            FormattedAddress = addre.FormattedAddress;
            GeoLocation      = new PostgisPoint(addre.Longitude, addre.Latitude)
            {
                SRID = Constants.SRID
            };
        }
		/**
		 * {@inheritDoc}
		 */
		public double Evaluate(RecommenderBuilder recommenderBuilder,
		                       DataModel dataModel,
		                       double trainingPercentage,
		                       double evaluationPercentage)
		{

			if (recommenderBuilder == null) 
            {
				throw new ArgumentNullException("recommenderBuilder is null");
			}
			if (dataModel == null) 
            {
				throw new ArgumentNullException("dataModel is null");
			}
			if (double.IsNaN(trainingPercentage) || trainingPercentage <= 0.0 || trainingPercentage >= 1.0) 
            {
				throw new ArgumentException("Invalid trainingPercentage: " + trainingPercentage);
			}
			if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0) 
            {
				throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
			}

			log.Info("Beginning evaluation using " + trainingPercentage + " of " + dataModel);

			int numUsers = dataModel.GetNumUsers();
			ICollection<User> trainingUsers = new List<User>(1 + (int) (trainingPercentage * (double) numUsers));
			IDictionary<User, ICollection<Preference>> testUserPrefs =
				new Dictionary<User, ICollection<Preference>>(1 + (int) ((1.0 - trainingPercentage) * (double) numUsers));

			foreach (User user in dataModel.GetUsers()) 
            {
				if (random.NextDouble() < evaluationPercentage) 
                {
					ICollection<Preference> trainingPrefs = new List<Preference>();
					ICollection<Preference> testPrefs = new List<Preference>();
                    Preference[] prefs = user.GetPreferencesAsArray();

					foreach (Preference pref in prefs) 
					{
						Item itemCopy = new GenericItem<String>(pref.Item.ID.ToString());
						Preference newPref = new GenericPreference(null, itemCopy, pref.Value);
						if (random.NextDouble() < trainingPercentage) 
						{
							trainingPrefs.Add(newPref);
						} else {
							testPrefs.Add(newPref);
						}
					}
					if (log.IsDebugEnabled) {
						log.Debug("Training against " + trainingPrefs.Count + " preferences");
						log.Debug("Evaluating accuracy of " + testPrefs.Count + " preferences");
					}
					if (trainingPrefs.Count > 0) 
					{
						User trainingUser = new GenericUser<String>(user.ID.ToString(), trainingPrefs);
						trainingUsers.Add(trainingUser);
						if (testPrefs.Count > 0) 
						{
							testUserPrefs.Add(trainingUser, testPrefs);
						}
					}
				}
			}

			DataModel trainingModel = new GenericDataModel(trainingUsers);
			Recommender recommender = recommenderBuilder.BuildRecommender(trainingModel);
			double result = GetEvaluation(testUserPrefs, recommender);
			log.Info("Evaluation result: " + result);
			return result;
		}
Exemplo n.º 13
0
 public RefreshTempUser(GenericUser user)
 {
     PhoneNumber = user.PhoneNumber;
     Token       = user.Token;
 }
Exemplo n.º 14
0
 public void testNoCorrelation2()
 {
     Preference pref1 = new GenericPreference(null, new GenericItem<String>("1"), 1.0);
     GenericUser<String> user1 = new GenericUser<String>("test1", ScalarToList<Preference>(pref1));
     Preference pref2 = new GenericPreference(null, new GenericItem<String>("2"), 1.0);
     GenericUser<String> user2 = new GenericUser<String>("test2", ScalarToList<Preference>(pref2));
     DataModel dataModel = GetDataModel(user1, user2);
     double correlation = new PearsonCorrelation(dataModel).GetUserCorrelation(user1, user2);
     Assert.IsTrue(Double.IsNaN(correlation));
 }
        public IRStatistics Evaluate(RecommenderBuilder recommenderBuilder,
                                     DataModel dataModel,
                                     int at,
                                     double relevanceThreshold,
                                     double evaluationPercentage)
        {
            if (recommenderBuilder == null)
            {
                throw new ArgumentNullException("recommenderBuilder is null");
            }
            if (dataModel == null)
            {
                throw new ArgumentNullException("dataModel is null");
            }
            if (at < 1)
            {
                throw new ArgumentException("at must be at least 1");
            }
            if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0)
            {
                throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
            }
            if (double.IsNaN(relevanceThreshold))
            {
                throw new ArgumentException("Invalid relevanceThreshold: " + evaluationPercentage);
            }

            RunningAverage precision = new FullRunningAverage();
            RunningAverage recall    = new FullRunningAverage();

            foreach (User user in dataModel.GetUsers())
            {
                Object id = user.ID;
                if (random.NextDouble() < evaluationPercentage)
                {
                    ICollection <Item> relevantItems = new HashedSet <Item>(/* at */);
                    Preference[]       prefs         = user.GetPreferencesAsArray();

                    foreach (Preference pref in prefs)
                    {
                        if (pref.Value >= relevanceThreshold)
                        {
                            relevantItems.Add(pref.Item);
                        }
                    }
                    int numRelevantItems = relevantItems.Count;
                    if (numRelevantItems > 0)
                    {
                        ICollection <User> trainingUsers = new List <User>(dataModel.GetNumUsers());
                        foreach (User user2 in dataModel.GetUsers())
                        {
                            if (id.Equals(user2.ID))
                            {
                                ICollection <Preference> trainingPrefs = new List <Preference>();
                                prefs = user2.GetPreferencesAsArray();
                                foreach (Preference pref in prefs)
                                {
                                    if (!relevantItems.Contains(pref.Item))
                                    {
                                        trainingPrefs.Add(pref);
                                    }
                                }
                                if (trainingPrefs.Count > 0)
                                {
                                    User trainingUser = new GenericUser <String>(id.ToString(), trainingPrefs);
                                    trainingUsers.Add(trainingUser);
                                }
                            }
                            else
                            {
                                trainingUsers.Add(user2);
                            }
                        }
                        DataModel   trainingModel = new GenericDataModel(trainingUsers);
                        Recommender recommender   = recommenderBuilder.BuildRecommender(trainingModel);

                        try
                        {
                            trainingModel.GetUser(id);
                        }
                        catch (NoSuchElementException)
                        {
                            continue;                             // Oops we excluded all prefs for the user -- just move on
                        }

                        int intersectionSize = 0;
                        foreach (RecommendedItem recommendedItem in recommender.Recommend(id, at))
                        {
                            if (relevantItems.Contains(recommendedItem.Item))
                            {
                                intersectionSize++;
                            }
                        }
                        precision.AddDatum((double)intersectionSize / (double)at);
                        recall.AddDatum((double)intersectionSize / (double)numRelevantItems);
                    }
                }
            }

            return(new IRStatisticsImpl(precision.Average, recall.Average));
        }
Exemplo n.º 16
0
 public static void Logoff(GenericUser user)
 {
     user.status = false; //static binding
 }
Exemplo n.º 17
0
 public static bool CheckIfOverride(GenericUser user)
 {
     return(TestNumbers.Contains(user.PhoneNumber) || user.Name.Contains(UserOverride));
 }
Exemplo n.º 18
0
 public static void Logon(GenericUser user)
 {
     user.status = true; //static binding
 }
Exemplo n.º 19
0
	    private DataModel CreateModel() 
	    {
		    List<Item> items = new List<Item>(NUM_ITEMS);
		    for (int i = 0; i < NUM_ITEMS; i++) 
		    {
			    items.Add(new GenericItem<String>(i.ToString()));
		    }

		    List<User> users = new List<User>(NUM_USERS);
		    for (int i = 0; i < NUM_USERS; i++) 
		    {
                int numPrefs = (int)(random.NextDouble() * NUM_PREFS) + 1;
			    List<Preference> prefs = new List<Preference>(numPrefs);
			    for (int j = 0; j < numPrefs; j++) 
			    {
				    prefs.Add(new GenericPreference(null, items[random.Next(NUM_ITEMS)], random.NextDouble()));
			    }
			    GenericUser<String> user = new GenericUser<String>(i.ToString(), prefs);
			    users.Add(user);
		    }

		    return new GenericDataModel(users);
	    }
Exemplo n.º 20
0
        /**
         * {@inheritDoc}
         */
        public double Evaluate(RecommenderBuilder recommenderBuilder,
                               DataModel dataModel,
                               double trainingPercentage,
                               double evaluationPercentage)
        {
            if (recommenderBuilder == null)
            {
                throw new ArgumentNullException("recommenderBuilder is null");
            }
            if (dataModel == null)
            {
                throw new ArgumentNullException("dataModel is null");
            }
            if (double.IsNaN(trainingPercentage) || trainingPercentage <= 0.0 || trainingPercentage >= 1.0)
            {
                throw new ArgumentException("Invalid trainingPercentage: " + trainingPercentage);
            }
            if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0)
            {
                throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
            }

            log.Info("Beginning evaluation using " + trainingPercentage + " of " + dataModel);

            int numUsers = dataModel.GetNumUsers();
            ICollection <User> trainingUsers = new List <User>(1 + (int)(trainingPercentage * (double)numUsers));
            IDictionary <User, ICollection <Preference> > testUserPrefs =
                new Dictionary <User, ICollection <Preference> >(1 + (int)((1.0 - trainingPercentage) * (double)numUsers));

            foreach (User user in dataModel.GetUsers())
            {
                if (random.NextDouble() < evaluationPercentage)
                {
                    ICollection <Preference> trainingPrefs = new List <Preference>();
                    ICollection <Preference> testPrefs     = new List <Preference>();
                    Preference[]             prefs         = user.GetPreferencesAsArray();

                    foreach (Preference pref in prefs)
                    {
                        Item       itemCopy = new GenericItem <String>(pref.Item.ID.ToString());
                        Preference newPref  = new GenericPreference(null, itemCopy, pref.Value);
                        if (random.NextDouble() < trainingPercentage)
                        {
                            trainingPrefs.Add(newPref);
                        }
                        else
                        {
                            testPrefs.Add(newPref);
                        }
                    }
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Training against " + trainingPrefs.Count + " preferences");
                        log.Debug("Evaluating accuracy of " + testPrefs.Count + " preferences");
                    }
                    if (trainingPrefs.Count > 0)
                    {
                        User trainingUser = new GenericUser <String>(user.ID.ToString(), trainingPrefs);
                        trainingUsers.Add(trainingUser);
                        if (testPrefs.Count > 0)
                        {
                            testUserPrefs.Add(trainingUser, testPrefs);
                        }
                    }
                }
            }

            DataModel   trainingModel = new GenericDataModel(trainingUsers);
            Recommender recommender   = recommenderBuilder.BuildRecommender(trainingModel);
            double      result        = GetEvaluation(testUserPrefs, recommender);

            log.Info("Evaluation result: " + result);
            return(result);
        }
        public async Task <GenericUser> Process(IHostingEnvironment hostingEnvironment, ITokenMemoryCache memoryCache, BusinessDbContext context, ValidationSender validation, TempUser tempUser)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                tempUser.PhoneNumber = tempUser.PhoneNumber.CleanPhone();
                // Check out our users, if we already someone, then no need to validate, its just an error
                var check = await context.Users.AnyAsync(u => (!string.IsNullOrEmpty(u.PhoneNumber) && (u.PhoneNumber == tempUser.PhoneNumber)) || (!string.IsNullOrEmpty(u.Email) && (u.Email == tempUser.Email)));

                if (check)
                {
                    throw new ProcessEventException("You have already signed up. Please login instead");
                }

                // Also need to check if their is any pending validation and in that case we would not take this info
                var waitingUeser = context.AllUsers.FirstOrDefault(
                    u =>
                    ((!string.IsNullOrEmpty(u.PhoneNumber) && u.PhoneNumber == tempUser.PhoneNumber) || (!string.IsNullOrEmpty(u.Email) && u.Email == tempUser.Email)) &&
                    u.Enabled == false);

                if (waitingUeser != null)
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(tempUser.Email))
                        {
                            Log.Information("Sending Email Validation to {user}", tempUser);

                            try
                            {
                                await validation.SendValidationToEmail(tempUser);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                throw new ProcessEventException("Could not send verification to that email. Please use a different email address");
                            }

                            memoryCache.SetForChallenge(tempUser);
                        }
                        else if (!string.IsNullOrWhiteSpace(tempUser.PhoneNumber))
                        {
                            Log.Information("Sending SMS Validation to {user}", tempUser);

                            try
                            {
                                await validation.SendValidationToSms(tempUser);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                throw new ProcessEventException("Could not send a verification message to that phone number. Please use a number able to receive texts.");
                            }

                            memoryCache.SetForChallenge(tempUser);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(e, "Error when sending out a validation email to an incoming user {email} , {phone}", tempUser.Email, tempUser.PhoneNumber);
                        throw new ProcessEventException("Could not send out a validation link to the number or email provided");
                    }

                    throw new ProcessEventException("Your already signed up, you just need to confirm your information. Check your inbox or text messages.");
                }

                // Create a temporary account now, just keep account disabled untill verified.
                // TODO: background cron job which purges accounts unvalidated after xxx amount of time

                var addr = new Address(tempUser);
                context.Address.Add(addr);

                var user = new GenericUser()
                {
                    Name        = tempUser.Name,
                    Email       = tempUser.Email,
                    PhoneNumber = tempUser.PhoneNumber,
                    Address     = addr,
                    UserName    = string.IsNullOrEmpty(tempUser.Email) ? tempUser.PhoneNumber : tempUser.Email
                };


                // Set our join date and last login
                user.JoinDate = user.LastLogin = DateTime.Now;
                context.AllUsers.Add(user);
                context.SaveChanges();
                user.SetPassword(tempUser.Password);
                context.SaveChanges();
                Log.Information("Created a new user, unvalidated {user}", user);

                // Need to set our tempUser id to our user
                tempUser.Id = user.Id;

                // TODO: Remove any chance of this obvious inserurity prior to real production usage via removing the check altogther.
                if (Constants.Testing.CheckIfOverride(tempUser) && (hostingEnvironment.IsDevelopment() || hostingEnvironment.IsEnvironment("Testing")))
                {
                    tempUser.Token = Constants.Testing.TestValidationToken;
                    // Hold our token and tempUser for a while to give our user a chance to validate their info
                    memoryCache.SetForChallenge(tempUser);
                    transaction.Commit();
                    return(user);
                }

                // We prefer to send validation through email but will send through sms if needed
                if (!string.IsNullOrWhiteSpace(tempUser.Email))
                {
                    Log.Information("Sending Email Validation to {user}", user.Email);

                    await validation.SendValidationToEmail(tempUser);

                    memoryCache.SetForChallenge(tempUser);
                }
                else if (!string.IsNullOrWhiteSpace(tempUser.PhoneNumber))
                {
                    Log.Information("Sending SMS Validation to {user}", user.PhoneNumber);

                    await validation.SendValidationToSms(tempUser);

                    memoryCache.SetForChallenge(tempUser);
                }

                transaction.Commit();
                return(user);
            }
        }
		public IRStatistics Evaluate(RecommenderBuilder recommenderBuilder,
		                             DataModel dataModel,
		                             int at,
		                             double relevanceThreshold,
		                             double evaluationPercentage) 
		{

			if (recommenderBuilder == null) {
				throw new ArgumentNullException("recommenderBuilder is null");
			}
			if (dataModel == null) {
				throw new ArgumentNullException("dataModel is null");
			}
			if (at < 1) {
				throw new ArgumentException("at must be at least 1");
			}
			if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0) 
			{
				throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
			}
			if (double.IsNaN(relevanceThreshold)) {
				throw new ArgumentException("Invalid relevanceThreshold: " + evaluationPercentage);
			}

			RunningAverage precision = new FullRunningAverage();
			RunningAverage recall = new FullRunningAverage();
			foreach (User user in dataModel.GetUsers()) 
			{
				Object id = user.ID;
				if (random.NextDouble() < evaluationPercentage) 
				{
					ICollection<Item> relevantItems = new HashedSet<Item>(/* at */);
                    Preference[] prefs = user.GetPreferencesAsArray();

					foreach (Preference pref in prefs) 
					{
						if (pref.Value >= relevanceThreshold) 
                        {
							relevantItems.Add(pref.Item);
						}
					}
					int numRelevantItems = relevantItems.Count;
					if (numRelevantItems > 0) 
                    {
						ICollection<User> trainingUsers = new List<User>(dataModel.GetNumUsers());
						foreach (User user2 in dataModel.GetUsers()) 
                        {
							if (id.Equals(user2.ID)) 
							{
								ICollection<Preference> trainingPrefs = new List<Preference>();
                                prefs = user2.GetPreferencesAsArray();
								foreach (Preference pref in prefs) 
								{
									if (!relevantItems.Contains(pref.Item)) 
									{
										trainingPrefs.Add(pref);
									}
								}
								if (trainingPrefs.Count > 0) 
								{
									User trainingUser = new GenericUser<String>(id.ToString(), trainingPrefs);
									trainingUsers.Add(trainingUser);
								}
							} 
                            else 
                            {
								trainingUsers.Add(user2);
							}

						}
						DataModel trainingModel = new GenericDataModel(trainingUsers);
						Recommender recommender = recommenderBuilder.BuildRecommender(trainingModel);

						try 
						{
							trainingModel.GetUser(id);
						} 
                        catch (NoSuchElementException) 
                        {
							continue; // Oops we excluded all prefs for the user -- just move on
						}
						
						int intersectionSize = 0;
						foreach (RecommendedItem recommendedItem in recommender.Recommend(id, at)) 
						{
							if (relevantItems.Contains(recommendedItem.Item)) 
							{
								intersectionSize++;
							}
						}
						precision.AddDatum((double) intersectionSize / (double) at);
						recall.AddDatum((double) intersectionSize / (double) numRelevantItems);					
					}
				}
			}

			return new IRStatisticsImpl(precision.Average, recall.Average);
		}