-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetector.js
113 lines (103 loc) · 3.67 KB
/
detector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Detector module. It holds the Detector class.
* @module Detector
*/
const applyStrategy = require( '../tools/merge' ).applyStrategy;
/**
* Detector constructor function. It defines the common prototype
* for future detectors.
* @constructs Detector
* @param {string} id - Id of the detector. This id would be use in
* HTTP request.
* @param {string} category - Category of the detector. Values can be
* 'face', 'voice','body', 'physio' and 'others'.
* @param {Array} media - Types of media the service can handle.
* @param {boolean} realTime - Boolean indicating if the API works in realTime.
* @param {string} url - Url to which the request will be sent.
* @param {Object} otherOptions - Other options, such as API keys, and so on.
*/
function Detector( id, category, media, realTime, url, otherOptions ) {
this.id = id;
this.category = category;
this.media = media;
this.realTime = realTime;
this.delay = 500;
this.url = url;
this.otherOptions = otherOptions;
this.rawResults = [ ];
this.padResults = [ ];
}
/**
* Auxiliar method to log in and perform other initialization tasks.
* If you need to add new parameters to your Detector object, you can do it here.
* @async
* @function initialize
* @memberof Detector
*/
Detector.prototype.initialize = async function( ) {
console.log( 'Initialize method in Detector class' );
};
/**
* Send the media passed to the correspondent API.
* @function extractEmotions
* @memberof Detector
* @param {Object} context - Context in which auxiliar functions will be called. Context will be 'this' most of the times.
* @param {string} media - Media to analyse. This media will be sent to the Detector's API.
* This string will be an absolute path/url pointing to where the media is stored.
* @param {Function} callback - Callback used to auxiliar tasks, like measuring times.
*/
Detector.prototype.extractEmotions = function( context, media, callback = ( ) => {} ) {
console.log( 'extractEmotions method in Detector class' );
};
/**
* Translated the raw results to the PAD format.
* @function translateToPAD
* @memberof Detector
* @param {Object} results - Results from the API that will be translated to the PAD space.
* @return {Object} Results expressed in the PAD space.
*/
Detector.prototype.translateToPAD = function( results ) {
console.log( 'Translate method in Detector class' );
return {};
};
/**
* Add the raw results and the PAD-translated version to the results arrays.
* @function addResults
* @memberof Detector
* @param {Object} results - Results as they come from the third party emotion detection service, hardware API, etc.
*/
Detector.prototype.addResults = function( results ) {
this.rawResults.push( results );
this.padResults.push( this.translateToPAD( results ) );
};
/**
* Delete all the previous results.
* @function cleanResults
* @memberof Detector
*/
Detector.prototype.cleanResults = function( ) {
this.rawResults = [ ];
this.padResults = [ ];
};
/**
* Translated the raw results to the PAD format.
* @function getResults
* @memberof Detector
* @param {string} resultsType - String with the type of results requested, i.e., 'pad' or 'raw'.
* @return {Array} Results requested.
*/
Detector.prototype.getResults = function( resultsType ) {
return this[ resultsType + 'Results' ];
};
/**
* Apply aggregation strategy to array of triplets.
* @function applyStrategy
* @memberof Detector
* @param {String} strategy - Name of the strategy which will be used to aggregate the PAD results.
* one triplet.
* @return {Array} Aggregated results.
*/
Detector.prototype.applyStrategy = function( strategy ) {
return applyStrategy( strategy, this.getResults( 'pad' ) );
};
module.exports.Detector = Detector;