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); }
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); } }
public Decomposed Execute( Factor factors, IDivider divider, dynamic algorithm, IUserAlgorithmStrategyProvider strategtProvider ) { factors = Normalize(factors); var decomposed = new Decomposed(); decomposed.Factors.Add(factors); var continueFlag = true; while (continueFlag) { continueFlag = false; var freeTermFactors = (List <int>)GetNumberFactors(decomposed.Factors.Last().Terms.Where(x => x.SymbolsPower == 0).Select(term => term.Number).FirstOrDefault(), algorithm, strategtProvider ); freeTermFactors.ForEach(coefficent => { var dividedPart = divider.Divide(decomposed.Factors.Last(), -coefficent); if (dividedPart != null) { Console.WriteLine(decomposed); var newdividerFactor = new Factor(); newdividerFactor.Terms = new List <Term>() { new Term { Number = 1, Sign = Sign.Plus, Symbol = 'x', SymbolsPower = 1 }, new Term { Number = Math.Abs(coefficent), Sign = (coefficent >= 0) ? Sign.Minus : Sign.Plus, SymbolsPower = 1 } }; decomposed.Factors.Insert(0, newdividerFactor); decomposed.Factors[decomposed.Factors.Count() - 1] = dividedPart; continueFlag = true; } }); } return(decomposed); }
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 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); }
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 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); }