Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
fix: support PI v2 profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Nov 18, 2018
1 parent f2cac23 commit d6c215c
Show file tree
Hide file tree
Showing 5 changed files with 665 additions and 7 deletions.
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

10 changes: 8 additions & 2 deletions app/util/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

'use strict';

var types = {
'personality': 0,
'needs': 1,
'values': 2,
};

/**
* Return the desired Traits normalized
* @param {tree} JSON personality results object
Expand All @@ -23,11 +29,11 @@
*/
var traits = function(tree, type) {
var profile = typeof(tree) === 'string' ? JSON.parse(tree) : tree;
var _traits = profile[type];
var _traits = profile[type] ? profile[type] : profile.tree.children[types[type]].children[0].children;
return _traits.map(function(trait) {
return {
name: trait.name,
value: trait.percentile
value: trait['percentile'] || trait['percentage']
};
});
};
Expand Down
9 changes: 5 additions & 4 deletions app/util/similarity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

'use strict';
var flatten = require('./flatten');

/**
* Return the euclidean distance between two profiles
Expand All @@ -25,13 +26,13 @@
var similarity = function( /*object*/ origin, /*object*/ target, type) {
origin = typeof(origin) === 'string' ? JSON.parse(origin) : origin;
target = typeof(target) === 'string' ? JSON.parse(target) : target;
var distance = 0.0,
origin_traits = origin[type],
target_traits = target[type];
var distance = 0.0;
var origin_traits = flatten.traits(origin, type);
var target_traits = flatten.traits(target, type);

// for each trait in origin personality...
origin_traits.forEach(function(trait, i) {
distance += Math.pow(trait.percentile - target_traits[i].percentile, 2);
distance += Math.pow(trait.value - target_traits[i].value, 2);
});
var ret = 1 - (Math.sqrt(distance / origin_traits.length));
return ret;
Expand Down
Loading

0 comments on commit d6c215c

Please sign in to comment.