Esempio n. 1
0
        public void MakeMatch(aspnet_User one, aspnet_User two)
        {
            // Compute
            var totalNumQuestions = db.Questions.Count();
            int scoreSame = 0;
            foreach (var q in db.Questions)
            {
                try
                {
                    var ansone = db.Responses.Where(u => u.UserId == one.UserId && u.QuestionId == q.Id).SingleOrDefault().AnswerId;
                    var anstwo = db.Responses.Where(u => u.UserId == two.UserId && u.QuestionId == q.Id).SingleOrDefault().AnswerId;
                    if (ansone == anstwo)
                    {
                        scoreSame++;
                    }
                }
                catch (NullReferenceException e)
                {
                    // If there was an error above, that means that one of them didn't answer the question because SingleOrDefault() returned null
                    // They can't answer only some of the questions and not the rest, so we don't need to check other questions
                    break; // keep scoreSame at 0, don't check other questions
                }
                catch
                {
                    // Other exception... uh, idk. Let it continue.
                }
            }
            var ratio = ((double)scoreSame) / totalNumQuestions;

            // Add noise
            var noiseInt = new Random().Next(1, 10); // 1% to 10% noise
            if (new Random().Next(0, 1) == 1)
            {
                noiseInt *= -1; // add or subtract
            }
            double noise = (double)noiseInt / 100;
            if (ratio + noise > 1 || ratio + noise < 0) // we want to limit to between 0 and 1
            {
                noise *= -1;
            }
            ratio += noise;

            // Get profiles
            var profile1 = AccountProfile.GetProfileOfUser(one.UserName);
            var profile2 = AccountProfile.GetProfileOfUser(two.UserName);

            // Write to DB
            var time = DateTime.Now;

            var m_one = new Match();
            m_one.RequestUser = one.UserId;
            m_one.MatchedUser = two.UserId;
            m_one.MatchedSex = (profile2.Sex == 2);
            m_one.AreSameGrade = profile1.Grade == profile2.Grade;
            m_one.CompatibilityIndex = ratio;
            m_one.DateCalculated = time;

            db.Matches.InsertOnSubmit(m_one);

            var m_two = new Match();
            m_two.RequestUser = two.UserId;
            m_two.MatchedUser = one.UserId;
            m_two.MatchedSex = (profile1.Sex == 2);
            m_two.AreSameGrade = profile1.Grade == profile2.Grade;
            m_two.CompatibilityIndex = ratio;
            m_two.DateCalculated = time;

            db.Matches.InsertOnSubmit(m_two);

            db.SubmitChanges();
        }
Esempio n. 2
0
 partial void DeleteMatch(Match instance);
Esempio n. 3
0
 partial void UpdateMatch(Match instance);
Esempio n. 4
0
 partial void InsertMatch(Match instance);
Esempio n. 5
0
		private void detach_Matches1(Match entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_User1 = null;
		}
Esempio n. 6
0
		private void attach_Matches(Match entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_User = this;
		}