Skip to content

Commit cd676f0

Browse files
author
minjk-bl
committed
Edit t-test group value's component
1 parent cc09c3f commit cd676f0

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

visualpython/html/m_stats/studentstTest.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@
4040
<label></label>
4141
<div class="vp-grid-col-95">
4242
<label for="group1">Group 1</label>
43-
<select id="group1" class="vp-select vp-state"></select>
43+
<div>
44+
<input id="group1" type="text" class="vp-input vp-state" placeholder="Select value"/>
45+
<label><input id="group1_istext" type="checkbox" class="vp-state" checked/><span>Text</span></label>
46+
</div>
4447
<label for="group2">Group 2</label>
45-
<select id="group2" class="vp-select vp-state"></select>
48+
<div>
49+
<input id="group2" type="text" class="vp-input vp-state" placeholder="Select value"/>
50+
<label><input id="group2_istext" type="checkbox" class="vp-state" checked/><span>Text</span></label>
51+
</div>
4652
</div>
4753
</div>
4854
<div class="vp-st-option two-sample-wide-data vp-grid-col-160">

visualpython/js/m_stats/StudentstTest.js

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ define([
2020
'vp_base/js/com/com_generatorV2',
2121
'vp_base/js/com/component/PopupComponent',
2222
'vp_base/js/com/component/DataSelector',
23+
'vp_base/js/com/component/SuggestInput',
2324
'vp_base/js/m_apps/Subset'
24-
], function(stHTML, com_util, com_Const, com_String, com_generator, PopupComponent, DataSelector, Subset) {
25+
], function(stHTML, com_util, com_Const, com_String, com_generator, PopupComponent, DataSelector, SuggestInput, Subset) {
2526

2627
/**
2728
* StudentstTest
@@ -46,6 +47,8 @@ define([
4647
groupingVariable: '',
4748
group1: '',
4849
group2: '',
50+
group1_istext: true,
51+
group2_istext: true,
4952
pairedVariable1: '',
5053
pairedVariable2: '',
5154
testValue: '',
@@ -126,24 +129,58 @@ define([
126129
// get result and load column list
127130
vpKernel.getColumnCategory(that.state.data, colCode).then(function(resultObj) {
128131
let { result } = resultObj;
129-
$(that.wrapSelector('#group1')).html('');
130-
$(that.wrapSelector('#group2')).html('');
132+
$(that.wrapSelector('#group1')).val('');
133+
$(that.wrapSelector('#group2')).val('');
134+
that.state.group1 = '';
135+
that.state.group2 = '';
136+
that.state.group1_istext = true;
137+
that.state.group2_istext = true;
131138
try {
132139
var category = JSON.parse(result);
133-
if (category && category.length > 0 && colDtype == 'object') {
134-
// if it's categorical column and its dtype is object, check 'Text' as default
135-
category.forEach(obj => {
136-
let selected1 = obj.value === that.state.group1;
137-
let selected2 = obj.value === that.state.group2;
138-
$(that.wrapSelector('#group1')).append(`<option value="${obj.value}" ${selected1?'selected':''}>${obj.label}</option>`);
139-
$(that.wrapSelector('#group2')).append(`<option value="${obj.value}" ${selected2?'selected':''}>${obj.label}</option>`);
140-
});
140+
// if (category && category.length > 0 && colDtype == 'object') {
141+
// // if it's categorical column and its dtype is object, check 'Text' as default
142+
// category.forEach(obj => {
143+
// let selected1 = obj.value === that.state.group1;
144+
// let selected2 = obj.value === that.state.group2;
145+
// $(that.wrapSelector('#group1')).append(`<option value="${obj.value}" ${selected1?'selected':''}>${obj.label}</option>`);
146+
// $(that.wrapSelector('#group2')).append(`<option value="${obj.value}" ${selected2?'selected':''}>${obj.label}</option>`);
147+
// });
148+
// }
149+
var groupSuggest1 = new SuggestInput();
150+
groupSuggest1.setComponentID('group1');
151+
groupSuggest1.addClass('vp-input vp-state');
152+
groupSuggest1.setSuggestList(function() { return category; });
153+
groupSuggest1.setNormalFilter(true);
154+
groupSuggest1.setPlaceholder('Select value');
155+
$(that.wrapSelector('#group1')).replaceWith(groupSuggest1.toTagString());
156+
var groupSuggest2 = new SuggestInput();
157+
groupSuggest2.setComponentID('group2');
158+
groupSuggest2.addClass('vp-input vp-state');
159+
groupSuggest2.setSuggestList(function() { return category; });
160+
groupSuggest2.setNormalFilter(true);
161+
groupSuggest2.setPlaceholder('Select value');
162+
$(that.wrapSelector('#group2')).replaceWith(groupSuggest2.toTagString());
163+
164+
if (category && category.length > 0) {
141165
that.state.group1 = category[0].value;
142166
that.state.group2 = category[0].value;
143167
}
168+
169+
if (colDtype == 'object') {
170+
// check as default
171+
$(that.wrapSelector('#group1_istext')).prop('checked', true);
172+
$(that.wrapSelector('#group2_istext')).prop('checked', true);
173+
that.state.group1_istext = true;
174+
that.state.group2_istext = true;
175+
} else {
176+
$(that.wrapSelector('#group1_istext')).prop('checked', false);
177+
$(that.wrapSelector('#group2_istext')).prop('checked', false);
178+
that.state.group1_istext = false;
179+
that.state.group2_istext = false;
180+
}
144181
} catch {
145-
$(that.wrapSelector('#group1')).html('');
146-
$(that.wrapSelector('#group2')).html('');
182+
$(that.wrapSelector('#group1')).val('');
183+
$(that.wrapSelector('#group2')).val('');
147184
}
148185
});
149186
});
@@ -231,7 +268,7 @@ define([
231268
testType, inputType, data,
232269
testVariable, testVariable1, testVariable2, groupingVariable,
233270
pairedVariable1, pairedVariable2,
234-
group1, group2,
271+
group1, group2, group1_istext, group2_istext,
235272
testValue, alterHypo, confInt
236273
} = this.state;
237274
let codeList = [];
@@ -276,8 +313,8 @@ define([
276313
code.appendLine("# Independent two-sample t-test");
277314
// variable declaration
278315
if (inputType === 'long-data') {
279-
code.appendFormatLine("vp_df1 = {0}[({1}[{2}] == '{3}')][{4}].dropna().copy()", data, data, groupingVariable, group1, testVariable);
280-
code.appendFormatLine("vp_df2 = {0}[({1}[{2}] == '{3}')][{4}].dropna().copy()", data, data, groupingVariable, group2, testVariable);
316+
code.appendFormatLine("vp_df1 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()", data, data, groupingVariable, com_util.convertToStr(group1, group1_istext), testVariable);
317+
code.appendFormatLine("vp_df2 = {0}[({1}[{2}] == {3})][{4}].dropna().copy()", data, data, groupingVariable, com_util.convertToStr(group2, group2_istext), testVariable);
281318
} else if (inputType === 'wide-data') {
282319
code.appendFormatLine("vp_df1 = {0}[{1}].dropna().copy()", data, testVariable1);
283320
code.appendFormatLine("vp_df2 = {0}[{1}].dropna().copy()", data, testVariable2);

0 commit comments

Comments
 (0)