Esempio n. 1
0
        public void ExecuteTest01()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams {
                CSVPath = "'../../../ToolsTests/testdata/TonnagePDF/ExampleGatm.csv'", IsTruncated = "TRUE", MinDepositCount = "3", PDFType = "'normal'", RandomSampleCount = "100", Seed = "3"
            };
            GradeTonnageTool tool = new GradeTonnageTool();
            var result            = tool.Execute(input);

            Assert.IsNotNull(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Run GradeTonnage with user input.
        /// </summary>
        private async void RunTool()
        {
            logger.Info("-->{0}", this.GetType().Name);
            // 1. Collect input parameters
            string rootFolder = settingsService.RootPath;

            if (Model.UseModelName == false)
            {
                Model.ExtensionFolder = "";
            }
            GradeTonnageInputParams inputParams = new GradeTonnageInputParams
            {
                CSVPath           = Model.CSVPath,
                IsTruncated       = Model.IsTruncated.ToString(),
                PDFType           = Model.PdfType,
                MinDepositCount   = Model.MinDepositCount.ToString(),
                RandomSampleCount = Model.RandomSampleCount.ToString(),
                Seed            = Model.Seed.ToString(),
                Folder          = rootFolder,
                ExtensionFolder = Model.ExtensionFolder,
                RunGrade        = Model.RunGrade,
                RunTonnage      = Model.RunTonnage,
                RunGradeTonnage = Model.RunGradeTonnage,
                ModelType       = Model.ModelType
            };

            logger.Trace(
                "GradeTonnageInputParams:\n" +
                "\tCSVPath: '{0}'\n" +
                "\tIsTruncated: '{1}'\n" +
                "\tPDFType: '{2}'\n" +
                "\tMinDepositCount: '{3}'\n" +
                "\tRandomSampleCount: '{4}'\n" +
                "\tSeed:'{5}'",
                inputParams.CSVPath,
                inputParams.IsTruncated,
                inputParams.PDFType,
                inputParams.MinDepositCount,
                inputParams.RandomSampleCount,
                inputParams.Seed,
                inputParams.Folder,
                inputParams.ModelType
                );
            // 2. Execute tool
            GradeTonnageResult tonnageResult = default(GradeTonnageResult);

            Model.IsBusy = true;
            try
            {
                await Task.Run(() =>
                {
                    GradeTonnageTool tool = new GradeTonnageTool();
                    logger.Info("calling GradeTonnageTool.Execute(inputParams)");
                    tonnageResult = tool.Execute(inputParams) as GradeTonnageResult;
                    logger.Trace("GradeTonnageResult:\n" +
                                 "\tPlotImage: '{0}'\n" +
                                 "\tTonnagePdf: '{1}'\n" +
                                 "\tSummary: '{2}'\n" +
                                 "\tOutput: '{3}'",
                                 tonnageResult.TonnagePlot,
                                 tonnageResult.TonnagePdf,
                                 tonnageResult.TonnageSummary,
                                 tonnageResult.GradePlot,
                                 tonnageResult.GradePdf,
                                 tonnageResult.GradeSummary,
                                 tonnageResult.Output
                                 );
                    // 3. Publish results
                    logger.Trace("Publishing results");
                    Result.TonnagePlot       = tonnageResult.TonnagePlot;
                    Result.TonnagePlotBitMap = BitmapFromUri(tonnageResult.TonnagePlot);
                    Result.Output            = tonnageResult.Output;
                    Result.TonnageSummary    = tonnageResult.TonnageSummary;
                    Result.TonnagePdf        = tonnageResult.TonnagePdf;
                    Result.GradePlot         = tonnageResult.GradePlot;
                    Result.GradePlotBitMap   = BitmapFromUri(tonnageResult.GradePlot);
                    Result.GradeSummary      = tonnageResult.GradeSummary;
                    Result.GradePdf          = tonnageResult.GradePdf;
                    Result.GradeTonnagePlot  = tonnageResult.GradeTonnagePlot;
                });

                var modelFolder = Path.Combine(inputParams.Env.RootPath, "GTModel", Model.ExtensionFolder);
                if (!Model.ModelNames.Contains(modelFolder))
                {
                    Model.ModelNames.Add(modelFolder);
                }
                string lastRunFile = Path.Combine(Path.Combine(inputParams.Env.RootPath, "GTModel", "GradeTonnage_last_run.lastrun"));
                File.Create(lastRunFile).Close();
                dialogService.ShowNotification("GradeTonnageTool completed successfully.", "Success");
                viewModelLocator.SettingsViewModel.WriteLogText("GradeTonnageTool completed successfully", "Success");
                if (tonnageResult.Warnings.Length > 0)
                {
                    viewModelLocator.SettingsViewModel.WriteLogText(tonnageResult.Warnings, "Warning");
                }
                Model.LastRunDate = "Last Run: " + DateTime.Now.ToString("g");
                Model.RunStatus   = 1;
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Failed to execute REngine() script");
                dialogService.ShowNotification("Run failed. Check output for details.\r\n- Are all input parameters correct?\r\n- Are all input files valid? \r\n- Are all input and output files closed?", "Error");
                viewModelLocator.SettingsViewModel.WriteLogText("Grade Tonnage tool run failed. Check output for details.\r\n- Are all input parameters correct?\r\n- Are all input files valid? \r\n- Are all input and output files closed?", "Error");
                Model.RunStatus = 0;
            }
            finally
            {
                Model.IsBusy = false;
            }
            logger.Info("<--{0} completed", this.GetType().Name);
        }