@@ -19,7 +19,7 @@ angular
19
19
this . setErrorHandler = function ( handler ) { errorHandler = handler ; } ;
20
20
21
21
this . $get = function ( Restangular , uploadHelper ,
22
- Datasets , Dictionaries , Jobs , Modalities , Models , OauthTokens , OauthApplications ,
22
+ Datafiles , Datasets , Dictionaries , Jobs , Modalities , Models , OauthTokens , OauthApplications ,
23
23
PreparationRules , Projects , Reports , UserSettings , Sources , Users , Variables ) {
24
24
var self = this ;
25
25
@@ -53,6 +53,7 @@ angular
53
53
} ) ;
54
54
55
55
return {
56
+ Datafiles : Datafiles ,
56
57
Datasets : Datasets ,
57
58
Dictionaries : Dictionaries ,
58
59
Jobs : Jobs ,
@@ -81,6 +82,140 @@ angular
81
82
} ;
82
83
} ) ;
83
84
85
+ /**
86
+ * @ngdoc service
87
+ * @name predicsis.jsSDK.models.Datafile
88
+ * @requires $q
89
+ * @requires Restangular
90
+ * @description
91
+ *
92
+ * <table>
93
+ * <tr>
94
+ * <td><span class="badge get">get</span> <kbd>/data_files</kbd></td>
95
+ * <td><kbd>{@link predicsis.jsSDK.models.Datafiles#methods_all Datafiles.all()}</kbd></td>
96
+ * <td></td>
97
+ * </tr>
98
+ * <tr>
99
+ * <td><span class="badge get">get</span> <kbd>/data_files/:id</kbd></td>
100
+ * <td><kbd>{@link predicsis.jsSDK.models.Datafiles#methods_get Datafiles.get()}</kbd></td>
101
+ * <td></td>
102
+ * </tr>
103
+ * <tr>
104
+ * <td><span class="badge get">get</span> <kbd>/data_files/:id/signed_url</kbd></td>
105
+ * <td><kbd>{@link predicsis.jsSDK.models.Datafiles#methods_get_signed_url Datafiles.getSignedUrl()}</kbd></td>
106
+ * <td></td>
107
+ * </tr>
108
+ * <tr>
109
+ * <td><span class="badge get">get</span> <kbd>/data_files/:id/signed_url</kbd></td>
110
+ * <td><kbd>{@link predicsis.jsSDK.models.Datafiles#methods_download Datafiles.download()}</kbd></td>
111
+ * <td></td>
112
+ * </tr>
113
+ * <tfoot>
114
+ * <tr><td colspan="3">Official documentation is available at https://developer.predicsis.com/doc/v1/data_management/data_file/</td></tr>
115
+ * </tfoot>
116
+ * </table>
117
+ *
118
+ * Output example of a <kbd>data_file</kbd>:
119
+ * <pre>
120
+ * {
121
+ * data_file: {
122
+ * id: "54edf76c6170700001870000",
123
+ * filename: "hello.csv",
124
+ * type: "S3",
125
+ * size: 24,
126
+ * signed_url: {
127
+ * links: {
128
+ * self: "https://api.predicsis.com/data_files/53c7e7b668796493d3010000/signed_url"
129
+ * }
130
+ * }
131
+ * }
132
+ * }
133
+ * </pre>
134
+ *
135
+ * Output example of a <kbd>signed_url</kbd>:
136
+ * <pre>
137
+ * {
138
+ * data_file: {
139
+ * signed_url: "http://prod.kml-api.s3-us-west-2.amazonaws.com/uploads/5347b31750432d45a5020000/sources/1415101671848/source.csv"
140
+ * }
141
+ * }
142
+ * </pre>
143
+ */
144
+ angular
145
+ . module ( 'predicsis.jsSDK.models' )
146
+ . service ( 'Datafiles' , function ( $q , Restangular ) {
147
+ 'use strict' ;
148
+
149
+ function dataFile ( id ) { return Restangular . one ( 'data_files' , id ) ; }
150
+ function dataFiles ( ) { return Restangular . all ( 'data_files' ) ; }
151
+
152
+ // -----------------------------------------------------------------------------------------------------------------
153
+
154
+ /**
155
+ * @ngdoc function
156
+ * @name all
157
+ * @methodOf predicsis.jsSDK.models.Datafiles
158
+ * @description Get all (or a list of) data files
159
+ * @param {Array } [dataFileIds] List of data files' ids you want to fetch
160
+ * @return {Promise } A list of data_files
161
+ */
162
+ this . all = function ( dataFileIds ) {
163
+ if ( dataFileIds === undefined ) {
164
+ return dataFiles ( ) . getList ( ) ;
165
+ } else {
166
+ dataFileIds = dataFileIds || [ ] ;
167
+
168
+ return $q . all ( dataFileIds . map ( function ( id ) {
169
+ return dataFile ( id ) . get ( ) ;
170
+ } ) ) ;
171
+ }
172
+ } ;
173
+
174
+ /**
175
+ * @ngdoc function
176
+ * @name get
177
+ * @methodOf predicsis.jsSDK.models.Datafiles
178
+ * @description Get a single data_file by its id
179
+ * @param {String } dataFileId data_file identifier
180
+ * @return {Promise } A single data_file
181
+ */
182
+ this . get = function ( dataFileId ) {
183
+ return dataFile ( dataFileId ) . get ( ) ;
184
+ } ;
185
+
186
+ /**
187
+ * @ngdoc function
188
+ * @name getSignedUrl
189
+ * @methodOf predicsis.jsSDK.models.Datafiles
190
+ * @description Get a signed_url of a data_file
191
+ * @param {String } datasetId dataset identifier
192
+ * @return {Promise } A signed url you can download raw file with
193
+ */
194
+ this . getSignedUrl = function ( datasetId ) {
195
+ return dataFile ( datasetId )
196
+ . one ( 'signed_url' , null ) . get ( )
197
+ . then ( function ( url ) {
198
+ return url . signed_url ;
199
+ } ) ;
200
+ } ;
201
+
202
+ /**
203
+ * @ngdoc function
204
+ * @name download
205
+ * @methodOf predicsis.jsSDK.models.Datafiles
206
+ * @description Convenience method to concretely download the file
207
+ * @param {String } datasetId dataset identifier
208
+ * @return {Promise } Once the signed url is resolved, we're using <code>window.location.assign</code> to download
209
+ * the file without changing page.
210
+ */
211
+ this . download = function ( datasetId ) {
212
+ this . getSignedUrl ( datasetId ) . then ( function ( signedUrl ) {
213
+ window . location . assign ( signedUrl ) ;
214
+ } ) ;
215
+ } ;
216
+
217
+ } ) ;
218
+
84
219
/**
85
220
* @ngdoc service
86
221
* @name predicsis.jsSDK.models.Datasets
@@ -177,13 +312,7 @@ angular
177
312
* children_dataset_ids: [],
178
313
* dictionary_ids: [],
179
314
* generated_dictionaries_ids: [],
180
- * data_file: {
181
- * id: '54904b09776f720001650000',
182
- * filename: 'learning-dataset.csv',
183
- * type: 'S3',
184
- * size: 538296,
185
- * url: S3_URL + '/download/file/from/s3/learning-dataset.csv'
186
- * },
315
+ * data_file: '54904b09776f720001650000',
187
316
* main_modality: null,
188
317
* classifier_id: null,
189
318
* dataset_id: null,
@@ -341,7 +470,7 @@ angular
341
470
source_ids : [ source . id ] ,
342
471
data_file : { filename : fileName }
343
472
} ) ;
344
- } )
473
+ } ) ;
345
474
} ;
346
475
347
476
/**
@@ -356,18 +485,20 @@ angular
356
485
* <li>Idem for learning/testing filenames</li>
357
486
* </ul>
358
487
*
359
- * @param {String } id Dataset id you want to split (called <em>original dataset</em>)
360
- * @param {String } name Name of the original dataset (used to name its subsets)
361
- * @param {String } filename Name of the original datafile (used to name its subsets's datafile)
362
- * @param {Number } [sampling=70] Examples: If you set <code>sampling</code> to 70, you are going to have:
488
+ * @param {String } id Dataset id you want to split (called <em>original dataset</em>)
489
+ * @param {String } name Name of the original dataset (used to name its subsets)
490
+ * @param {String } [ filename=name] Name of the original datafile (used to name its subsets's datafile). If undefined, value of <kbd>name</kbd> parameter is used
491
+ * @param {Number } [sampling=70] Examples: If you set <code>sampling</code> to 70, you are going to have:
363
492
* <ul>
364
493
* <li><code>70%</code> of your original dataset for <b>learning</b></li>
365
494
* <li><code>30%</code> of your original dataset for <b>testing</b></li>
366
495
* </ul><br/>
367
496
* @return {Promise } Subsets
368
497
*/
369
498
this . split = function ( id , name , filename , sampling ) {
499
+ filename = filename || name ;
370
500
sampling = sampling || 70 ;
501
+
371
502
var learn = {
372
503
parent_dataset_id : id ,
373
504
name : 'learned_' + name ,
0 commit comments