Skip to content

Commit 278532f

Browse files
committed
>>> Bump to version 0.1.8 <<<
1 parent fda6dfc commit 278532f

File tree

5 files changed

+82
-131
lines changed

5 files changed

+82
-131
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"authors": [
55
"Yllieth <[email protected]>",
66
"Dehau"

dist/predicsis-jsSDK.js

Lines changed: 78 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,19 @@ angular.module('predicsis.jsSDK')
769769
* Both <code>variable_id</code> and <code>dataset_id</code> are required.
770770
*
771771
* @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>
773785
*/
774786
this.create = function(params) {
775787
return jobsHelper.wrapAsyncPromise(modalities().post({modalities_set: params}));
@@ -1531,13 +1543,18 @@ angular.module('predicsis.jsSDK')
15311543
* }
15321544
* </pre>
15331545
*
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+
*
15341554
* See {@link predicsis.jsSDK.projectsHelper projects helper} to get the following methods:
15351555
* <ul>
15361556
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_isModelDone isModelDone(Projects project)}</code></li>
15371557
* <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>
15411558
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addLearningDataset addLearningDataset(Projects project, String datasetId)}</code></li>
15421559
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addScoringDataset addScoringDataset(Projects project, String datasetId)}</code></li>
15431560
* <li><code>{@link predicsis.jsSDK.projectsHelper#methods_addScoreset addScoreset(Projects project, String datasetId)}</code></li>
@@ -2448,7 +2465,7 @@ angular.module('predicsis.jsSDK')
24482465
* @ngdoc function
24492466
* @name all
24502467
* @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
24522469
* @param {String} dictionaryId Id of the container dictionary
24532470
* @param {Array} [variablesIds] List of variables' id you want to fetch
24542471
* @return {Object} Promise of a variables list
@@ -2460,7 +2477,7 @@ angular.module('predicsis.jsSDK')
24602477
variablesIds = variablesIds || [];
24612478

24622479
return $q.all(variablesIds.map(function(id) {
2463-
return variables(dictionaryId, id).get();
2480+
return variable(dictionaryId, id).get();
24642481
}));
24652482
}
24662483
};
@@ -2587,6 +2604,7 @@ angular.module('predicsis.jsSDK')
25872604
* - {@link predicsis.jsSDK.Projects Projects}
25882605
* - {@link predicsis.jsSDK.PreparationRules PreparationRules}
25892606
* - $q
2607+
* - $rootScope
25902608
*/
25912609
angular.module('predicsis.jsSDK')
25922610
.service('modelHelper', function($injector) {
@@ -2620,6 +2638,19 @@ angular.module('predicsis.jsSDK')
26202638
* <li><kbd>project.id</kbd> to store preparation rules set, classifier and reports ids.</li>
26212639
* </ul>
26222640
*
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+
*
26232654
* @param {Object} project Instance of a valid {@link predicsis.jsSDK.Projects Project}
26242655
* @return {Object} Instance of a complete {@link predicsis.jsSDK.Models Models}
26252656
*/
@@ -2630,14 +2661,19 @@ angular.module('predicsis.jsSDK')
26302661
var Projects = $injector.get('Projects');
26312662
var PreparationRules = $injector.get('PreparationRules');
26322663
var $q = $injector.get('$q');
2664+
var $rootScope = $injector.get('$rootScope');
26332665
var results = {};
26342666

2667+
$rootScope.$broadcast('jsSDK.learn.start-retrieving-train-dataset');
2668+
26352669
return Datasets.getChildren(project.learning_dataset_id)
26362670
.then(function(children) {
26372671
if(!children.train) {
26382672
throw 'Invalid project on POST preparation_rules, no valid train dataset found';
26392673
}
26402674

2675+
$rootScope.$broadcast('jsSDK.learn.start-creating-preparation-rules');
2676+
26412677
return PreparationRules.create({
26422678
variable_id: project.target_variable_id,
26432679
dataset_id: children.train.id
@@ -2646,6 +2682,7 @@ angular.module('predicsis.jsSDK')
26462682
// create the model from preparation rules set
26472683
.then(function(preparationRulesRet) {
26482684
results.preparation_rules_set = preparationRulesRet;
2685+
$rootScope.$broadcast('jsSDK.learn.start-learning');
26492686
return Models.createClassifier(preparationRulesRet.id);
26502687
})
26512688
// generate reports
@@ -2655,17 +2692,29 @@ angular.module('predicsis.jsSDK')
26552692
// but the PATCH request will occurs after the learn process.
26562693
// this tweak allow project generation.
26572694
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);
26632707
})
26642708
//update project
26652709
.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+
26692718
return Projects.update(project.id, {
26702719
preparation_rules_set_id: results.preparation_rules_set.id,
26712720
classifier_id: results.classifier.id,
@@ -2756,116 +2805,6 @@ angular.module('predicsis.jsSDK')
27562805
return Boolean(project.is_dictionary_verified);
27572806
};
27582807

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-
28692808
// --- Altering methods --------------------------------------------------------------------------------------------
28702809

28712810
/**
@@ -2989,8 +2928,11 @@ angular.module('predicsis.jsSDK')
29892928
* @ngdoc service
29902929
* @name predicsis.jsSDK.s3FileHelper
29912930
* @require $injector
2931+
* - Uploads
2932+
* - $q
29922933
*/
2993-
angular.module('predicsis.jsSDK')
2934+
angular
2935+
.module('predicsis.jsSDK')
29942936
.service('s3FileHelper', function($injector) {
29952937
'use strict';
29962938

@@ -3004,13 +2946,18 @@ angular.module('predicsis.jsSDK')
30042946
* @description upload a file to S3
30052947
*
30062948
* @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>
30082954
*/
30092955
this.upload = function(file, progressHandler) {
30102956
var deferred = $q.defer();
30112957
Upload.getCredentials('s3')
30122958
.then(function(credential) {
30132959
var key = credential.key.replace('${filename}', file.name);
2960+
var xhr2 = new XMLHttpRequest();
30142961
var form = formFactory({
30152962
key: key,
30162963
AWSAccessKeyId: credential.aws_access_key_id,
@@ -3022,21 +2969,25 @@ angular.module('predicsis.jsSDK')
30222969
}, {
30232970
file: file
30242971
});
3025-
var xhr2 = new XMLHttpRequest();
2972+
30262973
xhr2.open('POST', credential.s3_endpoint, true);
2974+
30272975
if(progressHandler) {
30282976
xhr2.upload.addEventListener('progress', progressHandler);
30292977
}
2978+
30302979
xhr2.addEventListener('load', function() {
30312980
if(xhr2.status === 201) {
30322981
deferred.resolve({filename: file.name, key: key});
30332982
} else {
30342983
deferred.reject({status: xhr2.status, err: xhr2.responseText});
30352984
}
30362985
});
2986+
30372987
xhr2.addEventListener('error', function(err) {
30382988
deferred.reject(err);
30392989
});
2990+
30402991
xhr2.send(form);
30412992
});
30422993
return deferred.promise;

0 commit comments

Comments
 (0)