@@ -769,7 +769,19 @@ angular.module('predicsis.jsSDK')
769
769
* Both <code>variable_id</code> and <code>dataset_id</code> are required.
770
770
*
771
771
* @param {Object } params See above example.
772
- * @return {Promise } New modalities set
772
+ * @return {Promise } Returned modalities set does not contain modalities themselves.
773
+ * If you want them, you must explicitly {@link predicsis.jsSDK.Modalities#methods_get get} them.
774
+ * In fact, you will get an object like:
775
+ * <pre>
776
+ * {
777
+ * id": "53fdfa7070632d0fc5030000",
778
+ * created_at: "2014-05-02T17:13:56.687Z",
779
+ * user_id: "5363b25c687964476d000000",
780
+ * dataset_id: "53c7dea470632d3417020000",
781
+ * variable_id: "5329601c1757f446e6000002",
782
+ * job_ids: [ "53c8c88970632d3b9a030001" ]
783
+ * }
784
+ * </pre>
773
785
*/
774
786
this . create = function ( params ) {
775
787
return jobsHelper . wrapAsyncPromise ( modalities ( ) . post ( { modalities_set : params } ) ) ;
@@ -1531,13 +1543,18 @@ angular.module('predicsis.jsSDK')
1531
1543
* }
1532
1544
* </pre>
1533
1545
*
1546
+ * <b><code>reports_ids</code></b> : is an array of ids where reports should always be stored in the same order:
1547
+ * <ol>
1548
+ * <li>classifier evaluation report for train part</li>
1549
+ * <li>classifier evaluation report for test part</li>
1550
+ * <li>univariate supervised report</li>
1551
+ * <li>univariate unsupervised report</li>
1552
+ * </ol>
1553
+ *
1534
1554
* See {@link predicsis.jsSDK.projectsHelper projects helper} to get the following methods:
1535
1555
* <ul>
1536
1556
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_isModelDone isModelDone(Projects project)}</code></li>
1537
1557
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_isDictionaryVerified isDictionaryVerified(Projects project)}</code></li>
1538
- * <li><code>{@link predicsis.jsSDK.projectsHelper#methods_getCurrentState getCurrentState(Projects project)}</code></li>
1539
- * <li><code>{@link predicsis.jsSDK.projectsHelper#methods_getCurrentStep getCurrentStep(String currentView)}</code></li>
1540
- * <li><code>{@link predicsis.jsSDK.projectsHelper#methods_getStateFromStep getStateFromStep(Projects project, String toStep)}</code></li>
1541
1558
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addLearningDataset addLearningDataset(Projects project, String datasetId)}</code></li>
1542
1559
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addScoringDataset addScoringDataset(Projects project, String datasetId)}</code></li>
1543
1560
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addScoreset addScoreset(Projects project, String datasetId)}</code></li>
@@ -2448,7 +2465,7 @@ angular.module('predicsis.jsSDK')
2448
2465
* @ngdoc function
2449
2466
* @name all
2450
2467
* @methodOf predicsis.jsSDK.Variables
2451
- * @description Get all (or a list of) generated dictionaries
2468
+ * @description Get all (or a list of) variables of a specified dictionary
2452
2469
* @param {String } dictionaryId Id of the container dictionary
2453
2470
* @param {Array } [variablesIds] List of variables' id you want to fetch
2454
2471
* @return {Object } Promise of a variables list
@@ -2460,7 +2477,7 @@ angular.module('predicsis.jsSDK')
2460
2477
variablesIds = variablesIds || [ ] ;
2461
2478
2462
2479
return $q . all ( variablesIds . map ( function ( id ) {
2463
- return variables ( dictionaryId , id ) . get ( ) ;
2480
+ return variable ( dictionaryId , id ) . get ( ) ;
2464
2481
} ) ) ;
2465
2482
}
2466
2483
} ;
@@ -2587,6 +2604,7 @@ angular.module('predicsis.jsSDK')
2587
2604
* - {@link predicsis.jsSDK.Projects Projects}
2588
2605
* - {@link predicsis.jsSDK.PreparationRules PreparationRules}
2589
2606
* - $q
2607
+ * - $rootScope
2590
2608
*/
2591
2609
angular . module ( 'predicsis.jsSDK' )
2592
2610
. service ( 'modelHelper' , function ( $injector ) {
@@ -2620,6 +2638,19 @@ angular.module('predicsis.jsSDK')
2620
2638
* <li><kbd>project.id</kbd> to store preparation rules set, classifier and reports ids.</li>
2621
2639
* </ul>
2622
2640
*
2641
+ * Please also note that if your project doesn't have a <code>main_modality</code> parameter, only univariate
2642
+ * supervised report will be created. If this property is here, we also generate classifier evaluation reports
2643
+ * for train and test datasets.
2644
+ *
2645
+ * We also broadcast the following events:
2646
+ * <ul>
2647
+ * <li>jsSDK.learn.start-retrieving-train-dataset</li>
2648
+ * <li>jsSDK.learn.start-creating-preparation-rules</li>
2649
+ * <li>jsSDK.learn.start-learning</li>
2650
+ * <li>jsSDK.learn.start-generating-reports</li>
2651
+ * <li>jsSDK.learn.start-updating-project</li>
2652
+ * </ul>
2653
+ *
2623
2654
* @param {Object } project Instance of a valid {@link predicsis.jsSDK.Projects Project}
2624
2655
* @return {Object } Instance of a complete {@link predicsis.jsSDK.Models Models}
2625
2656
*/
@@ -2630,14 +2661,19 @@ angular.module('predicsis.jsSDK')
2630
2661
var Projects = $injector . get ( 'Projects' ) ;
2631
2662
var PreparationRules = $injector . get ( 'PreparationRules' ) ;
2632
2663
var $q = $injector . get ( '$q' ) ;
2664
+ var $rootScope = $injector . get ( '$rootScope' ) ;
2633
2665
var results = { } ;
2634
2666
2667
+ $rootScope . $broadcast ( 'jsSDK.learn.start-retrieving-train-dataset' ) ;
2668
+
2635
2669
return Datasets . getChildren ( project . learning_dataset_id )
2636
2670
. then ( function ( children ) {
2637
2671
if ( ! children . train ) {
2638
2672
throw 'Invalid project on POST preparation_rules, no valid train dataset found' ;
2639
2673
}
2640
2674
2675
+ $rootScope . $broadcast ( 'jsSDK.learn.start-creating-preparation-rules' ) ;
2676
+
2641
2677
return PreparationRules . create ( {
2642
2678
variable_id : project . target_variable_id ,
2643
2679
dataset_id : children . train . id
@@ -2646,6 +2682,7 @@ angular.module('predicsis.jsSDK')
2646
2682
// create the model from preparation rules set
2647
2683
. then ( function ( preparationRulesRet ) {
2648
2684
results . preparation_rules_set = preparationRulesRet ;
2685
+ $rootScope . $broadcast ( 'jsSDK.learn.start-learning' ) ;
2649
2686
return Models . createClassifier ( preparationRulesRet . id ) ;
2650
2687
} )
2651
2688
// generate reports
@@ -2655,17 +2692,29 @@ angular.module('predicsis.jsSDK')
2655
2692
// but the PATCH request will occurs after the learn process.
2656
2693
// this tweak allow project generation.
2657
2694
project . classifier_id = classifier . id ;
2658
- return $q . all ( [
2659
- Reports . createTrainClassifierEvaluationReport ( project ) ,
2660
- Reports . createTestClassifierEvaluationReport ( project ) ,
2661
- Reports . createUnivariateSupervisedReport ( project )
2662
- ] ) ;
2695
+ $rootScope . $broadcast ( 'jsSDK.learn.start-generating-reports' ) ;
2696
+
2697
+ var requestedReports = {
2698
+ univariate_supervised_report : Reports . createUnivariateSupervisedReport ( project )
2699
+ } ;
2700
+
2701
+ if ( project . main_modality !== null ) {
2702
+ requestedReports [ 'train_classifier_evaluation_report' ] = Reports . createTrainClassifierEvaluationReport ( project ) ;
2703
+ requestedReports [ 'test_classifier_evaluation_reports' ] = Reports . createTestClassifierEvaluationReport ( project ) ;
2704
+ }
2705
+
2706
+ return $q . all ( requestedReports ) ;
2663
2707
} )
2664
2708
//update project
2665
2709
. then ( function ( reports ) {
2666
- var reportIds = reports . map ( function ( report ) {
2667
- return report . id ;
2668
- } ) ;
2710
+ var reportIds = [ ] ;
2711
+ reportIds [ 0 ] = reports . train_classifier_evaluation_report . id ;
2712
+ reportIds [ 1 ] = reports . test_classifier_evaluation_reports . id ;
2713
+ reportIds [ 2 ] = reports . univariate_supervised_report . id ;
2714
+ //reportIds[3] = reports.univariate_unsupervised_report.id;
2715
+
2716
+ $rootScope . $broadcast ( 'jsSDK.learn.start-updating-project' ) ;
2717
+
2669
2718
return Projects . update ( project . id , {
2670
2719
preparation_rules_set_id : results . preparation_rules_set . id ,
2671
2720
classifier_id : results . classifier . id ,
@@ -2756,116 +2805,6 @@ angular.module('predicsis.jsSDK')
2756
2805
return Boolean ( project . is_dictionary_verified ) ;
2757
2806
} ;
2758
2807
2759
- /**
2760
- * @ngdoc function
2761
- * @methodOf predicsis.jsSDK.projectsHelper
2762
- * @name getCurrentState
2763
- * @description Return current router state based on project content.
2764
- * @param {Object } project {@link API.model.Projects Projects model }
2765
- * @return {Object }
2766
- * <pre>
2767
- * {
2768
- * view: 'project.model_overview',
2769
- * properties: { projectId: ___, modelId: ___ }
2770
- * }
2771
- * </pre>
2772
- * <ul>
2773
- * <li>The <code>view</code> is the name of the state according to ui-router configuration</li>
2774
- * <li><code>properties</code> is a list of required params required to rebuild the url</li>
2775
- * </ul>
2776
- */
2777
- this . getCurrentState = function ( project ) {
2778
- if ( project . scoreset_ids && project . scoreset_ids . length ) {
2779
- //Scored files
2780
- return {
2781
- view : 'project.deploy-overview' ,
2782
- properties : { projectId : project . id }
2783
- } ;
2784
- } else if ( project . scoring_dataset_ids && project . scoring_dataset_ids . length ) {
2785
- //Deploy
2786
- return {
2787
- view : 'project.format-score' ,
2788
- properties : { projectId : project . id , datasetId : project . scoring_dataset_ids . slice ( - 1 ) [ 0 ] }
2789
- } ;
2790
- } else if ( project . classifier_id ) {
2791
- //Model Overview
2792
- return {
2793
- view : 'project.model_overview' ,
2794
- properties : { projectId : project . id , modelId : project . classifier_id }
2795
- } ;
2796
- } else if ( project . learning_dataset_id && project . dictionary_id ) {
2797
- //Create Model: config
2798
- return {
2799
- view : 'project.learn-config' ,
2800
- properties : { projectId : project . id , datasetId :project . learning_dataset_id , dictionaryId :project . dictionary_id }
2801
- } ;
2802
- } else {
2803
- //Create Model: upload
2804
- return {
2805
- view : 'project.select_learned_dataset' ,
2806
- properties : { projectId : project . id }
2807
- } ;
2808
- }
2809
- } ;
2810
-
2811
- /**
2812
- * @ngdoc function
2813
- * @methodOf predicsis.jsSDK.projectsHelper
2814
- * @name getCurrentStep
2815
- * @description Map view to project step (One of model-creation, model-overview, deploy, deploy-overview)
2816
- *
2817
- * @param {String } currentView State name of the current page
2818
- * @return {String } State name displayed as "current" in breadcrumb
2819
- */
2820
- this . getCurrentStep = function ( currentView ) {
2821
- if ( currentView === 'project.deploy-overview' ) {
2822
- return 'deploy-overview' ;
2823
- } else if ( [ 'project.model_overview' , 'project.variables-inspection' ] . indexOf ( currentView ) >= 0 ) {
2824
- return 'model-overview' ;
2825
- }
2826
- else if ( [ 'project.create' , 'project.select_learned_dataset' , 'project.format' , 'project.learn-config' , 'project.learn' ] . indexOf ( currentView ) >= 0 ) {
2827
- return 'model-creation' ;
2828
- } else {
2829
- return 'deploy' ;
2830
- }
2831
- } ;
2832
-
2833
- /**
2834
- * @ngdoc function
2835
- * @methodOf predicsis.jsSDK.projectsHelper
2836
- * @name getStateFromStep
2837
- * @param {Object } project {@link API.model.Projects Projects model }
2838
- * @param {String } toStep --
2839
- * @return {Object }
2840
- * <pre>
2841
- * {
2842
- * view: 'project.model_overview',
2843
- * properties: { projectId: ___, modelId: ___ }
2844
- * }
2845
- * </pre>
2846
- */
2847
- this . getStateFromStep = function ( project , toStep ) {
2848
- if ( toStep === 'model-overview' && project . classifier_id ) {
2849
- return {
2850
- view : 'project.model_overview' ,
2851
- properties : { projectId : project . id , modelId : project . classifier_id }
2852
- } ;
2853
- } else if ( toStep === 'deploy' && project . scoring_dataset_ids . length > 0 ) {
2854
- return {
2855
- view : 'project.select_scored_dataset' ,
2856
- properties : { projectId : project . id }
2857
- } ;
2858
- } else if ( toStep === 'deploy-overview' && project . scoreset_ids . length > 0 ) {
2859
- return {
2860
- view : 'project.deploy-overview' ,
2861
- properties : { projectId : project . id }
2862
- } ;
2863
- } else {
2864
- //Even on model-creation false should be returned has user never navigate to this step
2865
- return false ;
2866
- }
2867
- } ;
2868
-
2869
2808
// --- Altering methods --------------------------------------------------------------------------------------------
2870
2809
2871
2810
/**
@@ -2989,8 +2928,11 @@ angular.module('predicsis.jsSDK')
2989
2928
* @ngdoc service
2990
2929
* @name predicsis.jsSDK.s3FileHelper
2991
2930
* @require $injector
2931
+ * - Uploads
2932
+ * - $q
2992
2933
*/
2993
- angular . module ( 'predicsis.jsSDK' )
2934
+ angular
2935
+ . module ( 'predicsis.jsSDK' )
2994
2936
. service ( 's3FileHelper' , function ( $injector ) {
2995
2937
'use strict' ;
2996
2938
@@ -3004,13 +2946,18 @@ angular.module('predicsis.jsSDK')
3004
2946
* @description upload a file to S3
3005
2947
*
3006
2948
* @param {Object } file html5 File instance
3007
- * @return {Promise }
2949
+ * @return {Promise } Resolved promise my have 2 response whether if upload success or fail:
2950
+ * <ul>
2951
+ * <li><b>Success</b> <code>{filename: file.name, key: key}</code></li>
2952
+ * <li><b>Fail</b> <code>{status: xhr2.status, err: xhr2.responseText}</code></li>
2953
+ * </ul>
3008
2954
*/
3009
2955
this . upload = function ( file , progressHandler ) {
3010
2956
var deferred = $q . defer ( ) ;
3011
2957
Upload . getCredentials ( 's3' )
3012
2958
. then ( function ( credential ) {
3013
2959
var key = credential . key . replace ( '${filename}' , file . name ) ;
2960
+ var xhr2 = new XMLHttpRequest ( ) ;
3014
2961
var form = formFactory ( {
3015
2962
key : key ,
3016
2963
AWSAccessKeyId : credential . aws_access_key_id ,
@@ -3022,21 +2969,25 @@ angular.module('predicsis.jsSDK')
3022
2969
} , {
3023
2970
file : file
3024
2971
} ) ;
3025
- var xhr2 = new XMLHttpRequest ( ) ;
2972
+
3026
2973
xhr2 . open ( 'POST' , credential . s3_endpoint , true ) ;
2974
+
3027
2975
if ( progressHandler ) {
3028
2976
xhr2 . upload . addEventListener ( 'progress' , progressHandler ) ;
3029
2977
}
2978
+
3030
2979
xhr2 . addEventListener ( 'load' , function ( ) {
3031
2980
if ( xhr2 . status === 201 ) {
3032
2981
deferred . resolve ( { filename : file . name , key : key } ) ;
3033
2982
} else {
3034
2983
deferred . reject ( { status : xhr2 . status , err : xhr2 . responseText } ) ;
3035
2984
}
3036
2985
} ) ;
2986
+
3037
2987
xhr2 . addEventListener ( 'error' , function ( err ) {
3038
2988
deferred . reject ( err ) ;
3039
2989
} ) ;
2990
+
3040
2991
xhr2 . send ( form ) ;
3041
2992
} ) ;
3042
2993
return deferred . promise ;
0 commit comments