public void Execute(dynamic jObject, UserAlgorithmStore store)
        {
            var expressionCalculator = new UserExpressionCalculator();

            SetUserAlgorithmModel model = jObject.ToObject <SetUserAlgorithmModel>();
            var value = expressionCalculator.Calculate(model.Value, store);

            store.NumverVariables[model.Variable] = value;
        }
        public void Execute(dynamic jObject, UserAlgorithmStore store)
        {
            var expressionCalculator = new UserExpressionCalculator();

            AppendUserAlgorithmModel model = jObject.ToObject <AppendUserAlgorithmModel>();
            var value = expressionCalculator.Calculate(model.Value, store);

            store.ListVariables[model.Variable].Add(value);
        }
예제 #3
0
        public List <int> GetNumberFactors(
            double number,
            dynamic algorithm,
            IUserAlgorithmStrategyProvider strategtProvider
            )
        {
            var store = new UserAlgorithmStore();
            var numberFactorsExecutor = new NumberFactorsCalculator();

            var numbers = (List <double>)numberFactorsExecutor.GetNumberFactors((int)number, algorithm, strategtProvider, store);
            var result  = numbers.Select(x => (int)x).ToList();

            return(result);
        }
예제 #4
0
        public DrawerModel[] GetDrawerData(
            dynamic algorithm,
            IUserAlgorithmStrategyProvider strategtProvider
            )
        {
            var store = new UserAlgorithmStore();
            var userGrapgicDataInitializer = new UserGraphicDataInitializer();

            dynamic userFunction        = algorithm["Function"];
            var     drawerFunctionModel = (DrawerModel)userGrapgicDataInitializer.GetGraphicDataFromFunction(userFunction, strategtProvider, store);

            dynamic userSetOfPoints        = algorithm["SetOfPoints"];
            var     drawerSetOfPointsModel = (DrawerModel)userGrapgicDataInitializer.GetGraphicDataFromSetOfPoints(userSetOfPoints, strategtProvider, store);

            return(new DrawerModel[] { drawerFunctionModel, drawerSetOfPointsModel });
        }
        public void Execute(dynamic jObject, UserAlgorithmStore store)
        {
            var expressionCalculator  = new UserExpressionCalculator();
            var numberFactorsExecutor = new NumberFactorsCalculator();

            WhileUserAlgorithmModel model = jObject.ToObject <WhileUserAlgorithmModel>();

            var firstPart  = expressionCalculator.Calculate(model.FirstPart, store);
            var secondPart = expressionCalculator.Calculate(model.SecondPart, store);

            switch (model.Condition)
            {
            case Condition.More:
                if (firstPart > secondPart)
                {
                    numberFactorsExecutor.ExecuteAlgorithm(model.Algorithm, new UserAlgorithmStrategyProvider(), store);
                    Execute(jObject, store);
                }
                break;

            case Condition.Less:
                if (firstPart < secondPart)
                {
                    numberFactorsExecutor.ExecuteAlgorithm(model.Algorithm, new UserAlgorithmStrategyProvider(), store);
                    Execute(jObject, store);
                }
                break;

            case Condition.Equals:
                if (firstPart == secondPart)
                {
                    numberFactorsExecutor.ExecuteAlgorithm(model.Algorithm, new UserAlgorithmStrategyProvider(), store);
                    Execute(jObject, store);
                }
                break;

            case Condition.NotEquals:
                if (firstPart != secondPart)
                {
                    numberFactorsExecutor.ExecuteAlgorithm(model.Algorithm, new UserAlgorithmStrategyProvider(), store);
                    Execute(jObject, store);
                }
                break;
            }
        }
예제 #6
0
        public double Calculate(JsonTerm expression, UserAlgorithmStore store)
        {
            if (expression.Operation != Operation.Empty)
            {
                var firstFactor  = Calculate(expression.FirstParam, store);
                var secondFactor = Calculate(expression.SecondParam, store);

                switch (expression.Operation)
                {
                case Operation.Plus:
                    return(firstFactor + secondFactor);

                case Operation.Minus:
                    return(firstFactor - secondFactor);

                case Operation.Multiply:
                    return(firstFactor * secondFactor);

                case Operation.Divide:
                    return(firstFactor / secondFactor);

                case Operation.Power:
                    return(Math.Pow(firstFactor, secondFactor));

                case Operation.Mod:
                    return(firstFactor % secondFactor);

                default:
                    throw (new Exception("Unrecognized operation."));
                }
            }
            else if (expression.NumberValue != null)
            {
                return(expression.NumberValue.Value);
            }
            else if (expression.SymbolicValue != null)
            {
                return(store.NumverVariables[expression.SymbolicValue.Value.ToString()]);
            }
            else
            {
                throw (new Exception("Unrecognized operation."));
            }
        }
예제 #7
0
        public void Execute(dynamic jObject, UserAlgorithmStore store)
        {
            DeclareUserAlgorithmModel model = jObject.ToObject <DeclareUserAlgorithmModel>();

            switch (model.Type)
            {
            case VatiableType.number:
            {
                store.NumverVariables.Add(model.Variable, 0);
                break;
            }

            case VatiableType.list:
            {
                store.ListVariables.Add(model.Variable, new List <double>());
                break;
            }
            }
        }
예제 #8
0
        public void Execute(dynamic jObject, UserAlgorithmStore store)
        {
            ReturnUserAlgorithmModel model = jObject.ToObject <ReturnUserAlgorithmModel>();

            store.ReturnVariable = model.Variable;
        }
예제 #9
0
        public List <double> GetNumberFactors(int number, dynamic algorithm, IUserAlgorithmStrategyProvider strategyProvider, UserAlgorithmStore store)
        {
            store.NumverVariables["n"] = number;

            ExecuteAlgorithm(algorithm.Algorithm, strategyProvider, store);
            var returnVariable = store.ReturnVariable;

            var result = store.ListVariables[store.ReturnVariable];

            return(result);
        }
 public void ExecuteAlgorithm(dynamic algorithm, IUserAlgorithmStrategyProvider strategyProvider, UserAlgorithmStore store)
 {
     foreach (var step in algorithm)
     {
         var stratgy = strategyProvider.GetStrategy((string)step.Operation);
         stratgy.Execute(step, store);
     }
 }
예제 #11
0
        public DrawerModel GetGraphicDataFromSetOfPoints(dynamic setOfPoints, IUserAlgorithmStrategyProvider strategyProvider, UserAlgorithmStore store)
        {
            var drawerModel = new DrawerModel();

            if (setOfPoints == null)
            {
                return(drawerModel);
            }

            var points = setOfPoints.ToObject <PointModel[]>();

            (points as PointModel[]).ToList().ForEach(point =>
            {
                drawerModel.AddData(point.X, point.Y);
            });

            return(drawerModel);
        }
예제 #12
0
        public DrawerModel GetGraphicDataFromFunction(dynamic algorithm, IUserAlgorithmStrategyProvider strategyProvider, UserAlgorithmStore store)
        {
            var drawerModel = new DrawerModel();

            if (algorithm == null)
            {
                return(drawerModel);
            }

            ExecuteAlgorithm(algorithm.Algorithm, strategyProvider, store);
            var returnVariable = store.ReturnVariable;

            var xs = store.ListVariables["x"];
            var ys = store.ListVariables["y"];

            if (xs.Count != ys.Count)
            {
                throw new Exception("Mistake in Graphic builder algorithm");
            }

            for (var i = 0; i < xs.Count; i++)
            {
                drawerModel.AddData(xs[i], ys[i]);
            }

            return(drawerModel);
        }