Skip to content

Commit

Permalink
Created faceResult object
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca committed Aug 9, 2019
1 parent 59d3163 commit f9ce0d7
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,55 @@
processData: false,
data: blobData
})
.done(function (data) {

var faceResult = {
peopleCount: data.length
};

console.log("Face API result: ", faceResult, data);

})
.fail(function (err) {
console.err("Face API error");
})
.done(function (data) {

var faceResult = {
peopleCount: data.length,
people: []
};

$.each(data, (index, value) => {

var emotions = value.faceAttributes.emotion;
var emotionsRatings = [];
for (let index = 0; index < Object.keys(emotions).length; index++) {
emotionsRatings.push(parseFloat(emotions[Object.keys(emotions)[index]]));
}
var emotionWithHighestRating = $.inArray(Math.max.apply(Math, emotionsRatings), emotionsRatings);
var mostRatedEmotion = Object.keys(emotions)[emotionWithHighestRating];
var currentPersonData = {
age: value.faceAttributes.age,
gender: { name: value.faceAttributes.gender, id: (value.faceAttributes.gender == 'male' ? 1 : 2) },
emotion: { name: mostRatedEmotion, id: emotionWithHighestRating }
};

faceResult.people.push(currentPersonData);

});

// Group analisys
var ages = $.map(faceResult.people, (people, index) => {
return people.age;
});
if (faceResult.peopleCount == 1) {
faceResult.groupType = { name: 'solo', id: 1 }
}
else if (faceResult.peopleCount == 2) {
if (Math.max.apply(Math, ages) - Math.min.apply(Math, ages) < 15)
faceResult.groupType = { name: 'couple', id: 2 }
else
faceResult.groupType = { name: 'group', id: 3 }

} else if (faceResult.peopleCount > 2) {
faceResult.groupType = { name: 'group', id: 3 }
}

console.log("Face API result: ", faceResult, data);

})
.fail(function (err) {
console.err("Face API error");
});
});

});
Expand Down

0 comments on commit f9ce0d7

Please sign in to comment.