Exemplo n.º 1
0
        protected float EvaluateBool(int gameId, int actorId, EvaluationCriteria completionCriteria)
        {
            var evaluationDataController = new EvaluationDataController(EvaluationDataLogger, ContextFactory, completionCriteria.EvaluationDataCategory);

            switch (completionCriteria.CriteriaQueryType)
            {
            case CriteriaQueryType.Any:
                var any = evaluationDataController.List(gameId, actorId, completionCriteria.EvaluationDataKey, EvaluationDataType.Boolean);
                return(!any.Any() ? 0 : any.Max(value => CompareValues(bool.Parse(value.Value), bool.Parse(completionCriteria.Value), completionCriteria.ComparisonType, completionCriteria.EvaluationDataType)));

            case CriteriaQueryType.Latest:
                if (!evaluationDataController.TryGetLatest(gameId, actorId, completionCriteria.EvaluationDataKey, out var latest, EvaluationDataType.Boolean))
                {
                    return(0);
                }
                return(CompareValues(bool.Parse(latest.Value), bool.Parse(completionCriteria.Value), completionCriteria.ComparisonType, completionCriteria.EvaluationDataType));

            case CriteriaQueryType.Count:
                var count = evaluationDataController.List(gameId, actorId, completionCriteria.EvaluationDataKey, EvaluationDataType.Boolean).Count;
                return(CompareValues(count, long.Parse(completionCriteria.Value), completionCriteria.ComparisonType, EvaluationDataType.Long));

            default:
                return(0);
            }
        }
Exemplo n.º 2
0
        public static EvaluationData ComposeEvaluationData(int actorId, EvaluationCriteria evaluationCriteria, int gameId, string value = "50")
        {
            return(new EvaluationData
            {
                Key = evaluationCriteria.EvaluationDataKey,
                EvaluationDataType = evaluationCriteria.EvaluationDataType,

                ActorId = actorId,
                GameId = gameId,

                Value = value
            });
        }
Exemplo n.º 3
0
        protected float EvaluateManyBool(int gameId, List <int> actors, EvaluationCriteria completionCriteria)
        {
            var evaluationDataController = new EvaluationDataController(EvaluationDataLogger, ContextFactory, completionCriteria.EvaluationDataCategory);

            switch (completionCriteria.CriteriaQueryType)
            {
            case CriteriaQueryType.Count:
                var count = actors
                            .Sum(actorId => evaluationDataController
                                 .List(gameId, actorId, completionCriteria.EvaluationDataKey, EvaluationDataType.Boolean)
                                 .Count);
                return(CompareValues(count, long.Parse(completionCriteria.Value), completionCriteria.ComparisonType, EvaluationDataType.Long));

            default:
                return(0);
            }
        }
Exemplo n.º 4
0
        protected float Evaluate(int gameId, int actorId, EvaluationCriteria completionCriteria, ActorType actorType, EvaluationType evaluationType)
        {
            switch (completionCriteria.Scope)
            {
            case CriteriaScope.Actor:
                switch (completionCriteria.EvaluationDataType)
                {
                case EvaluationDataType.Boolean:
                    return(EvaluateBool(gameId, actorId, completionCriteria));

                case EvaluationDataType.String:
                    return(EvaluateString(gameId, actorId, completionCriteria));

                case EvaluationDataType.Float:
                    return(EvaluateFloat(gameId, actorId, completionCriteria));

                case EvaluationDataType.Long:
                    return(EvaluateLong(gameId, actorId, completionCriteria));

                default:
                    return(0);
                }

            case CriteriaScope.RelatedUsers:
                var relatedUsers = RelationshipCoreController.GetRelatedActors(actorId, ActorType.User).Select(a => a.Id).ToList();
                if (actorType == ActorType.User)
                {
                    relatedUsers.Add(actorId);
                    relatedUsers = relatedUsers.Distinct().ToList();
                }
                switch (completionCriteria.EvaluationDataType)
                {
                case EvaluationDataType.Boolean:
                    return(EvaluateManyBool(gameId, relatedUsers, completionCriteria));

                case EvaluationDataType.String:
                    return(EvaluateManyString(gameId, relatedUsers, completionCriteria));

                case EvaluationDataType.Float:
                    return(EvaluateManyFloat(gameId, relatedUsers, completionCriteria));

                case EvaluationDataType.Long:
                    return(EvaluateManyLong(gameId, relatedUsers, completionCriteria));

                default:
                    return(0);
                }

            case CriteriaScope.RelatedGroups:
                if (actorType == ActorType.User)
                {
                    throw new NotImplementedException("RelatedGroups Scope is only implemented for groups");
                }
                var relatedGroups = RelationshipCoreController.GetRelatedActors(actorId, ActorType.Group).Select(a => a.Id).ToList();
                relatedGroups.Add(actorId);
                relatedGroups = relatedGroups.Distinct().ToList();
                switch (completionCriteria.EvaluationDataType)
                {
                case EvaluationDataType.Boolean:
                    return(EvaluateManyBool(gameId, relatedGroups, completionCriteria));

                case EvaluationDataType.String:
                    return(EvaluateManyString(gameId, relatedGroups, completionCriteria));

                case EvaluationDataType.Float:
                    return(EvaluateManyFloat(gameId, relatedGroups, completionCriteria));

                case EvaluationDataType.Long:
                    return(EvaluateManyLong(gameId, relatedGroups, completionCriteria));

                default:
                    return(0);
                }

            case CriteriaScope.RelatedGroupUsers:
                if (actorType == ActorType.User)
                {
                    throw new NotImplementedException("RelatedGroupUsers Scope is only implemented for groups");
                }
                var groups = RelationshipCoreController.GetRelatedActors(actorId, ActorType.Group).Select(a => a.Id).ToList();
                groups.Add(actorId);
                groups = groups.Distinct().ToList();
                var relatedGroupUsers = groups.SelectMany(g => RelationshipCoreController.GetRelatedActors(g, ActorType.User).Select(a => a.Id)).Distinct().ToList();
                switch (completionCriteria.EvaluationDataType)
                {
                case EvaluationDataType.Boolean:
                    return(EvaluateManyBool(gameId, relatedGroupUsers, completionCriteria));

                case EvaluationDataType.String:
                    return(EvaluateManyString(gameId, relatedGroupUsers, completionCriteria));

                case EvaluationDataType.Float:
                    return(EvaluateManyFloat(gameId, relatedGroupUsers, completionCriteria));

                case EvaluationDataType.Long:
                    return(EvaluateManyLong(gameId, relatedGroupUsers, completionCriteria));

                default:
                    return(0);
                }

            default:
                return(0);
            }
        }