Kaydet (Commit) 2ffe2282 authored tarafından Dennis Francis's avatar Dennis Francis

Allow forcing of intercept to zero in regression dialog

Change-Id: I3958c139141a9e717256a638d319e0bb5879e6a4
Reviewed-on: https://gerrit.libreoffice.org/58565
Tested-by: Jenkins
Reviewed-by: 's avatarDennis Francis <dennis.francis@collabora.co.uk>
üst 6b8874e7
...@@ -31,17 +31,18 @@ class regression(UITestCase): ...@@ -31,17 +31,18 @@ class regression(UITestCase):
document = self.ui_test.get_component() document = self.ui_test.get_component()
# Initially the final check status is "FALSE" (failed). # Initially the final check status is "FALSE" (failed).
self.assertEqual(get_cell_by_position(document, 11, 1, 5).getString(), "FALSE", self.assertEqual(get_cell_by_position(document, 14, 1, 6).getString(), "FALSE",
"Check status must be FALSE before the test") "Check status must be FALSE before the test")
self._do_regression(regression_type = "LINEAR", data_groupedby_column = data_groupedby_column) self._do_regression(regression_type = "LINEAR", data_groupedby_column = data_groupedby_column, calc_intercept = True)
self._do_regression(regression_type = "LINEAR", data_groupedby_column = data_groupedby_column, calc_intercept = False)
self._do_regression(regression_type = "LOG", data_groupedby_column = data_groupedby_column) self._do_regression(regression_type = "LOG", data_groupedby_column = data_groupedby_column)
self._do_regression(regression_type = "POWER", data_groupedby_column = data_groupedby_column) self._do_regression(regression_type = "POWER", data_groupedby_column = data_groupedby_column)
self.assertEqual(get_cell_by_position(document, 11, 1, 5).getString(), "TRUE", self.assertEqual(get_cell_by_position(document, 14, 1, 6).getString(), "TRUE",
"One of more of the checks failed for data_groupedby_column = {}, manually try with the document". "One of more of the checks failed for data_groupedby_column = {}, manually try with the document".
format(data_groupedby_column)) format(data_groupedby_column))
self.ui_test.close_doc() self.ui_test.close_doc()
def _do_regression(self, regression_type, data_groupedby_column = True): def _do_regression(self, regression_type, data_groupedby_column = True, calc_intercept = True):
assert(regression_type == "LINEAR" or regression_type == "LOG" or regression_type == "POWER") assert(regression_type == "LINEAR" or regression_type == "LOG" or regression_type == "POWER")
self.ui_test.execute_modeless_dialog_through_command(".uno:RegressionDialog") self.ui_test.execute_modeless_dialog_through_command(".uno:RegressionDialog")
xDialog = self.xUITest.getTopFocusWindow() xDialog = self.xUITest.getTopFocusWindow()
...@@ -54,6 +55,7 @@ class regression(UITestCase): ...@@ -54,6 +55,7 @@ class regression(UITestCase):
xlinearradio = xDialog.getChild("linear-radio") xlinearradio = xDialog.getChild("linear-radio")
xlogarithmicradio = xDialog.getChild("logarithmic-radio") xlogarithmicradio = xDialog.getChild("logarithmic-radio")
xpowerradio = xDialog.getChild("power-radio") xpowerradio = xDialog.getChild("power-radio")
xnointerceptcheck = xDialog.getChild("nointercept-check")
## Set the X, Y and output ranges ## Set the X, Y and output ranges
xvariable1rangeedit.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow xvariable1rangeedit.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
...@@ -79,7 +81,10 @@ class regression(UITestCase): ...@@ -79,7 +81,10 @@ class regression(UITestCase):
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
if regression_type == "LINEAR": if regression_type == "LINEAR":
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinear.$A$1"})) if calc_intercept:
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinear.$A$1"}))
else:
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinearNoIntercept.$A$1"}))
elif regression_type == "LOG": elif regression_type == "LOG":
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLog.$A$1"})) xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLog.$A$1"}))
else: else:
...@@ -97,6 +102,9 @@ class regression(UITestCase): ...@@ -97,6 +102,9 @@ class regression(UITestCase):
else: else:
xpowerradio.executeAction("CLICK", tuple()) xpowerradio.executeAction("CLICK", tuple())
if not calc_intercept:
xnointerceptcheck.executeAction("CLICK", tuple())
xOKBtn = xDialog.getChild("ok") xOKBtn = xDialog.getChild("ok")
self.ui_test.close_dialog_through_button(xOKBtn) self.ui_test.close_dialog_through_button(xOKBtn)
......
...@@ -116,9 +116,9 @@ namespace ...@@ -116,9 +116,9 @@ namespace
OUString constTemplateLINEST[] = OUString constTemplateLINEST[] =
{ {
"=LINEST(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE% ; TRUE ; TRUE)", "=LINEST(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE% ; %CALC_INTERCEPT% ; TRUE)",
"=LINEST(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%) ; TRUE ; TRUE)", "=LINEST(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)",
"=LINEST(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%) ; TRUE ; TRUE)" "=LINEST(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)"
}; };
OUString constRegressionFormula[] = OUString constRegressionFormula[] =
...@@ -147,7 +147,8 @@ ScRegressionDialog::ScRegressionDialog( ...@@ -147,7 +147,8 @@ ScRegressionDialog::ScRegressionDialog(
mbUnivariate(true), mbUnivariate(true),
mnNumIndependentVars(1), mnNumIndependentVars(1),
mnNumObservations(0), mnNumObservations(0),
mbUse3DAddresses(false) mbUse3DAddresses(false),
mbCalcIntercept(true)
{ {
get(mpWithLabelsCheckBox, "withlabels-check"); get(mpWithLabelsCheckBox, "withlabels-check");
get(mpLinearRadioButton, "linear-radio"); get(mpLinearRadioButton, "linear-radio");
...@@ -155,10 +156,10 @@ ScRegressionDialog::ScRegressionDialog( ...@@ -155,10 +156,10 @@ ScRegressionDialog::ScRegressionDialog(
get(mpPowerRadioButton, "power-radio"); get(mpPowerRadioButton, "power-radio");
get(mpConfidenceLevelField, "confidencelevel-spin"); get(mpConfidenceLevelField, "confidencelevel-spin");
get(mpCalcResidualsCheckBox, "calcresiduals-check"); get(mpCalcResidualsCheckBox, "calcresiduals-check");
get(mpNoInterceptCheckBox, "nointercept-check");
get(mpErrorMessage, "error-message"); get(mpErrorMessage, "error-message");
mpWithLabelsCheckBox->SetToggleHdl(LINK(this, ScRegressionDialog, CheckBoxHdl)); mpWithLabelsCheckBox->SetToggleHdl(LINK(this, ScRegressionDialog, CheckBoxHdl));
mpConfidenceLevelField->SetModifyHdl(LINK(this, ScRegressionDialog, NumericFieldHdl)); mpConfidenceLevelField->SetModifyHdl(LINK(this, ScRegressionDialog, NumericFieldHdl));
mpCalcResidualsCheckBox->SetToggleHdl(LINK(this, ScRegressionDialog, CheckBoxHdl));
} }
ScRegressionDialog::~ScRegressionDialog() ScRegressionDialog::~ScRegressionDialog()
...@@ -179,6 +180,7 @@ void ScRegressionDialog::dispose() ...@@ -179,6 +180,7 @@ void ScRegressionDialog::dispose()
mpPowerRadioButton.disposeAndClear(); mpPowerRadioButton.disposeAndClear();
mpConfidenceLevelField.disposeAndClear(); mpConfidenceLevelField.disposeAndClear();
mpCalcResidualsCheckBox.disposeAndClear(); mpCalcResidualsCheckBox.disposeAndClear();
mpNoInterceptCheckBox.disposeAndClear();
mpErrorMessage.disposeAndClear(); mpErrorMessage.disposeAndClear();
ScStatisticsTwoVariableDialog::dispose(); ScStatisticsTwoVariableDialog::dispose();
} }
...@@ -194,6 +196,7 @@ ScRange ScRegressionDialog::ApplyOutput(ScDocShell* pDocShell) ...@@ -194,6 +196,7 @@ ScRange ScRegressionDialog::ApplyOutput(ScDocShell* pDocShell)
formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv)); formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
FormulaTemplate aTemplate(mDocument); FormulaTemplate aTemplate(mDocument);
aTemplate.autoReplaceUses3D(mbUse3DAddresses); aTemplate.autoReplaceUses3D(mbUse3DAddresses);
mbCalcIntercept = !mpNoInterceptCheckBox->IsChecked();
// max col of our output should account for // max col of our output should account for
// 1. constant term column, // 1. constant term column,
...@@ -378,7 +381,10 @@ void ScRegressionDialog::WriteRawRegressionResults(AddressWalkerWriter& rOutput, ...@@ -378,7 +381,10 @@ void ScRegressionDialog::WriteRawRegressionResults(AddressWalkerWriter& rOutput,
rOutput.writeString(ScResId(STR_LINEST_RAW_OUTPUT_TITLE)); rOutput.writeString(ScResId(STR_LINEST_RAW_OUTPUT_TITLE));
rOutput.newLine(); rOutput.newLine();
rOutput.push(); rOutput.push();
rTemplate.setTemplate(constTemplateLINEST[nRegressionIndex]);
rTemplate.setTemplate(constTemplateLINEST[nRegressionIndex].
replaceFirst("%CALC_INTERCEPT%",
mbCalcIntercept ? OUString("TRUE") : OUString("FALSE")));
rOutput.writeMatrixFormula(rTemplate.getTemplate(), 1 + mnNumIndependentVars, 5); rOutput.writeMatrixFormula(rTemplate.getTemplate(), 1 + mnNumIndependentVars, 5);
// Add LINEST result components to template // Add LINEST result components to template
// 1. Add ranges for coefficients and standard errors for indep. vars and the intercept. // 1. Add ranges for coefficients and standard errors for indep. vars and the intercept.
...@@ -423,7 +429,8 @@ void ScRegressionDialog::WriteRegressionStatistics(AddressWalkerWriter& rOutput, ...@@ -423,7 +429,8 @@ void ScRegressionDialog::WriteRegressionStatistics(AddressWalkerWriter& rOutput,
"=%SERRORY_ADDR%", "=%SERRORY_ADDR%",
"=" + OUString::number(mnNumIndependentVars), "=" + OUString::number(mnNumIndependentVars),
"=" + OUString::number(mnNumObservations), "=" + OUString::number(mnNumObservations),
"=1 - (1 - %RSQUARED_ADDR%)*(%NUMOBS_ADDR% - 1)/(%NUMOBS_ADDR% - %NUMXVARS_ADDR% - 1)" "=1 - (1 - %RSQUARED_ADDR%)*(%NUMOBS_ADDR% - 1)/(%NUMOBS_ADDR% - %NUMXVARS_ADDR%" +
(mbCalcIntercept ? OUString(" - 1)") : OUString(")"))
}; };
rTemplate.autoReplaceAddress("%NUMXVARS_ADDR%", rOutput.current(1, 2)); rTemplate.autoReplaceAddress("%NUMXVARS_ADDR%", rOutput.current(1, 2));
......
...@@ -22,11 +22,13 @@ class ScRegressionDialog : public ScStatisticsTwoVariableDialog ...@@ -22,11 +22,13 @@ class ScRegressionDialog : public ScStatisticsTwoVariableDialog
VclPtr<FixedText> mpErrorMessage; VclPtr<FixedText> mpErrorMessage;
VclPtr<NumericField> mpConfidenceLevelField; VclPtr<NumericField> mpConfidenceLevelField;
VclPtr<CheckBox> mpCalcResidualsCheckBox; VclPtr<CheckBox> mpCalcResidualsCheckBox;
VclPtr<CheckBox> mpNoInterceptCheckBox;
bool mbUnivariate; bool mbUnivariate;
size_t mnNumIndependentVars; size_t mnNumIndependentVars;
size_t mnNumObservations; size_t mnNumObservations;
bool mbUse3DAddresses; bool mbUse3DAddresses;
bool mbCalcIntercept;
public: public:
ScRegressionDialog( ScRegressionDialog(
......
...@@ -484,7 +484,17 @@ ...@@ -484,7 +484,17 @@
</packing> </packing>
</child> </child>
<child> <child>
<placeholder/> <object class="GtkCheckButton" id="nointercept-check">
<property name="label" translatable="yes" context="regressiondialog|nointercept-check">Force intercept to be zero</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child> </child>
</object> </object>
</child> </child>
......
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