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

Commit

Permalink
fix: Update to PI v3
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Nov 18, 2018
1 parent f73a87c commit f2cac23
Show file tree
Hide file tree
Showing 15 changed files with 942 additions and 1,477 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you are having difficulties running the app or have a question about the serv

# Issues

If you encounter an issue with this sample app, you are welcome to submit a [bug report](https://github.com/watson-developer-cloud/yourcelebritymatch/issues). Before that, please search for similar issues. It's possible somebody has encountered this issue already.
If you encounter an issue with this sample app, you are welcome to submit a [bug report](https://github.com/watson-developer-cloud/your-celebrity-match/issues). Before that, please search for similar issues. It's possible somebody has encountered this issue already.

# Pull Requests

Expand Down
38 changes: 12 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ The application uses [The Personality Insights API](https://www.ibm.com/watson/d

# How it works

Steps |
:------------: |
<img src="http://s7.postimg.org/odqyly6vv/1_enter_handle.gif" alt="You input your Twitter handle" width="100px" height="100px"><br>You input your Twitter handle.<br> |
<img src="http://s7.postimg.org/ag8sgn8t7/2_twitter_feed.gif" alt="Calls the Twitter API." width="100px" height="100px"><br> Calls the Twitter API to get the latest 2300 tweets from your public feed.<br> |
<img src="http://s7.postimg.org/ltvbrujbv/3_UM_api.gif" alt="Calls the Personality Insights API." width="100px" height="100px"><br> Calls the Personality Insights API to analyze the language in your tweets and apply it to a spectrum of characteristics.<br> |
<img src="http://s7.postimg.org/nmy8g64ij/4_compare_results.gif" alt="Compares your Personality Insights profile to 232 celebrity profiles analyzed with the service." width="100px" height="100px"><br> Compares your Personality Insights profile to 232 celebrity profiles analyzed with the service.<br> |
<img src="http://s7.postimg.org/we59afntn/5_celeb_match.png" alt="Sorts your matches and shows you the highest and lowest. These are calculated by the euclidean distance between the two." width="100px" height="100px"><br> Sorts your matches and shows you the highest and lowest. These are calculated by the euclidean distance between the two.<br> |
1. You input your Twitter handle.
1. Calls the Twitter API to get the latest 2300 tweets from your public feed.
1. Calls the Personality Insights API to analyze the language in your tweets and apply it to a spectrum of characteristics.
1. Compares your Personality Insights profile to 232 celebrity profiles analyzed with the service.
1. Sorts your matches and shows you the highest and lowest. These are calculated by the euclidean distance between the two.

## Prerequisites

Expand All @@ -45,31 +43,23 @@ Steps |
This instructions will help you install the celebrities app in your local environment.

1. Clone the repository with:

```sh
$ git clone [email protected]:watson-developer-cloud/your-celebrity-match.git
```

1. Install [node][node] (use v0.10.31)

1. Install [node][node]
1. Install [mongodb][mongodb]

1. Install the npm modules:

```sh
$ npm install
```
**Note:** Make sure you are in the project directory, the `package.json` file should be visible.

1. Start mongodb

```sh
$ mongod
```
(Run this in a separate terminal window)

1. You need some credentials to use Twitter API, Personality Insights and MongoDC:
- Get credentials to use Personality Insights.
1. You need some credentials to use Twitter API, Personality Insights and MongoDB:
- Get credentials to use Personality Insights.
- Create a **FREE** Mongodb database using [MongoLab](https://mlab.com/).
- Create a Twitter app and get the API credentials [here][twitter_app].
1. Update the Twitter, MongoDB and Personality Insights credentials in `config/config.js`
Expand All @@ -79,11 +69,9 @@ This instructions will help you install the celebrities app in your local enviro
{
personality_insights: {
version: '2017-10-13',
url: '<url>',
username: '<username>',
password: '<password>'
// If your credentials have an apikey field use
// iam_apikey: '<apikey>',
iam_apikey: '<username>'s
},
twitter: [{
Expand All @@ -102,7 +90,6 @@ This instructions will help you install the celebrities app in your local enviro
```

1. Update the database with the celebrities by making a **POST** request to:

`http://localhost:3000/celebrities/syncdb`

The celebrities are not added by default. Hence the above step is recommended. Refer #Celebrities section below for more information.
Expand All @@ -116,7 +103,7 @@ This instructions will help you install the celebrities app in your local enviro


## Celebrities
The application comes with two 'celebrity' profiles: [@germanatt][german_twitter] and [@nfriedly][nathan_twitter]. If you want to add more profiles, you have two options:
The application comes with 1 'celebrity' profile: [@germanatt][german_twitter]. If you want to add more profiles, you have two options:

### Auto-Lookup
1. Choose a person on Twitter to include as a 'celebrity'. Ensure this person is verified, has at least 10,000 followers, and has over 1,000 tweets.
Expand Down Expand Up @@ -146,10 +133,9 @@ This instructions will help you install the celebrities app in your local enviro
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)

[bluemix]: https://console.ng.bluemix.net/
[node]: http://nodejs.org/download
[node]: http://nodejs.org/
[mongodb]: http://docs.mongodb.org/manual/installation/
[twitter_app]: https://apps.twitter.com/app/new
[german_twitter]: https://twitter.com/germanatt
[nathan_twitter]: https://twitter.com/nfriedly
[pi_docs]: https://console.bluemix.net/docs/services/personality-insights/index.html
[vcap_environment]: https://console.bluemix.net/docs/services/watson/getting-started-variables.html
6 changes: 3 additions & 3 deletions app/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var celebs =[];
var getCelebrityFromDB = Q.denodeify(Profile.find.bind(Profile));

// Constants for types of profiles
var PERSONALITY = 0,
NEEDS = 1,
VALUES = 2;
var PERSONALITY = 'personality',
NEEDS = 'needs',
VALUES = 'values';

/**
* Updates an array with the celebrity profile pictures.
Expand Down
4 changes: 2 additions & 2 deletions app/util/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
var traits = function(tree, type) {
var profile = typeof(tree) === 'string' ? JSON.parse(tree) : tree;
var _traits = profile.tree.children[type].children[0].children;
var _traits = profile[type];
return _traits.map(function(trait) {
return {
name: trait.name,
value: trait.percentage
value: trait.percentile
};
});
};
Expand Down
6 changes: 3 additions & 3 deletions app/util/similarity.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ 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.tree.children[type].children[0].children,
target_traits = target.tree.children[type].children[0].children;
origin_traits = origin[type],
target_traits = target[type];

// for each trait in origin personality...
origin_traits.forEach(function(trait, i) {
distance += Math.pow(trait.percentage - target_traits[i].percentage, 2);
distance += Math.pow(trait.percentile - target_traits[i].percentile, 2);
});
var ret = 1 - (Math.sqrt(distance / origin_traits.length));
return ret;
Expand Down
2 changes: 0 additions & 2 deletions app/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ module.exports = {
toContentItem : function(tweet) {
return {
id: tweet.id_str,
userid: tweet.user.id_str,
sourceid: 'twitter',
language: (tweet.lang && (['es','en'].indexOf(tweet.lang) > -1)) ? tweet.lang : 'en',
contenttype: 'text/plain',
content: tweet.text.replace('[^(\\x20-\\x7F)]*',''),
Expand Down
2 changes: 1 addition & 1 deletion app/views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ block content
.row.extra-links
.col-md-12
p.text-center
a(href='https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/') Built with IBM Watson
a(href='https://www.ibm.com/watson/developer/') Built with IBM Watson
.row.extra-links
.col-md-12
p.text-center
Expand Down
2 changes: 1 addition & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {

// Personality Insights credentials
personality_insights: {
version: 'v3'
version: '2017-10-13'
},

// Twitter app credentials: https://apps.twitter.com/app
Expand Down
2 changes: 0 additions & 2 deletions config/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ module.exports = function (app) {
// 2. helmet with defaults
app.use(helmet({ cacheControl: false }));

app.use(helmet.frameguard('allow-from', 'https://ibm-sxsw.mybluemix.net'));

// 3. rate-limit to /api/
app.use('/like/', rateLimit({
windowMs: 30 * 1000, // seconds
Expand Down
Loading

0 comments on commit f2cac23

Please sign in to comment.