datly 0.0.2 → 0.0.3

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.
@@ -1,205 +0,0 @@
1
- class Validator {
2
- validateData(dataset) {
3
- const errors = [];
4
- const warnings = [];
5
-
6
- if (!dataset || typeof dataset !== 'object') {
7
- errors.push('Dataset must be an object');
8
- return { valid: false, errors, warnings };
9
- }
10
-
11
- if (!dataset.data || !Array.isArray(dataset.data)) {
12
- errors.push('Dataset must contain a data array');
13
- }
14
-
15
- if (!dataset.headers || !Array.isArray(dataset.headers)) {
16
- errors.push('Dataset must contain a headers array');
17
- }
18
-
19
- if (dataset.data && dataset.data.length === 0) {
20
- warnings.push('Dataset is empty');
21
- }
22
-
23
- if (dataset.data && dataset.headers) {
24
- const headerSet = new Set(dataset.headers);
25
- if (headerSet.size !== dataset.headers.length) {
26
- errors.push('Duplicate column headers found');
27
- }
28
-
29
- dataset.data.forEach((row, index) => {
30
- const rowKeys = Object.keys(row);
31
- const missingHeaders = dataset.headers.filter(h => !rowKeys.includes(h));
32
- const extraKeys = rowKeys.filter(k => !dataset.headers.includes(k));
33
-
34
- if (missingHeaders.length > 0) {
35
- warnings.push(`Row ${index}: Missing columns: ${missingHeaders.join(', ')}`);
36
- }
37
-
38
- if (extraKeys.length > 0) {
39
- warnings.push(`Row ${index}: Extra columns: ${extraKeys.join(', ')}`);
40
- }
41
- });
42
- }
43
-
44
- return {
45
- valid: errors.length === 0,
46
- errors,
47
- warnings
48
- };
49
- }
50
-
51
- validateNumericColumn(column) {
52
- if (!Array.isArray(column)) {
53
- throw new Error('Column must be an array');
54
- }
55
-
56
- const numericValues = column.filter(val =>
57
- typeof val === 'number' && !isNaN(val) && isFinite(val)
58
- );
59
-
60
- if (numericValues.length === 0) {
61
- throw new Error('Column contains no valid numeric values');
62
- }
63
-
64
- return {
65
- valid: true,
66
- validCount: numericValues.length,
67
- invalidCount: column.length - numericValues.length,
68
- cleanData: numericValues
69
- };
70
- }
71
-
72
- validateSampleSize(sample, minSize = 2) {
73
- if (!Array.isArray(sample)) {
74
- throw new Error('Sample must be an array');
75
- }
76
-
77
- if (sample.length < minSize) {
78
- throw new Error(`Sample size (${sample.length}) must be at least ${minSize}`);
79
- }
80
-
81
- return true;
82
- }
83
-
84
- validateConfidenceLevel(confidence) {
85
- if (typeof confidence !== 'number' || confidence <= 0 || confidence >= 1) {
86
- throw new Error('Confidence level must be a number between 0 and 1');
87
- }
88
- return true;
89
- }
90
-
91
- validateCorrelationInputs(col1, col2) {
92
- this.validateNumericColumn(col1);
93
- this.validateNumericColumn(col2);
94
-
95
- if (col1.length !== col2.length) {
96
- throw new Error('Columns must have the same length');
97
- }
98
-
99
- if (col1.length < 3) {
100
- throw new Error('Need at least 3 paired observations for correlation');
101
- }
102
-
103
- return true;
104
- }
105
-
106
- validateRegressionInputs(x, y) {
107
- this.validateNumericColumn(x);
108
- this.validateNumericColumn(y);
109
-
110
- if (x.length !== y.length) {
111
- throw new Error('X and Y arrays must have the same length');
112
- }
113
-
114
- if (x.length < 3) {
115
- throw new Error('Need at least 3 data points for regression');
116
- }
117
-
118
- const xVariance = this.calculateVariance(x);
119
- if (xVariance === 0) {
120
- throw new Error('X values must have non-zero variance');
121
- }
122
-
123
- return true;
124
- }
125
-
126
- calculateVariance(arr) {
127
- const mean = arr.reduce((sum, val) => sum + val, 0) / arr.length;
128
- return arr.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / (arr.length - 1);
129
- }
130
-
131
- validateGroupsForANOVA(groups) {
132
- if (!Array.isArray(groups) || groups.length < 2) {
133
- throw new Error('ANOVA requires at least 2 groups');
134
- }
135
-
136
- groups.forEach((group, index) => {
137
- if (!Array.isArray(group)) {
138
- throw new Error(`Group ${index} must be an array`);
139
- }
140
-
141
- this.validateSampleSize(group, 2);
142
- this.validateNumericColumn(group);
143
- });
144
-
145
- return true;
146
- }
147
-
148
- validateContingencyTable(col1, col2) {
149
- if (!Array.isArray(col1) || !Array.isArray(col2)) {
150
- throw new Error('Both columns must be arrays');
151
- }
152
-
153
- if (col1.length !== col2.length) {
154
- throw new Error('Columns must have the same length');
155
- }
156
-
157
- if (col1.length < 5) {
158
- throw new Error('Need at least 5 observations for chi-square test');
159
- }
160
-
161
- return true;
162
- }
163
-
164
- isInteger(value) {
165
- return typeof value === 'number' && Number.isInteger(value);
166
- }
167
-
168
- isPositive(value) {
169
- return typeof value === 'number' && value > 0;
170
- }
171
-
172
- isInRange(value, min, max) {
173
- return typeof value === 'number' && value >= min && value <= max;
174
- }
175
-
176
- hasMinimumObservations(data, minimum) {
177
- return Array.isArray(data) && data.length >= minimum;
178
- }
179
-
180
- checkForConstantValues(column) {
181
- const uniqueValues = new Set(column);
182
- return uniqueValues.size === 1;
183
- }
184
-
185
- validateHypothesisTestInputs(sample1, sample2, testType) {
186
- this.validateSampleSize(sample1, 2);
187
-
188
- if (testType === 'two-sample' || testType === 'paired') {
189
- this.validateSampleSize(sample2, 2);
190
-
191
- if (testType === 'paired' && sample1.length !== sample2.length) {
192
- throw new Error('Paired samples must have the same length');
193
- }
194
- }
195
-
196
- this.validateNumericColumn(sample1);
197
- if (sample2) {
198
- this.validateNumericColumn(sample2);
199
- }
200
-
201
- return true;
202
- }
203
- }
204
-
205
- export default Validator;