Balanced and spontaneous user
Inheritance: IEntity
        public void CreaeteFromMealAndUserDataTest_ShouldCreateUserMealProfileObjectWithCorrectCalculatedCarbsDeviation_and_MealCarbsAmount_Properies()
        {
            Meal userMeal = new Meal()
            {
                Id = Guid.NewGuid(),
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170,
                CarbAmount = 85
            };
            string userName = "******";
            UserBaseInsulinCalcProfile insulineProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 40,
                InsulinCarbohydrateRatio = 12.5,
                MaxSugarRange = 150
            };
            SpontaneousUserModel userData = new SpontaneousUserModel()
            {
                BaseInsulinCalcProfile = insulineProfile,
            };

            //act
            UserMealProfileFactory mealFactory = new UserMealProfileFactory();
            UserMealProfile mealProfile = mealFactory.CreaeteFromMealAndUserData(userMeal, userName, userData);

            AlgorithmCalculations.AlgorithmResult algResult = AlgorithmCalculations.CalcMealCarbsDeviation(userMeal, mealProfile.UserInsulinProfile);

            //assert
            Assert.IsNotNull(mealProfile);
            Assert.AreEqual(mealProfile.CalculatedCarbsDeviation, algResult.Result);
            Assert.AreEqual(mealProfile.MealCarbsAmount, mealProfile.ExpectedCarbsAmount + algResult.Result);
        }
        public void CreaeteFromMealAndUserDataTest_ShouldCreateUserMealProfileObjectWithAllRelevantDataOfInputParameters()
        {
            Meal userMeal = new Meal()
            {
                Id = Guid.NewGuid(),
                PreMealSugarLevel = 290,
                PostMealSugarLevel = 170
            };
            string userName = "******";
            UserBaseInsulinCalcProfile insulineProfile = new RapidInsulinProfile()
            {
                UnitReductionValue = 40,
                InsulinCarbohydrateRatio = 12.5,
                MaxSugarRange = 150
            };
            SpontaneousUserModel userData = new SpontaneousUserModel()
            {
                BaseInsulinCalcProfile = insulineProfile,
            };

            //act
            UserMealProfileFactory mealFactory = new UserMealProfileFactory();
            UserMealProfile mealProfile = mealFactory.CreaeteFromMealAndUserData(userMeal, userName, userData);

            //assert
            Assert.IsNotNull(mealProfile);
            Assert.AreEqual(mealProfile.MealId, userMeal.Id);
            Assert.AreEqual(mealProfile.UserName, userName);
            Assert.AreEqual(mealProfile.UserInsulinProfile, insulineProfile);
        }
 public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
 {
     if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
     {
         //1 Still not acquired check
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is WelcomeUserMedal) return null;
         }
     }
     //2 10 views
     int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
     if (avtivityCount >= 1)
     {
         // need to check if medal created with CreatedAt propertie
         UserMedal medal = new WelcomeUserMedal();
         log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
         return medal;
     }
     else
     {
         log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
     }
     return null;
 }
        public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
        {
            UserMedal currentMedal = new RestaurantAdviserMedal();
            currentMedal.CreatedAt = new DateTime(0);
            if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
            {
                //if (IfAlreadyHave(statistic)) return null;
                currentMedal = getLastMedal(statistic);
            }

            //Check if current activity is meets requirement
            string activityName = activity.GetType().Name;
            int activityCount = 0;
            if (activity is MedalViewActivity)
            {
                activityCount = statistic.GetActivityCount(activityName, ((MedalViewActivity)activity).MedalType, currentMedal.CreatedAt);
            }
            else
            {
                activityCount = statistic.GetActivityCount(activityName, currentMedal.CreatedAt);
            }

            //Check if current activity is in requirement list
            if (RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName) != null)
            {
                if (activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count)
                {
                    //Current activity is meets requirement
                    //Check if meets other requirements necessary for the medal
                    foreach (var requirement in RequirementsList)
                    {
                        activityName = requirement.Activity.GetType().Name;
                        //avtivityCount = statistic.GetActivityCount(activityName);
                        if (requirement.Activity is MedalViewActivity)
                        {
                            activityCount = statistic.GetActivityCount(activityName, "RestaurantAdviserMedal", currentMedal.CreatedAt);
                        }
                        else
                        {
                            activityCount = statistic.GetActivityCount(activityName, currentMedal.CreatedAt);
                        }
                        if (!(activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count))
                        {
                            log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Still not win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
                            return null;
                        }
                    }
                    UserMedal medal = new RestaurantAdviserMedal();
                    log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
                    return medal;
                }
            }
            else
            {
                log.InfoFormat("[RestaurantAdviserChecker]: CheckIfFullfiledRequirement] Still not win RestaurantAdviser Medal. avtivityCount={0}", activityCount);
            }
            return null;
        }
 /// <summary>
 ///     
 /// </summary>
 /// <param name="userStatistic"></param>
 /// <param name="producedActivity"></param>
 /// <returns>
 /// In case requirements was fullfiled return medal for giving to user.
 /// This should be save outside of method
 /// </returns>
 public List<UserMedal> ObtainMedalBecauseOfActivity(SpontaneousUserModel userStatistic, UserActivity producedActivity)
 {
     List<UserMedal> returnValue = new List<UserMedal>();
     String activityClassName = producedActivity.GetType().Name;
     if (m_activityMedalMap.ContainsKey(activityClassName))
     {
         UserMedal medal = m_activityMedalMap[activityClassName].CheckIfFullfiledRequirement(userStatistic, producedActivity);
         if (medal != null) returnValue.Add(medal);
     }
     return returnValue;
 }
 public bool IfValidParameters(Meal userMeal, string userName, SpontaneousUserModel userData)
 {
     if (userMeal != null && userData != null && !string.IsNullOrEmpty(userName))
     {
         log.InfoFormat("[CarbohydratesVerification.IfValidParameters] Valid parameters: Meal.Id={0}, userName={1}.", userMeal.Id.ToString(), userName);
         return true;
     }
     else
     {
         log.ErrorFormat("[CarbohydratesVerification.IfValidParameters] Some of input parameters not valid.");
         return false;
     }
 }
 public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
 {
     // need implement, now return medal for test
     if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
     {
         //1 Still not acquired check
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is WelcomeUserMedal) return null;
         }
     }
     return new AddRestaurantMedal();
 }
        public void SaveDataInUserMealProfile(Meal userMeal, string userName, SpontaneousUserModel userData)
        {
            UserMealProfile mealProfile = null;
            if (IfValidParameters(userMeal, userName, userData))
            {
                mealProfile = CreaeteFromMealAndUserData(userMeal, userName, userData);
            }

            if (mealProfile != null)
            {
                UserMealProfileUtilities.AddUserMealProfileToDB(mealProfile);
                log.InfoFormat("[SaveDataInUserMealProfile] Saved UserMealProfile Id={0}, userMeal.Id={1}, userName={2}.",
                    mealProfile.Id.ToString(), userMeal.Id.ToString(), userName);
            }
            else log.ErrorFormat("[SaveDataInUserMealProfile] Error: Created mealProfile was null.");
        }
        public void CheckIfFullfiledRequirementTest_ShouldCheckListWhichAlredyContainThisMedalAndReturnEmptyMedalList()
        {
            //Arrange
            SpontaneousUserModel userModelWithMedal = new SpontaneousUserModel()
            {
                UserMedalsList = new List<UserMedal>()
            };
            userModelWithMedal.UserMedalsList.Add(new WelcomeUserMedal());
            UserActivity userActivity = new PageViewActivity("TestPage");

            //Act
            MedalRequirementsChecker medalChecker = new PlatefulMedalRequirementChecker();
            List<UserMedal> userModelWithMedalResult = medalChecker.ObtainMedalBecauseOfActivity(userModelWithMedal, userActivity);

            //Assert
            Assert.AreEqual(userModelWithMedalResult.Count, 0);
        }
        public List<MedalProgress> getMedalProgresses(SpontaneousUserModel userStatistic)
        {
            List<MedalProgress> returnValue = new List<MedalProgress>();

            foreach (var item in m_activityMedalMap)
            {
                foreach (var checker in item.Value)
                {
                    string medalType = checker.MedalType;
                    //need to implement check if user allready have this type of medal
                    var specificProgress = checker.GetProgress(userStatistic);
                    if (specificProgress != null)
                        returnValue.Add(specificProgress);
                }
            }
            return returnValue;
        }
 public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
 {
     if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
     {
         //1 Still not acquired check
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is WelcomeUserMedal) return null;
         }
     }
     //2 20 views
     int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
     if (avtivityCount >= 20)
     {
         // need to check if medal created with CreatedAt propertie
         UserMedal medal = new AdultUserMedal();
         return medal;
     }
     return null;
 }
        public MedalProgress getClosesMedal(SpontaneousUserModel userStatistic)
        {
            var allProgreses = getMedalProgresses(userStatistic);
            MedalProgress returnValue = null;

            if(allProgreses != null && allProgreses.Count > 0)
            {
                foreach (var progress in allProgreses)
                {
                    if (returnValue == null) returnValue = progress;
                    else
                    {
                        if (returnValue.pointsRequired > progress.pointsRequired)
                        {
                            returnValue = progress;
                        }
                    }
                }
            }
            return returnValue;
        }
        public void CheckIfFullfiledRequirementTest_ShouldCheckListWithoutThisMedalAndRequirementForThisMedalNotAchieved_MustReturnNotEmptyMedalList()
        {
            //Arrange
            SpontaneousUserModel userModelWithOutMedal = new SpontaneousUserModel()
            {
                UserActivityList = new List<UserActivity>(),
                UserMedalsList = new List<UserMedal>()
            };
            //Requirement = 3
            //for (int i = 0; i < 2; i++)
            //{
            //    userModelWithOutMedal.UserActivityList.Add(new PageViewActivity("TestPage"));
            //}
            UserActivity userActivity = new PageViewActivity("TestPage");

            //Act
            MedalRequirementsChecker medalChecker = new PlatefulMedalRequirementChecker();
            List<UserMedal> userModelWithMedalResult = medalChecker.ObtainMedalBecauseOfActivity(userModelWithOutMedal, userActivity);

            //Assert
            Assert.AreEqual(userModelWithMedalResult.Count, 0);
        }
        public UserMealProfile CreaeteFromMealAndUserData(Meal userMeal, string userName, SpontaneousUserModel userData)
        {
            log.InfoFormat("[CreaeteFromMealAndUserData] userMeal.Id={0}, userName={1}.", userMeal.Id.ToString(), userName);
            UserMealProfile mealProfile = new UserMealProfile()
            {
                MealId = userMeal.Id,
                UserName = userName,
                ExpectedCarbsAmount = userMeal.CarbAmount
            };

            if (userData.BaseInsulinCalcProfile != null)
            {
                mealProfile.UserInsulinProfile = userData.BaseInsulinCalcProfile;
                AlgorithmCalculations.AlgorithmResult algResult =  AlgorithmCalculations.CalcMealCarbsDeviation(userMeal, mealProfile.UserInsulinProfile);
                if (algResult.Status == "Success")
                {
                    mealProfile.CalculatedCarbsDeviation = algResult.Result;
                    mealProfile.MealCarbsAmount = mealProfile.ExpectedCarbsAmount + mealProfile.CalculatedCarbsDeviation;
                }
            }
            return mealProfile;
        }
        public void CheckIfFullfiledRequirementTest_ShouldCheckListWithOtherMedalAndReturnNotEmptyMedalList()
        {
            //Arrange
            SpontaneousUserModel userModelWithOtherMedal = new SpontaneousUserModel()
            {
                UserActivityList = new List<UserActivity>(),
                UserMedalsList = new List<UserMedal>()
            };
            for (int i = 0; i < 3; i++)
            {
                userModelWithOtherMedal.UserActivityList.Add(new PageViewActivity("TestPage"));
            }
            userModelWithOtherMedal.UserMedalsList.Add(new AddRestaurantMedal());
            UserActivity userActivity = new PageViewActivity("TestPage");

            //Act
            MedalRequirementsChecker medalChecker = new PlatefulMedalRequirementChecker();
            List<UserMedal> userModelWithOtherMedalResult = medalChecker.ObtainMedalBecauseOfActivity(userModelWithOtherMedal, userActivity);

            //Assert
            Assert.AreNotEqual(userModelWithOtherMedalResult.Count, 0);
        }
        public override MedalProgress GetProgress(SpontaneousUserModel statistic)
        {
            if (!IfAlreadyHave(statistic))
            {
                MedalProgress returnValue = new MedalProgress()
                {
                    MedalType = MedalType,
                    totalPointsRequired = 0,
                    pointsRequired = 0
                };
                //Calculate total points required for the medal
                foreach (var requirement in RequirementsList)
                {
                    returnValue.totalPointsRequired += requirement.Activity.Points * requirement.Count;
                }

                returnValue.pointsRequired = returnValue.totalPointsRequired;

                if (statistic != null && statistic.UserActivityList != null)
                {
                    //Calculate points still required for the medal
                    bool PageViewActivityFlag = false;
                    foreach (UserActivity userActivity in statistic.UserActivityList)
                    {
                        if (userActivity is PageViewActivity)
                        {
                            if (!PageViewActivityFlag)
                            {
                                returnValue.pointsRequired -= userActivity.Points;
                                PageViewActivityFlag = true;
                            }
                        }
                    }
                    // if points grater then required
                    if (returnValue.pointsRequired < 0) returnValue.pointsRequired = 0;
                }
                return returnValue;
            }
            return null;
        }
Beispiel #17
0
 public static SpontaneousUserModel GetUserData(this ProfileBase userData)
 {
     SpontaneousUserModel returnValue = null;
     var userDataObejct = userData.GetPropertyValue(C_UserProfilDataId_Name);
     if (userDataObejct != null)
     {
         returnValue = FetchUserData((Guid)userDataObejct);
     }
     else
     {
         returnValue = new SpontaneousUserModel();
         returnValue.id = Guid.NewGuid();
     }
     return returnValue;
 }
 public UserMedal getLastMedal(SpontaneousUserModel statistic)
 {
     UserMedal returnValue = new RestaurantAdviserMedal();
     returnValue.CreatedAt = new DateTime(0);
     if (statistic != null && statistic.UserMedalsList != null && IfAlreadyHave(statistic))
     {
         var adviserMedalList = statistic.UserMedalsList.Where(c => c is RestaurantAdviserMedal);
         if (adviserMedalList != null)
         {
             returnValue = adviserMedalList.OrderBy(o => o.CreatedAt).ToList().LastOrDefault();
         }
     }
     log.DebugFormat("[RestaurantAdviserChecker]: getLastMedal, CreatedAt={0}", returnValue.CreatedAt);
     return returnValue;
 }
Beispiel #19
0
        public void GetCouponForMedal_Should_ResiveUserDataAndFindNearestCouponAccordinlyToActivityLocation()
        {
            CouponType tempCoupon1 = new CouponType()
            {
                Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "11111" },
                LocationsList = new List<Location>() { new Location(1,1) }
            };
            CouponType tempCoupon2 = new CouponType()
            {
                Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "22222" },
                LocationsList = new List<Location>() { new Location(0,0) }
            };
            CouponType tempCoupon3 = new CouponType()
            {
                Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "33333" },
                LocationsList = new List<Location>() { new Location(1,1) }
            };
            CouponType tempCoupon4 = new CouponType()
            {
                Description = "1+1 על כל בירה מהחבית במסעדת Red Burger Bar, כל יום עד שעה 19:00.",
                RestaurantsIDs = new List<string>() { "44444" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(1,1) }
            };
            CouponType tempCoupon5 = new CouponType()
            {
                Description = "1+1 על סטייק אנטריקוט, בהזמנה מנה עיקרית ושתייה, במסעדת Red Burger Bar.",
                RestaurantsIDs = new List<string>() { "55555" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(32.067141, 34.804314) }
            };
            CouponType tempCoupon6 = new CouponType()
            {
                Description = "מנת ילד חינם בהזמנה מנה עיקרית למבוגר במסעדת Palamida, ביום שישי 12:00-16:00",
                RestaurantsIDs = new List<string>() { "66666" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(0, 1) }
            };
            CouponType tempCoupon7 = new CouponType()
            {
                Description = "ארוחה זוגית ב- 200 שח הארוחה כוללת: - 2 כוסות יין הבית - 2 מרק + לחם הבית - מיקס פירות ים, במסעדת Palamida.",
                RestaurantsIDs = new List<string>() { "77777" },
                ValidFrom = DateTime.UtcNow,
                ValidUntil = new DateTime(2014, 1, 31),
                LocationsList = new List<Location>() { new Location(1, 1) }
            };
            string savedCouponId1 = serviceLayer.AddCouponToDB(tempCoupon1);
            string savedCouponId2 = serviceLayer.AddCouponToDB(tempCoupon2);
            string savedCouponId3 = serviceLayer.AddCouponToDB(tempCoupon3);
            string savedCouponId4 = serviceLayer.AddCouponToDB(tempCoupon4);
            string savedCouponId5 = serviceLayer.AddCouponToDB(tempCoupon5);
            string savedCouponId6 = serviceLayer.AddCouponToDB(tempCoupon6);
            string savedCouponId7 = serviceLayer.AddCouponToDB(tempCoupon7);

            UserActivity activity1 = new PageViewActivity("test") { ActivityLocation = new Location(1, 1) };
            UserActivity activity2 = new PageViewActivity("test") { ActivityLocation = new Location(32.067141, 34.804314) };

            SpontaneousUserModel userModel = new SpontaneousUserModel()
            {
                UserMedalsList = new List<UserMedal>()
            };
            userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon1 });
            userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon2 });
            userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon3 });
            userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon4 });

            //Act
            CouponType coupon1 = serviceLayer.GetCoupon(userModel, activity1);
            CouponType coupon2 = serviceLayer.GetCoupon(userModel, activity2);

            // clean DB from temp coupons
            serviceLayer.DeleteCoupon(savedCouponId1);
            serviceLayer.DeleteCoupon(savedCouponId2);
            serviceLayer.DeleteCoupon(savedCouponId3);
            serviceLayer.DeleteCoupon(savedCouponId4);
            serviceLayer.DeleteCoupon(savedCouponId5);
            serviceLayer.DeleteCoupon(savedCouponId6);
            serviceLayer.DeleteCoupon(savedCouponId7);

            //Assert
            Assert.IsNotNull(coupon1);
            //Assert.AreNotEqual(coupon.Id, tempCoupon1.Id);

            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId1);
            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId2);
            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId3);
            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId4);
            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId5);
            Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId6);
            Assert.AreEqual(coupon1.Id.ToString(), savedCouponId7);
            Assert.AreEqual(coupon1.Description, tempCoupon7.Description);
        }
        public override MedalProgress GetProgress(SpontaneousUserModel statistic)
        {
            //if (!IfAlreadyHave(statistic))
            //{
                UserMedal currentMedal = new FlowCompleteMedal();
                currentMedal.CreatedAt = new DateTime(0);
                if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
                {
                    currentMedal = getLastMedal(statistic);
                }

                MedalProgress returnValue = new MedalProgress()
                {
                    MedalType = MedalType,
                };
                //Calculate total points required for the medal
                foreach (var requirement in RequirementsList)
                {
                    returnValue.totalPointsRequired += requirement.Activity.Points * requirement.Count;
                }

                returnValue.pointsRequired = returnValue.totalPointsRequired;

                if (statistic != null && statistic.UserActivityList != null)
                {
                    //Calculate points still required for the medal
                    bool RestaurantMenuEnterActivityFlag = false;
                    bool MenuLinkPushActivityFlag = false;
                    bool ApproveMealPushActivityFlag = false;
                    bool SendMealSummaryActivityFlag = false;
                    bool PreMealSugarApproveActivityFlag = false;
                    bool PostMealSugarApproveActivityFlag = false;
                    bool PostMealCarbBlameActivityFlag = false;
                    foreach (UserActivity userActivity in statistic.UserActivityList)
                    {
                        if (userActivity.Date > currentMedal.CreatedAt)
                        {
                            SpontaneousMedalRequirementChecker.ActivityType type =
                                (SpontaneousMedalRequirementChecker.ActivityType)System.Enum.Parse(typeof(SpontaneousMedalRequirementChecker.ActivityType), userActivity.GetType().Name);
                            //int activityType = (int)type;
                            var dateDiff = (DateTime.UtcNow - userActivity.Date).TotalDays;

                            switch (type)
                            {
                                case SpontaneousMedalRequirementChecker.ActivityType.PageViewActivity:
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.RestaurantMenuEnterActivity:
                                    if (!RestaurantMenuEnterActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired =
                                            returnValue.pointsRequired -= userActivity.Points;
                                        RestaurantMenuEnterActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.MenuLinkPushActivity:
                                    if (!MenuLinkPushActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        MenuLinkPushActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.ApproveMealPushActivity:
                                    if (!ApproveMealPushActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        ApproveMealPushActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.SendMealSummaryActivity:
                                    if (!SendMealSummaryActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        SendMealSummaryActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.PreMealSugarApproveActivity:
                                    if (!PreMealSugarApproveActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        PreMealSugarApproveActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.PostMealSugarApproveActivity:
                                    if (!PostMealSugarApproveActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        PostMealSugarApproveActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.PostMealCarbBlameActivity:
                                    if (!PostMealCarbBlameActivityFlag && dateDiff < 1)
                                    {
                                        returnValue.pointsRequired -= userActivity.Points;
                                        PostMealCarbBlameActivityFlag = true;
                                    }
                                    break;
                                case SpontaneousMedalRequirementChecker.ActivityType.MedalViewActivity:
                                    break;
                                default:
                                    break;
                            }

                        }//if (userActivity.Date > currentMedal.CreatedAt)
                    }
                    if (returnValue.pointsRequired < 0) returnValue.pointsRequired = 0;
                }
                return returnValue;
            //}
            //return null;
        }
 public override bool IfAlreadyHave(SpontaneousUserModel statistic)
 {
     if (statistic != null && statistic.UserMedalsList != null)
     {
         foreach (UserMedal medal in statistic.UserMedalsList)
         {
             if (medal is AddRestaurantMedal) return true;
         }
     }
     return false;
 }
 public abstract UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity);
Beispiel #23
0
 private static void UpsertUserModel(SpontaneousUserModel usermodel)
 {
     using (CrawledRecipes recipesDb = new CrawledRecipes())
     {
         MongoEntityRepositoryBase<SpontaneousUserModel> basicData =
             new MongoEntityRepositoryBase<SpontaneousUserModel>(recipesDb.DB);
         basicData.Upsert(usermodel);
     }
 }
        public override UserMedal CheckIfFullfiledRequirement(SpontaneousUserModel statistic, UserActivity activity)
        {
            if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
            {
                if (IfAlreadyHave(statistic)) return null;
            }

            //int avtivityCount = statistic.GetActivityCount(activity.GetType().Name);
            //if (avtivityCount >= RequirementsList[0].Count)
            //{
            //    UserMedal medal = new WelcomeUserMedal();
            //    log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", avtivityCount);
            //    return medal;
            //}
            string activityName = activity.GetType().Name;
            int activityCount = 0;
            if (activity is MedalViewActivity)
            {
                activityCount = statistic.GetActivityCount(activityName, ((MedalViewActivity)activity).MedalType);
            }
            else
            {
                activityCount = statistic.GetActivityCount(activityName);
            }

            //Check if current activity is in requirement list
            if (RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName) != null)
            {
                if (activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count)
                {
                    //Current activity is meets requirement
                    //Check if meets other requirements necessary for the medal
                    foreach (var requirement in RequirementsList)
                    {
                        activityName = requirement.Activity.GetType().Name;
                        //avtivityCount = statistic.GetActivityCount(activityName);
                        if (requirement.Activity is MedalViewActivity)
                        {
                            activityCount = statistic.GetActivityCount(activityName, "WelcomeUserMedal");
                        }
                        else
                        {
                            activityCount = statistic.GetActivityCount(activityName);
                        }
                        if (!(activityCount >= RequirementsList.FirstOrDefault(r => r.Activity.GetType().Name == activityName).Count))
                        {
                            log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", activityCount);
                            return null;
                        }
                    }
                    UserMedal medal = new WelcomeUserMedal();
                    log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Win WelcomeUser Medal. avtivityCount={0}", activityCount);
                    return medal;
                }
            }
            else
            {
                log.InfoFormat("[WelcomeUserChecker: CheckIfFullfiledRequirement] Still not win WelcomeUser Medal. avtivityCount={0}", activityCount);
            }
            return null;
        }
        public override MedalProgress GetProgress(SpontaneousUserModel statistic)
        {
            //if (!IfAlreadyHave(statistic))
            //{
                UserMedal currentMedal = new RestaurantAdviserMedal();
                currentMedal.CreatedAt = new DateTime(0);
                if (statistic.UserMedalsList != null && statistic.UserMedalsList.Count > 0)
                {
                    currentMedal = getLastMedal(statistic);
                }

                MedalProgress returnValue = new MedalProgress()
                {
                    MedalType = MedalType,
                };
                //Calculate total points required for the medal
                foreach (var requirement in RequirementsList)
                {
                    returnValue.totalPointsRequired += requirement.Activity.Points * requirement.Count;
                }

                returnValue.pointsRequired = returnValue.totalPointsRequired;

                if (statistic != null && statistic.UserActivityList != null)
                {
                    //Calculate points still required for the medal
                    bool inviteFriendActivityFlag = false;
                    foreach (UserActivity userActivity in statistic.UserActivityList)
                    {
                        if (userActivity.Date > currentMedal.CreatedAt)
                        {
                            if (userActivity is InviteFriendActivity)
                            {
                                if (!inviteFriendActivityFlag)
                                {
                                    returnValue.pointsRequired =
                                        returnValue.pointsRequired -= userActivity.Points;
                                    inviteFriendActivityFlag = true;
                                }
                            }
                        }//if (userActivity.Date > currentMedal.CreatedAt)
                    }
                    if (returnValue.pointsRequired < 0) returnValue.pointsRequired = 0;
                }
                return returnValue;
            //}
            //return null;
        }
Beispiel #26
0
 //public static SpontaneousUserModel GetUserData(this ProfileBase userData)
 //{
 //    SpontaneousUserModel returnValue = null;
 //    var userDataObejct = userData.GetPropertyValue(C_UserProfileData_Name);
 //    if (userDataObejct != null)
 //    {
 //        returnValue = userDataObejct as SpontaneousUserModel;
 //    }
 //    else
 //    {
 //        returnValue = new SpontaneousUserModel();
 //    }
 //    return returnValue;
 //}
 //public static void SetUserData(this ProfileBase userData, SpontaneousUserModel usermodel)
 //{
 //    userData.SetPropertyValue(C_UserProfileData_Name, usermodel);
 //}
 public static void SetUserData(this ProfileBase userData, SpontaneousUserModel usermodel)
 {
     if (usermodel.id == Guid.Empty)
         usermodel.id = Guid.NewGuid();
     userData.SetPropertyValue(C_UserProfilDataId_Name, usermodel.id);
     UpsertUserModel(usermodel);
 }
Beispiel #27
0
        public void Test_Meal_BSONSerialization()
        {
            List<Meal> meals = new List<Meal>();

            var meal = new Meal()
            {
                Id = Guid.NewGuid(),

            };
            meals.Add(meal);
            SpontaneousUserModel userModel = new SpontaneousUserModel()
            {
                UserMeals = meals,
            };
            m_Testdb.GetCollection<SpontaneousUserModel>(typeof(SpontaneousUserModel).Name).Insert(userModel);
        }
Beispiel #28
0
        public void GetCouponForMedal_Should_ResiveUserDataAndDecideWhichCouponToReturn()
        {
            CouponType tempCoupon1 = new CouponType()
            {
                Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "11111" }
            };
            CouponType tempCoupon2 = new CouponType()
            {
                Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "22222" }
            };
            CouponType tempCoupon3 = new CouponType()
            {
                Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס",
                ValidFrom = new DateTime(0),
                ValidUntil = DateTime.UtcNow.AddHours(1),
                RestaurantsIDs = new List<string>() { "33333" }
            };
            string savedCouponId1 = serviceLayer.AddCouponToDB(tempCoupon1);
            string savedCouponId2 = serviceLayer.AddCouponToDB(tempCoupon2);
            string savedCouponId3 = serviceLayer.AddCouponToDB(tempCoupon3);
            SpontaneousUserModel userModel = new SpontaneousUserModel()
            {
                UserMedalsList = new List<UserMedal>()
            };
            //userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon1 });
            userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon2 });
            userModel.UserMedalsList.Add(new WelcomeUserMedal());
            userModel.UserMedalsList.Add(new RestaurantAdviserMedal());

            //Act
            CouponType coupon = serviceLayer.GetCoupon(userModel, new PageViewActivity("test"));
            serviceLayer.DeleteCoupon(savedCouponId1);
            serviceLayer.DeleteCoupon(savedCouponId2);
            serviceLayer.DeleteCoupon(savedCouponId3);

            //Assert
            Assert.IsNotNull(coupon);
            //Assert.AreNotEqual(coupon.Id, tempCoupon1.Id);
            Assert.AreNotEqual(coupon.Id, tempCoupon2.Id);
        }
        public override MedalProgress GetProgress(SpontaneousUserModel statistic)
        {
            if (!IfAlreadyHave(statistic))
            {
                MedalProgress returnValue = new MedalProgress()
                {
                    MedalType = MedalType,
                    totalPointsRequired = 0,
                    pointsRequired = 0
                };
                //Calculate total points required for the medal
                foreach (var requirement in RequirementsList)
                {
                    returnValue.totalPointsRequired += requirement.Activity.Points * requirement.Count;
                }

                returnValue.pointsRequired = returnValue.totalPointsRequired;

                if (statistic != null && statistic.UserActivityList != null)
                {
                    //Calculate points still required for the medal
                    foreach (var userActivity in statistic.UserActivityList)
                    {
                        if (userActivity is AddRestaurantActivity)
                        {
                            returnValue.pointsRequired = returnValue.totalPointsRequired - statistic.GetActivityCount(userActivity.GetType().Name) * userActivity.Points;
                        }
                    }
                    if (returnValue.pointsRequired < 0) returnValue.pointsRequired = 0;
                }
                return returnValue;
            }
            return null;
        }
 public UserMedal getLastMedal(SpontaneousUserModel statistic)
 {
     UserMedal returnValue = new FlowCompleteMedal();
     returnValue.CreatedAt = new DateTime(0);
     if (statistic != null && statistic.UserMedalsList != null && IfAlreadyHave(statistic))
     {
         var flowMedalList = statistic.UserMedalsList.Where(c => c is FlowCompleteMedal);
         if (flowMedalList != null) {
             returnValue = flowMedalList.OrderBy(o => o.CreatedAt).ToList().LastOrDefault();
         }
     }
     log.DebugFormat("[FlowCompleteChecker: getLastMedal, CreatedAt={0}", returnValue.CreatedAt);
     return returnValue;
 }