Skip to content

Commit 758ce70

Browse files
author
minjk-bl
committed
Action/Info app prototype
1 parent a003a16 commit 758ce70

File tree

7 files changed

+378
-27
lines changed

7 files changed

+378
-27
lines changed

data/libraries.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,34 @@
32393239
"icon": "apps/apps_dimension.svg"
32403240
}
32413241
},
3242+
{
3243+
"id" : "ml_fitPredict",
3244+
"type" : "function",
3245+
"level": 1,
3246+
"name" : "Fit/Predict",
3247+
"tag" : "FIT,PREDICT,MACHINE LEARNING,ML",
3248+
"path" : "visualpython - machine_learning - fit_predict",
3249+
"desc" : "Model fit/predict for machine learning",
3250+
"file" : "m_ml/FitPredict",
3251+
"apps" : {
3252+
"color": 8,
3253+
"icon": "apps/apps_evaluate.svg"
3254+
}
3255+
},
3256+
{
3257+
"id" : "ml_modelInfo",
3258+
"type" : "function",
3259+
"level": 1,
3260+
"name" : "Model Info",
3261+
"tag" : "MODEL INFO,INFORMATION,MACHINE LEARNING,ML",
3262+
"path" : "visualpython - machine_learning - model_info",
3263+
"desc" : "Model information for machine learning",
3264+
"file" : "m_ml/ModelInfo",
3265+
"apps" : {
3266+
"color": 8,
3267+
"icon": "apps/apps_evaluate.svg"
3268+
}
3269+
},
32423270
{
32433271
"id" : "ml_evaluation",
32443272
"type" : "function",

html/m_ml/fitPredict.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<body>
2+
<div class="vp-grid-box vp-model-box" data-type="selection">
3+
<div class="vp-grid-border-box vp-grid-col-110">
4+
<label for="model" class="vp-orange-text">Model</label>
5+
<select id="model" class="vp-select vp-state" style="width: 200px;">
6+
<!-- Auto Create -->
7+
</select>
8+
</div>
9+
<div class="vp-grid-border-box">
10+
<div id="instanceEditor">
11+
<!-- instanceEditor -->
12+
</div>
13+
</div>
14+
<div class="vp-grid-col-110 vp-model-instance-option-box">
15+
16+
</div>
17+
</div>
18+
</body>

html/m_ml/model.html

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<body>
22
<div class="vp-grid-box">
3-
<select id="modelControlType" class="vp-big-select vp-state">
4-
<option value="creation">Model Creation</option>
5-
<option value="selection">Model Selection</option>
6-
</select>
3+
<div>
4+
<label class="vp-bold">Model Creation</label>
5+
</div>
76
<div class="vp-grid-box vp-model-box" data-type="creation">
87
<div class="vp-grid-border-box">
98
<div class="vp-grid-col-110">
@@ -24,27 +23,5 @@
2423
<input type="text" class="vp-input vp-state" id="allocateToCreation" placeholder="New variable name" value="model"/>
2524
</div>
2625
</div>
27-
<div class="vp-grid-box vp-model-box" data-type="selection">
28-
<div class="vp-grid-border-box vp-grid-col-110">
29-
<label for="model" class="vp-orange-text">Model</label>
30-
<select id="model" class="vp-select vp-state" style="width: 200px;">
31-
<!-- Auto Create -->
32-
</select>
33-
</div>
34-
<div class="vp-grid-border-box">
35-
<div id="instanceEditor">
36-
<!-- instanceEditor -->
37-
</div>
38-
</div>
39-
<div class="vp-grid-col-110 vp-model-instance-option-box">
40-
41-
</div>
42-
<!-- <div class="vp-grid-border-box vp-grid-col-110">
43-
<label for="featureData" class="vp-orange-text">Feature data</label>
44-
<input type="text" class="vp-input vp-state" id="featureData" placeholder="Select feature data" value="X_train"/>
45-
<label for="targetData" class="vp-orange-text">Target data</label>
46-
<input type="text" class="vp-input vp-state" id="targetData" placeholder="Select target data" value="y_train"/>
47-
</div> -->
48-
</div>
4926
</div>
5027
</body>

html/m_ml/modelInfo.html

Whitespace-only changes.

js/com/component/ModelEditor.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,20 @@ define([
883883
});
884884
}
885885

886-
show() {
886+
/**
887+
* Show Model Editor
888+
* @param {*} showType all / action / info
889+
*/
890+
show(showType='all') {
887891
$(this.wrapSelector()).show();
892+
893+
// show type
894+
if (showType == 'action') {
895+
$(this.wrapSelector(''))
896+
} else if (showType == 'info') {
897+
898+
}
899+
888900
this.reload();
889901
}
890902

js/m_ml/FitPredict.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Project Name : Visual Python
3+
* Description : GUI-based Python code generator
4+
* File Name : FitPredict.js
5+
* Author : Black Logic
6+
* Note : Model fit / predict
7+
* License : GNU GPLv3 with Visual Python special exception
8+
* Date : 2022. 04. 20
9+
* Change Date :
10+
*/
11+
12+
//============================================================================
13+
// [CLASS] FitPredict
14+
//============================================================================
15+
define([
16+
'text!vp_base/html/m_ml/fitPredict.html!strip',
17+
'vp_base/js/com/com_util',
18+
'vp_base/js/com/com_interface',
19+
'vp_base/js/com/com_String',
20+
'vp_base/js/com/com_generatorV2',
21+
'vp_base/data/m_ml/mlLibrary',
22+
'vp_base/js/com/component/PopupComponent',
23+
'vp_base/js/com/component/VarSelector2',
24+
'vp_base/js/com/component/ModelEditor'
25+
], function(msHtml, com_util, com_interface, com_String, com_generator, ML_LIBRARIES, PopupComponent, VarSelector2, ModelEditor) {
26+
27+
/**
28+
* FitPredict
29+
*/
30+
class FitPredict extends PopupComponent {
31+
_init() {
32+
super._init();
33+
this.config.sizeLevel = 2;
34+
this.config.dataview = false;
35+
36+
this.state = {
37+
// model selection
38+
model: '',
39+
method: '',
40+
...this.state
41+
}
42+
43+
this.modelConfig = ML_LIBRARIES;
44+
}
45+
46+
_bindEvent() {
47+
super._bindEvent();
48+
/** Implement binding events */
49+
var that = this;
50+
51+
// change model
52+
$(this.wrapSelector('#model')).on('change', function() {
53+
that.modelEditor.reload();
54+
});
55+
}
56+
57+
templateForBody() {
58+
let page = $(msHtml);
59+
60+
let that = this;
61+
62+
//================================================================
63+
// Model selection
64+
//================================================================
65+
// set model list
66+
let modelOptionTag = new com_String();
67+
vpKernel.getModelList().then(function(resultObj) {
68+
let { result } = resultObj;
69+
var modelList = JSON.parse(result);
70+
modelList && modelList.forEach(model => {
71+
let selectFlag = '';
72+
if (model.varName == that.state.model) {
73+
selectFlag = 'selected';
74+
}
75+
modelOptionTag.appendFormatLine('<option value="{0}" data-type="{1}" {2}>{3} ({4})</option>',
76+
model.varName, model.varType, selectFlag, model.varName, model.varType);
77+
});
78+
$(page).find('#model').html(modelOptionTag.toString());
79+
$(that.wrapSelector('#model')).html(modelOptionTag.toString());
80+
81+
if (!that.state.model || that.state.model == '') {
82+
that.state.model = $(that.wrapSelector('#model')).val();
83+
}
84+
85+
that.modelEditor.show('action');
86+
});
87+
88+
//================================================================
89+
// Load state
90+
//================================================================
91+
Object.keys(this.state).forEach(key => {
92+
let tag = $(page).find('#' + key);
93+
let tagName = $(tag).prop('tagName'); // returns with UpperCase
94+
let value = that.state[key];
95+
if (value == undefined) {
96+
return;
97+
}
98+
switch(tagName) {
99+
case 'INPUT':
100+
let inputType = $(tag).prop('type');
101+
if (inputType == 'text' || inputType == 'number' || inputType == 'hidden') {
102+
$(tag).val(value);
103+
break;
104+
}
105+
if (inputType == 'checkbox') {
106+
$(tag).prop('checked', value);
107+
break;
108+
}
109+
break;
110+
case 'TEXTAREA':
111+
case 'SELECT':
112+
default:
113+
$(tag).val(value);
114+
break;
115+
}
116+
});
117+
118+
return page;
119+
}
120+
121+
templateForOption(modelType) {
122+
let config = this.modelConfig[modelType];
123+
let state = this.state;
124+
125+
let optBox = new com_String();
126+
// render tag
127+
config.options.forEach(opt => {
128+
optBox.appendFormatLine('<label for="{0}" title="{1}">{2}</label>'
129+
, opt.name, opt.name, com_util.optionToLabel(opt.name));
130+
let content = com_generator.renderContent(this, opt.component[0], opt, state);
131+
optBox.appendLine(content[0].outerHTML);
132+
});
133+
// render user option
134+
optBox.appendFormatLine('<label for="{0}">{1}</label>', 'userOption', 'User option');
135+
optBox.appendFormatLine('<input type="text" class="vp-input vp-state" id="{0}" placeholder="{1}" value="{2}"/>',
136+
'userOption', 'key=value, ...', this.state.userOption);
137+
return optBox.toString();
138+
}
139+
140+
render() {
141+
super.render();
142+
143+
// Model Editor
144+
this.modelEditor = new ModelEditor(this, "model", "instanceEditor");
145+
}
146+
147+
generateCode() {
148+
let { model } = this.state;
149+
let code = new com_String();
150+
code.append(this.modelEditor.getCode({'${model}': model}));
151+
152+
return code.toString();
153+
}
154+
155+
}
156+
157+
return FitPredict;
158+
});

0 commit comments

Comments
 (0)