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