@@ -101,75 +101,24 @@ def create_package_from_astore(table):
101
101
:meth:`model_repository.import_model_from_zip <.ModelRepository.import_model_from_zip>`
102
102
103
103
"""
104
- if swat is None :
105
- raise RuntimeError ("The 'swat' package is required to work with "
106
- "ASTORE models." )
107
-
108
- assert isinstance (table , swat .CASTable )
109
-
110
- sess = table .session .get_connection ()
111
- sess .loadactionset ('astore' )
112
-
113
- result = sess .astore .describe (rstore = table , epcode = True )
114
- astore = sess .astore .download (rstore = table )
115
- if not hasattr (astore , "blob" ):
116
- raise ValueError ("Failed to download binary data for ASTORE '%s'."
117
- % astore )
118
- astore = astore .blob
119
-
120
- astore = bytes (astore ) # Convert from SWAT blob type
121
-
122
- # Raise error if describe action fails
123
- if result .status_code != 0 :
124
- raise RuntimeError (result )
125
-
126
- astore_key = result .Key .Key [0 ].strip ()
127
- ep_ds2 = result .epcode
128
- package_ds2 = _generate_package_code (result )
129
- model_properties = _get_model_properties (result )
130
- input_vars = [get_variable_properties (var )
131
- for var in result .InputVariables .itertuples ()]
132
- output_vars = [get_variable_properties (var )
133
- for var in result .OutputVariables .itertuples ()]
134
- astore_filename = '_' + uuid .uuid4 ().hex [:25 ].upper ()
135
-
136
- # Copy the ASTORE table to the ModelStore.
137
- # Raise an error if the action fails
138
- with swat .options (exception_on_severity = 2 ):
139
- table .save (name = astore_filename , caslib = 'ModelStore' , replace = True )
140
-
141
- file_metadata = [{'role' : 'analyticStore' , 'name' : '' },
142
- {'role' : 'score' , 'name' : 'dmcas_packagescorecode.sas' }]
143
-
144
- astore_metadata = [{'name' : astore_filename ,
145
- 'caslib' : 'ModelStore' ,
146
- 'uri' : '/dataTables/dataSources/cas~fs~cas-shared-default~fs~ModelStore/tables/{}' .format (astore_filename ),
147
- 'key' : astore_key }]
148
-
149
- zip_file = _build_zip_from_files ({
150
- 'dmcas_packagescorecode.sas' : '\n ' .join (package_ds2 ),
151
- 'dmcas_epscorecode.sas' : ep_ds2 ,
152
- astore_filename : astore ,
153
- 'ModelProperties.json' : model_properties ,
154
- 'fileMetadata.json' : file_metadata ,
155
- 'AstoreMetadata.json' : astore_metadata ,
156
- 'inputVar.json' : input_vars ,
157
- 'outputVar.json' : output_vars
158
- })
159
-
160
- return zip_file
104
+ files = _create_files_from_astore (table )
161
105
106
+ return _build_zip_from_files (files )
162
107
163
108
164
109
def _create_files_from_astore (table ):
165
- """Generate files for
110
+ """Generate files for importing a model from an ASTORE.
166
111
167
112
Parameters
168
113
----------
169
- table
114
+ table : swat.CASTable
115
+ The CAS table containing the ASTORE.
116
+
170
117
171
118
Returns
172
119
-------
120
+ dict
121
+ Dictionary of filename: content pairs.
173
122
174
123
"""
175
124
if swat is None :
0 commit comments