Beispiel #1
0
        public void SaveTestRandomSampleCount()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.RandomSampleCount = "555";
            input.Save(output_json_file1);
            input.RandomSampleCount = "";
            input.Load(output_json_file1);
            Assert.AreEqual("555", input.RandomSampleCount);
        }
Beispiel #2
0
        public void SaveTestSeed()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.Seed = "123";
            input.Save(output_json_file1);
            input.Seed = "";
            input.Load(output_json_file1);
            Assert.AreEqual("123", input.Seed);
        }
Beispiel #3
0
        public void SaveTestPDFType()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.PDFType = "normal";
            input.Save(output_json_file1);
            input.PDFType = "";
            input.Load(output_json_file1);
            Assert.AreEqual("normal", input.PDFType);
        }
Beispiel #4
0
        public void SaveTestCSVPath()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.CSVPath = @"c:\path\to\file.json";
            input.Save(output_json_file1);
            input.CSVPath = "";
            input.Load(output_json_file1);
            Assert.AreEqual(@"c:\path\to\file.json", input.CSVPath);
        }
Beispiel #5
0
        public void SaveTestIsTruncated()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.IsTruncated = "TRUE";
            input.Save(output_json_file1);
            input.IsTruncated = "";
            input.Load(output_json_file1);
            Assert.AreEqual("TRUE", input.IsTruncated);
        }
Beispiel #6
0
        public void SaveTestMinDepositCount()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.MinDepositCount = "1000";
            input.Save(output_json_file1);
            input.MinDepositCount = "";
            input.Load(output_json_file1);
            Assert.AreEqual("1000", input.MinDepositCount);
        }
Beispiel #7
0
        public void SaveTestCSVPath()
        {
            string output_json_file1      = @"C:\Temp\mapWizard\DepositDensity\output\output_test.json";
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.CSVPath = @"c:\path\to\file.json";
            input.Save(output_json_file1);
            input.CSVPath = "";
            input.Load(output_json_file1);
            Assert.AreEqual(@"c:\path\to\file.json", input.CSVPath);
        }
Beispiel #8
0
        public void LoadValidFromFile()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.Load(test_json_file_good);

            Assert.AreEqual(@"'e:/data/ExampleGatm.csv'", input.CSVPath);
            Assert.AreEqual("TRUE", input.IsTruncated);
            Assert.AreEqual("3", input.MinDepositCount);
            Assert.AreEqual("'normal'", input.PDFType);
            Assert.AreEqual("100", input.RandomSampleCount);
            Assert.AreEqual("3", input.Seed);
        }
Beispiel #9
0
        public void SaveTestComplete()
        {
            loadedParams.Save(output_json_file1);
            GradeTonnageInputParams second = new GradeTonnageInputParams();

            second.Load(output_json_file1);

            Assert.AreEqual(loadedParams.CSVPath, second.CSVPath);
            Assert.AreEqual(loadedParams.IsTruncated, second.IsTruncated);
            Assert.AreEqual(loadedParams.MinDepositCount, second.MinDepositCount);
            Assert.AreEqual(loadedParams.PDFType, second.PDFType);
            Assert.AreEqual(loadedParams.RandomSampleCount, second.RandomSampleCount);
            Assert.AreEqual(loadedParams.Seed, second.Seed);
        }
Beispiel #10
0
        /// <summary>
        /// Select certain result.
        /// </summary>
        private void SelectResult()
        {
            if (Model.ModelNames.Count <= 0 || Model.DepositModelsExtension.Length == 0)
            {
                dialogService.ShowNotification("Either the model was not selected or it was not given a name. ", "Error");
                viewModelLocator.SettingsViewModel.WriteLogText("Either the model was not selected or it was not given a name.", "Error");
                return;
            }
            try
            {
                var modelDirPath          = Model.ModelNames[Model.SelectedModelIndex];
                var modelDirInfo          = new DirectoryInfo(Model.ModelNames[Model.SelectedModelIndex]);
                var selectedProjectFolder = Path.Combine(settingsService.RootPath, "GTModel", "SelectedResult");
                if (modelDirPath == selectedProjectFolder)
                {
                    dialogService.ShowNotification("SelectedResult folder cannot be selected. ", "Error");
                    return;
                }
                if (!Directory.Exists(selectedProjectFolder))
                {
                    Directory.CreateDirectory(selectedProjectFolder);
                }
                DirectoryInfo dir = new DirectoryInfo(selectedProjectFolder);
                // Deletes all files and directories before adding new files.
                foreach (FileInfo file in dir.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo direk in dir.GetDirectories())
                {
                    direk.Delete(true);
                }
                // Get files from selected model root folder and add them into SelectedResult folder.
                foreach (FileInfo file2 in modelDirInfo.GetFiles())
                {
                    var destPath   = Path.Combine(selectedProjectFolder, file2.Name);
                    var sourcePath = Path.Combine(modelDirPath, file2.Name);
                    if (File.Exists(destPath))
                    {
                        File.Delete(destPath);
                    }
                    File.Copy(sourcePath, destPath);
                    if (Model.SaveToDepositModels == true)
                    {
                        var depositPath = Path.Combine(settingsService.DepositModelsPath, "DepositModels", "GradeTonnage", Model.DepositModelsExtension);
                        Directory.CreateDirectory(depositPath);
                        destPath = Path.Combine(depositPath, file2.Name);
                        var depositDirInfo = new DirectoryInfo(depositPath);
                        if (File.Exists(destPath))
                        {
                            File.Delete(destPath);
                        }
                        File.Copy(sourcePath, destPath);
                    }
                }
                string modelNameFile = Path.Combine(selectedProjectFolder, "GTModelName.txt");
                File.Create(modelNameFile).Close();
                using (StreamWriter writeStream = new StreamWriter(new FileStream(modelNameFile, FileMode.Open, FileAccess.ReadWrite), Encoding.Default))
                {
                    writeStream.Write(Model.DepositModelsExtension);
                }
                // Get parameters of the selected project.
                GradeTonnageInputParams inputParams = new GradeTonnageInputParams();
                string param_json = Path.Combine(selectedProjectFolder, "GradeTonnage_input_params.json");
                // Check if result files were moved into SelectedResult folder.
                if (File.Exists(param_json))
                {
                    inputParams.Load(param_json);
                    Model.CSVPath           = inputParams.CSVPath;
                    Model.IsTruncated       = inputParams.IsTruncated;
                    Model.PdfType           = inputParams.PDFType;
                    Model.MinDepositCount   = Convert.ToInt32(inputParams.MinDepositCount);
                    Model.RandomSampleCount = Convert.ToInt32(inputParams.RandomSampleCount);
                    Model.Seed            = Convert.ToInt32(inputParams.Seed);
                    Model.Folder          = inputParams.Folder;
                    Model.ExtensionFolder = inputParams.ExtensionFolder;
                    Model.RunGrade        = inputParams.RunGrade;
                    Model.RunTonnage      = inputParams.RunTonnage;
                    Model.ModelType       = inputParams.ModelType;
                }
                // Update info to the Reporting tool.
                if ((File.Exists(Path.Combine(selectedProjectFolder, "grade_summary.txt")) && File.Exists(Path.Combine(selectedProjectFolder, "grade_plot.jpeg"))) ||
                    (File.Exists(Path.Combine(selectedProjectFolder, "tonnage_summary.txt")) && File.Exists(Path.Combine(selectedProjectFolder, "tonnage_plot.jpeg"))))
                {
                    viewModelLocator.ReportingViewModel.Model.GTModelPath = selectedProjectFolder;
                    viewModelLocator.ReportingViewModel.Model.GTModelName = Model.DepositModelsExtension;
                    viewModelLocator.ReportingViewModel.SaveInputs();
                    viewModelLocator.ReportingAssesmentViewModel.Model.GTModelPath = selectedProjectFolder;
                    viewModelLocator.ReportingAssesmentViewModel.Model.GTModelName = Model.DepositModelsExtension;
                    viewModelLocator.ReportingAssesmentViewModel.SaveInputs();
                }
                Model.DepositModelsExtension = "";
                Model.SaveToDepositModels    = false;
                dialogService.ShowNotification("Model selected successfully.", "Success");
                viewModelLocator.SettingsViewModel.WriteLogText("Grade Tonnage model selected successfully.", "Success");
            }
            catch (Exception ex)
            {
                // TAGGED: Initialize new model?
                logger.Trace(ex, "Error in Model Selection");
                dialogService.ShowNotification("Failed to select model.", "Error");
                viewModelLocator.SettingsViewModel.WriteLogText("Failed to select model in Grade Tonnage tool.", "Error");
            }
            var metroWindow = (Application.Current.MainWindow as MetroWindow);
            var dialog      = metroWindow.GetCurrentDialogAsync <BaseMetroDialog>();

            metroWindow.HideMetroDialogAsync(dialog.Result);
            LoadResults();
        }
Beispiel #11
0
        /// <summary>
        /// Initializes a new instance of the GradeTonnageViewModel class.
        /// </summary>
        /// <param name="logger">Logging for the MapWizard.</param>
        /// <param name="dialogService">Service for using dialogs and notifications.</param>
        /// <param name="settingsService">Service for using and editing settings.</param>
        public GradeTonnageViewModel(ILogger logger, IDialogService dialogService, ISettingsService settingsService)
        {
            this.logger          = logger;
            this.dialogService   = dialogService;
            this.settingsService = settingsService;
            var GTFolder  = Path.Combine(settingsService.RootPath, "GTModel");
            var GTDirInfo = new DirectoryInfo(GTFolder);

            if (!Directory.Exists(GTFolder))
            {
                Directory.CreateDirectory(GTFolder);
            }
            RunToolCommand         = new RelayCommand(RunTool, CanRunTool);
            SelectFileCommand      = new RelayCommand(SelectFile, CanRunTool);
            SelectMetalFileCommand = new RelayCommand(SelectMetalFile, CanRunTool);
            SelectFolderCommand    = new RelayCommand(SelectFolder, CanRunTool);
            SelectModelCommand     = new RelayCommand(SelectResult, CanRunTool);
            ShowModelDialog        = new RelayCommand(OpenModelDialog, CanRunTool);
            OpenGradePlotCommand   = new RelayCommand(OpenGradePlot, CanRunTool);
            OpenTonnagePlotCommand = new RelayCommand(OpenTonnagePlot, CanRunTool);
            viewModelLocator       = new ViewModelLocator();
            result = new GradeTonnageResultModel();
            GradeTonnageInputParams inputParams = new GradeTonnageInputParams();
            string projectFolder         = Path.Combine(settingsService.RootPath, "GTModel");
            string selectedProjectFolder = Path.Combine(settingsService.RootPath, "GTModel", "SelectedResult");

            if (!Directory.Exists(selectedProjectFolder))
            {
                Directory.CreateDirectory(selectedProjectFolder);
            }
            string param_json = Path.Combine(selectedProjectFolder, "GradeTonnage_input_params.json");

            if (File.Exists(param_json))
            {
                try
                {
                    inputParams.Load(param_json);
                    Model = new GradeTonnageModel
                    {
                        CSVPath           = inputParams.CSVPath,
                        IsTruncated       = inputParams.IsTruncated,
                        PdfType           = inputParams.PDFType,
                        MinDepositCount   = Convert.ToInt32(inputParams.MinDepositCount),
                        RandomSampleCount = Convert.ToInt32(inputParams.RandomSampleCount),
                        Seed            = Convert.ToInt32(inputParams.Seed),
                        Folder          = inputParams.Folder,
                        ExtensionFolder = inputParams.ExtensionFolder,
                        RunGrade        = inputParams.RunGrade,
                        RunTonnage      = inputParams.RunTonnage,
                        ModelType       = inputParams.ModelType
                    };
                }
                catch (Exception ex)
                {
                    Model = new GradeTonnageModel();
                    logger.Error(ex, "Failed to read json file");
                    dialogService.ShowNotification("Couldn't load Grade Tonnage tool's inputs correctly.", "Error");
                    viewModelLocator.SettingsViewModel.WriteLogText("Couldn't load Grade Tonnage tool's inputs correctly.", "Error");
                }
            }
            else
            {
                Model = new GradeTonnageModel();
            }
            if (Directory.GetFiles(selectedProjectFolder).Length != 0)
            {
                LoadResults();
            }
            FindModelnames(projectFolder);
            var lastRunFile = Path.Combine(projectFolder, "GradeTonnage_last_run.lastrun");

            if (File.Exists(lastRunFile))
            {
                Model.LastRunDate = "Last Run: " + (new FileInfo(lastRunFile)).LastWriteTime.ToString();
            }
        }
Beispiel #12
0
        public void LoadNonExisting2()
        {
            GradeTonnageInputParams input = new GradeTonnageInputParams();

            input.Load(@"testdata\ToolParam_not_found\not_found.json");
        }
Beispiel #13
0
 public static void ClassInit(TestContext context)
 {
     loadedParams = new GradeTonnageInputParams();
     loadedParams.Load(test_json_file_good);
 }