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