Beispiel #1
0
 private async Task FillUsers()
 {
     var personQuality = new PersonQuality {
         Id = "PersonQuality1", Name = "Холерик"
     };
     var personQualityWithScore = new PersonQualityIdWithScore {
         PersonQualityId = personQuality.Id, Score = 2
     };
     var repo = IocConfig.GetConfiguredContainer().Resolve <IUserRepository>();
     await
     repo.AddUser(
         new User
     {
         Id                        = "User1Id",
         AvatarUrl                 = "http://cs540104.vk.me/c540102/v540102420/e88c/P64liS_pPNk.jpg",
         DateOfBirth               = new DateTime(1990, 1, 1),
         NickName                  = "John",
         HomeCoordinate            = new GeoCoordinate(53.9, 27.56667, 199),
         KindScale                 = 87,
         Points                    = 120,
         EnablePushNotifications   = true,
         Level                     = 7,
         Sex                       = Sex.Male,
         PersonQualitiesWithScores = new List <PersonQualityIdWithScore> {
             personQualityWithScore
         }
     });
 }
Beispiel #2
0
        /// <summary>
        ///     Updates the user after answering question.
        /// </summary>
        /// <param name="questionsOptions">The questions options.</param>
        /// <param name="user">The user.</param>
        public static void UpdateUserAfterAnsweringQuestion(PersonQualityIdWithScore[] questionsOptions, User user)
        {
            user.PersonQualitiesWithScores = user.PersonQualitiesWithScores ?? new List <PersonQualityIdWithScore>();

            foreach (var questionOption in questionsOptions)
            {
                var existingScore =
                    user.PersonQualitiesWithScores.FirstOrDefault(score => score.PersonQualityId == questionOption.PersonQualityId);
                if (existingScore == null)
                {
                    existingScore = new PersonQualityIdWithScore {
                        PersonQualityId = questionOption.PersonQualityId
                    };
                    user.PersonQualitiesWithScores.Add(existingScore);
                }
                existingScore.Score = questionOption.Score;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Converts to domain.
        /// </summary>
        /// <returns>Question.</returns>
        internal Question ConvertToDomain()
        {
            var question = new Question {
                Id = Id, Name = Name, Text = Text,
            };

            if (QuestionOptions != null)
            {
                var options = QuestionOptions.Select(
                    t =>
                {
                    var option = new QuestionOption
                    {
                        Number         = t.Number,
                        Text           = t.Text,
                        NextQuestionId = t.NextQuestionId,
                    };
                    if (t.PersonQualitiesWithScores != null)
                    {
                        option.PersonQualitiesWithScores =
                            t.PersonQualitiesWithScores.Where(ptws => ptws.PersonQualityId != null)
                            .GroupBy(ptws => ptws.PersonQualityId)
                            .Select(grp => grp.First())
                            .Select(
                                ptws =>
                        {
                            var personQualityWithScore = new PersonQualityIdWithScore
                            {
                                PersonQualityId = ptws.PersonQualityId,
                                Score           = ptws.Score
                            };
                            return(personQualityWithScore);
                        }).ToList();
                    }
                    return(option);
                }).ToList();

                question.Options = options;
            }

            return(question);
        }
Beispiel #4
0
        /// <summary>
        /// Converts to domain.
        /// </summary>
        /// <returns>
        /// MissionDraft.
        /// </returns>
        internal new MissionDraft ConvertToDomain()
        {
            var draft = new MissionDraft
            {
                AddDate        = AddDate,
                AgeFrom        = AgeFrom,
                AgeTo          = AgeTo,
                Author         = Author,
                CorrectAnswers = CorrectAnswers,
                Description    = Description,
                Difficulty     = Difficulty,
                Id             = Id,
                Name           = Name,
                PhotoUrl       = PhotoUrl
            };

            if (PersonQualitiesWithScores != null)
            {
                draft.PersonQualities =
                    PersonQualitiesWithScores.Where(ptws => ptws.PersonQualityId != null)
                    .GroupBy(ptws => ptws.PersonQualityId)
                    .Select(grp => grp.First())
                    .Select(
                        ptws =>
                {
                    var personQualityWithScore = new PersonQualityIdWithScore
                    {
                        PersonQualityId = ptws.PersonQualityId,
                        Score           = ptws.Score
                    };
                    return(personQualityWithScore);
                }).ToList();
            }

            return(draft);
        }
Beispiel #5
0
        /// <summary>
        /// Excecutes the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns>OperationResult.</returns>
        public async Task <OperationResult> Excecute(params object[] args)
        {
            var repo = IocConfig.GetConfiguredContainer().Resolve <IUserRepository>();
            var missionRepository     = IocConfig.GetConfiguredContainer().Resolve <IMissionRepository>();
            var kindActionsRepository = IocConfig.GetConfiguredContainer().Resolve <IKindActionRepository>();

            var usersToUpdate = await repo.GetUsers(new QueryOptions <User>() { Expand = new List <string> {
                                                                                    "PersonQualities"
                                                                                } });

            var missions = await missionRepository.GetMissions(new QueryOptions <Mission>() { Expand = new List <string> {
                                                                                                  "PersonQualities"
                                                                                              } });

            foreach (var user in usersToUpdate)
            {
                var lightScore = user.PersonQualitiesWithScores?.FirstOrDefault(q => q.PersonQualityId == GameConstants.PersonQuality.LightQualityId);
                if (lightScore == null)
                {
                    lightScore = new PersonQualityIdWithScore {
                        PersonQualityId = GameConstants.PersonQuality.LightQualityId
                    };
                    if (user.PersonQualitiesWithScores == null)
                    {
                        user.PersonQualitiesWithScores = new List <PersonQualityIdWithScore>();
                    }
                    user.PersonQualitiesWithScores.Add(lightScore);
                }
                lightScore.Score = 0;
                if (user.CompletedMissionIds.AnyValues())
                {
                    foreach (var missionId in user.CompletedMissionIds)
                    {
                        var mission           = missions.First(m => m.Id == missionId);
                        var missionLightScore = mission.PersonQualities?.FirstOrDefault(pq => pq.PersonQualityId == GameConstants.PersonQuality.LightQualityId);
                        if (missionLightScore != null)
                        {
                            lightScore.Score += missionLightScore.Score;
                        }
                    }
                }
                if (user.FailedMissionIds.AnyValues())
                {
                    foreach (var missionId in user.FailedMissionIds)
                    {
                        var mission           = missions.First(m => m.Id == missionId);
                        var missionLightScore = mission.PersonQualities?.FirstOrDefault(pq => pq.PersonQualityId == GameConstants.PersonQuality.LightQualityId);
                        if (missionLightScore != null)
                        {
                            lightScore.Score -= missionLightScore.Score;
                        }
                    }
                }

                await kindActionsRepository.RemoveDuplicateKindActions(user.Id);

                var userKindActionsCount =
                    await kindActionsRepository.GetKindActions(
                        new QueryOptions <KindAction> {
                    Filter = (kindAction) => kindAction.UserId == user.Id
                });

                lightScore.Score += userKindActionsCount.Count * GameConstants.PersonQuality.IncreasePerKindAction;
                if (lightScore.Score > 0)
                {
                    await repo.UpdateUser(user);
                }
            }
            return(new OperationResult(OperationResultStatus.Success));
        }
Beispiel #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="UserRepository" /> class.
        /// </summary>
        public UserRepository()
        {
            if (!_allUsers.Any())
            {
                var personQuality = new PersonQuality
                {
                    Id   = GameConstants.PersonQuality.ActivityQualityId,
                    Name = "Активность"
                };
                var personQualityWithScore = new PersonQualityIdWithScore
                {
                    PersonQualityId = personQuality.Id,
                    Score           = -2
                };
                var personQuality2 = new PersonQuality
                {
                    Id   = GameConstants.PersonQuality.CommunicationQualityId,
                    Name = "Коммуникативность"
                };
                var personQualityWithScore2 = new PersonQualityIdWithScore
                {
                    PersonQualityId = personQuality2.Id,
                    Score           = 2
                };

                _allUsers.Add(
                    new User
                {
                    Id                       = "User1Id",
                    AvatarUrl                = "http://cs540104.vk.me/c540102/v540102420/e88c/P64liS_pPNk.jpg",
                    DateOfBirth              = new DateTime(1990, 1, 1),
                    NickName                 = "John",
                    HomeCoordinate           = new GeoCoordinate(53.9, 27.56667, 199),
                    BaseSouthCoordinate      = new GeoCoordinate(53.897863, 27.566649),
                    BaseWestCoordinate       = new GeoCoordinate(53.899994, 27.562583),
                    BaseEastCoordinate       = new GeoCoordinate(53.900019, 27.570415),
                    BaseNorthCoordinate      = new GeoCoordinate(53.902503, 27.566606),
                    Selected2BaseCoordinates = new List <string> {
                        "East", "North"
                    },
                    RadarCoordinate         = new GeoCoordinate(53.900493, 27.567513),
                    KindScale               = 87,
                    Points                  = 120,
                    EnablePushNotifications = true,
                    Level                     = 7,
                    LevelPoints               = 50,
                    Sex                       = Sex.Male,
                    RadrugaColor              = "e27b2f",
                    CityShortName             = "Brest",
                    CountryShortName          = "Belarus",
                    PersonQualitiesWithScores =
                        new List <PersonQualityIdWithScore>
                    {
                        personQualityWithScore,
                        personQualityWithScore2
                    },
                    ActiveMissionIds =
                        new List <MissionIdWithSetId>
                    {
                        new MissionIdWithSetId {
                            MissionId = "Mission1"
                        },
                        new MissionIdWithSetId {
                            MissionId = "fe9b1f3a-059b-4b4e-8f08-0a22a21a1ed0"
                        },
                        new MissionIdWithSetId {
                            MissionId = "3c27b903-cf03-447e-9682-f756e70ca908"
                        },
                        new MissionIdWithSetId {
                            MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd5d"
                        },
                        new MissionIdWithSetId {
                            MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd6d"
                        },
                        new MissionIdWithSetId {
                            MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd7d"
                        },
                        new MissionIdWithSetId {
                            MissionId = "33f075f4-4e8c-47bc-b0d7-9661f4ecdd8d"
                        },
                        new MissionIdWithSetId {
                            MissionId = "2ddf9168-b030-4b6c-a038-72593e7a75f1"
                        },
                        new MissionIdWithSetId {
                            MissionId = "2ddf9168-b030-4b6c-a038-72593e7a75f2"
                        },
                        new MissionIdWithSetId {
                            MissionId = "d061155a-9504-498d-a6e7-bcc20c295cde"
                        },
                        new MissionIdWithSetId {
                            MissionId = "8ab5fa9b-15a7-49ec-8d5f-2a47d4affd52"
                        },
                        new MissionIdWithSetId {
                            MissionId = "71130d2e-e513-4b29-ad12-7a368f4d927a"
                        },
                        new MissionIdWithSetId {
                            MissionId = "19e18c3f-2daa-4e18-bf32-2a1f77fdc73f"
                        },
                        new MissionIdWithSetId {
                            MissionId = "b23f79fe-08d3-4d24-a293-51f67e2131be"
                        },
                        new MissionIdWithSetId {
                            MissionId = "524b9f98-88b2-460a-ae3f-e15df4cef2ae"
                        },
                        new MissionIdWithSetId {
                            MissionId = "2c187275-97c0-4dcf-a1f0-89d7018a03e2"
                        },
                        new MissionIdWithSetId {
                            MissionId = "3be2d03c-f100-42be-bc9f-54166e108d43"
                        },
                        new MissionIdWithSetId {
                            MissionId = "8c67c3de-5458-4c6a-a09e-be2d06cdcb2e"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d3"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d4"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d5"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d6"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c17d7"
                        },
                        new MissionIdWithSetId {
                            MissionId = "68d75498-e44f-4bf8-a2ee-13b4998c1725"
                        },
                        new MissionIdWithSetId {
                            MissionId = "5823973e-ac62-4efe-9c5d-1755df874d99"
                        }
                    },
                    ActiveMissionSetIds =
                        new List <string>
                    {
                        GameConstants.MissionSet.FirstSetId, GameConstants.MissionSet.SecondSetId,
                        GameConstants.MissionSet.ThirdSetId
                    },
                    MissionSetIds =
                        new List <MissionSetIdWithOrder>
                    {
                        new MissionSetIdWithOrder
                        {
                            MissionSetId =
                                GameConstants.MissionSet.FirstSetId,
                            Order = 0
                        },
                        new MissionSetIdWithOrder
                        {
                            MissionSetId =
                                GameConstants.MissionSet.SecondSetId,
                            Order = 1
                        },
                        new MissionSetIdWithOrder
                        {
                            MissionSetId =
                                GameConstants.MissionSet.ThirdSetId,
                            Order = 2
                        }
                    }
                });
                _allUsers.Add(
                    new User
                {
                    Id                        = "User2Id",
                    AvatarUrl                 = "https://pp.vk.me/c622726/v622726000/276d6/g6W5sDwP0jc.jpg",
                    DateOfBirth               = new DateTime(1990, 1, 1),
                    NickName                  = "Jim",
                    HomeCoordinate            = new GeoCoordinate(55.5554, 28.7778),
                    KindScale                 = 87,
                    Points                    = 60,
                    EnablePushNotifications   = true,
                    Level                     = 7,
                    LevelPoints               = 50,
                    Sex                       = Sex.Male,
                    RadrugaColor              = "e27b2f",
                    PersonQualitiesWithScores =
                        new List <PersonQualityIdWithScore>
                    {
                        personQualityWithScore,
                        personQualityWithScore2
                    },
                    ActiveMissionIds =
                        new List <MissionIdWithSetId>
                    {
                        new MissionIdWithSetId {
                            MissionId = "Mission1"
                        },
                        new MissionIdWithSetId {
                            MissionId = "Mission2"
                        }
                    },
                    ActiveMissionSetIds =
                        new List <string>
                    {
                        GameConstants.MissionSet.FirstSetId, GameConstants.MissionSet.SecondSetId,
                        GameConstants.MissionSet.ThirdSetId
                    },
                    MissionSetIds =
                        new List <MissionSetIdWithOrder>
                    {
                        new MissionSetIdWithOrder
                        {
                            MissionSetId =
                                GameConstants.MissionSet.FirstSetId,
                            Order = 0
                        },
                        new MissionSetIdWithOrder
                        {
                            MissionSetId =
                                GameConstants.MissionSet.SecondSetId,
                            Order = 1
                        }
                    }
                });
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Converts to domain.
        /// </summary>
        /// <returns>Mission.</returns>
        internal Mission ConvertToDomain()
        {
            var mission = new Mission
            {
                // Common
                Id                     = Id,
                Name                   = Name,
                PhotoUrl               = PhotoUrl,
                Description            = Description,
                Difficulty             = Difficulty,
                AgeFrom                = AgeFrom,
                AgeTo                  = AgeTo,
                ExecutionType          = ExecutionType,
                DependsOn              = DependsOn,
                IsFinal                = IsFinal,
                MessageAfterCompletion = MessageAfterCompletion,
                MissionSetId           = MissionSetId,

                // Right answer type
                AnswersCount   = AnswersCount,
                ExactAnswer    = ExactAnswer,
                CorrectAnswers = CorrectAnswers,
                TriesFor1Star  = TriesFor1Star,
                TriesFor2Stars = TriesFor2Stars,
                TriesFor3Stars = TriesFor3Stars,

                // Text Creation
                MinCharsCount = MinCharsCount,

                // Photo Creation
                NumberOfPhotos = NumberOfPhotos,

                // GeoCoordinates + GeoPath
                AccuracyRadius   = AccuracyRadius,
                CommonPlaceAlias = CommonPlaceAlias,
                UserCoordinatesCalculationFunction = UserCoordinatesCalculationFunction,
                CalculationFunctionParameters      = CalculationFunctionParameters,
                SecondsFor1Star  = SecondsFor1Star,
                SecondsFor2Stars = SecondsFor2Stars,
                SecondsFor3Stars = SecondsFor3Stars,
                Hints            = Hints
            };

            if (PersonQualitiesWithScores != null)
            {
                var qualitiesWithScores =
                    PersonQualitiesWithScores.Where(ptws => ptws.PersonQualityId != null)
                    .GroupBy(ptws => ptws.PersonQualityId)
                    .Select(grp => grp.First())
                    .Select(
                        ptws =>
                {
                    var personQualityWithScore = new PersonQualityIdWithScore
                    {
                        PersonQualityId = ptws.PersonQualityId,
                        Score           = ptws.Score
                    };
                    return(personQualityWithScore);
                }).ToList();

                mission.PersonQualities = qualitiesWithScores.Any() ? qualitiesWithScores : null;
            }
            return(mission);
        }