private void outcome_code_sampling_btn_Click(object sender, EventArgs e) { DataminingInputDialog id = new DataminingInputDialog(new string[] { "instrument", "indicatorId", "normalizedDifference", "outcomeTimeframe", "steps" }, dataminingDb.getInfo()); id.ShowDialog(); if (id.isValidResult()) { new Thread(delegate() { Dictionary <string, string> parameters = id.getResult(); if (Directory.Exists(Application.StartupPath + @"\Analysis\") == false) { Directory.CreateDirectory(Application.StartupPath + @"\Analysis\"); } SampleOutcomeCodeExcelGenerator excel = new SampleOutcomeCodeExcelGenerator(Application.StartupPath + @"\Analysis\" + DateTime.Now.ToString("yyyy_dd_mm") + "_" + parameters["instrument"] + ".xls"); setState("OutcomeCodeSampling"); dataminingDb.getOutcomeCodeIndicatorSampling(excel, parameters["indicatorId"], Convert.ToInt32(parameters["steps"]), dataminingDb.getInfo(parameters["indicatorId"]).getDecentRange(), double.Parse(parameters["normalizedDifference"], CultureInfo.InvariantCulture), Convert.ToInt32(parameters["outcomeTimeframe"]), parameters["instrument"]); excel.FinishDoc(); excel.ShowDocument(); }).Start(); } }
private void maxPpOutcomeCodeBtn_Click(object sender, EventArgs e) { DataminingInputDialog id = new DataminingInputDialog(new string[] { "instrument", "outcomeCodeId" }, dataminingDb.getInfo()); id.ShowDialog(); long operationSum = 0; int operationsCount = 0; if (id.isValidResult()) { string instrument = id.getResult()["instrument"]; string outcomeId = id.getResult()["outcomeCodeId"]; string folderPath = Config.startupPath + "/analysis/"; if (Directory.Exists(folderPath) == false) { Directory.CreateDirectory(folderPath); } string graphFolderPath = folderPath + "ppForIndicators-" + outcomeId + "/"; Directory.CreateDirectory(graphFolderPath); string indicatorListFilename = folderPath + "ppForIndicators-" + outcomeId + ".csv"; if (File.Exists(indicatorListFilename) == false) { writeTextToFile(indicatorListFilename, "OverHalf;MaxDiff;Direction;LinRegr;LogRegr;Indicator" + Environment.NewLine); } //Start some threads for for (int threadId = 0; threadId < 2; threadId++) //Todo: Do 4 threads { new Thread(delegate() { while (true) { try { Stopwatch watch = new Stopwatch(); watch.Start(); WalkerIndicator indicator = IndicatorGenerator.getRandomIndicator(); string indicatorId = "mid-" + indicator.getName(); Logger.log("Start indicator: " + indicatorId, "maxPp"); setState("Max pp: avg" + Math.Round(operationSum / 1000d / (operationsCount != 0 ? operationsCount : 1)) + "s" + " n" + operationsCount); try { dataminingDb.addIndicator(indicator, instrument, "mid"); } catch (IndicatorNeverValidException) { writeTextToFile(indicatorListFilename, "x;x;x;" + indicatorId + Environment.NewLine); Logger.log("Invalid Indicator " + indicatorId, "maxPp"); continue; } Logger.log("Get info", "maxPp"); DistributionRange range = dataminingDb.getInfo(indicatorId).ranges["5"]; SampleOutcomeCodeExcelGenerator excel = new SampleOutcomeCodeExcelGenerator(graphFolderPath + indicatorId + ".xls"); Logger.log("Start sampling", "maxPp"); double[] ppMethod1 = dataminingDb.getOutcomeCodeIndicatorSampling(excel, indicatorId, 20, range, outcomeId, instrument); excel.FinishDoc(); /*double[][] inputsTraining = new double[0][], outputsTraining = new double[0][]; * dataminingDb.getInputOutputArrays(new string[] { indicatorId }, outcomeId, instrument, ref inputsTraining, ref outputsTraining, DataGroup.All, 1000 * 20, 0); * * double[][] inputsTest = new double[0][], outputsTest = new double[0][]; * dataminingDb.getInputOutputArrays(new string[] { indicatorId }, outcomeId, instrument, ref inputsTest, ref outputsTest, DataGroup.All, 5000, 1); * * double ppMethod2 = PredictivePowerAnalyzer.getPredictivePowerWithMl(inputsTraining, outputsTraining, inputsTest, outputsTest, MLMethodForPPAnalysis.LinearRegression); * * double ppMethod3 = PredictivePowerAnalyzer.getPredictivePowerWithMl(inputsTraining, outputsTraining, inputsTest, outputsTest, MLMethodForPPAnalysis.LogRegression);*/ Logger.log("write to file", "maxPp"); //over 0.5, maxDiff, direction string resultLine = ppMethod1[0] + ";" + ppMethod1[1] + ";" + ppMethod1[2] + ";" + "ni" + ";" + "ni" + ";" + indicatorId; writeTextToFile(indicatorListFilename, resultLine + Environment.NewLine); Logger.sendImportantMessage(DateTime.Now.ToShortTimeString() + " - " + resultLine); Logger.log("remove datasets", "maxPp"); dataminingDb.removeDataset(indicatorId, instrument); watch.Stop(); operationSum += watch.ElapsedMilliseconds; operationsCount++; } catch { Logger.log("Error in thread method", "maxPp"); } } }).Start(); } } }