Beispiel #1
0
        public void AddCondition(int index)
        {
            if (index >= Conditions.Length)
            {
                return;
            }

            ConditionList.Add(Conditions[index]);
        }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            ConditionView conditionView = new ConditionView();

            conditionView.ShowDialog();
            if (conditionView.DialogResult == DialogResult.OK)
            {
                conditions.Add(conditionView.curCondition);
                LoadList();
            }
        }
Beispiel #3
0
        public override void RecoverySerialObject()
        {
            var r = new BacktestingResource();

            if (TestStrategySerial != null)
            {
                var s = TestStrategySerial.CreateInstance(BacktestingResource.CommonResource.StrategyPrototypeList.Cast <ISerialSupport>().ToList());
                if (s != null)
                {
                    TestStrategy = s as IStrategy;
                }
            }
            if (DataSourceSerial != null)
            {
                var s = DataSourceSerial.CreateInstance(BacktestingResource.CommonResource.DataSourcePrototypeList.Cast <ISerialSupport>().ToList());
                if (s != null)
                {
                    CurrentDataSource = s as IDataSource;
                }
            }
            if (TradeGateSerial != null)
            {
                var s = TradeGateSerial.CreateInstance(BacktestingResource.CommonResource.TradeGatePrototypeList.Cast <ISerialSupport>().ToList());
                if (s != null)
                {
                    CurrentTradeGate = s as ITradeGate;
                }
            }
            if (RiskPolicySerial != null)
            {
                var s = RiskPolicySerial.CreateInstance(BacktestingResource.CommonResource.RiskControlPrototypeList.Cast <ISerialSupport>().ToList());
                if (s != null)
                {
                    RiskPolicy = s as IRiskControl;
                }
            }
            ConditionList.Clear();
            ConditionSerialList.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    ConditionList.Add(i as ICondition);
                }
            });
        }
Beispiel #4
0
        public int SetConditionInfo(string s)
        {
            var l = CommonLib.CommonProc.ConvertStringToObject <List <SerialInfo> >(s);

            if (l == null || l.Count == 0)
            {
                return(0);
            }
            ConditionList.Clear();
            l.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    ConditionList.Add(i as ICondition);
                }
            });
            return(l.Count);
        }
        public virtual void InitContextMenu()
        {
            ConditionMenuList.Clear();
            MainViewModel.Resource.ConditionPrototypeList.ForEach(v =>
            {
                var command = new CommonCommand((obj) =>
                {
                    var o = v.CreateInstance() as ICondition;
                    o.GetInstrumentList = () => {
                        var l = new List <IInstrument>();
                        foreach (var inst in InstrumentList)
                        {
                            l.Add(inst);
                        }
                        return(l);
                    };

                    o.AnalyseDataSource = CurrentDataSource;
                    var vm = new ConditionViewModel()
                    {
                        TargetObject = o
                    };
                    ConditionList.Add(vm);
                    GetTargetProject().ConditionList.Add(o);
                });
                command.Name            = "New " + v.Name;
                command.Memo            = v.Memo;
                command.ForegroundBrush = new SolidColorBrush(Colors.Blue);
                ConditionMenuList.Add(command);
            });
            var dcommand = new CommonCommand((obj) =>
            {
                if (CurrentCondition != null && ConditionList.Contains(CurrentCondition))
                {
                    ConditionList.Remove(CurrentCondition);
                }
            });

            dcommand.Name            = "Delete Condition";
            dcommand.Memo            = "Delete Current Condition";
            dcommand.ForegroundBrush = new SolidColorBrush(Colors.Orange);
            ConditionMenuList.Add(dcommand);
        }
        /// <summary>
        /// Fills the MedicationList and ConditionList with the data from the reportModel.Medications and reportCofig.Symptoms variables, respectively.
        /// reportModel variable is set from GetReportJSONFile()
        /// </summary>
        public void GetListOfMedicationsConditionsFromModel()
        {
            //add to list of medications and conditions from the config file
            int index = 1;

            foreach (string medication in reportModel?.Medications)
            {
                MedicationList.Add(new MedicationCheckBoxClass {
                    Medication = medication, Index = index, IsSelected = false
                });
                index++;
            }
            index = 1;
            foreach (string condition in reportModel?.Symptoms)
            {
                ConditionList.Add(new ConditionCheckBoxClass {
                    Condition = condition, Index = index, IsSelected = false
                });
                index++;
            }
        }
Beispiel #7
0
        public override void RecoverySerialObject()
        {
            ConditionList.Clear();
            ConditionSerialList.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    ConditionList.Add(i as ICondition);
                }
            });

            PredicateList.Clear();
            PredicateSerialList.ForEach(v =>
            {
                var i = v.CreateInstance(BacktestingResource.CommonResource.ConditionPrototypeList.Cast <ISerialSupport>().ToList());
                if (i != null)
                {
                    PredicateList.Add(i as ICondition);
                }
            });
        }
Beispiel #8
0
        public override void LoadInfo()
        {
            if (TargetProject == null)
            {
                return;
            }

            ConditionList.Clear();
            TargetProject.ConditionList.ForEach(v => ConditionList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));
            InstrumentList.Clear();
            TargetProject.InstrumentList.ForEach(v => InstrumentList.Add(v));
            CurrentStrategy   = TargetProject.TestStrategy;
            CurrentTradeGate  = TargetProject.CurrentTradeGate;
            CurrentDataSource = TargetProject.CurrentDataSource;
            IsChanged         = false;
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
        }
Beispiel #9
0
        public override void LoadInfo()
        {
            if (TargetProject == null)
            {
                return;
            }
            ConditionList.Clear();
            TargetProject.ConditionList.ForEach(v => ConditionList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));
            PredicateList.Clear();
            TargetProject.PredicateList.ForEach(v => PredicateList.Add(new ConditionViewModel()
            {
                TargetObject = v
            }));

            InstrumentList.Clear();
            TargetProject.InstrumentList.ForEach(v => InstrumentList.Add(v));
            ResultList.Clear();
            TargetProject.ResultList.ForEach(v => ResultList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            TargetProject.BlockList.ForEach(v => BlockList.Add(new InstrumentViewModel()
            {
                TargetObject = v, GetCurrentDataSource = () => { return(CurrentDataSource); }
            }));
            CurrentDataSource = TargetProject.CurrentDataSource;

            IsChanged = false;
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
        }
        private Expression MakeInnerJoin(Expression outerExpression, Expression innerExpression,
            string[] leftFieldsNames, string[] rightFieldsNames,
            ConditionList conditions)
        {
            Checker.CheckArgumentNull(outerExpression, "outerExpression");
            Checker.CheckArgumentNull(innerExpression, "innerExpression");
            Checker.CheckArgumentNull(leftFieldsNames, "leftFieldsNames");
            Checker.CheckArgumentNull(outerExpression, "outerExpression");

            int fieldsCount = leftFieldsNames.Length;
            if (fieldsCount != rightFieldsNames.Length)
            {
                throw new SpoltyException("Number of fields mismatch");
            }

            Type outerType = ExpressionHelper.GetGenericType(outerExpression);
            ParameterExpression outerParam = ExpressionHelper.CreateOrGetParameterExpression(outerType, outerType.Name, Factory.Store);
            Type innerType = ExpressionHelper.GetGenericType(innerExpression);
            ParameterExpression innerParam = ExpressionHelper.CreateOrGetParameterExpression(innerType, innerType.Name, Factory.Store);

            var clw = new ConditionList();

            for (int index = 1; index < fieldsCount; index++)
            {
                var fieldCondition =
                    new FieldCondition(leftFieldsNames[index],
                                       ConditionOperator.EqualTo, rightFieldsNames[index], outerType, innerType);
                clw.Add(fieldCondition);
            }

            PropertyInfo outerPropertyInfo = outerType.GetProperty(leftFieldsNames[0]);
            if (outerPropertyInfo == null)
            {
                throw new SpoltyException("Property not found");
            }
            PropertyInfo innerPropertyInfo = innerType.GetProperty(rightFieldsNames[0]);
            if (innerPropertyInfo == null)
            {
                throw new SpoltyException("Property not found");
            }

            Expression outerPropertyExpression = Expression.Property(outerParam, outerPropertyInfo);
            Expression innerPropertyExpression = Expression.Property(innerParam, innerPropertyInfo);

            Type type = outerPropertyInfo.PropertyType;
            innerPropertyExpression =
                ExpressionHelper.ConvertOrCastInnerPropertyExpression(type, innerPropertyInfo, innerPropertyExpression);

            LambdaExpression outerKeySelector = Expression.Lambda(outerPropertyExpression, outerParam);
            LambdaExpression innerKeySelector = Expression.Lambda(innerPropertyExpression, innerParam);
            LambdaExpression resultSelector = Expression.Lambda(outerParam, outerParam, innerParam);

            if (conditions != null && conditions.Count > 0)
            {
                clw.AddConditions(conditions);
            }

            Expression resultJoinExpression = CallJoinMethod(outerExpression, innerExpression, outerKeySelector,
                                                             innerKeySelector,
                                                             resultSelector);
            resultJoinExpression = Factory.CreateConditionExpressionMaker().Make(clw, resultJoinExpression);
            return resultJoinExpression;
        }
Beispiel #11
0
 public void AddCondition(int index)
 {
     ConditionList.Add(Conditions[index]);
 }
Beispiel #12
0
 public void Add(Condition item)
 {
     ConditionList.Add(item);
 }
        public ConditionListView()
        {
            InitializeComponent();

            conditions = new ConditionList();

            Variables = new VariableList();
            Variables.Add(new Variable("Value0", 0));
            Variables.Add(new Variable("Value1", 1));
            Variables.Add(new Variable("Value2", 2));
            Variables.Add(new Variable("Value3", 3));
            Variables.Add(new Variable("Value4", 4));
            Variables.Add(new Variable("Value5", 5));
            Variables.Add(new Variable("Value6", 6));
            Variables.Add(new Variable("Value7", 7));
            Variables.Add(new Variable("Value8", 8));
            Variables.Add(new Variable("Value9", 9));
            Variables.Add(new Variable("Value10", 10));

            int testNum = 6;

            switch (testNum)
            {
            case 1:
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[4], Operator.EqualTo, 10));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                // Outcome:
                break;

            case 2:
                conditions.Add(new Condition(Variables[10], Operator.GreaterThan, 8, Grouping.OpenGrouping, Connector.And));
                // Outcome:
                break;

            case 3:
                conditions.Add(new Condition(Variables[7], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 10));
                // Outcome:
                break;

            case 4:
                conditions.Add(new Condition(Variables[1], Operator.NotEqualTo, 1, Grouping.OpenAndCloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 5:
                conditions.Add(new Condition(Variables[9], Operator.GreaterThanOrEqualTo, 8, Grouping.OpenGrouping, Connector.Xor));
                conditions.Add(new Condition(Variables[6], Operator.EqualTo, 6, Grouping.CloseGrouping, Connector.And));
                // Outcome:
                break;

            case 6:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[9], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[7], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[8], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[4], Operator.GreaterThanOrEqualTo, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[8], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[9], Operator.GreaterThan, 4, Grouping.NoGrouping, Connector.And));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                // Outcome: true
                break;

            case 7:
                conditions.Add(new Condition(Variables[1], Operator.LessThan, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[3], Operator.GreaterThan, 2, Grouping.OpenGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 4));
                conditions.Add(new Condition(Variables[6], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.GreaterThan, 5, Grouping.CloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 8:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                // Outcome:
                break;

            case 9:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 10:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[9], Operator.LessThan, 15, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.NotEqualTo, 6, Grouping.NoGrouping, Connector.Or));
                // Outcome:
                break;

            default:
                break;
            }

            LoadList();
        }