/src/libreoffice/sc/source/ui/StatisticsDialogs/FTestDialog.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | */ |
10 | | |
11 | | #include <memory> |
12 | | |
13 | | #include <vcl/weld/Dialog.hxx> |
14 | | |
15 | | #include <reffact.hxx> |
16 | | #include <TableFillingAndNavigationTools.hxx> |
17 | | #include <FTestDialog.hxx> |
18 | | #include <scresid.hxx> |
19 | | #include <strings.hrc> |
20 | | |
21 | | ScFTestDialog::ScFTestDialog( |
22 | | SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, |
23 | | weld::Window* pParent, ScViewData& rViewData ) : |
24 | 0 | ScStatisticsTwoVariableDialog( |
25 | 0 | pSfxBindings, pChildWindow, pParent, rViewData, |
26 | 0 | u"modules/scalc/ui/ttestdialog.ui"_ustr, u"TTestDialog"_ustr ) |
27 | 0 | { |
28 | 0 | m_xDialog->set_title(ScResId(STR_FTEST)); |
29 | 0 | } |
30 | | |
31 | | ScFTestDialog::~ScFTestDialog() |
32 | 0 | {} |
33 | | |
34 | | void ScFTestDialog::Close() |
35 | 0 | { |
36 | 0 | DoClose( ScFTestDialogWrapper::GetChildWindowId() ); |
37 | 0 | } |
38 | | |
39 | | TranslateId ScFTestDialog::GetUndoNameId() |
40 | 0 | { |
41 | 0 | return STR_FTEST_UNDO_NAME; |
42 | 0 | } |
43 | | |
44 | | ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell) |
45 | 0 | { |
46 | 0 | AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument, |
47 | 0 | formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv)); |
48 | 0 | FormulaTemplate aTemplate(&mDocument); |
49 | |
|
50 | 0 | std::unique_ptr<DataRangeIterator> pVariable1Iterator; |
51 | 0 | if (mGroupedBy == GroupedBy::BY_COLUMN) |
52 | 0 | pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range)); |
53 | 0 | else |
54 | 0 | pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range)); |
55 | |
|
56 | 0 | std::unique_ptr<DataRangeIterator> pVariable2Iterator; |
57 | 0 | if (mGroupedBy == GroupedBy::BY_COLUMN) |
58 | 0 | pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range)); |
59 | 0 | else |
60 | 0 | pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range)); |
61 | |
|
62 | 0 | aTemplate.autoReplaceRange(u"%VARIABLE1_RANGE%"_ustr, pVariable1Iterator->get()); |
63 | 0 | aTemplate.autoReplaceRange(u"%VARIABLE2_RANGE%"_ustr, pVariable2Iterator->get()); |
64 | |
|
65 | 0 | aOutput.writeBoldString(ScResId(STR_FTEST_UNDO_NAME)); |
66 | 0 | aOutput.newLine(); |
67 | | |
68 | | // Alpha |
69 | 0 | aOutput.writeString(ScResId(STR_LABEL_ALPHA)); |
70 | 0 | aOutput.nextColumn(); |
71 | 0 | aOutput.writeValue(0.05); |
72 | 0 | aTemplate.autoReplaceAddress(u"%ALPHA%"_ustr, aOutput.current()); |
73 | 0 | aOutput.newLine(); |
74 | |
|
75 | 0 | aOutput.nextColumn(); |
76 | 0 | aOutput.writeBoldString(ScResId(STR_VARIABLE_1_LABEL)); |
77 | 0 | aOutput.nextColumn(); |
78 | 0 | aOutput.writeBoldString(ScResId(STR_VARIABLE_2_LABEL)); |
79 | 0 | aOutput.newLine(); |
80 | |
|
81 | 0 | aOutput.writeString(ScResId(STRID_CALC_MEAN)); |
82 | 0 | aOutput.nextColumn(); |
83 | 0 | aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)"); |
84 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
85 | 0 | aOutput.nextColumn(); |
86 | 0 | aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)"); |
87 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
88 | 0 | aOutput.newLine(); |
89 | |
|
90 | 0 | aOutput.writeString(ScResId(STRID_CALC_VARIANCE)); |
91 | 0 | aOutput.nextColumn(); |
92 | 0 | aTemplate.setTemplate("=VAR(%VARIABLE1_RANGE%)"); |
93 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
94 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE1_VARIANCE%"_ustr, aOutput.current()); |
95 | 0 | aOutput.nextColumn(); |
96 | 0 | aTemplate.setTemplate("=VAR(%VARIABLE2_RANGE%)"); |
97 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
98 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE2_VARIANCE%"_ustr, aOutput.current()); |
99 | 0 | aOutput.newLine(); |
100 | |
|
101 | 0 | aOutput.writeString(ScResId(STR_OBSERVATIONS_LABEL)); |
102 | 0 | aOutput.nextColumn(); |
103 | 0 | aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)"); |
104 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
105 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE1_OBSERVATIONS%"_ustr, aOutput.current()); |
106 | 0 | aOutput.nextColumn(); |
107 | 0 | aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)"); |
108 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
109 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE2_OBSERVATIONS%"_ustr, aOutput.current()); |
110 | 0 | aOutput.newLine(); |
111 | |
|
112 | 0 | aOutput.writeString(ScResId(STR_ANOVA_LABEL_DF)); |
113 | 0 | aOutput.nextColumn(); |
114 | 0 | aTemplate.setTemplate("=%VARIABLE1_OBSERVATIONS% - 1"); |
115 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
116 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE1_DEGREE_OF_FREEDOM%"_ustr, aOutput.current()); |
117 | 0 | aOutput.nextColumn(); |
118 | 0 | aTemplate.setTemplate("=%VARIABLE2_OBSERVATIONS% - 1"); |
119 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
120 | 0 | aTemplate.autoReplaceAddress(u"%VARIABLE2_DEGREE_OF_FREEDOM%"_ustr, aOutput.current()); |
121 | 0 | aOutput.newLine(); |
122 | |
|
123 | 0 | aOutput.writeString(ScResId(STR_ANOVA_LABEL_F)); |
124 | 0 | aOutput.nextColumn(); |
125 | 0 | aTemplate.setTemplate("=%VARIABLE1_VARIANCE% / %VARIABLE2_VARIANCE%"); |
126 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
127 | 0 | aTemplate.autoReplaceAddress(u"%F_VALUE%"_ustr, aOutput.current()); |
128 | 0 | aOutput.newLine(); |
129 | |
|
130 | 0 | aOutput.writeString(ScResId(STR_FTEST_P_RIGHT_TAIL)); |
131 | 0 | aOutput.nextColumn(); |
132 | 0 | aTemplate.setTemplate("=FDIST(%F_VALUE%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)"); |
133 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
134 | 0 | aTemplate.autoReplaceAddress(u"%P_RIGHT_TAIL_VALUE%"_ustr, aOutput.current()); |
135 | 0 | aOutput.newLine(); |
136 | |
|
137 | 0 | aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_RIGHT_TAIL)); |
138 | 0 | aOutput.nextColumn(); |
139 | 0 | aTemplate.setTemplate("=FINV(%ALPHA%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)"); |
140 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
141 | 0 | aOutput.newLine(); |
142 | |
|
143 | 0 | aOutput.writeString(ScResId(STR_FTEST_P_LEFT_TAIL)); |
144 | 0 | aOutput.nextColumn(); |
145 | 0 | aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%"); |
146 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
147 | 0 | aTemplate.autoReplaceAddress(u"%P_LEFT_TAIL_VALUE%"_ustr, aOutput.current()); |
148 | 0 | aOutput.newLine(); |
149 | |
|
150 | 0 | aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_LEFT_TAIL)); |
151 | 0 | aOutput.nextColumn(); |
152 | 0 | aTemplate.setTemplate("=FINV(1-%ALPHA%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)"); |
153 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
154 | 0 | aOutput.newLine(); |
155 | |
|
156 | 0 | aOutput.writeString(ScResId(STR_FTEST_P_TWO_TAIL)); |
157 | 0 | aOutput.nextColumn(); |
158 | 0 | aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)"); |
159 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
160 | 0 | aOutput.newLine(); |
161 | |
|
162 | 0 | aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_TWO_TAIL)); |
163 | 0 | aOutput.nextColumn(); |
164 | 0 | aTemplate.setTemplate("=FINV(1-(%ALPHA%/2); %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)"); |
165 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
166 | 0 | aOutput.nextColumn(); |
167 | 0 | aTemplate.setTemplate("=FINV(%ALPHA%/2; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)"); |
168 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
169 | |
|
170 | 0 | return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress); |
171 | 0 | } |
172 | | |
173 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |