Beispiel #1
0
        public async Task <Result <bool> > ExportToExcel(string fileDataFileName,
                                                         CoverSampleResult coverSample,
                                                         DataTable dataMatrix,
                                                         DataTable testMatrix)
        {
            var coverMatrix = coverSample.CoverResult;

            var excelStream = ExportToStream(coverSample, dataMatrix, testMatrix);

            var suffix = $"{coverSample.FileName}_SLOW_{coverSample.SLOW}_SHIGH_{coverSample.SHIGH}_LOW_{coverMatrix.DataMatrix.LOW}_HIGH_{coverMatrix.DataMatrix.HIGH}_STEP_{coverSample.STEP}_METHOD_{coverSample.SelecteMethod.Replace(' ', NewChar).ToUpper()}_PARAM_{coverSample.SelecteMethodParam}_GRADE_{coverSample.CoverResult.Grade}";

            var sfdResult = await SaveFileDialog(fileDataFileName, suffix, excelStream.Value);

            string fileName;

            if (sfdResult.Value)
            {
                fileName = _newSFD.FileName;
            }
            else
            {
                return(new Result <bool>(NieZapisanoPliku));
            }

            return(SaveAndOpenFile(fileName));
        }
Beispiel #2
0
        public Result <bool> AddRaport(XLWorkbook wb, CoverSampleResult coverMatrix)
        {
            wb.Worksheets.Add(name);
            IXLWorksheet ws = wb.Worksheets.Worksheet(name);

            ws.Columns().Width = 17;
            var lastcol        = 1;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.DataMatrix.LOW));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.DataMatrix.HIGH));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.HIGHGood));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.HIGHBad));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.LOWGood));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.LOWBad));
            lastcol++;

            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.Grade));

            lastcol++;
            ws.Cell(1, lastcol).Style.Font.SetBold();
            ws.Cell(1, lastcol).SetValue(nameof(coverMatrix.CoverResult.GoodgGrade));

            var row = 2;

            foreach (var cov in coverMatrix.Samples.OrderByDescending(x => x.Grade))
            {
                lastcol = 1;
                ws.Cell(row, lastcol).SetValue(cov.DataMatrix.LOW);
                ws.Cell(row, ++lastcol).SetValue(cov.DataMatrix.HIGH);
                ws.Cell(row, ++lastcol).SetValue(cov.HIGHGood);
                ws.Cell(row, ++lastcol).SetValue(cov.HIGHBad);
                ws.Cell(row, ++lastcol).SetValue(cov.LOWGood);
                ws.Cell(row, ++lastcol).SetValue(cov.LOWBad);
                ws.Cell(row, ++lastcol).SetValue(cov.Grade);
                ws.Cell(row, ++lastcol).SetValue(cov.GoodgGrade);
                row++;
            }
            return(new Result <bool>(true));
        }
Beispiel #3
0
        public Result <byte[]> ExportToStream(CoverSampleResult coverSample,
                                              DataTable dataMatrix,
                                              DataTable testMatrix)
        {
            var coverMatrix = coverSample.CoverResult;

            using (var wb = new XLWorkbook())
            {
                var dataTable =
                    _dataObjectsConverter.ConvertToDataTable(coverMatrix.DataObjects.Concat(coverMatrix.TestObjects)
                                                             .ToArray());

                var result = AddDataTableToExcel(dataTable, wb, Obiekty);
                if (result.HasErrors())
                {
                    return(new Result <byte[]>(result.Error));
                }

                result = _attributeWriter.AddRaport(wb, coverSample);
                if (result.HasErrors())
                {
                    return(new Result <byte[]>(result.Error));
                }

                result = AddDataTableToExcel(dataMatrix, wb, MacierzPredykcjiTreningowe);
                if (result.HasErrors())
                {
                    return(new Result <byte[]>(result.Error));
                }

                result = _attributeWriter.AddAttributes(wb, coverMatrix);
                if (result.HasErrors())
                {
                    return(new Result <byte[]>(result.Error));
                }

                result = AddDataTableToExcel(testMatrix, wb, MacierzPredykcjiTestowe);
                if (result.HasErrors())
                {
                    return(new Result <byte[]>(result.Error));
                }

                var excelStream = new MemoryStream();
                wb.SaveAs(excelStream);

                return(new Result <byte[]>(excelStream.ToArray()));
            }
        }
        public async Task <Result <CoverSampleResult> > GetMatrix(
            FileData fileData,
            double low,
            double high,
            IGroupingMethod groupMethod,
            double paramInput,
            double step,
            ProgressBarModel progressBarModel,
            Task waitRun)
        {
            var both = GetLowsAndHighs(low, high, step).ToArray();

            var lows  = both.AsParallel().Select(x => x.Item1).ToArray();
            var highs = both.AsParallel().Select(x => x.Item2).ToArray();

            var matrices = (await ComputeForEvery2(fileData, groupMethod, paramInput, highs, lows, progressBarModel, waitRun)).OrderByDescending(y => y.Grade).ToList();

            var max = matrices.First();

            var testMatrixRows = _coverMatrixClassificator.Classify(fileData.TestObjects, max.AttributesCovers, max.HighZeroColumns, max.LowZeroColumns);

            max.TestMatrix =
                new Core.Common.Items.MatrixFeatures.Matrix(testMatrixRows);

            var dataMatrix = _matrixToGridMatrix.TransformToDataTable(max.DataMatrix);
            var testMatrix = _matrixToGridMatrix.TransformToDataTable(max.TestMatrix);

            var result = new CoverSampleResult(max, matrices, fileData.FileName)
            {
                SLOW               = low,
                SHIGH              = high,
                SelecteMethod      = groupMethod.MethodName,
                SelecteMethodParam = paramInput,
                STEP               = step
            };

            max.DataMatrix.DataTable = dataMatrix;
            max.TestMatrix.DataTable = testMatrix;
            DataObject.SchemeObject  = null;

            return(new Result <CoverSampleResult>(result));
        }