コード例 #1
0
        private void FillStatisticalColumns(IExcelSheet sheet, ref int currentColumnIndex)
        {
            int rowIndex = 1;

            var sampleMeanColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[sampleMeanColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.SampleMeanColumnName);

            var sampleVarianceColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[sampleVarianceColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.SampleVarianceColumnName);

            var sampleDeviationColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[sampleDeviationColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.SampleDeviationColumnName);

            var normalizedMeanColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[normalizedMeanColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.NormalizedMeanColumnName);

            var normalizedVarienceColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[normalizedVarienceColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.NormalizedVarienceColumnName);

            var alphaColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[alphaColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.AlphaColumnName);

            var betaColumnIndex = currentColumnIndex++.AsEnum <ExcelColumnIndex>();

            sheet[betaColumnIndex, rowIndex].SetValue(ExcelStringsPhaseTwo.BetaColumnName);

            ++rowIndex;
            int launchesColumnIndex     = 0;
            int firstRowIndex           = ExcelWrapperForPhaseTwo.GetFirstDataRowIndex();
            int lastRowIndex            = ExcelWrapperForPhaseTwo.GetLastDataRowIndex(_args);
            int firstNormalizedRowIndex = ExcelWrapperForPhaseTwo.GetFirstNormalizedDataRowIndex(_args);
            int lastNormalizedRowIndex  = ExcelWrapperForPhaseTwo.GetLastNormalizedDataRowIndex(_args);

            for (int launchesNumber = _args.StartValue; launchesNumber <= _args.EndValue;
                 launchesNumber += _args.Step)
            {
                var launchesColumnIndexEnum = launchesColumnIndex++.AsEnum <ExcelColumnIndex>();

                string dataRange =
                    $"{sheet[launchesColumnIndexEnum, firstRowIndex].Address}:" +
                    $"{sheet[launchesColumnIndexEnum, lastRowIndex].Address}";

                string sampleMeanFormula = sheet.FormulaProvider.Average(dataRange);
                sheet[sampleMeanColumnIndex, rowIndex].SetFormula(sampleMeanFormula);

                string sampleVarienceFormula = sheet.FormulaProvider.Var(dataRange);
                sheet[sampleVarianceColumnIndex, rowIndex].SetFormula(sampleVarienceFormula);

                string sampleDeviationFormula = sheet.FormulaProvider.StdDev(dataRange);
                sheet[sampleDeviationColumnIndex, rowIndex].SetFormula(sampleDeviationFormula);

                string normalizedDataRange =
                    $"{sheet[launchesColumnIndexEnum, firstNormalizedRowIndex].Address}:" +
                    $"{sheet[launchesColumnIndexEnum, lastNormalizedRowIndex].Address}";

                string normalizedMeanFormula = sheet.FormulaProvider.Average(normalizedDataRange);
                sheet[normalizedMeanColumnIndex, rowIndex].SetFormula(normalizedMeanFormula);

                string normalizedVarienceFormula = sheet.FormulaProvider.Var(normalizedDataRange);
                sheet[normalizedVarienceColumnIndex, rowIndex].SetFormula(normalizedVarienceFormula);

                string normalizedMeanAddress     = sheet[normalizedMeanColumnIndex, rowIndex].Address;
                string normalizedVarienceAddress = sheet[normalizedVarienceColumnIndex, rowIndex].Address;

                string alphaFormula = ManualFormulaProvider.Alpha(
                    normalizedMeanAddress, normalizedVarienceAddress
                    );
                sheet[alphaColumnIndex, rowIndex].SetFormula(alphaFormula);

                string betaFormula = ManualFormulaProvider.Beta(
                    normalizedMeanAddress, normalizedVarienceAddress
                    );
                sheet[betaColumnIndex, rowIndex].SetFormula(betaFormula);

                ++rowIndex;
            }

            sheet.AutoSizeColumn(sampleMeanColumnIndex);
            sheet.AutoSizeColumn(sampleVarianceColumnIndex);
            sheet.AutoSizeColumn(sampleDeviationColumnIndex);
            sheet.AutoSizeColumn(normalizedMeanColumnIndex);
            sheet.AutoSizeColumn(normalizedVarienceColumnIndex);
            sheet.AutoSizeColumn(alphaColumnIndex);
            sheet.AutoSizeColumn(betaColumnIndex);
        }