public PetDetailsViewModel(Dataset dataset, string resultsDirectory) { DetailsDataset = dataset; ResultsDirectory = resultsDirectory; RecordCount = 0; MgaFilename = ""; MgaFilePath = ""; PetPath = ""; if (DetailsDataset.Kind == Dataset.DatasetKind.PetResult) { var datasetPath = System.IO.Path.Combine(resultsDirectory, DetailsDataset.Folders[0]); Manifest = MetaTBManifest.Deserialize(datasetPath); try { var jsonFileName = Path.Combine(ResultsDirectory, DetailsDataset.Folders[0].Replace("testbench_manifest.json", "mdao_config.json")); using (var reader = File.OpenText(jsonFileName)) { var serializer = new JsonSerializer(); var mdaoConfig = (PETConfig)serializer.Deserialize(reader, typeof(PETConfig)); if (!string.IsNullOrEmpty(mdaoConfig.MgaFilename)) { MgaFilePath = mdaoConfig.MgaFilename; MgaFilename = Path.GetFileName(MgaFilePath); } if (!string.IsNullOrEmpty(mdaoConfig.PETName)) { PetPath = mdaoConfig.PETName; } } } catch (Exception e) { Console.WriteLine("Error occurred reading mdao_config.json: "); Console.WriteLine(e); Trace.TraceError("Error occurred reading mdao_config.json: "); Trace.TraceError(e.ToString()); } ComputeStatistics(); } else { Manifest = null; } }
public TBManifestViewModel(string manifestPath) { Manifest = MetaTBManifest.Deserialize(manifestPath); Dependencies = new ListCollectionView(Manifest.Dependencies); Artifacts = new ListCollectionView(Manifest.Artifacts); Artifacts.SortDescriptions.Add(new SortDescription("Tag", ListSortDirection.Ascending)); VisualizationArtifacts = new ListCollectionView(Manifest.VisualizationArtifacts); VisualizationArtifacts.SortDescriptions.Add(new SortDescription("Tag", ListSortDirection.Ascending)); Metrics = new ListCollectionView(Manifest.Metrics); Metrics.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); Parameters = new ListCollectionView(Manifest.Parameters); Parameters.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); Steps = new ListCollectionView(Manifest.Steps); }
private static void WriteDatasetToCsv(Dataset d, ref List <string> headers, CsvWriter writer, string dataDirectoryPath, bool writeNoneAsEmpty, bool documentCfdID, bool documentAlternatives, bool documentOptionals) { Console.WriteLine(d.Name); foreach (var folder in d.Folders) { bool firstHeaderReadForFolder = true; var addedHeaders = new Dictionary <string, string>(); var headersPresent = new Dictionary <string, bool>(); if (documentCfdID) { addedHeaders["CfgID"] = "Unknown"; } string testbenchManifestFilePath; string csvFileName; if (d.Kind == Dataset.DatasetKind.PetResult) { testbenchManifestFilePath = Path.Combine(dataDirectoryPath, DatasetStore.ResultsDirectory, folder); csvFileName = Path.Combine(dataDirectoryPath, DatasetStore.ResultsDirectory, folder.Replace("testbench_manifest.json", "output.csv")); // Try to get the CfgID and alternatives to append to 'mergedPET.csv' try { var Manifest = MetaTBManifest.Deserialize(testbenchManifestFilePath); if (documentCfdID & Manifest.CfgID != null) { addedHeaders["CfgID"] = Manifest.CfgID; } if (Manifest.Design != null) { var Decisions = FlattenDesignType(Manifest.Design).Where(a => a.Type == "Alternative" | a.Type == "Optional"); if (!documentAlternatives) { Decisions = Decisions.Where(a => a.Type != "Alternative"); } if (!documentOptionals) { Decisions = Decisions.Where(a => a.Type != "Optional"); } foreach (var Decision in Decisions) { var Choices = Decision.Children.Where(a => DesignTypeIsSelected(a) == true); if (Choices.Count() == 0) { addedHeaders[Decision.Name] = "None"; } else { foreach (var Choice in Choices) { addedHeaders[Decision.Name] = Choice.Name; } } //Console.WriteLine("DesignType: {0} ({1}): {2}", Decision.Name, Decision.Type, addedHeaders[Decision.Name]); } } } catch (FileNotFoundException) { //Don't adjust configuration name if we don't find a corresponding testbenchmanifest in its results folder } catch (DirectoryNotFoundException) { //Don't adjust configuration name if we don't find its directory } } else if (d.Kind == Dataset.DatasetKind.MergedPet || d.Kind == Dataset.DatasetKind.Pet) { csvFileName = Path.Combine(dataDirectoryPath, DatasetStore.MergedDirectory, folder, "mergedPET.csv"); } else { csvFileName = Path.Combine(dataDirectoryPath, DatasetStore.ArchiveDirectory, folder); } Console.WriteLine("Exporting CSV {0}", csvFileName); //Assume the added columns don't exist in the data we're reading from foreach (var header in addedHeaders) { headersPresent[header.Key] = false; } try { using (var csvFile = new StreamReader(File.Open(csvFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8)) { var csvReader = new CsvReader(csvFile, new CsvConfiguration() { HasHeaderRecord = true }); while (csvReader.Read()) { // Is this the first dataset being written to the CSV? if (headers == null) { // Yes. Let's setup the authority on what variables should be present. Console.Out.WriteLine(csvFileName); headers = new List <string>(csvReader.FieldHeaders); foreach (var addedHeader in addedHeaders) { if (headers.Contains(addedHeader.Key)) { headersPresent[addedHeader.Key] = true; } else { headers.Add(addedHeader.Key); } } headers.Sort(); firstHeaderReadForFolder = false; foreach (var header in headers) { writer.WriteField <string>(header); } writer.NextRecord(); } else { // No. Let's see if the headers match up. if (firstHeaderReadForFolder) { var otherHeaders = new List <string>(csvReader.FieldHeaders); foreach (var addedHeader in addedHeaders) { if (otherHeaders.Contains(addedHeader.Key)) { headersPresent[addedHeader.Key] = true; } else { otherHeaders.Add(addedHeader.Key); } } otherHeaders.Sort(); if (!headers.SequenceEqual(otherHeaders)) { Console.WriteLine("Headers for {0} didn't match initial headers", csvFileName); break; } } } foreach (var header in headers) { if (addedHeaders.ContainsKey(header) && !headersPresent[header]) { writer.WriteField <string>(addedHeaders[header]); } else { string fieldValue = csvReader.GetField <string>(header); if (writeNoneAsEmpty && fieldValue == "None") { writer.WriteField <string>(""); } else { writer.WriteField <string>(fieldValue); } } } writer.NextRecord(); } } } catch (CsvReaderException e) { Console.WriteLine("Invalid CSV found at {0}", csvFileName); Trace.TraceWarning("Invalid CSV found at {0}", csvFileName); } catch (FileNotFoundException e) { Console.WriteLine("Missing CSV at {0}", csvFileName); Trace.TraceWarning("Missing CSV at {0}", csvFileName); } } }