File tree 4 files changed +47
-4
lines changed
4 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 5
5
6
6
from cesium import data_management , time_series
7
7
from cesium .util import shorten_fname
8
+ from ..tests .fixtures import create_test_dataset
8
9
9
10
import os
10
11
from os .path import join as pjoin
@@ -24,6 +25,12 @@ def _get_dataset(self, dataset_id):
24
25
return d
25
26
26
27
def post (self ):
28
+ if self .get_argument ('create_example' ):
29
+ project_id = self .get_argument ('projectID' )
30
+ p = Project .get (Project .id == project_id )
31
+ with create_test_dataset (p , delete_after = False ) as d :
32
+ return self .success (d , 'cesium/FETCH_DATASETS' )
33
+
27
34
if not 'tarFile' in self .request .files :
28
35
return self .error ('No tar file uploaded' )
29
36
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def create_test_project():
29
29
30
30
31
31
@contextmanager
32
- def create_test_dataset (project , label_type = 'class' ):
32
+ def create_test_dataset (project , label_type = 'class' , delete_after = True ):
33
33
"""Create and yield test labeled dataset, then delete.
34
34
35
35
Params
@@ -57,12 +57,16 @@ def create_test_dataset(project, label_type='class'):
57
57
tarball = shutil .copy2 (tarball , cfg ['paths' ]['upload_folder' ])
58
58
ts_paths = data_management .parse_and_store_ts_data (
59
59
tarball , cfg ['paths' ]['ts_data_folder' ], header )
60
- d = m .Dataset .add (name = 'test_ds' , project = project , file_uris = ts_paths )
60
+
61
+ name = 'Example Dataset'
62
+ d = m .Dataset .add (name = name , project = project , file_uris = ts_paths )
61
63
d .save ()
64
+
62
65
try :
63
66
yield d
64
67
finally :
65
- d .delete_instance ()
68
+ if delete_after :
69
+ d .delete_instance ()
66
70
67
71
68
72
@contextmanager
Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ let DatasetForm = (props) => {
63
63
64
64
< SubmitButton label = "Upload Dataset" disabled = { submitting } />
65
65
</ Form >
66
+ < button
67
+ onClick = { props . createExampleDataset }
68
+ >
69
+ Use Example Dataset
70
+ </ button >
66
71
67
72
< CesiumTooltip
68
73
id = "headerfileTooltip"
@@ -101,7 +106,8 @@ const dsMapDispatchToProps = (dispatch, ownProps) => (
101
106
{
102
107
onSubmit : form => (
103
108
dispatch ( Action . uploadDataset ( form ) )
104
- )
109
+ ) ,
110
+ createExampleDataset : ( ) => dispatch ( Action . createExampleDataset ( ownProps . selectedProject . id ) )
105
111
}
106
112
) ;
107
113
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export const FETCH_DATASETS = 'cesium/FETCH_DATASETS';
17
17
export const RECEIVE_DATASETS = 'cesium/RECEIVE_DATASETS' ;
18
18
export const UPLOAD_DATASET = 'cesium/UPLOAD_DATASET' ;
19
19
export const DELETE_DATASET = 'cesium/DELETE_DATASET' ;
20
+ export const CREATE_EXAMPLE_DATASET = 'cesium/CREATE_EXAMPLE_DATASET' ;
20
21
21
22
export const FETCH_FEATURES = 'cesium/FETCH_FEATURES' ;
22
23
export const FETCH_FEATURESETS = 'cesium/FETCH_FEATURESETS' ;
@@ -228,6 +229,31 @@ function receiveDatasets(datasets) {
228
229
}
229
230
230
231
232
+ // Create example dataset
233
+ export function createExampleDataset ( projectID ) {
234
+ var form_data = new FormData ( ) ;
235
+ form_data . append ( 'projectID' , projectID ) ;
236
+ form_data . append ( 'create_example' , true ) ;
237
+
238
+ return dispatch =>
239
+ promiseAction (
240
+ dispatch ,
241
+ CREATE_EXAMPLE_DATASET ,
242
+
243
+ fetch ( '/dataset' , {
244
+ method : 'POST' ,
245
+ body : form_data ,
246
+ } )
247
+ . then ( response => response . json ( ) )
248
+ . then ( ( json ) => {
249
+ dispatch ( fetchDatasets ( ) ) ;
250
+ dispatch ( hideExpander ( 'newDatasetExpander' ) ) ;
251
+ dispatch ( resetForm ( 'newDataset' ) ) ;
252
+ } ) . catch ( ex => console . log ( 'createExampleDataset' , ex ) )
253
+ ) ;
254
+ }
255
+
256
+
231
257
// Download featuresets
232
258
export function fetchFeaturesets ( ) {
233
259
return dispatch =>
You can’t perform that action at this time.
0 commit comments