Esempio n. 1
0
        public static async Task <string> GetCombinedStudyScalarDataCsv(
            IRootFolder root,
            IFileWriter writer,
            StudyScalarFiles studyScalarFiles)
        {
            if (studyScalarFiles.ScalarResults == null || studyScalarFiles.ScalarInputs == null)
            {
                return(null);
            }

            var results  = new List <ScalarResultItem>();
            var metadata = new List <ScalarMetadataItem>();

            var scalarResultsFile  = studyScalarFiles.ScalarResults;
            var scalarMetadataFile = studyScalarFiles.ScalarMetadata;

            var(scalarResults, scalarMetadata, jobIndexColumn) = await GetStudyScalarResultsFileContent(scalarResultsFile, scalarMetadataFile);

            if (scalarResults.Count == 0 || scalarMetadata.Count == 0 || jobIndexColumn == null)
            {
                return(null);
            }

            var scalarInputs = await LoadScalarResults(studyScalarFiles.ScalarInputs);

            var scalarInputsMetadata = await LoadScalarInputsMetadata(studyScalarFiles.ScalarInputsMetadata);

            scalarInputsMetadata = scalarInputsMetadata.Skip(1).ToList(); // Skip the column titles row.

            scalarInputs = scalarInputs.Select((v, i) => v.WithMetadata(scalarInputsMetadata?.Count > i ? scalarInputsMetadata[i] : null)).ToList();

            // Now we add the job index, then the scalar inputs, then the scalar results.
            results.Add(jobIndexColumn);
            results.AddRange(scalarInputs);
            results.AddRange(scalarResults);

            metadata.AddRange(scalarInputsMetadata);
            metadata.AddRange(scalarMetadata);

            var csv = new StringBuilder();

            csv.AppendLine(string.Join(",", results.Select(r => r.Metadata?.Description?.WithQuotes() ?? string.Empty)));
            csv.AppendLine(string.Join(",", results.Select(r => (r.Metadata?.FullName ?? r.Name).WithQuotes())));
            csv.AppendLine(string.Join(",", results.Select(r => r.Metadata?.Units?.WithQuotes() ?? string.Empty)));

            for (int resultDataIndex = 0; resultDataIndex < jobIndexColumn.Data.Count; resultDataIndex++)
            {
                var jobIndex = (int)jobIndexColumn.Data[resultDataIndex].ParseJavascriptDouble();
                var lineData = new List <string> {
                    jobIndex.ToJavascriptString()
                }
                .Concat(scalarInputs.Select(v => v.Data[jobIndex].WithQuotes()))
                .Concat(scalarResults.Select(v => v.Data[resultDataIndex].WithQuotes())).ToList();

                csv.AppendLine(string.Join(",", lineData));
            }

            return(csv.ToString());
        }
Esempio n. 2
0
        public static async Task ExecuteAsync(
            IRootFolder root,
            IFileWriter writer,
            StudyScalarFiles studyScalarFiles)
        {
            var content = await GetCombinedStudyScalarDataCsv(root, writer, studyScalarFiles);

            if (content != null)
            {
                var bytes = Encoding.UTF8.GetBytes(content.ToString());
                await writer.WriteNewFile(root, string.Empty, "scalar-results-merged.csv", bytes);
            }
        }