-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathSaveLoad.js
More file actions
121 lines (101 loc) · 4.13 KB
/
SaveLoad.js
File metadata and controls
121 lines (101 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : SaveLoad.js
* Author : Black Logic
* Note : Save and load models
* License : GNU GPLv3 with Visual Python special exception
* Date : 2023. 03. 09
* Change Date :
*/
//============================================================================
// [CLASS] DataSets
//============================================================================
define([
__VP_CSS_LOADER__('vp_base/css/m_ml/saveLoad'),
__VP_TEXT_LOADER__('vp_base/html/m_ml/saveLoad.html'),
'vp_base/js/com/com_util',
'vp_base/js/com/com_Const',
'vp_base/js/com/com_String',
'vp_base/js/com/com_generatorV2',
'vp_base/js/com/component/PopupComponent',
'vp_base/js/com/component/FileNavigation',
'vp_base/data/m_ml/mlLibrary',
], function(slCss, slHTML, com_util, com_Const, com_String, com_generator, PopupComponent, FileNavigation, ML_LIBRARIES) {
/**
* SaveLoad
*/
class SaveLoad extends PopupComponent {
_init() {
super._init();
this.config.sizeLevel = 2;
this.config.dataview = false;
this.config.checkModules = ['joblib'];
this.state = {
modelio: 'model_save', // model_save / model_load
target: '',
allocateTo: '',
userOption: '',
savePath: '',
loadPath: '',
...this.state
}
this.mlConfig = ML_LIBRARIES;
}
_bindEvent() {
super._bindEvent();
let that = this;
// select model
$(this.wrapSelector('#modelio')).on('change', function() {
let modelio = $(this).val();
that.state.modelio = modelio;
$(that.wrapSelector('.vp-modelio-option-box')).html(that.templateForOption(modelio));
$(that.wrapSelector('#userOption')).val('');
});
// user option
$(this.wrapSelector('#userOption')).on('change', function() {
that.state.userOption = $(this).val();
})
}
templateForBody() {
let page = $(slHTML);
// render option page
$(page).find('.vp-modelio-option-box').html(this.templateForOption(this.state.modelio));
$(page).find('#modelio').val(this.state.modelio);
$(page).find('#userOption').val(this.state.userOption);
return page;
}
templateForOption(modelio) {
let config = this.mlConfig[modelio];
let state = this.state;
let optBox = new com_String();
// render tag
config.options.forEach(opt => {
optBox.appendFormatLine('<label for="{0}" title="{1}">{2}</label>'
, opt.name, opt.name, com_util.optionToLabel(opt.name));
let content = com_generator.renderContent(this, opt.component[0], opt, state);
optBox.appendLine(content[0].outerHTML);
});
// render file navigation
// show user option
if (config.code.includes('${etc}')) {
// render user option
optBox.appendFormatLine('<label for="{0}">{1}</label>', 'userOption', 'User option');
optBox.appendFormatLine('<input type="text" class="vp-input vp-state" id="{0}" placeholder="{1}" value="{2}"/>',
'userOption', 'key=value, ...', this.state.userOption);
}
return optBox.toString();
}
generateCode() {
let { modelio, userOption } = this.state;
let code = new com_String();
if (userOption && userOption != '') {
userOption = ', ' + userOption;
}
let modelCode = com_generator.vp_codeGenerator(this, this.mlConfig[modelio], this.state, userOption);
code.append(modelCode);
return code.toString();
}
}
return SaveLoad;
});