Skip to content

Commit c56c0c7

Browse files
committed
before rebase
1 parent ac4ff86 commit c56c0c7

File tree

6 files changed

+281
-6
lines changed

6 files changed

+281
-6
lines changed

client/src/components/HomePage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React, { Component } from 'react';
22
import { Grid, Segment, Card } from 'semantic-ui-react';
33
import LiveDataTable from './LiveDataTable';
44
import StrategyChart from './StrategyChart';
5+
import HomePageTweets from './HomePageTweets';
6+
import WatsonSummary from './WatsonSummary';
57

68
const divStyle= {
7-
height: '40vh'
9+
height: '40vh',
810
};
9-
1011
class HomePage extends Component {
1112
render() {
1213
return (
@@ -35,7 +36,6 @@ class HomePage extends Component {
3536
</Grid.Column>
3637
</Grid.Row>
3738
</Grid>
38-
3939
</div>
4040
);
4141
}

client/src/components/Mood.js

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,137 @@
1-
import React from 'react';
2-
import { Bar } from 'react-chartjs-2';
1+
import React, { Component } from 'react';
2+
import Bar from 'react-chartjs-2';
33

4+
class Mood extends Component {
5+
constructor(props) {
6+
super(props);
7+
this.state = {
8+
emotionData: {
9+
labels: ['Anger', 'Joy', 'Disgust', 'Sadness', 'Fear'],
10+
datasets: [{
11+
// label: props.songNameAndArtist[0] + ' - ' + props.songNameAndArtist[1],
12+
label: '12345',
13+
data: [
14+
1.5,
15+
2.0,
16+
3.3,
17+
5,
18+
10,
19+
// props.watson.anger,
20+
// props.watson.joy,
21+
// props.watson.disgust,
22+
// props.watson.fear,
23+
// props.watson.sadness
24+
],
25+
backgroundColor: [
26+
'rgba(252, 61, 57, 1)',
27+
'rgba(254, 203, 46, 1)',
28+
'rgba(83, 215, 105, 1)',
29+
'rgba(20, 126, 251, 1)',
30+
'rgba(193, 53, 132, 1)',
31+
],
32+
borderColor: [
33+
'rgba(252, 61, 57, 1)',
34+
'rgba(254, 203, 46, 1)',
35+
'rgba(83, 215, 105, 1)',
36+
'rgba(20, 126, 251, 1)',
37+
'rgba(193, 53, 132, 1)',
38+
],
39+
borderWidth: 3,
40+
}],
41+
},
442

43+
emotionOptions: {
44+
title: {
45+
display: false,
46+
text: 'Kanye West - Famous',
47+
fontSize: 24,
48+
},
49+
},
50+
languageData: {
51+
labels: ['Analytical', 'Confident', 'Tentative'],
52+
datasets: [{
53+
// label: props.songNameAndArtist[0] + ' - ' + props.songNameAndArtist[1],
54+
label: '54321',
55+
data: [
56+
// props.watson.analytical, props.watson.confident, props.watson.tentative
57+
10,
58+
1,
59+
5,
60+
10,
61+
20,
62+
],
63+
backgroundColor: [
64+
'rgba(252, 61, 57, 1)',
65+
'rgba(254, 203, 46, 1)',
66+
'rgba(83, 215, 105, 1)',
67+
],
68+
borderColor: [
69+
'rgba(252, 61, 57, 1)',
70+
'rgba(254, 203, 46, 1)',
71+
'rgba(83, 215, 105, 1)',
72+
],
73+
borderWidth: 3,
74+
}],
75+
},
76+
languageOptions: {
77+
title: {
78+
display: false,
79+
// text: props.songNameAndArtist[0] + ' - ' + props.songNameAndArtist[1],
80+
text: '5555',
81+
fontSize: 24,
82+
},
83+
},
84+
socialData: {
85+
labels: ["Openness", "Conscientiousness", "Extraversion", "Agreeableness", "Emotional Range"],
86+
datasets: [{
87+
label: 'hahaha',
88+
data: [
89+
3,
90+
2,
91+
1,
92+
10,
93+
5,
94+
// props.watson.openness,
95+
// props.watson.conscientiousness,
96+
// props.watson.extraversion,
97+
// props.watson.agreeableness,
98+
// props.watson.emotionalrange
99+
],
100+
backgroundColor: [
101+
'rgba(252, 61, 57, 1)',
102+
'rgba(254, 203, 46, 1)',
103+
'rgba(83, 215, 105, 1)',
104+
'rgba(20, 126, 251, 1)',
105+
'rgba(193, 53, 132, 1)',
106+
],
107+
borderColor: [
108+
'rgba(252, 61, 57, 1)',
109+
'rgba(254, 203, 46, 1)',
110+
'rgba(83, 215, 105, 1)',
111+
'rgba(20, 126, 251, 1)',
112+
'rgba(193, 53, 132, 1)',
113+
],
114+
borderWidth: 3,
115+
}],
116+
},
117+
socialOptions: {
118+
title: {
119+
display: false,
120+
text: 'hihi',
121+
fontSize: 24,
122+
},
123+
},
124+
};
125+
}
126+
127+
render() {
128+
return (
129+
<div className="maingraph">
130+
<h2>Emotion</h2>
131+
<Bar data={this.state.emotionData} options={this.state.emotionOptions} width={500} />
132+
</div>
133+
);
134+
}
135+
}
136+
137+
export default Mood;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import React, { Component } from 'react';
2+
import Chart from 'chart.js';
3+
import axios from 'axios';
4+
import './css/WatsonSummary.css';
5+
6+
let ctx;
7+
let barChart;
8+
9+
class WatsonSummary extends Component {
10+
constructor(props) {
11+
super(props);
12+
this.state = {
13+
watsonChart: 'watsonChart',
14+
companiesSummary: [['bitcoin', 2, 0.12], ['ethereum', 13, -0.2], ['dash', 8, 0.21], ['litecoin', 6, 0.11], ['ripple', 4, 0.20], ['IOTA', 2, 0.15], ['Zcash', 1, 0.10]],
15+
};
16+
17+
this.generateChart = this.generateChart.bind(this);
18+
this.update = this.update.bind(this);
19+
}
20+
21+
22+
componentDidMount() {
23+
this.update();
24+
this.generateChart();
25+
}
26+
27+
componentDidUpdate() {
28+
// this.update();
29+
this.generateChart();
30+
}
31+
32+
update() {
33+
axios.get('/retrieveCryptoMoods', { list: ['Bitcoin', 'Ethereum', 'Dash', 'Litecoin', 'Ripple'] })
34+
.then( response => {
35+
36+
})
37+
.catch( err => {
38+
console.error(err);
39+
}
40+
41+
42+
43+
this.setState({
44+
companiesSummary: [['bitcoin', , 0.12], ['ethereum', , -0.2], ['dash', 8, 0.21], ['litecoin', 6, 0.11], ['ripple', 4, 0.20]],
45+
});
46+
}
47+
48+
generateChart() {
49+
console.log('*** companiesSummary length: ', this.state.companiesSummary.length || 'companiesSummary is empty');
50+
51+
if (this.state.companiesSummary.length !== 0) {
52+
const labels = this.state.companiesSummary.map(tuple => tuple[0]);
53+
const data = this.state.companiesSummary.map(tuple => tuple[2] * 100);
54+
55+
let axisMax = Math.max(Math.max.apply(null, data), -Math.min.apply(null, data));
56+
axisMax = Math.min(100, Math.ceil((axisMax / 100) * 4) * 25);
57+
58+
const colors = data.map((score) => {
59+
if (score >= 0) {
60+
return `rgba(31, 122, 31, ${Math.max(score / axisMax, 0.25)})`;
61+
}
62+
return `rgba(153, 0, 0, ${Math.max(-score / axisMax, 0.25)})`;
63+
});
64+
65+
ctx = document.getElementById('watson-chart');
66+
ctx.height = '10vh';
67+
68+
if (barChart !== undefined) barChart.destroy();
69+
70+
barChart = new Chart(ctx, {
71+
type: 'horizontalBar',
72+
data: {
73+
labels,
74+
datasets: [{
75+
label: 'Watson Score',
76+
data,
77+
backgroundColor: colors,
78+
borderColor: colors,
79+
borderWidth: 1,
80+
}],
81+
},
82+
options: {
83+
scales: {
84+
xAxes: [{
85+
ticks: {
86+
min: -axisMax, // Edit the value according to what you need
87+
max: axisMax,
88+
},
89+
}],
90+
yAxes: [{
91+
stacked: true,
92+
}],
93+
},
94+
},
95+
});
96+
}
97+
}
98+
99+
render() {
100+
return (
101+
<div className="watson-bg">
102+
<canvas width="50px" onLoad={this.generateChart} height="100px" id="watson-chart" />
103+
</div>
104+
);
105+
}
106+
107+
108+
}
109+
110+
export default WatsonSummary;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.watson-bg {
2+
width: 99%;
3+
/*height: auto;*/
4+
height: 99%;
5+
background-color: whitesmoke;
6+
border-radius: 5px;
7+
padding: 2px;
8+
display: inline-block;
9+
10+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"axios": "^0.16.2",
1515
"bluebird": "^3.5.0",
1616
"body-parser": "^1.17.2",
17-
"chart": "^0.1.2",
17+
"chart.js": "^2.6.0",
1818
"compression-webpack-plugin": "^1.0.0",
1919
"cors": "^2.8.4",
2020
"csv": "^1.1.1",

server/app.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ app.get('/retrieveCryptoMood/:source/:keyword', (req, res) => {
2828
} else { res.send({ error: 'invalid source' }); }
2929
});
3030

31+
app.get('/retrieveCryptoMoods/', (req, res) => {
32+
const searchTextArray = req.params.list;
33+
let returnArray = [];
34+
console.log(searchTextArray);
35+
searchTextArray.forEach((searchText) => {
36+
getAll(searchText, (emotions) => {
37+
const { joy, sadness, anger, disgust, fear } = emotions;
38+
returnArray.push([searchText, null, (joy * 4) - sadness - anger - disgust - fear]);
39+
});
40+
});
41+
returnArray = returnArray.sort((a, b) => {
42+
if (a[2] > b[2]) {
43+
return 1;
44+
} else if (a[2] < b[2]) {
45+
return -1;
46+
}
47+
});
48+
49+
return returnArray;
50+
});
51+
52+
3153
app.get('/fetchTweets', (req, res) => {
3254
return fetchTweets()
3355
.then((data) => {

0 commit comments

Comments
 (0)