Line data Source code
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 <sfx2/dispatch.hxx>
12 : #include <svl/zforlist.hxx>
13 : #include <svl/undo.hxx>
14 : #include <boost/random.hpp>
15 : #include <boost/scoped_ptr.hpp>
16 :
17 : #include "formulacell.hxx"
18 : #include "rangelst.hxx"
19 : #include "scitems.hxx"
20 : #include "docsh.hxx"
21 : #include "document.hxx"
22 : #include "uiitems.hxx"
23 : #include "reffact.hxx"
24 : #include "strload.hxx"
25 : #include "docfunc.hxx"
26 : #include "StatisticsDialogs.hrc"
27 : #include "TableFillingAndNavigationTools.hxx"
28 :
29 : #include "FTestDialog.hxx"
30 :
31 : namespace
32 : {
33 :
34 76 : static const OUString strWildcardVariable1Range("%VAR1_RANGE%");
35 76 : static const OUString strWildcardVariable2Range("%VAR2_RANGE%");
36 :
37 : }
38 :
39 0 : ScFTestDialog::ScFTestDialog(
40 : SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
41 : vcl::Window* pParent, ScViewData* pViewData ) :
42 : ScStatisticsTwoVariableDialog(
43 : pSfxBindings, pChildWindow, pParent, pViewData,
44 0 : "TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
45 : {
46 0 : SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST));
47 0 : }
48 :
49 0 : ScFTestDialog::~ScFTestDialog()
50 0 : {}
51 :
52 0 : bool ScFTestDialog::Close()
53 : {
54 0 : return DoClose( ScFTestDialogWrapper::GetChildWindowId() );
55 : }
56 :
57 0 : sal_Int16 ScFTestDialog::GetUndoNameId()
58 : {
59 0 : return STR_FTEST_UNDO_NAME;
60 : }
61 :
62 0 : ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
63 : {
64 : AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
65 0 : formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
66 0 : FormulaTemplate aTemplate(mDocument);
67 :
68 0 : boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
69 0 : if (mGroupedBy == BY_COLUMN)
70 0 : pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
71 : else
72 0 : pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
73 :
74 0 : boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
75 0 : if (mGroupedBy == BY_COLUMN)
76 0 : pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
77 : else
78 0 : pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
79 :
80 0 : aTemplate.autoReplaceRange(strWildcardVariable1Range, pVariable1Iterator->get());
81 0 : aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
82 :
83 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_UNDO_NAME));
84 0 : aOutput.newLine();
85 :
86 0 : aOutput.writeString("Alpha");
87 0 : aOutput.nextColumn();
88 0 : aOutput.writeValue(0.05);
89 0 : aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
90 0 : aOutput.newLine();
91 :
92 0 : aOutput.nextColumn();
93 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
94 0 : aOutput.nextColumn();
95 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
96 0 : aOutput.newLine();
97 :
98 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
99 0 : aOutput.nextColumn();
100 0 : aTemplate.setTemplate("=AVERAGE(%VAR1_RANGE%)");
101 0 : aOutput.writeFormula(aTemplate.getTemplate());
102 0 : aOutput.nextColumn();
103 0 : aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
104 0 : aOutput.writeFormula(aTemplate.getTemplate());
105 0 : aOutput.newLine();
106 :
107 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
108 0 : aOutput.nextColumn();
109 0 : aTemplate.setTemplate("=VAR(%VAR1_RANGE%)");
110 0 : aOutput.writeFormula(aTemplate.getTemplate());
111 0 : aTemplate.autoReplaceAddress("%VAR1_VARIANCE%", aOutput.current());
112 0 : aOutput.nextColumn();
113 0 : aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
114 0 : aOutput.writeFormula(aTemplate.getTemplate());
115 0 : aTemplate.autoReplaceAddress("%VAR2_VARIANCE%", aOutput.current());
116 0 : aOutput.newLine();
117 :
118 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
119 0 : aOutput.nextColumn();
120 0 : aTemplate.setTemplate("=COUNT(%VAR1_RANGE%)");
121 0 : aOutput.writeFormula(aTemplate.getTemplate());
122 0 : aTemplate.autoReplaceAddress("%VAR1_OBSERVATIONS%", aOutput.current());
123 0 : aOutput.nextColumn();
124 0 : aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
125 0 : aOutput.writeFormula(aTemplate.getTemplate());
126 0 : aTemplate.autoReplaceAddress("%VAR2_OBSERVATIONS%", aOutput.current());
127 0 : aOutput.newLine();
128 :
129 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
130 0 : aOutput.nextColumn();
131 0 : aTemplate.setTemplate("=%VAR1_OBSERVATIONS% - 1");
132 0 : aOutput.writeFormula(aTemplate.getTemplate());
133 0 : aTemplate.autoReplaceAddress("%VAR1_DEGREE_OF_FREEDOM%", aOutput.current());
134 0 : aOutput.nextColumn();
135 0 : aTemplate.setTemplate("=%VAR2_OBSERVATIONS% - 1");
136 0 : aOutput.writeFormula(aTemplate.getTemplate());
137 0 : aTemplate.autoReplaceAddress("%VAR2_DEGREE_OF_FREEDOM%", aOutput.current());
138 0 : aOutput.newLine();
139 :
140 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_F));
141 0 : aOutput.nextColumn();
142 0 : aTemplate.setTemplate("=%VAR1_VARIANCE% / %VAR2_VARIANCE%");
143 0 : aOutput.writeFormula(aTemplate.getTemplate());
144 0 : aTemplate.autoReplaceAddress("%F_VALUE%", aOutput.current());
145 0 : aOutput.newLine();
146 :
147 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_RIGHT_TAIL));
148 0 : aOutput.nextColumn();
149 0 : aTemplate.setTemplate("=FDIST(%F_VALUE%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
150 0 : aOutput.writeFormula(aTemplate.getTemplate());
151 0 : aTemplate.autoReplaceAddress("%P_RIGHT_TAIL_VALUE%", aOutput.current());
152 0 : aOutput.newLine();
153 :
154 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_RIGHT_TAIL));
155 0 : aOutput.nextColumn();
156 0 : aTemplate.setTemplate("=FINV(%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
157 0 : aOutput.writeFormula(aTemplate.getTemplate());
158 0 : aOutput.newLine();
159 :
160 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_LEFT_TAIL));
161 0 : aOutput.nextColumn();
162 0 : aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%");
163 0 : aOutput.writeFormula(aTemplate.getTemplate());
164 0 : aTemplate.autoReplaceAddress("%P_LEFT_TAIL_VALUE%", aOutput.current());
165 0 : aOutput.newLine();
166 :
167 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_LEFT_TAIL));
168 0 : aOutput.nextColumn();
169 0 : aTemplate.setTemplate("=FINV(1-%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
170 0 : aOutput.writeFormula(aTemplate.getTemplate());
171 0 : aOutput.newLine();
172 :
173 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_TWO_TAIL));
174 0 : aOutput.nextColumn();
175 0 : aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)");
176 0 : aOutput.writeFormula(aTemplate.getTemplate());
177 0 : aOutput.newLine();
178 :
179 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_TWO_TAIL));
180 0 : aOutput.nextColumn();
181 0 : aTemplate.setTemplate("=FINV(1-(%ALPHA%/2); %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
182 0 : aOutput.writeFormula(aTemplate.getTemplate());
183 0 : aOutput.nextColumn();
184 0 : aTemplate.setTemplate("=FINV(%ALPHA%/2; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
185 0 : aOutput.writeFormula(aTemplate.getTemplate());
186 :
187 0 : return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
188 228 : }
189 :
190 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|