Example #1
0
 public Detective(DataTable T, EStrategy es, Dictionary <string, CommandLineArgument> arguments, string path)
 {
     strategy             = es;
     hitSpectraData       = T;
     commandLineArguments = arguments;
     parentPath           = path;
 }
Example #2
0
            public void ReturnCountersCorrectly(EStrategy strategyIndex, long expectedResult)
            {
                var strategy = GetStrategy(strategyIndex);
                var result   = strategy.Compute(_samples.Keys.First());

                Assert.AreEqual(expectedResult, result.Item2);
            }
Example #3
0
        protected void _init()
        {
            _log.Debug("加载{0}策略的仓位信息", Desc.Id);
            String path = String.Format("/user/{0}", ConstantsHelper.AKKA_PATH_PERSISTENCE);

            persistenceActor = Context.ActorSelection(path);
            PersistenceRequest req = new PersistenceRequest()
            {
                Type = PersistenceType.FIND, Body = String.Format("from EStrategy where Id={0}", Desc.Id)
            };
            var ret = persistenceActor.Ask <EStrategy>(req, TimeSpan.FromSeconds(1));

            ret.Wait();
            Desc = ret.Result;

            _log.Debug("{0}策略连接交易接口", Desc.Id);
            if (Desc.Trader != null)
            {
                String tpath = String.Format("/user/{0}/{1}", ConstantsHelper.AKKA_PATH_TRADER, Desc.Trader.Id);
                tradeActor = Context.ActorSelection(tpath);
            }
            else
            {
                // 默认的trade actor is /user/trader/ths
                tradeActor = Context.ActorSelection("/user/trader");
            }

            onInit();
        }
Example #4
0
        protected void _init()
        {
            _log.Info("加载{0}策略的仓位信息", Desc.Id);
            try {
                String path = String.Format("/user/{0}", ConstantsHelper.AKKA_PATH_PERSISTENCE);
                persistenceActor = Context.ActorSelection(path);
                PersistenceRequest req = new PersistenceRequest()
                {
                    Type = PersistenceType.FIND, Body = String.Format("from EStrategy where Id={0}", Desc.Id)
                };
                var ret = persistenceActor.Ask <EStrategy>(req, TimeSpan.FromSeconds(10));
                ret.Wait();
                Desc = ret.Result;
            } catch (Exception e)
            {
                _log.Error("发生异常 {0}", e.StackTrace);
                showLog(String.Format("必须重新启动,策略{0}加载超时", Desc.Id));
            }

            _log.Info("{0}策略连接交易接口", Desc.Id);
            if (Desc.Trader != null)
            {
                String tpath = String.Format("/user/{0}/{1}", ConstantsHelper.AKKA_PATH_TRADER, Desc.Trader.Id);
                tradeActor = Context.ActorSelection(tpath);
            }
            else
            {
                // 默认的trade actor is /user/trader/ths
                // tradeActor = Context.ActorSelection("/user/trader");
            }

            onInit();
        }
Example #5
0
            public void ReturnExactResultForIteration(EStrategy strategy)
            {
                var result = Executor.ExecuteStrategy(_samples.Keys.ToList(), _samples.Keys.Select(key => _samples[key]).ToList(), GetStrategy(strategy), 1);

                Assert.AreEqual(0, result.MaxError);
                Assert.AreEqual(0, result.RelativeError);
                Assert.AreEqual(GetStrategy(strategy).Id, result.StrategyId);
            }
Example #6
0
        public FaultLocalizer(int[,] testcaseMatrix, string[] fctNames, EStrategy strategy)
        {
            this.testcaseMatrix = testcaseMatrix;
            this.functionNames  = fctNames;
            this.strategy       = strategy;
            createRankingStrategyInstance();

            suspiciousnessRanking = new List <Item>();
        }
Example #7
0
        private bool determineFaultLocalizationStrategy(string cmdStrategy)
        {
            foreach (EStrategy es in Enum.GetValues(typeof(EStrategy)))
            {
                if (es.ToString().Equals(cmdStrategy, StringComparison.OrdinalIgnoreCase))
                {
                    faultLocalizationStrategy = es;
                    return(true);
                }
            }

            return(false);
        }
Example #8
0
        public void save_update_load_find_delete_strategy()
        {
            TestActorRef <PersistenceActor> persistenceActorRef = ActorOfAsTestActorRef <PersistenceActor>("persistence");
            EStrategy strategy = new EStrategy()
            {
                Type = "Quanter.Strategy.Demo.DemoStrategyActor, Quanter.Strategy.Demo", Desc = "测试策略", Name = "策略DEMO", Date = DateTime.Now
            };
            PersistenceRequest req = new PersistenceRequest()
            {
                Type = PersistenceType.SAVE, Body = strategy
            };

            persistenceActorRef.Tell(req);
        }
Example #9
0
 private void _createStrategyActor(EStrategy sd)
 {
     if (!strategyActors.ContainsKey(sd.Id))
     {
         // String[] ary = sd.Type.Split(new string[] { "," }, StringSplitOptions.None);
         Type t             = Type.GetType(sd.Type);
         var  strategyActor = Context.ActorOf(Props.Create(t, sd), sd.Id.ToString());
         strategyActors.Add(sd.Id, strategyActor);
     }
     else
     {
         _log.Warning("重复注册策略,策略号 {0}", sd.Id);
     }
 }
Example #10
0
        private Dictionary <int, double[]> idClusterDistance;// int is the id of cluster and the double array contains the distance array generated for that cluster

        public Clustering(DataTable dataTable, string parentPath, EStrategy faultLocalizationStrategy)
        {
            this.hitSpectraMatrix          = dataTable;
            this.parentPath                = parentPath;
            this.faultLocalizationStrategy = faultLocalizationStrategy;

            buildHitSpectraMatrixArray();
            buildFailedTestcasesInHitSpectraMatrixArray();
            buildPassedTestcasesInHitSpectraMatrixArray();
            try
            {
                matlabClustering = new MatlabClustering();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #11
0
 private void _createStrategyActor(EStrategy sd)
 {
     if (!strategyActors.ContainsKey(sd.Id))
     {
         _log.Info("创建策略 {0}", sd.Id);
         Type t             = Type.GetType(sd.Type);
         var  strategyActor = Context.ActorOf(Props.Create(t, sd), sd.Id.ToString());
         strategyActor.Tell(new StrategyRequest()
         {
             Type = StrategyRequestType.INIT
         });
         strategyActors.Add(sd.Id, strategyActor);
     }
     else
     {
         _log.Warning("重复注册策略,策略号 {0}", sd.Id);
     }
 }
Example #12
0
        private void btnRegStrategy_Click(object sender, EventArgs e)
        {
            // Load一个新的策略实例
            EStrategy strategy1 = new EStrategy()
            {
                Id   = 1,
                Type = "Quanter.Strategy.Demo.DemoStrategyActor, Quanter.Strategy.Demo",
                Name = "Demo示例",
                Desc = "Demo实例"
            };

            EStrategy strategy2 = new EStrategy()
            {
                Id   = 2,
                Type = "Quanter.Strategy.XueQiuStrategy.TraceXueQiuStrategyActor, Quanter.Strategy.XueQiuStrategy",
                Name = "雪球策略",
                Desc = "雪球实例"
            };

            EStrategy strategy3 = new EStrategy()
            {
                Id   = 3,
                Type = "Quanter.Strategy.RationBStrategyActor, Quanter.Strategy.RationB",
                Name = "分级策略",
                Desc = "雪球实例"
            };

            StrategyRequest req = new StrategyRequest()
            {
                Type = StrategyRequestType.CREATE, Body = strategy1
            };

            strategyActor.Tell(req);
            //req = new StrategyRequest() { Type = StrategyRequestType.CREATE, Body = strategy2 };
            //strategyActor.Tell(req);
            //req = new StrategyRequest() { Type = StrategyRequestType.CREATE, Body = strategy3 };
            //strategyActor.Tell(req);
        }
Example #13
0
        public void save_update_load_find_delete_strategy()
        {
            ETrader trader = new ETrader()
            {
                Username = "******", Password = "******", ServicePwd = "012345678", Path = "c:/xiadan/xiadan.exe", Date = DateTime.Now
            };
            PersistenceRequest req = new PersistenceRequest()
            {
                Type = PersistenceType.SAVE, Body = trader
            };

            persistenceActorRef.Tell(req);
            var result = ExpectMsg <ETrader>();

            EStrategy strategy = new EStrategy()
            {
                Type = "Quanter.Strategy.Demo.DemoStrategyActor, Quanter.Strategy.Demo", Desc = "测试策略", Name = "策略DEMO", EnableBalance = 50000, FrozenBalance = 0, Enabled = true, Date = DateTime.Now, Trader = result
            };

            req = new PersistenceRequest()
            {
                Type = PersistenceType.SAVE, Body = strategy
            };
            persistenceActorRef.Tell(req);
            var result1 = ExpectMsg <EStrategy>();

            Assert.NotEqual(0, result1.Id);

            req = new PersistenceRequest()
            {
                Type = PersistenceType.FIND, Body = "from EStrategy where Id=1"
            };
            persistenceActorRef.Tell(req);
            var result2 = ExpectMsg <EStrategy>();

            Assert.Equal(1, result2.Id);
            Assert.Equal("012345678", result2.Trader.Username);
        }
Example #14
0
 public DemoStrategyActor(EStrategy strategy) : base(strategy)
 {
     _log.Debug("创建编码为 {0} StrategyActor实例", strategy.Id);
 }
Example #15
0
 public BaseStrategyActor(EStrategy strategy)
 {
     this.Desc = strategy;
 }
 public ChatBot(EStrategy strategy, string[] answers)
 {
     Strategy = strategy;
     Answers  = answers;
 }
Example #17
0
 private IStrategy GetStrategy(EStrategy strategyIndex)
 {
     return(Strategies[(int)strategyIndex]);
 }
Example #18
0
        /// <summary>
        /// the main function.
        /// Aletheia starts here. It directs the program what to do based on command line input
        /// </summary>
        /// <param name="args">It is an array of argument</param>
        public static void Main(string[] args)
        {
            // Reading command line arguments
            CommandLineReader commandLineReader = new CommandLineReader(args);

            commandLineArguments = commandLineReader.CommandLineArguments;
            if (commandLineArguments.Count() == 0)
            {
                Console.WriteLine("No Recognized parameter\n\n use Spectralizer.exe do=getHelp for help\n");
                return;
            }


            printCommandLineParameters();


            //check which operation is seleced

            if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.OPERATION))
            {
                throw new Exception("Please select a operation: GenerateHitSpectra/Cluster/FaultLocalization!");
            }
            operation = commandLineArguments[PossibleCommandLineArguments.OPERATION].Value;
            // Check, which mode is selected
            //if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.MODE)) throw new Exception("Please select a operation mode!");
            //mode = commandLineArguments[PossibleCommandLineArguments.MODE].Value;

            string outputDirectory = "";

            //check debug value
            if (commandLineArguments.Keys.Contains(PossibleCommandLineArguments.DEBUG))
            {
                DEBUG = Convert.ToBoolean(commandLineArguments[PossibleCommandLineArguments.DEBUG].Value);
            }

            // Check, if output directory is available
            if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.OUTPUT_DIRECTORY))
            {
                outputDirectory = "C:\\HitSpectras";
            }
            else
            {
                outputDirectory = commandLineArguments[PossibleCommandLineArguments.OUTPUT_DIRECTORY].Value;
            }
            if ((workingDirectory = Program.createWorkingDirectory(outputDirectory)) == null)
            {
                return;
            }

            // Check if clustering should be done
            //if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.CLUSTERING)) return;
            //clustering = Convert.ToBoolean(commandLineArguments[PossibleCommandLineArguments.CLUSTERING].Value);

            if (operation.Equals("GenerateHitSpectra", StringComparison.OrdinalIgnoreCase))
            {
                if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.GTEST_PATH))
                {
                    Console.WriteLine("Gtest path is mandatory for current settings.\n");
                    return;
                }
                HitSpectra.Spectralizer spectralizer = new HitSpectra.Spectralizer(commandLineArguments, workingDirectory);
                if (DEBUG)
                {
                    Console.WriteLine("Generation of Spectralizer object is complete\n");
                }
                spectralizer.executeTestSuite();
                if (DEBUG)
                {
                    Console.WriteLine("Execution of Test Suite is complete\n");
                }
                spectralizer.exportHitSpectraMatrices();
                if (DEBUG)
                {
                    Console.WriteLine("Exporting of HitSpectra matrix is complete\n");
                }

                FunctionHitSpectraMatrix = spectralizer.FunctionHitSpectraMatrix;
                CountingFunctionInvokationsHitSpectraMatrix    = spectralizer.CountingFunctionInvokationsHitSpectraMatrix;
                InvokedFunctionsHitSpectraMatrix               = spectralizer.InvokedFunctionsHitSpectraMatrix;
                InvokedFunctionsWithParametersHitSpectraMatrix = spectralizer.InvokedFunctionsWithParametersHitSpectraMatrix;
                LineCoverageHitSpectraMatrix = spectralizer.LineCoverageHitSpectraMatrix;
                Console.WriteLine("Spectra Matrix generated\n");
            }
            else if (operation.Equals("Cluster", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nClustering Given HitSpectraMatrix\n";
                if (operation.Equals("Cluster", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLinePrinter.printToCommandLine(output);
                }
                else
                {
                    Console.WriteLine("\nCreating Fault Localization with given HitSpectra");
                }

                char   separator;
                string inputPath;

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.SEPARATOR))
                {
                    separator = ' ';
                }
                else
                {
                    separator = commandLineArguments[PossibleCommandLineArguments.SEPARATOR].Value.Trim()[0];
                }

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.INPUT_PATH))
                {
                    throw new Exception("No input path");
                }
                inputPath = commandLineArguments[PossibleCommandLineArguments.INPUT_PATH].Value;

                HitSpectraCsvSheetReader reader = new HitSpectraCsvSheetReader(inputPath, separator);
                reader.parseSheet();
                DataTable dataTable = reader.getDataTable();

                string pathAdditional = "Clustering";
                string path           = workingDirectory + "\\" + pathAdditional;

                doClustering(dataTable, path);
            }
            else if (operation.Equals("faultLocalization", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nRunning Fault Localization\n";

                CommandLinePrinter.printToCommandLine(output);
                char   separator;
                string inputPath;

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.SEPARATOR))
                {
                    separator = ' ';
                }
                else
                {
                    separator = commandLineArguments[PossibleCommandLineArguments.SEPARATOR].Value.Trim()[0];
                }

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.INPUT_PATH))
                {
                    throw new Exception("No input path");
                }
                inputPath = commandLineArguments[PossibleCommandLineArguments.INPUT_PATH].Value;

                HitSpectraCsvSheetReader reader = new HitSpectraCsvSheetReader(inputPath, separator);
                reader.parseSheet();
                DataTable dataTable = reader.getDataTable();

                string pathAdditional = "FaultLocalization";
                string path           = workingDirectory + "\\" + pathAdditional;
                if (commandLineArguments.ContainsKey(PossibleCommandLineArguments.FAULT_RANKING_METRIC))
                {
                    rankingMetric = commandLineArguments[PossibleCommandLineArguments.FAULT_RANKING_METRIC].Value;
                }
                EStrategy rankingStrategy = getFaultLocalizationStrategy(rankingMetric);
                Detective detective       = new Clustering.FaultLocalization.Detective(dataTable, rankingStrategy, commandLineArguments, path);
                detective.DetectFault();
                CommandLinePrinter.printToCommandLine("Fault Localization complete\n");
            }
            else if (operation.Equals("getHelp", StringComparison.OrdinalIgnoreCase))
            {
                String output = "These are accepted command parameters\nCommand should be given in key=value fashion\n\n";
                output += "do: specifies the operation to be performed\n\tPossible values={'GenerateHitSpectra', 'Cluster', 'FaultLocalization', 'GetHelp'}\n";
                output += "separator: specifies the separator character for csv file\nBy default white space is the separator\n";
                output += "output_directory: where the output will be generated, default output directory is C:\\HitSpectras\n";
                output += "project_path: it is a mandatory argument for HitSpectra Generation part, show the *.vcxproj file\n";

                output += "source_directory: show the directory where the source files are located\n";
                output += "degreeofparallelism: number of threads to run in parallel for HitSpectra generation, default value is 12\n";
                output += "gtest_path: mandatory argument for HitSpectra Generation, show the exe file of test project\n";
                output += "ranking_metric: ranking metric for fault localization, default is Jaccard";
                output += "clustering_method: default is maxclust\n";
                output += "linkage_method: default is average\n";
                output += "linkage_metric: default is euclidean\n";
                output += "similarity_threshold: default is 0.8\ncomparison_range: default is 0.1\n";
                output += "function_coverage: boolean argument, default is true\n";
                output += "invoked_function_coverage: boolean argument, default is true\n";
                output += "invoked_function_with_param_coverage: boolean argument, default is true\n";
                output += "counting_function_invokation_coverage: boolean argument, default is true\n";
                output += "line_coverage: boolean argument, default is true\n";
                CommandLinePrinter.printToCommandLine(output);
            }


            // Do the clustering
            //if (clustering)
            if (operation.Equals("clustering", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nClustering   HitSpectraMatrices\n";
                CommandLinePrinter.printToCommandLine(output);
                if (FunctionHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_FunctionHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(FunctionHitSpectraMatrix, path);
                }

                if (CountingFunctionInvokationsHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_CountingFunctionInvokationsHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(CountingFunctionInvokationsHitSpectraMatrix, path);
                }

                if (InvokedFunctionsHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_InvokedFunctionsHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(InvokedFunctionsHitSpectraMatrix, path);
                }

                if (InvokedFunctionsWithParametersHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_InvokedFunctionsWithParametersHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(InvokedFunctionsWithParametersHitSpectraMatrix, path);
                }

                if (LineCoverageHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_LineCoverageHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(LineCoverageHitSpectraMatrix, path);
                }
            }
        }
Example #19
0
        public void save_update_load_find_delete_cube()
        {
            PersistenceRequest req = new PersistenceRequest()
            {
                Type = PersistenceType.LIST, Body = "from ECube"
            };

            persistenceActorRef.Tell(req);
            var result0 = ExpectMsg <List <object> >();

            Assert.Equal(0, result0.Count);

            // 先保存Trader
            ETrader trader = new ETrader()
            {
                Username = "******", Password = "******", ServicePwd = "012345678", Path = "c:/xiadan/xiadan.exe", Date = DateTime.Now
            };

            req = new PersistenceRequest()
            {
                Type = PersistenceType.SAVE, Body = trader
            };
            persistenceActorRef.Tell(req);
            var result = ExpectMsg <ETrader>();

            // 保存strategy
            EStrategy strategy = new EStrategy()
            {
                Type = "Quanter.Strategy.XueQiuStrategy.TraceXueQiuStrategyActor, Quanter.Strategy.XueQiuStrategy", Desc = "测试策略", Name = "组合策略DEMO", EnableBalance = 50000, FrozenBalance = 0, Enabled = true, Date = DateTime.Now, Trader = null
            };
            EStockHolder holder = new EStockHolder()
            {
                Strategy = strategy, Code = "000001", Symbol = "000001.XSHE", Name = "平安银行", CostPrice = 11.03f, LastPrice = 12.0f, IncomeAmount = 1000, EnableAmount = 1000
            };
            EStockHolder holder1 = new EStockHolder()
            {
                Strategy = strategy, Code = "000002", Symbol = "000002.XSHE", Name = "万科A", CostPrice = 9.03f, LastPrice = 12.0f, IncomeAmount = 1000, EnableAmount = 1000
            };

            strategy.Holders.Add(holder);
            strategy.Holders.Add(holder1);


            ECube cube = new ECube()
            {
                Strategy        = strategy,
                Symbol          = "ZH000003",
                PreAdjustmentId = 0,
            };

            req = new PersistenceRequest()
            {
                Type = PersistenceType.SAVE, Body = cube
            };
            persistenceActorRef.Tell(req);
            var result2 = ExpectMsg <ECube>();

            Assert.NotEqual(0, result2.Id);
            Assert.Equal(result2.Symbol, "ZH000003");

            req = new PersistenceRequest()
            {
                Type = PersistenceType.LIST, Body = "from ECube"
            };
            persistenceActorRef.Tell(req);
            var result3 = ExpectMsg <List <object> >();

            Assert.NotEqual(0, result3.Count);
            Assert.Equal("ZH000003", ((ECube)result3[0]).Symbol);
        }
Example #20
0
 public PaymentContext(EStrategy str)
 {
     strategy = dic[str];
 }
Example #21
0
 public void Remove(EStrategy sd)
 {
     sds.Remove(sd);
 }
Example #22
0
 public void Add(EStrategy sd)
 {
     sds.Add(sd);
 }