[education/labplot] /: [scripting] added bindings for HypothesisTest.
Alexander Semke <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit e37b356313384a3cf3e868c4321580e998237be3 by Alexander Semke.
Committed on 09/08/2026 at 08:54.
Pushed by asemke into branch 'master'.
[scripting] added bindings for HypothesisTest.
M +2 -0 lib/python/CMakeLists.txt
M +1 -0 lib/python/bindings.h
M +20 -0 lib/python/bindings.xml
M +45 -0 src/backend/statistics/HypothesisTest.cpp
M +6 -0 src/backend/statistics/HypothesisTest.h
https://invent.kde.org/education/labplot/-/commit/e37b356313384a3cf3e868c4321580e998237be3
diff --git a/lib/python/CMakeLists.txt b/lib/python/CMakeLists.txt
index 592d110a84..9cfc568702 100644
--- a/lib/python/CMakeLists.txt
+++ b/lib/python/CMakeLists.txt
@@ -118,6 +118,8 @@ set(generated_sources
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/ranget_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/statisticsspreadsheet_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/statisticsspreadsheet_wrapper.h
+ ${CMAKE_CURRENT_BINARY_DIR}/pylabplot/hypothesistest_wrapper.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/pylabplot/hypothesistest_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/symbol_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/symbol_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/pylabplot/value_wrapper.cpp
diff --git a/lib/python/bindings.h b/lib/python/bindings.h
index 5c51336bf6..edd813410f 100644
--- a/lib/python/bindings.h
+++ b/lib/python/bindings.h
@@ -58,6 +58,7 @@
#include "src/backend/worksheet/Line.h"
#include "src/backend/lib/Range.h"
#include "src/backend/spreadsheet/StatisticsSpreadsheet.h"
+#include "src/backend/statistics/HypothesisTest.h"
#include "src/backend/worksheet/plots/cartesian/Symbol.h"
#include "src/backend/worksheet/plots/cartesian/Value.h"
diff --git a/lib/python/bindings.xml b/lib/python/bindings.xml
index cc5366cc1e..658ccd2083 100644
--- a/lib/python/bindings.xml
+++ b/lib/python/bindings.xml
@@ -29,6 +29,7 @@
<reject-enum-value name="AbstractAspect"/>
<reject-enum-value name="Script"/>
<reject-enum-value name="StatisticsSpreadsheet"/>
+ <reject-enum-value name="HypothesisTest"/>
</enum-type>
<?if scripting ?>
<function signature="project()"/>
@@ -500,6 +501,24 @@
<declare-function signature="metrics()const" return-type="StatisticsSpreadsheet::Metrics"/>
<declare-function signature="setMetrics(StatisticsSpreadsheet::Metrics)" return-type="void"/>
</object-type>
+ <rejection class="HypothesisTest" field-name="*"/>
+ <rejection class="HypothesisTest" function-name="*"/>
+ <object-type name="HypothesisTest" disable-wrapper="yes">
+ <enum-type name="Test"/>
+ <declare-function signature="HypothesisTest(const QString&)" return-type="void"/>
+ <declare-function signature="dataColumns()const" return-type="QVector<const AbstractColumn*>"/>
+ <declare-function signature="setDataColumns(const QVector<const AbstractColumn*>&)" return-type="void"/>
+ <declare-function signature="resultHtml()const" return-type="QString"/>
+ <declare-function signature="setTestMean(double)" return-type="void"/>
+ <declare-function signature="testMean()const" return-type="double"/>
+ <declare-function signature="setSignificanceLevel(double)" return-type="void"/>
+ <declare-function signature="significanceLevel()const" return-type="double"/>
+ <declare-function signature="setTail(nsl_stats_tail_type)" return-type="void"/>
+ <declare-function signature="tail()const" return-type="nsl_stats_tail_type"/>
+ <declare-function signature="setTest(HypothesisTest::Test)" return-type="void"/>
+ <declare-function signature="test()const" return-type="HypothesisTest::Test"/>
+ <declare-function signature="recalculate()" return-type="void"/>
+ </object-type>
<rejection class="Symbol" field-name="*"/>
<rejection class="Symbol" function-name="*"/>
<object-type name="Symbol" disable-wrapper="yes">
@@ -1679,4 +1698,5 @@
<enum-type name="nsl_smooth_type"/>
<enum-type name="nsl_smooth_pad_mode"/>
<enum-type name="nsl_smooth_weight_type"/>
+ <enum-type name="nsl_stats_tail_type"/>
</typesystem>
diff --git a/src/backend/statistics/HypothesisTest.cpp b/src/backend/statistics/HypothesisTest.cpp
index 7896d67181..0cc5814252 100644
--- a/src/backend/statistics/HypothesisTest.cpp
+++ b/src/backend/statistics/HypothesisTest.cpp
@@ -24,6 +24,7 @@
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QPrinter>
+#include <QRegularExpression>
#include <QtConcurrent/QtConcurrent>
#include <KConfig>
@@ -47,6 +48,50 @@ QString HypothesisTest::resultHtml() const {
return d->resultText;
}
+QString HypothesisTest::resultText() const {
+ Q_D(const HypothesisTest);
+ QString text = d->resultText;
+
+ // Convert HTML to plain text
+ // Replace headers
+ text.replace(QRegularExpression(QStringLiteral("<h1>(.*?)</h1>")), QStringLiteral("\\1\n") + QString(QStringLiteral("=")).repeated(40) + QStringLiteral("\n"));
+ text.replace(QRegularExpression(QStringLiteral("<h2>(.*?)</h2>")), QStringLiteral("\n\\1\n") + QString(QStringLiteral("-")).repeated(40) + QStringLiteral("\n"));
+
+ // Replace bold tags
+ text.replace(QStringLiteral("<b>"), QString());
+ text.replace(QStringLiteral("</b>"), QString());
+
+ // Replace line breaks
+ text.replace(QStringLiteral("<br>"), QStringLiteral("\n"));
+
+ // Remove table tags and format as plain text
+ text.remove(QRegularExpression(QStringLiteral("</?table[^>]*>")));
+ text.remove(QRegularExpression(QStringLiteral("</?thead[^>]*>")));
+ text.remove(QRegularExpression(QStringLiteral("</?tbody[^>]*>")));
+ text.replace(QRegularExpression(QStringLiteral("<tr[^>]*>")), QString());
+ text.replace(QStringLiteral("</tr>"), QStringLiteral("\n"));
+ text.replace(QRegularExpression(QStringLiteral("<th[^>]*>")), QString());
+ text.replace(QStringLiteral("</th>"), QStringLiteral("\t"));
+ text.replace(QRegularExpression(QStringLiteral("<td[^>]*>")), QString());
+ text.replace(QStringLiteral("</td>"), QStringLiteral("\t"));
+
+ // Clean up any remaining HTML tags
+ text.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
+
+ // Convert HTML entities
+ text.replace(QStringLiteral(" "), QStringLiteral(" "));
+ text.replace(QStringLiteral("<"), QStringLiteral("<"));
+ text.replace(QStringLiteral(">"), QStringLiteral(">"));
+ text.replace(QStringLiteral("&"), QStringLiteral("&"));
+
+ // Clean up excessive whitespace
+ text.replace(QRegularExpression(QStringLiteral("[ \\t]+\n")), QStringLiteral("\n")); // trailing spaces
+ text.replace(QRegularExpression(QStringLiteral("\n{3,}")), QStringLiteral("\n\n")); // multiple blank lines
+
+ return text.trimmed();
+}
+
+
void HypothesisTest::setDataColumns(const QVector<const AbstractColumn*>& cols) {
Q_D(HypothesisTest);
auto [min, max] = variableCount(d->test);
diff --git a/src/backend/statistics/HypothesisTest.h b/src/backend/statistics/HypothesisTest.h
index d9acac22d9..7de93caaab 100644
--- a/src/backend/statistics/HypothesisTest.h
+++ b/src/backend/statistics/HypothesisTest.h
@@ -26,7 +26,12 @@ extern "C" {
#include "backend/nsl/nsl_statistical_test.h"
}
+#ifdef SDK
+#include "labplot_export.h"
+class LABPLOT_EXPORT HypothesisTest : public AbstractPart {
+#else
class HypothesisTest : public AbstractPart {
+#endif
Q_OBJECT
public:
@@ -66,6 +71,7 @@ public:
const QVector<QString>& dataColumnPaths() const;
QString resultHtml() const;
+ QString resultText() const;
void setTestMean(double);
double testMean() const;