Kaydet (Commit) a204a7cc authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

sc: Add newLine() convenience method to AddressWalker

And use the newLine() method in t-test and F-test.

Change-Id: I6372fe1fbc1f63bca56b110115732de96eb2afcf
üst 2afa719d
......@@ -80,22 +80,19 @@ ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_UNDO_NAME));
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString("Alpha");
aOutput.nextColumn();
aOutput.writeValue(0.05);
aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.nextColumn();
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
aOutput.nextColumn();
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
aOutput.nextColumn();
......@@ -104,8 +101,7 @@ ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
aOutput.nextColumn();
aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
aOutput.nextColumn();
......@@ -116,8 +112,7 @@ ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_VARIANCE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
aOutput.nextColumn();
......@@ -128,8 +123,7 @@ ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_OBSERVATIONS%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
aOutput.nextColumn();
......@@ -140,54 +134,46 @@ ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=%VAR2_OBSERVATIONS% - 1");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_DEGREE_OF_FREEDOM%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_F));
aOutput.nextColumn();
aTemplate.setTemplate("=%VAR1_VARIANCE% / %VAR2_VARIANCE%");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%F_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_RIGHT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FDIST(%F_VALUE%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%P_RIGHT_TAIL_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_RIGHT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_LEFT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%P_LEFT_TAIL_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_LEFT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(1-%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_TWO_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_TWO_TAIL));
aOutput.nextColumn();
......
......@@ -81,22 +81,19 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_UNDO_NAME));
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString("Alpha");
aOutput.nextColumn();
aOutput.writeValue(0.05);
aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.nextColumn();
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
aOutput.nextColumn();
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
aOutput.nextColumn();
......@@ -105,8 +102,7 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aOutput.nextColumn();
aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
aOutput.nextColumn();
......@@ -115,8 +111,7 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aOutput.nextColumn();
aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// Observations
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
......@@ -126,24 +121,21 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aOutput.nextColumn();
aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// Pearson Correlation
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_PEARSON_CORRELATION));
aOutput.nextColumn();
aTemplate.setTemplate("=CORREL(%VAR1_RANGE%;%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// Hypothesized mean difference
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_HYPOTHESIZED_MEAN_DIFFERENCE));
aOutput.nextColumn();
aOutput.writeValue(2);
aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// Observed mean difference
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_OBSERVED_MEAN_DIFFERENCE));
......@@ -151,8 +143,7 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=AVERAGE(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// Variance of the Differences
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_VARIANCE_OF_THE_DIFFERENCES));
......@@ -160,8 +151,7 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=VAR(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VARIANCE_OF_DIFFERENCES%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// df
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
......@@ -169,8 +159,7 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=SUM(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)) - 1");
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%DEGREE_OF_FREEDOM%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// t stat
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_STAT));
......@@ -178,39 +167,34 @@ ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / (%VARIANCE_OF_DIFFERENCES% / ( %DEGREE_OF_FREEDOM% + 1)) ^ 0.5");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%T_STAT%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// P one-tail
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_ONE_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 1)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// T critical one-tail
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_ONE_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=TINV(2*0.05; %DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// P two-tail
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_TWO_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 2)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.newLine();
// T critical two-tail
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_TWO_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=TINV(0.05; %DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
}
......
......@@ -111,6 +111,12 @@ void AddressWalker::reset()
mCurrentAddress = mAddressStack.back();
}
void AddressWalker::newLine()
{
resetColumn();
nextRow();
}
ScAddress AddressWalker::current(SCCOL aRelCol, SCROW aRelRow, SCTAB aRelTab)
{
return ScAddress(
......
......@@ -64,12 +64,14 @@ public:
AddressWalker(ScAddress aInitialAddress, bool aTrackRange = true);
ScAddress current(SCCOL aRelativeCol = 0, SCROW aRelativeRow = 0, SCTAB aRelativeTab = 0);
void reset();
void resetColumn();
void resetRow();
void nextColumn();
void nextRow();
void push(SCCOL aRelativeCol = 0, SCROW aRelativeRow = 0, SCTAB aRelativeTab = 0);
void reset();
void resetColumn();
void resetRow();
void nextColumn();
void nextRow();
void newLine();
void push(SCCOL aRelativeCol = 0, SCROW aRelativeRow = 0, SCTAB aRelativeTab = 0);
};
class AddressWalkerWriter : public AddressWalker
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment