statstudio 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. statstudio/__init__.py +9 -0
  2. statstudio/__main__.py +3 -0
  3. statstudio/app.py +83 -0
  4. statstudio/cli.py +116 -0
  5. statstudio/core/__init__.py +3 -0
  6. statstudio/core/archive.py +27 -0
  7. statstudio/core/commands.py +67 -0
  8. statstudio/core/formula_catalog.py +74 -0
  9. statstudio/core/formulas.py +605 -0
  10. statstudio/core/joins.py +123 -0
  11. statstudio/core/project.py +358 -0
  12. statstudio/core/runtime.py +321 -0
  13. statstudio/core/scripting.py +594 -0
  14. statstudio/core/table.py +796 -0
  15. statstudio/core/transform.py +450 -0
  16. statstudio/feature_help.py +595 -0
  17. statstudio/io/__init__.py +3 -0
  18. statstudio/io/docx.py +201 -0
  19. statstudio/io/export.py +99 -0
  20. statstudio/io/file_import.py +199 -0
  21. statstudio/io/odbc.py +334 -0
  22. statstudio/io/sample_data.py +164 -0
  23. statstudio/io/table_io.py +118 -0
  24. statstudio/plots/__init__.py +19 -0
  25. statstudio/plots/advanced.py +651 -0
  26. statstudio/plots/basic.py +957 -0
  27. statstudio/plots/bayesian_plots.py +94 -0
  28. statstudio/plots/common.py +334 -0
  29. statstudio/plots/diagnostics.py +214 -0
  30. statstudio/plots/doe_plots.py +235 -0
  31. statstudio/plots/plotly_builders.py +719 -0
  32. statstudio/plots/predictive_plots.py +72 -0
  33. statstudio/plots/registry.py +251 -0
  34. statstudio/plugins.py +111 -0
  35. statstudio/resources/help_topics.json +13195 -0
  36. statstudio/resources/logo.ico +0 -0
  37. statstudio/resources/logo.png +0 -0
  38. statstudio/resources/statstudio.svg +8 -0
  39. statstudio/stats/__init__.py +42 -0
  40. statstudio/stats/bayesian.py +1094 -0
  41. statstudio/stats/bayesian_optimization.py +590 -0
  42. statstudio/stats/common.py +140 -0
  43. statstudio/stats/correlation.py +135 -0
  44. statstudio/stats/custom_doe.py +1714 -0
  45. statstudio/stats/descriptive.py +200 -0
  46. statstudio/stats/desirability.py +132 -0
  47. statstudio/stats/distributions.py +331 -0
  48. statstudio/stats/doe.py +1070 -0
  49. statstudio/stats/hypothesis.py +1305 -0
  50. statstudio/stats/multivariate.py +307 -0
  51. statstudio/stats/optimal_doe.py +264 -0
  52. statstudio/stats/power.py +194 -0
  53. statstudio/stats/predictive.py +605 -0
  54. statstudio/stats/profiler.py +379 -0
  55. statstudio/stats/quality.py +1218 -0
  56. statstudio/stats/regression.py +1600 -0
  57. statstudio/stats/results.py +235 -0
  58. statstudio/stats/simulator.py +95 -0
  59. statstudio/stats/survival.py +637 -0
  60. statstudio/stats/timeseries.py +643 -0
  61. statstudio/stats/tolerance.py +154 -0
  62. statstudio/ui/__init__.py +0 -0
  63. statstudio/ui/analysis_hub.py +271 -0
  64. statstudio/ui/command_catalog.py +460 -0
  65. statstudio/ui/command_palette.py +55 -0
  66. statstudio/ui/console.py +239 -0
  67. statstudio/ui/dialogs/__init__.py +0 -0
  68. statstudio/ui/dialogs/advanced_dialogs.py +392 -0
  69. statstudio/ui/dialogs/base.py +537 -0
  70. statstudio/ui/dialogs/bayesian_dialogs.py +488 -0
  71. statstudio/ui/dialogs/bayesian_optimization_dialog.py +299 -0
  72. statstudio/ui/dialogs/custom_doe_dialog.py +467 -0
  73. statstudio/ui/dialogs/doe_dialogs.py +220 -0
  74. statstudio/ui/dialogs/extended_dialogs.py +665 -0
  75. statstudio/ui/dialogs/graph_builder.py +139 -0
  76. statstudio/ui/dialogs/help_dialog.py +207 -0
  77. statstudio/ui/dialogs/help_topics.py +280 -0
  78. statstudio/ui/dialogs/lazy.py +184 -0
  79. statstudio/ui/dialogs/odbc_dialog.py +311 -0
  80. statstudio/ui/dialogs/plot_dialog.py +1385 -0
  81. statstudio/ui/dialogs/report_composer.py +218 -0
  82. statstudio/ui/dialogs/script_dialogs.py +267 -0
  83. statstudio/ui/dialogs/stats_dialogs.py +1688 -0
  84. statstudio/ui/dialogs/table_dialogs.py +997 -0
  85. statstudio/ui/dialogs/window.py +58 -0
  86. statstudio/ui/docks/__init__.py +0 -0
  87. statstudio/ui/formula_editor.py +121 -0
  88. statstudio/ui/icons.py +257 -0
  89. statstudio/ui/jobs.py +179 -0
  90. statstudio/ui/main_window.py +3934 -0
  91. statstudio/ui/plot_interaction.py +178 -0
  92. statstudio/ui/profiler_widget.py +437 -0
  93. statstudio/ui/recent.py +82 -0
  94. statstudio/ui/reports/__init__.py +0 -0
  95. statstudio/ui/reports/report_view.py +1632 -0
  96. statstudio/ui/script_jobs.py +35 -0
  97. statstudio/ui/scripts_panel.py +271 -0
  98. statstudio/ui/table_document.py +233 -0
  99. statstudio/ui/table_model.py +285 -0
  100. statstudio/ui/table_view.py +285 -0
  101. statstudio/ui/theme.py +645 -0
  102. statstudio/ui/welcome.py +453 -0
  103. statstudio/ui/window_controls.py +53 -0
  104. statstudio/ui/workers.py +53 -0
  105. statstudio-0.1.0.dist-info/METADATA +261 -0
  106. statstudio-0.1.0.dist-info/RECORD +110 -0
  107. statstudio-0.1.0.dist-info/WHEEL +5 -0
  108. statstudio-0.1.0.dist-info/entry_points.txt +5 -0
  109. statstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
  110. statstudio-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,220 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ from PySide6.QtWidgets import (
5
+ QAbstractItemView,
6
+ QHBoxLayout,
7
+ QPushButton,
8
+ QTableWidget,
9
+ QTableWidgetItem,
10
+ QWidget,
11
+ )
12
+
13
+ from statstudio.core.table import DataTable
14
+ from statstudio.stats import doe, optimal_doe
15
+ from statstudio.ui.dialogs.base import BaseDialog, combo_value, text_value
16
+
17
+
18
+ class DOEDesignDialog(BaseDialog):
19
+ def help_topic(self) -> str:
20
+ design_type = combo_value(self.type_combo)
21
+ if design_type in {"Central Composite", "Box-Behnken", "Mixture"}:
22
+ return "response-surface-designs"
23
+ if design_type in {"D-Optimal"}:
24
+ return "custom-doe"
25
+ return "factorial-designs"
26
+
27
+ def __init__(self, parent=None, design_type: str | None = None) -> None:
28
+ super().__init__(None, "Create DOE Design", parent)
29
+ self.type_combo = self.add_combo(
30
+ "Design",
31
+ ["Full Factorial", "3-Level Factorial", "Fractional Factorial", "Plackett-Burman Screening", "Central Composite", "Box-Behnken", "D-Optimal", "Mixture"],
32
+ default=design_type or "Full Factorial",
33
+ )
34
+ self.add_label(
35
+ "Define two levels for each factor. StatStudio randomizes runs and stores the design metadata "
36
+ "so the analysis platform can code factors and build response-surface models."
37
+ )
38
+ self.factor_table = QTableWidget(2, 4)
39
+ self.factor_table.setHorizontalHeaderLabels(["Factor", "Low", "High", "Units"])
40
+ self.factor_table.horizontalHeader().setStretchLastSection(True)
41
+ self.factor_table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
42
+ self._set_factor_row(0, "A", 0.0, 1.0, "")
43
+ self._set_factor_row(1, "B", 0.0, 1.0, "")
44
+ self.add_row("Factors", self.factor_table)
45
+ buttons = QHBoxLayout()
46
+ add_button = QPushButton("Add factor")
47
+ add_button.clicked.connect(self._add_factor)
48
+ remove_button = QPushButton("Remove selected")
49
+ remove_button.clicked.connect(self._remove_factor)
50
+ buttons.addWidget(add_button)
51
+ buttons.addWidget(remove_button)
52
+ buttons.addStretch(1)
53
+ holder = QWidget()
54
+ holder.setLayout(buttons)
55
+ self.add_row("", holder)
56
+ self.replicates_spin = self.add_int("Replicates", 1, 1, 100)
57
+ self.centers_spin = self.add_int("Center points", 0, 0, 100)
58
+ self.randomize_check = self.add_bool("Randomize run order", True)
59
+ self.seed_spin = self.add_int("Random seed", 42, 0, 2_000_000_000)
60
+ self.resolution_combo = self.add_combo("Fractional resolution", ["Auto", "III", "IV", "V"], default="Auto")
61
+ self.levels_spin = self.add_int("Factorial levels", 3, 2, 5)
62
+ self.runs_combo = self.add_combo("Screening runs", ["8", "12", "16", "20", "24", "32", "44", "48", "64"], default="16")
63
+ self.alpha_edit = self.add_text("CCD alpha (blank = rotatable)", "")
64
+ self.name_edit = self.add_text("Table name", "")
65
+ self.optimal_runs_spin = self.add_int("Optimal design runs", 12, 3, 500)
66
+ self.optimal_criterion_combo = self.add_combo("Optimality criterion", ["D", "A", "I"], default="D")
67
+
68
+ def _set_factor_row(self, row: int, name: str, low: float, high: float, units: str) -> None:
69
+ self.factor_table.setItem(row, 0, QTableWidgetItem(name))
70
+ self.factor_table.setItem(row, 1, QTableWidgetItem(str(low)))
71
+ self.factor_table.setItem(row, 2, QTableWidgetItem(str(high)))
72
+ self.factor_table.setItem(row, 3, QTableWidgetItem(units))
73
+
74
+ def _add_factor(self) -> None:
75
+ row = self.factor_table.rowCount()
76
+ self.factor_table.insertRow(row)
77
+ self._set_factor_row(row, chr(ord("A") + row) if row < 26 else f"F{row + 1}", 0.0, 1.0, "")
78
+
79
+ def _remove_factor(self) -> None:
80
+ rows = sorted({index.row() for index in self.factor_table.selectedIndexes()}, reverse=True)
81
+ for row in rows:
82
+ self.factor_table.removeRow(row)
83
+
84
+ def _factors(self) -> list[doe.Factor]:
85
+ factors = []
86
+ names = set()
87
+ for row in range(self.factor_table.rowCount()):
88
+ name_item = self.factor_table.item(row, 0)
89
+ name = name_item.text().strip() if name_item else ""
90
+ if not name:
91
+ continue
92
+ if name in names:
93
+ raise ValueError(f"Duplicate factor name: {name}")
94
+ names.add(name)
95
+ try:
96
+ low = float(self.factor_table.item(row, 1).text())
97
+ high = float(self.factor_table.item(row, 2).text())
98
+ except Exception as exc:
99
+ raise ValueError(f"Factor {name}: enter numeric low and high levels.") from exc
100
+ if high <= low:
101
+ raise ValueError(f"Factor {name}: high level must be greater than low level.")
102
+ units_item = self.factor_table.item(row, 3)
103
+ factors.append(doe.Factor(name=name, low=low, high=high, units=units_item.text().strip() if units_item else ""))
104
+ if len(factors) < 2:
105
+ raise ValueError("Define at least two factors.")
106
+ return factors
107
+
108
+ def make_job(self):
109
+ values = self._request()
110
+ return lambda token, progress: self._run_request(values)
111
+
112
+ def _request(self):
113
+ factors = self._factors()
114
+ return {
115
+ "factors": factors,
116
+ "design_type": combo_value(self.type_combo),
117
+ "replicates": self.replicates_spin.value(),
118
+ "centers": self.centers_spin.value(),
119
+ "randomize": self.randomize_check.isChecked(),
120
+ "seed": self.seed_spin.value(),
121
+ "levels": self.levels_spin.value(),
122
+ "resolution": combo_value(self.resolution_combo) or "IV",
123
+ "runs": int(combo_value(self.runs_combo) or "16"),
124
+ "alpha": text_value(self.alpha_edit),
125
+ "optimal_runs": self.optimal_runs_spin.value(),
126
+ "criterion": combo_value(self.optimal_criterion_combo) or "D",
127
+ }
128
+
129
+ @staticmethod
130
+ def _run_request(values):
131
+ factors = values["factors"]
132
+ design_type = values["design_type"]
133
+ replicates = values["replicates"]
134
+ centers = values["centers"]
135
+ randomize = values["randomize"]
136
+ seed = values["seed"]
137
+ if design_type == "Full Factorial":
138
+ return doe.full_factorial(factors, replicates, centers, randomize, seed)
139
+ if design_type == "3-Level Factorial":
140
+ return doe.factorial_levels(factors, values["levels"], replicates, randomize, seed)
141
+ if design_type == "Fractional Factorial":
142
+ if len(factors) < 3:
143
+ raise ValueError("Fractional factorial designs need at least three factors.")
144
+ return doe.fractional_factorial(factors, values["resolution"], replicates, centers, randomize, seed)
145
+ if design_type == "Plackett-Burman Screening":
146
+ return doe.screening_design(factors, values["runs"], centers, randomize, seed)
147
+ if design_type == "Central Composite":
148
+ alpha = float(values["alpha"]) if values["alpha"] else None
149
+ return doe.central_composite(factors, alpha, max(1, centers), replicates, randomize, seed)
150
+ if design_type == "Box-Behnken":
151
+ return doe.box_behnken(factors, max(1, centers), replicates, randomize, seed)
152
+ if design_type == "D-Optimal":
153
+ return optimal_doe.optimal_design(factors, values["optimal_runs"], values["criterion"], 20, seed)
154
+ names = [factor.name for factor in factors]
155
+ return optimal_doe.mixture_design(names, values["levels"], 1.0, seed)
156
+
157
+ def compute(self) -> DataTable:
158
+ factors = self._factors()
159
+ design_type = combo_value(self.type_combo)
160
+ replicates = self.replicates_spin.value()
161
+ centers = self.centers_spin.value()
162
+ randomize = self.randomize_check.isChecked()
163
+ seed = self.seed_spin.value()
164
+ if design_type == "Full Factorial":
165
+ table = doe.full_factorial(factors, replicates, centers, randomize, seed)
166
+ elif design_type == "3-Level Factorial":
167
+ table = doe.factorial_levels(factors, self.levels_spin.value(), replicates, randomize, seed)
168
+ elif design_type == "Fractional Factorial":
169
+ if len(factors) < 3:
170
+ raise ValueError("Fractional factorial designs need at least three factors.")
171
+ table = doe.fractional_factorial(
172
+ factors,
173
+ combo_value(self.resolution_combo) or "IV",
174
+ replicates,
175
+ centers,
176
+ randomize,
177
+ seed,
178
+ )
179
+ elif design_type == "Plackett-Burman Screening":
180
+ table = doe.screening_design(factors, int(combo_value(self.runs_combo) or "16"), centers, randomize, seed)
181
+ elif design_type == "Central Composite":
182
+ alpha_text = text_value(self.alpha_edit)
183
+ alpha = float(alpha_text) if alpha_text else None
184
+ table = doe.central_composite(factors, alpha, max(1, centers), replicates, randomize, seed)
185
+ elif design_type == "Box-Behnken":
186
+ table = doe.box_behnken(factors, max(1, centers), replicates, randomize, seed)
187
+ elif design_type == "D-Optimal":
188
+ table = optimal_doe.optimal_design(
189
+ factors,
190
+ self.optimal_runs_spin.value(),
191
+ combo_value(self.optimal_criterion_combo) or "D",
192
+ 20,
193
+ seed,
194
+ )
195
+ elif design_type == "Mixture":
196
+ table = optimal_doe.mixture_design([factor.name for factor in factors], max(2, self.levels_spin.value()), 1.0, seed)
197
+ else:
198
+ raise ValueError("Unknown design type.")
199
+ name = text_value(self.name_edit)
200
+ if name:
201
+ table.name = name
202
+ return table
203
+
204
+ def design_spec(self) -> dict:
205
+ factors = self._factors()
206
+ alpha_text = text_value(self.alpha_edit)
207
+ return {
208
+ "design_type": combo_value(self.type_combo),
209
+ "factors": [factor.to_dict() for factor in factors],
210
+ "replicates": self.replicates_spin.value(),
211
+ "centers": self.centers_spin.value(),
212
+ "randomize": self.randomize_check.isChecked(),
213
+ "seed": self.seed_spin.value(),
214
+ "resolution": combo_value(self.resolution_combo) or "IV",
215
+ "levels": self.levels_spin.value(),
216
+ "runs": int(combo_value(self.runs_combo) or "16"),
217
+ "alpha": float(alpha_text) if alpha_text else None,
218
+ "optimal_runs": self.optimal_runs_spin.value(),
219
+ "criterion": combo_value(self.optimal_criterion_combo) or "D",
220
+ }