@@ -164,16 +164,19 @@ export default class extends Controller {
164164 }
165165
166166 renderAnalysisResult ( ) {
167- fetch ( `/html/snapshots/analysis/?snapshot_id=${ this . snapshotData . id } ` )
167+ const snapshotData = this . projectData . models [ 0 ] . snapshot
168+
169+ console . log ( "Fetching analysis" )
170+ fetch ( `/html/snapshots/analysis/?snapshot_id=${ snapshotData . id } ` )
168171 . then ( res => res . text ( ) )
169172 . then ( html => this . analysisResultTarget . innerHTML = html )
170173 . then ( ( ) => {
171174 // Render charts
172- for ( name in this . snapshotData . columns ) {
175+ for ( name in snapshotData . columns ) {
173176 const sample = JSON . parse ( document . getElementById ( name ) . textContent )
174- renderDistribution ( name , sample , this . snapshotData . analysis [ `${ name } _dip` ] )
177+ renderDistribution ( name , sample , snapshotData . analysis [ `${ name } _dip` ] )
175178
176- for ( target of this . snapshotData . y_column_name ) {
179+ for ( target of snapshotData . y_column_name ) {
177180 if ( target === name )
178181 continue
179182
@@ -182,9 +185,9 @@ export default class extends Controller {
182185 }
183186 }
184187
185- for ( target of this . snapshotData . y_column_name ) {
188+ for ( target of snapshotData . y_column_name ) {
186189 const targetSample = JSON . parse ( document . getElementById ( target ) . textContent )
187- renderOutliers ( target , targetSample , this . snapshotData . analysis [ `${ target } _stddev` ] )
190+ renderOutliers ( target , targetSample , snapshotData . analysis [ `${ target } _stddev` ] )
188191 }
189192
190193 this . progressBarProgress = 100
@@ -215,52 +218,34 @@ export default class extends Controller {
215218 createSnapshot ( event ) {
216219 event . preventDefault ( )
217220
218- const request = {
219- "relation_name" : this . tableName ,
220- "y_column_name" : Array . from ( this . targetNames ) ,
221- }
221+ // Train a linear algorithm by default
222+ this . algorithmNames . add ( "linear" )
222223
223224 this . nextStep ( )
224225
225226 // Start the progress bar :)
226227 this . progressBarProgress = 2
227- this . progressBarInterval = setInterval ( this . renderProgressBar . bind ( this ) , 750 )
228- console . log ( "interval set to " , this . progressBarInterval )
228+ this . progressBarInterval = setInterval ( this . renderProgressBar . bind ( this ) , 850 )
229229
230- fetch ( `/api/snapshots/snapshot/` , {
231- method : "POST" ,
232- cache : "no-cache" ,
233- headers : {
234- "Content-Type" : "application/json" ,
235- } ,
236- redirect : "follow" ,
237- body : JSON . stringify ( request ) ,
238- } )
239- . then ( res => {
240- if ( res . ok ) {
241- return res . json ( )
242- } else {
243- alert ( "Failed to create snapshot" )
244- throw Error ( "Failed to create snapshot" )
245- }
246- } )
247- . then ( json => {
248- this . snapshotData = json
230+ this . createProject ( event , false , ( ) => {
249231 this . renderAnalysisResult ( )
232+ this . algorithmNames . delete ( "linear" )
250233 } )
251234 }
252235
253- createProject ( event ) {
236+ createProject ( event , redirect = true , callback = null ) {
254237 event . preventDefault ( )
255238
256239 const request = {
257240 "project_name" : this . projectName ,
258241 "objective" : this . objectiveName ,
259242 "algorithms" : Array . from ( this . algorithmNames ) ,
260- "snapshot_id" : this . snapshotData . id ,
243+ "relation_name" : this . tableName ,
244+ "y_column_name" : Array . from ( this . targetNames ) ,
261245 }
262246
263- this . createLoader ( )
247+ if ( redirect )
248+ this . createLoader ( )
264249
265250 fetch ( `/api/projects/train/` , {
266251 method : "POST" ,
@@ -280,7 +265,13 @@ export default class extends Controller {
280265 }
281266 } )
282267 . then ( json => {
283- window . location . assign ( `/projects/${ json . id } ` ) ;
268+ this . projectData = json
269+
270+ if ( redirect )
271+ window . location . assign ( `/projects/${ json . id } ` ) ;
272+
273+ if ( callback )
274+ callback ( )
284275 } )
285276 }
286277
0 commit comments