From 772ef2238131900926060b88d80c983186f2789e Mon Sep 17 00:00:00 2001 From: Raphael Ugha Date: Wed, 26 Sep 2018 15:52:36 +0100 Subject: [PATCH 01/15] sentiment function resolved --- client/src/models/searches.js | 1 - client/src/views/totals_view.js | 36 ++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/client/src/models/searches.js b/client/src/models/searches.js index 33a6113..f165251 100644 --- a/client/src/models/searches.js +++ b/client/src/models/searches.js @@ -106,7 +106,6 @@ Searches.prototype.calculator = function (tweetData) { totals.retweets += tweet.retweets; totals.favourites += tweet.favourites; }) - console.log(totals) return totals; } module.exports = Searches; diff --git a/client/src/views/totals_view.js b/client/src/views/totals_view.js index 946d8f1..0768785 100644 --- a/client/src/views/totals_view.js +++ b/client/src/views/totals_view.js @@ -2,30 +2,52 @@ const PubSub = require('../helpers/pub_sub.js'); const TotalsView = function (formElement) { this.formElement = formElement; + this.sadTweets = 0; + this.sadRetweets = 0; + this.happyRetweets = 0; + this.happyFavourites = 0; + this.sadFavourites = 0; } TotalsView.prototype.bindEvents = function () { - PubSub.subscribe('Searches:totals-calulated', (event) => { - this.renderTotals(event.detail); + PubSub.subscribe('Searches:happy-totals-calulated', (event) => { + this.happyRetweets = event.detail.retweets; + this.happyFavourites = event.detail.favourites; }) + PubSub.subscribe('Searches:sad-totals-calulated', (event) => { + this.sadTweets = event.detail.totalTweets; + this.sadRetweets = event.detail.retweets; + this.sadFavourites = event.detail.favourites; + + this.renderTotals() + }) } -TotalsView.prototype.renderTotals = function (totalData) { +TotalsView.prototype.renderTotals = function () { const firstContentElement = document.querySelector('#grid-item-5'); - firstContentElement.textContent = totalData.totalTweets; + firstContentElement.textContent = this.sadTweets; const secondContentElement = document.querySelector('#grid-item-6'); - secondContentElement.textContent = totalData.favourites; + secondContentElement.textContent = this.sadRetweets+this.happyRetweets; const thirdContentElement = document.querySelector('#grid-item-7'); - thirdContentElement.textContent = totalData.retweets; + thirdContentElement.textContent = this.sadFavourites+this.happyFavourites; const fourthContentElement = document.querySelector('#grid-item-8'); - // fourthContentElement.textContent = totalData.XXXX; + const sentiment = this.determineSentiment(); + fourthContentElement.textContent = sentiment; +} +TotalsView.prototype.determineSentiment = function() { + if (this.sadRetweets + this.sadFavourites <= this.happyRetweets + this.happyFavourites){ + return ':)' + } + return ':(' } + + module.exports = TotalsView; \ No newline at end of file From 1a6df67fb125b9bebd164e9e32d76efc4f495f51 Mon Sep 17 00:00:00 2001 From: Vicky Jackson Date: Wed, 26 Sep 2018 16:13:38 +0100 Subject: [PATCH 02/15] Added favourites chart --- client/src/views/chart_view.js | 39 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/client/src/views/chart_view.js b/client/src/views/chart_view.js index 3cf1199..83f6c69 100644 --- a/client/src/views/chart_view.js +++ b/client/src/views/chart_view.js @@ -1,7 +1,7 @@ var echarts = require('echarts'); const PubSub = require('../helpers/pub_sub.js'); -const ViewChart = function(chartHtmlElement){ +const ViewChart = function (chartHtmlElement) { this.myChart_1 = null; this.myChart_2 = null; this.chartHtmlElement = chartHtmlElement; @@ -10,29 +10,42 @@ const ViewChart = function(chartHtmlElement){ ViewChart.prototype.bindEvents = function () { - + this.myChart_1 = echarts.init(document.getElementById('chart_1')) this.myChart_2 = echarts.init(document.getElementById('chart_2')) - this.retweetsValues = []; - this.favouritesValues = []; + this.retweetsValues = {}; + this.favouritesValues = {}; PubSub.subscribe('Searches:happy-totals-calulated', (event) => { - this.retweetsValues.push(event.detail.retweets); + this.retweetsValues.happyRetweets = event.detail.retweets; + this.favouritesValues.happyFavourites = event.detail.favourites; console.log('happy retweets from event: ', event.detail.retweets); - if (this.retweetsValues.length === 2){ - console.log('both values are ready from happy listener: ', this.retweetsValues); - this.renderChart(this.retweetsValues[0], this.retweetsValues[1], 'Positive vs Negative Retweets', this.myChart_1); - this.retweetsValues = []; + console.log('happy retweets from object: ', this.retweetsValues); + if (this.retweetsValues.happyRetweets && this.retweetsValues.sadRetweets) { + console.log('both values are ready from happy listener: ', this.retweetsValues); + this.renderChart(this.retweetsValues.happyRetweets, this.retweetsValues.sadRetweets, 'Positive vs Negative Retweets', this.myChart_1); + //this.retweetsValues = []; + } + if (this.favouritesValues.happyFavourites && this.favouritesValues.sadFavourites) { + console.log('both values are ready from happy listener: ', this.favouritesValues); + this.renderChart(this.favouritesValues.happyFavourites, this.favouritesValues.sadFavourites, 'Positive vs Negative Retweets', this.myChart_2); + //this.retweetsValues = []; } //this.renderChart(event.detail.favourites, event.detail.favourites, 'Positive vs Negative Likes', this.myChart_2); }) PubSub.subscribe('Searches:sad-totals-calulated', (event) => { - this.retweetsValues.push(event.detail.retweets); + this.retweetsValues.sadRetweets = event.detail.retweets; + this.favouritesValues.sadFavourites = event.detail.favourites; console.log('sad retweets from event: ', event.detail.retweets); - if (this.retweetsValues.length === 2){ + if (this.retweetsValues.length === 2) { console.log('both values are ready from sad listener: ', this.retweetsValues); - this.renderChart(this.retweetsValues[0], this.retweetsValues[1], 'Positive vs Negative Retweets', this.myChart_1); - this.retweetsValues = []; + this.renderChart(this.retweetsValues.happyRetweets, this.retweetsValues.sadRetweets, 'Positive vs Negative Retweets', this.myChart_1); + //this.retweetsValues = []; + } + if (this.favouritesValues.happyFavourites && this.favouritesValues.sadFavourites) { + console.log('both values are ready from happy listener: ', this.favouritesValues); + this.renderChart(this.favouritesValues.happyFavourites, this.favouritesValues.sadFavourites, 'Positive vs Negative Retweets', this.myChart_2); + //this.retweetsValues = []; } //this.renderChart(event.detail.favourites, event.detail.favourites, 'Positive vs Negative Likes', this.myChart_2); }) From 3d7b4ef82dbf37fec3da39cb511a7fe6f3907fa7 Mon Sep 17 00:00:00 2001 From: Raphael Ugha Date: Wed, 26 Sep 2018 16:27:46 +0100 Subject: [PATCH 03/15] hiiden made visible --- client/public/index.html | 2 +- client/src/views/totals_view.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/public/index.html b/client/public/index.html index 6456c5f..2744ffc 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -57,7 +57,7 @@

Ever wondered where all those tweets come from?

-
+ diff --git a/client/src/models/searches.js b/client/src/models/searches.js index b977b2e..1841660 100644 --- a/client/src/models/searches.js +++ b/client/src/models/searches.js @@ -13,6 +13,7 @@ Searches.prototype.bindEvents = function (sentimentQuery, primary) { // todo move the db stuff to another bit if (primary) { this.postSearch(event.detail); + this.renderLoadingSpinner(); } this.getSearchResults(event.detail.searchTerm, sentimentQuery); @@ -116,4 +117,12 @@ Searches.prototype.calculator = function (tweetData) { }) return totals; } + +Searches.prototype.renderLoadingSpinner = function() { + const loadingOverlay = document.querySelector('#loading-overlay'); + const loadingModal = document.querySelector('#loading-modal'); + loadingOverlay.classList.remove('hidden'); + loadingModal.classList.remove('hidden'); +}; + module.exports = Searches; diff --git a/client/src/views/map_view.js b/client/src/views/map_view.js index 7e0940f..5b25d86 100644 --- a/client/src/views/map_view.js +++ b/client/src/views/map_view.js @@ -9,8 +9,10 @@ const geoJsonTest = new GeoJsonTest(); MapView.prototype.bindEvents = function () { this.renderMap(); PubSub.subscribe('Searches:tweet-coordinates-loaded', (event) => { + // console.log('event', event); this.renderMap(event.detail); + this.removeLoadingSpinner(); }); }; @@ -167,4 +169,11 @@ const json = { } +MapView.prototype.removeLoadingSpinner = function(){ + const loadingOverlay = document.querySelector('#loading-overlay'); + const loadingModal = document.querySelector('#loading-modal'); + loadingOverlay.classList.add('hidden'); + loadingModal.classList.add('hidden'); +} + module.exports = MapView; From ec3bc8c12190d4130d182e91f5c4d2dfa74c9d10 Mon Sep 17 00:00:00 2001 From: Vicky Jackson Date: Wed, 26 Sep 2018 23:16:22 +0100 Subject: [PATCH 11/15] Fixed styling on loading spinner --- client/public/css/main.css | 18 ++++++++++++------ client/public/index.html | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/public/css/main.css b/client/public/css/main.css index cf7a8ae..66b7c5d 100644 --- a/client/public/css/main.css +++ b/client/public/css/main.css @@ -224,6 +224,14 @@ button#submit:hover{ opacity: 0.7; } +.modal-content { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; +} + #loading-modal{ background-color: white; position: absolute; @@ -231,16 +239,14 @@ button#submit:hover{ margin-left: 2rem; margin-bottom: 2rem; margin-right: 2rem; - top: 36%; - right: 16%; - height: 10rem; - width: 30%; + top: 39%; + right: 21%; + height: 6rem; + width: 20%; z-index: 999; justify-self: flex-end; opacity: 1; color: black; - text-align: center; - vertical-align: middle; } #result-container { diff --git a/client/public/index.html b/client/public/index.html index 280a593..67cb92f 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -44,12 +44,12 @@

CodeClan Analytica

Ever wondered where all those tweets come from?

-

When you enter a word or phrase above, we use it to gather all the tweets from the last 7 days that mention +

When you enter a word or phrase above, we use it to gather the last 3000 tweets in realtime that mention that word or phrase.

Since the tweets come from all over the world, we can anaylse their location data - and plot on the map exactly where they originated from

... for research.

+ and plot on the map exactly where they originated from.

... for research purposes.

- +
From 0d3d6186cd8e5e3e168903a14cc6002b749731a5 Mon Sep 17 00:00:00 2001 From: Vicky Jackson Date: Wed, 26 Sep 2018 23:19:45 +0100 Subject: [PATCH 12/15] Centered map properly --- client/src/views/map_view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/views/map_view.js b/client/src/views/map_view.js index 5b25d86..fdb7cd7 100644 --- a/client/src/views/map_view.js +++ b/client/src/views/map_view.js @@ -37,7 +37,7 @@ const json = { var map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/light-v9', - center: [-20, 20], + center: [0, 45], zoom: 0.65 }); From 3b591ff79c0c5cb11c06d643656b2e054d0d6621 Mon Sep 17 00:00:00 2001 From: Vicky Jackson Date: Wed, 26 Sep 2018 23:51:21 +0100 Subject: [PATCH 13/15] Fixed bug with coordinates only loading one set instead of 2 --- client/src/models/searches.js | 9 +++++---- client/src/views/map_view.js | 35 +++++++++++++++++++++++++++++++---- server/helpers/twitter.js | 1 + 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/client/src/models/searches.js b/client/src/models/searches.js index 1841660..999fbba 100644 --- a/client/src/models/searches.js +++ b/client/src/models/searches.js @@ -36,12 +36,14 @@ Searches.prototype.getSearchResults = function (searchTerm, sentimentQuery) { let query = null; let tweetChannel = null; let calculationChannel = null; + let coordinateChannel = null; // if there is no sentiment query // search without one and set the channel variable to be generic if (!sentimentQuery){ query = `?query=${searchTerm}`; tweetChannel = 'Searches:tweet-data-loaded'; calculationChannel = 'Searches:totals-calulated'; + coordinateChannel = 'Searches:tweet-coordinates-loaded'; // if there is a sentiment query // add the query to the search } else @@ -51,6 +53,7 @@ Searches.prototype.getSearchResults = function (searchTerm, sentimentQuery) { if (sentimentQuery === '%20%3A%29'){ tweetChannel = 'Searches:happy-tweet-data-loaded'; calculationChannel = 'Searches:happy-totals-calulated'; + coordinateChannel = 'Searches:happy-tweet-coordinates-loaded'; } // if the extra query is for sad sentiment @@ -58,6 +61,7 @@ Searches.prototype.getSearchResults = function (searchTerm, sentimentQuery) { else if (sentimentQuery === '%20%3A%28'){ tweetChannel = 'Searches:sad-tweet-data-loaded'; calculationChannel = 'Searches:sad-totals-calulated'; + coordinateChannel = 'Searches:sad-tweet-coordinates-loaded'; } console.log("searching for " + query); @@ -81,10 +85,7 @@ console.log("searching for " + query); } }) PubSub.publish(tweetChannel, tweets); - - const stringifiedCoordinates = JSON.stringify(tweetsCoordinates); - // console.log('stringifiedtweetscoordinates: ', stringifiedCoordinates); - PubSub.publish('Searches:tweet-coordinates-loaded', tweetsCoordinates); + PubSub.publish(coordinateChannel, tweetsCoordinates); }) .catch(console.error); }; diff --git a/client/src/views/map_view.js b/client/src/views/map_view.js index fdb7cd7..7d6959b 100644 --- a/client/src/views/map_view.js +++ b/client/src/views/map_view.js @@ -7,12 +7,39 @@ const MapView = function(){ const geoJsonTest = new GeoJsonTest(); MapView.prototype.bindEvents = function () { + let eventCounter = 0; + let allCoordinates = []; + + // load empty map on start this.renderMap(); - PubSub.subscribe('Searches:tweet-coordinates-loaded', (event) => { - // console.log('event', event); - this.renderMap(event.detail); - this.removeLoadingSpinner(); + PubSub.subscribe('FormView:search-term-submitted', (event) => { + eventCounter = 0; + allCoordinates = []; + }); + + PubSub.subscribe('Searches:happy-tweet-coordinates-loaded', (event) => { + eventCounter += 1; + allCoordinates = allCoordinates.concat(event.detail, allCoordinates); + if (eventCounter === 2){ + console.log('all coords happy', allCoordinates); + this.renderMap(allCoordinates); + this.removeLoadingSpinner(); + } else { + console.log('all coords sad was resolved first', allCoordinates); + } + }); + + PubSub.subscribe('Searches:sad-tweet-coordinates-loaded', (event) => { + eventCounter += 1; + allCoordinates = allCoordinates.concat(event.detail, allCoordinates); + if (eventCounter === 2){ + console.log('all coords sad', allCoordinates); + this.renderMap(allCoordinates); + this.removeLoadingSpinner(); + } else { + console.log('all coords happy was resolved first', allCoordinates); + } }); }; diff --git a/server/helpers/twitter.js b/server/helpers/twitter.js index 73e2316..95ce953 100644 --- a/server/helpers/twitter.js +++ b/server/helpers/twitter.js @@ -51,6 +51,7 @@ Twitter.prototype.getSinglePageOfResultsFromLast7Days = function (searchTerm, ne // set nextResults to the value from the metadata nextResultsQuery = data.search_metadata.next_results; let nextPageNumber = currentPageNumber + 1; + console.log('Fetched a page', currentPageNumber, searchTerm, nextResultsQuery); // call this method recursively with the new values from the first call this.getSinglePageOfResultsFromLast7Days(searchTerm, nextResultsQuery, nextPageNumber, maxPages, allResults, resolve, reject); // otherwise, exit now and resolve with the data From f08323da1f223bc063e35919691396ad5e03bb32 Mon Sep 17 00:00:00 2001 From: Vicky Jackson Date: Thu, 27 Sep 2018 00:43:56 +0100 Subject: [PATCH 14/15] Added top 5 tweets --- client/public/css/main.css | 18 ++++++--- client/public/index.html | 36 ++++++++++++++---- client/src/views/list_view.js | 71 +++++++++++++++++++++++++++-------- server/helpers/twitter.js | 2 +- 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/client/public/css/main.css b/client/public/css/main.css index 66b7c5d..24fe494 100644 --- a/client/public/css/main.css +++ b/client/public/css/main.css @@ -100,8 +100,7 @@ body { } .content-bottom { grid-area: content-top; - display: flex; - flex-direction: row; + margin-bottom: 2rem; } /* --------------------charts: */ .showFlex{ @@ -254,9 +253,9 @@ button#submit:hover{ margin-left: 2rem; } -h2 { +/* h2 { font-size: 18px; -} +} */ .h2 { font-size: 28px; @@ -281,10 +280,17 @@ ul#search-results-list { color: black; background-color: white; background-clip: content-box; - padding-left: 100px; - padding-right: 250px; + list-style: none; + margin: 0; + padding: 0; } +ul#search-results-list li { + margin-bottom: 1rem; +} + + + .hidden { display: none; diff --git a/client/public/index.html b/client/public/index.html index 67cb92f..0f4178b 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -5,6 +5,22 @@ + @@ -44,12 +60,14 @@

CodeClan Analytica

Ever wondered where all those tweets come from?

-

When you enter a word or phrase above, we use it to gather the last 3000 tweets in realtime that mention - that word or phrase.

Since the tweets come from all over the world, we can anaylse their location data - and plot on the map exactly where they originated from.

... for research purposes.

+

When you enter a word or phrase above, we use it to gather the last 3000 tweets in realtime that mention that + word or phrase.

Since the tweets come from all over the world, we can anaylse their location data and + plot on the map exactly where they originated from.

... for research purposes.

- +
@@ -79,10 +97,12 @@

Ever wondered where all those tweets come from?

-
- +
diff --git a/client/src/views/list_view.js b/client/src/views/list_view.js index 14920b6..78bedc4 100644 --- a/client/src/views/list_view.js +++ b/client/src/views/list_view.js @@ -8,6 +8,14 @@ const ListView = function (listElement, searchResultsListElement) { } ListView.prototype.bindEvents = function () { + let allTweets = []; + let eventCounter = 0; + + PubSub.subscribe('FormView:search-term-submitted', (event) => { + eventCounter = 0; + allTweets = []; + }); + PubSub.subscribe('Searches:searches-data-loaded', (event) => { this.render(event.detail); }) @@ -15,14 +23,24 @@ ListView.prototype.bindEvents = function () { // console.log('got all tweets') // this.renderSearchResultsList(event.detail); // }); - // PubSub.subscribe('Searches:happy-tweet-data-loaded', (event) => { - // console.log('got happy tweets') - // this.renderSearchResultsList(event.detail); - // }); - // PubSub.subscribe('Searches:sad-tweet-data-loaded', (event) => { - // console.log('got sad tweets') - // this.renderSearchResultsList(event.detail); - // }); + PubSub.subscribe('Searches:happy-tweet-data-loaded', (event) => { + eventCounter += 1; + allTweets = allTweets.concat(event.detail, allTweets); + if (eventCounter === 2) { + this.renderTop5Tweets(allTweets); + } + console.log('got happy tweets') + //this.renderSearchResultsList(event.detail); + }); + PubSub.subscribe('Searches:sad-tweet-data-loaded', (event) => { + eventCounter += 1; + allTweets = allTweets.concat(event.detail, allTweets); + if (eventCounter === 2) { + this.renderTop5Tweets(allTweets); + } + console.log('got sad tweets') + //this.renderSearchResultsList(event.detail); + }); }; ListView.prototype.renderSearchResultsList = function (searchResults) { @@ -35,7 +53,17 @@ ListView.prototype.renderSearchResultsList = function (searchResults) { ListView.prototype.renderOneSearchResult = function (searchResult) { const searchResultItem = document.createElement('li'); searchResultItem.textContent = searchResult.text; + searchResultItem.id = 'tweet' + searchResult.id; + //console.log(searchResult.retweets); this.searchResultsListElement.appendChild(searchResultItem); + twttr.widgets.createTweet( + ' ' + searchResult.id, + document.getElementById('tweet' + searchResult.id), + console.log(searchResult.id), + { + theme: 'light' + } + ); } ListView.prototype.render = function (searches) { @@ -61,14 +89,27 @@ ListView.prototype.createDeleteButton = function (listItemId) { PubSub.publish('ListView:delete-clicked', listItemId); }) - const historyButtons = document.querySelectorAll('#list button'); - const list = document.querySelector('#list'); - const buttonCount = historyButtons.length; - if (buttonCount >= 4) { - list.lastChild.remove(); - }; + // const historyButtons = document.querySelectorAll('#list button'); + // const list = document.querySelector('#list'); + // const buttonCount = historyButtons.length; + // if (buttonCount >= 6) { + // list.lastChild.remove(); + // }; return deleteButton } +ListView.prototype.renderTop5Tweets = function (tweets) { + tweets.sort((a, b) => { + return b.retweets - a.retweets; + }); + const top5Tweets = tweets.slice(0, 5); + const container = document.querySelector('#result-container'); + container.classList.remove('hidden'); + this.searchResultsListElement.innerHTML = ""; + top5Tweets.forEach((tweet) => { + this.renderOneSearchResult(tweet); + }); +}; + -module.exports = ListView; \ No newline at end of file +module.exports = ListView; diff --git a/server/helpers/twitter.js b/server/helpers/twitter.js index 95ce953..7906ea3 100644 --- a/server/helpers/twitter.js +++ b/server/helpers/twitter.js @@ -39,7 +39,7 @@ Twitter.prototype.getSinglePageOfResultsFromLast7Days = function (searchTerm, ne // and the we're definately not on the last page // add the data so far to allResults const tweets = data.statuses.map(tweet => { - return { text: tweet.full_text, location: tweet.user.location, retweets: tweet.retweet_count, favourites: tweet.favorite_count } + return { text: tweet.full_text, location: tweet.user.location, retweets: tweet.retweet_count, favourites: tweet.favorite_count, id: tweet.id } }); tweets.forEach((tweet) => { From 9e0a5a670149074599aef5c558c7be199e6bb185 Mon Sep 17 00:00:00 2001 From: Emil Vaklinov Date: Mon, 1 Oct 2018 17:50:21 +0100 Subject: [PATCH 15/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1409504..df25169 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CodeClan Collaborative Projekt - Tweet analysis app +# CodeClan Collaborative Project - Tweet analysis app We’ve been approached by an organisation that would like the ability to find out tweet frequency or sentiment by location. We will build a Minimum Viable Product that will retrieve data from Twitter and display it to the user, then explore ways to analyze and display meaningful data in an interesting way.