[Libreoffice-commits] core.git: sc/qa sc/source sc/uiconfig
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Aug 3 17:13:01 UTC 2018
sc/qa/uitest/statistics/data/regression.ods |binary
sc/qa/uitest/statistics/regression.py | 18 ++++++++++++-----
sc/source/ui/StatisticsDialogs/RegressionDialog.cxx | 21 +++++++++++++-------
sc/source/ui/inc/RegressionDialog.hxx | 2 +
sc/uiconfig/scalc/ui/regressiondialog.ui | 12 ++++++++++-
5 files changed, 40 insertions(+), 13 deletions(-)
New commits:
commit 2ffe228264caa77b18c3bea56823f000b2d01a7e
Author: Dennis Francis <dennis.francis at collabora.co.uk>
AuthorDate: Wed Aug 1 17:59:23 2018 +0530
Commit: Dennis Francis <dennis.francis at collabora.co.uk>
CommitDate: Fri Aug 3 19:12:36 2018 +0200
Allow forcing of intercept to zero in regression dialog
Change-Id: I3958c139141a9e717256a638d319e0bb5879e6a4
Reviewed-on: https://gerrit.libreoffice.org/58565
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis at collabora.co.uk>
diff --git a/sc/qa/uitest/statistics/data/regression.ods b/sc/qa/uitest/statistics/data/regression.ods
index f9f65bfda0f5..1c8b72cc912b 100644
Binary files a/sc/qa/uitest/statistics/data/regression.ods and b/sc/qa/uitest/statistics/data/regression.ods differ
diff --git a/sc/qa/uitest/statistics/regression.py b/sc/qa/uitest/statistics/regression.py
index ccf1258a776e..6f5fd2ca0e27 100644
--- a/sc/qa/uitest/statistics/regression.py
+++ b/sc/qa/uitest/statistics/regression.py
@@ -31,17 +31,18 @@ class regression(UITestCase):
document = self.ui_test.get_component()
# 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")
- 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 = "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".
format(data_groupedby_column))
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")
self.ui_test.execute_modeless_dialog_through_command(".uno:RegressionDialog")
xDialog = self.xUITest.getTopFocusWindow()
@@ -54,6 +55,7 @@ class regression(UITestCase):
xlinearradio = xDialog.getChild("linear-radio")
xlogarithmicradio = xDialog.getChild("logarithmic-radio")
xpowerradio = xDialog.getChild("power-radio")
+ xnointerceptcheck = xDialog.getChild("nointercept-check")
## Set the X, Y and output ranges
xvariable1rangeedit.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
@@ -79,7 +81,10 @@ class regression(UITestCase):
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
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":
xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLog.$A$1"}))
else:
@@ -97,6 +102,9 @@ class regression(UITestCase):
else:
xpowerradio.executeAction("CLICK", tuple())
+ if not calc_intercept:
+ xnointerceptcheck.executeAction("CLICK", tuple())
+
xOKBtn = xDialog.getChild("ok")
self.ui_test.close_dialog_through_button(xOKBtn)
diff --git a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
index b3e744cdf71d..5cc45f1cee4a 100644
--- a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
@@ -116,9 +116,9 @@ namespace
OUString constTemplateLINEST[] =
{
- "=LINEST(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE% ; TRUE ; TRUE)",
- "=LINEST(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%) ; TRUE ; TRUE)",
- "=LINEST(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%) ; TRUE ; TRUE)"
+ "=LINEST(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE% ; %CALC_INTERCEPT% ; TRUE)",
+ "=LINEST(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)",
+ "=LINEST(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)"
};
OUString constRegressionFormula[] =
@@ -147,7 +147,8 @@ ScRegressionDialog::ScRegressionDialog(
mbUnivariate(true),
mnNumIndependentVars(1),
mnNumObservations(0),
- mbUse3DAddresses(false)
+ mbUse3DAddresses(false),
+ mbCalcIntercept(true)
{
get(mpWithLabelsCheckBox, "withlabels-check");
get(mpLinearRadioButton, "linear-radio");
@@ -155,10 +156,10 @@ ScRegressionDialog::ScRegressionDialog(
get(mpPowerRadioButton, "power-radio");
get(mpConfidenceLevelField, "confidencelevel-spin");
get(mpCalcResidualsCheckBox, "calcresiduals-check");
+ get(mpNoInterceptCheckBox, "nointercept-check");
get(mpErrorMessage, "error-message");
mpWithLabelsCheckBox->SetToggleHdl(LINK(this, ScRegressionDialog, CheckBoxHdl));
mpConfidenceLevelField->SetModifyHdl(LINK(this, ScRegressionDialog, NumericFieldHdl));
- mpCalcResidualsCheckBox->SetToggleHdl(LINK(this, ScRegressionDialog, CheckBoxHdl));
}
ScRegressionDialog::~ScRegressionDialog()
@@ -179,6 +180,7 @@ void ScRegressionDialog::dispose()
mpPowerRadioButton.disposeAndClear();
mpConfidenceLevelField.disposeAndClear();
mpCalcResidualsCheckBox.disposeAndClear();
+ mpNoInterceptCheckBox.disposeAndClear();
mpErrorMessage.disposeAndClear();
ScStatisticsTwoVariableDialog::dispose();
}
@@ -194,6 +196,7 @@ ScRange ScRegressionDialog::ApplyOutput(ScDocShell* pDocShell)
formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
FormulaTemplate aTemplate(mDocument);
aTemplate.autoReplaceUses3D(mbUse3DAddresses);
+ mbCalcIntercept = !mpNoInterceptCheckBox->IsChecked();
// max col of our output should account for
// 1. constant term column,
@@ -378,7 +381,10 @@ void ScRegressionDialog::WriteRawRegressionResults(AddressWalkerWriter& rOutput,
rOutput.writeString(ScResId(STR_LINEST_RAW_OUTPUT_TITLE));
rOutput.newLine();
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);
// Add LINEST result components to template
// 1. Add ranges for coefficients and standard errors for indep. vars and the intercept.
@@ -423,7 +429,8 @@ void ScRegressionDialog::WriteRegressionStatistics(AddressWalkerWriter& rOutput,
"=%SERRORY_ADDR%",
"=" + OUString::number(mnNumIndependentVars),
"=" + 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));
diff --git a/sc/source/ui/inc/RegressionDialog.hxx b/sc/source/ui/inc/RegressionDialog.hxx
index 722fece34279..de01004dcc35 100644
--- a/sc/source/ui/inc/RegressionDialog.hxx
+++ b/sc/source/ui/inc/RegressionDialog.hxx
@@ -22,11 +22,13 @@ class ScRegressionDialog : public ScStatisticsTwoVariableDialog
VclPtr<FixedText> mpErrorMessage;
VclPtr<NumericField> mpConfidenceLevelField;
VclPtr<CheckBox> mpCalcResidualsCheckBox;
+ VclPtr<CheckBox> mpNoInterceptCheckBox;
bool mbUnivariate;
size_t mnNumIndependentVars;
size_t mnNumObservations;
bool mbUse3DAddresses;
+ bool mbCalcIntercept;
public:
ScRegressionDialog(
diff --git a/sc/uiconfig/scalc/ui/regressiondialog.ui b/sc/uiconfig/scalc/ui/regressiondialog.ui
index faa4aa307cfd..58ead6ca7f12 100644
--- a/sc/uiconfig/scalc/ui/regressiondialog.ui
+++ b/sc/uiconfig/scalc/ui/regressiondialog.ui
@@ -484,7 +484,17 @@
</packing>
</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>
</object>
</child>
More information about the Libreoffice-commits
mailing list