Pointing on the map the collected tweets and specifying its sentiment using IBM Watson.
-
-
Save imv7/458020e67d8d4cd8bf1f7882eda2bd4d to your computer and use it in GitHub Desktop.
Pointing on the map the collected tweets and specifying its sentiment using IBM Watson.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"c6c00eab.0e129","type":"websocket out","z":"ccc0d28.d6bdb3","name":"REST","server":"f97b2f53.bbc41","client":"","x":770,"y":380,"wires":[]},{"id":"ab8fff60.34a06","type":"websocket in","z":"ccc0d28.d6bdb3","name":"REST","server":"f97b2f53.bbc41","client":"","x":341,"y":377.9999694824219,"wires":[["d77ae9ab.53a3e8"]]},{"id":"d77ae9ab.53a3e8","type":"function","z":"ccc0d28.d6bdb3","name":"Get Global context","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\n\nmsg.payload = context.global.location;\nreturn msg;","outputs":"1","noerr":0,"x":575,"y":379.0000305175781,"wires":[["c6c00eab.0e129"]]},{"id":"c093b6d9.b755c","type":"template","z":"ccc0d28.d6bdb3","name":"HTML output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n\n<head>\n <title>Sentiment Twitter Map</title>\n <script src=\"http://use.edgefonts.net/antic-didone:n4:all.js\"></script>\n <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js\"></script>\n <script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=true\"></script>\n <script type=\"text/javascript\" src=\"http://yourjavascript.com/4594301102/gmaps.js\"></script>\n <script type=\"text/javascript\" src=\"http://yourjavascript.com/190225905/autolinker-min.js\"></script>\n <style type=\"text/css\" media=\"screen\">\n #map {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n }\n \n #content {\n font-size: 10px;\n }\n \n p {\n font-family: verdana;\n text-align: center\n }\n \n .maptitle {\n position: absolute;\n border-radius: 10px;\n top: .3em;\n right: .3em;\n color: white;\n background: black;\n opacity: 0.7;\n padding: 0 10px;\n }\n \n .titletext {\n font-family: antic-didone;\n font-size: 3em;\n font-weight: 100;\n margin-top: 0;\n margin-bottom: 0;\n line-height: 1em;\n }\n \n .subtitle {\n color: darkolivegreen;\n font-size: .8em;\n line-height: .3em;\n vertical-align: middle;\n }\n \n .credit {\n position: absolute;\n bottom: 0;\n left: 10em;\n font-size: .6em;\n color: #222;\n }\n \n .legend {\n font-size: .6em;\n color: #000;\n }\n </style>\n</head>\n\n<body>\n\n <div id=\"map\"></div>\n <div class=maptitle>\n <p class=titletext> Legend</p>\n <div class=subtitle>\n <p>Sentiment (negative to positive)</p>\n </div>\n <div class=legend>\n <p>Sentiment:\n <br>\n <img src=\"http://demo-nodered-sam.mybluemix.net/images/tweet-r2.png\">\n <img src=\"http://demo-nodered-sam.mybluemix.net/images/tweet-r1.png\">\n <img src=\"http://demo-nodered-sam.mybluemix.net/images/tweet-w.png\">\n <img src=\"http://demo-nodered-sam.mybluemix.net/images/tweet-g1.png\">\n <img src=\"http://demo-nodered-sam.mybluemix.net/images/tweet-g2.png\">\n </p>\n </div>\n </div>\n <div class=credit>\n \n </div>\n <script type=\"text/javascript\">\n var geocoder = new google.maps.Geocoder();\n var autolinker = new Autolinker( {\n newWindow : true,\n truncate : 30\n } );\n \n var socketaddy = \"ws://{{req.headers.host}}/ws/location\";\n var map;\n var sock;\n $(document).ready(function()\n {\n // Houston Lat Long in Degrees\n // Latitude: 29.7632836\n // Longitude: -95.3632715 \n map = new GMaps({\n div: '#map',\n //lat: -12.043333,\n //lng: -77.028333,\n lat: 29.7632836,\n lng: -95.3632715,\n minZoom: 3\n });\n \n // Use HTML5 geolocation if user allows it.\n if (navigator.geolocation)\n {\n navigator.geolocation.getCurrentPosition(function(position) {\n var pos = {\n lat: position.coords.latitude,\n lng: position.coords.longitude\n };\n\n map.setCenter(pos);\n });\n }\n\n \n map.setZoom (3);\n \n sock = new WebSocket(socketaddy);\n sock.onopen = function()\n {\n console.log(\"WebSocket - Connected\");\n console.log(\"WebSocket - Sending ping\");\n sock.send(\"Ping.\");\n console.log(\"WebSocket - Ping sent\");\n };\n sock.onerror = function()\n {\n console.log(\"WebSocket - Error\");\n };\n sock.onmessage = function(evt)\n {\n var msgparse = JSON.parse(evt.data);\n console.log (\"User: @\" + msgparse.user);\n console.log (msgparse.location );\n \n GMaps.geocode({\n address: msgparse.location,\n callback: function(results, status)\n {\n if (status == 'OK')\n {\n var latlng = results[0].geometry.location;\n // map.removeMarkers();\n \t// map.setCenter(latlng[0].lat, latlng[0].lng);\n // Create marker\n var infoWindow = new google.maps.InfoWindow({ \n content: '<b>heading</b><br>more text'\n });\n \n var infoText = '<b>@' + msgparse.user + ':</b> ' + \n '<div id=content>' + msgparse.tweet + '</div>'\n var html = autolinker.link( infoText );\n \n // Sets the Default Tweet Icon\n var iconfile = 'http://demo-nodered-sam.mybluemix.net/images/tweet';\n var sentimentScore = msgparse.sentiment.score == \"\" ? 0 : parseFloat (msgparse.sentiment.score);\n \n // User NodeRed Sentiment\n if (sentimentScore < -6.0) \n iconfile += '-r2'\n else if (sentimentScore < -2.0)\n iconfile += '-r1'\n else if (sentimentScore >= -2.0 && sentimentScore < 2.0)\n iconfile += '-w'\n else if (sentimentScore >= 2.0 && sentimentScore < 6.0)\n iconfile += '-g1'\n else if (sentimentScore >= 6.0)\n iconfile += '-g2';\n \n iconfile += '.png';\n console.log ('sentiment ' + JSON.stringify(msgparse.sentiment) + ' score: ' + sentimentScore);\n console.log ('--> icon=' + iconfile);\n var marker = map.addMarker({\n lat: latlng.lat(),\n lng: latlng.lng(),\n title: msgparse.user,\n infoWindow: {\n content: html,\n maxWidth: 300\n },\n icon: iconfile\n });\n console.log (\"added marker: \" + marker.title);\n // map.setCenter(latlng.lat(), latlng.lng());\n }\n else\n {\n console.log (\"GMaps.geocode unsuccessful\");\n }\n }\n });\n console.log (msgparse.tweet);\n }\n });\n </script>\n</body>\n\n</html>","output":"str","x":579.272705078125,"y":455.2727355957031,"wires":[["aa341cf3.c02478"]]},{"id":"aa341cf3.c02478","type":"http response","z":"ccc0d28.d6bdb3","name":"","statusCode":"","headers":{},"x":764.9999732971191,"y":454.9999713897705,"wires":[]},{"id":"5d93b9fc.acf838","type":"http in","z":"ccc0d28.d6bdb3","name":"","url":"/map","method":"get","upload":false,"swaggerDoc":"","x":359.00000381469726,"y":454.9999713897705,"wires":[["c093b6d9.b755c"]]},{"id":"2bb90b41.2558c4","type":"function","z":"ccc0d28.d6bdb3","name":"Load map json","func":"// Alchemy Method\n//var sentiment;\n//if (msg.features === undefined) \n// sentiment = \"\"\n//else\n// sentiment = msg.features[\"doc-sentiment\"];\n\n// NodeRed Sentiment Method\nvar sentiment = msg.sentiment; //.score\n\nvar msg2 = { payload : {\n\t\tuser: msg.tweet.user.screen_name,\n\t\tlocation: msg.location === undefined ? \"\" : msg.location.place,\n\t\tlang : msg.lang,\n\t\tsentiment: sentiment,\n\t\ttweet: msg.tweet.text}\n\t};\n\n// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\ncontext.global.location = msg2.payload;\nreturn msg2;\n","outputs":1,"noerr":0,"x":565.0000152587891,"y":306.19993591308593,"wires":[["c6c00eab.0e129","e63633ca.751c3"]]},{"id":"cd2be9bb.6695d","type":"function","z":"ccc0d28.d6bdb3","name":"Set Payload=Tweet","func":"msg.payload = msg.tweet.text;\nreturn msg;","outputs":1,"noerr":0,"x":370.20001220703125,"y":257.3999328613281,"wires":[["193f5152.104ac7"]]},{"id":"42569415.304dec","type":"function","z":"ccc0d28.d6bdb3","name":"set _id","func":"msg._id = msg.tweet.id_str;\nreturn msg;","outputs":1,"noerr":0,"x":747,"y":218.19992065429687,"wires":[["5dbbf4b8.2611dc"]]},{"id":"193f5152.104ac7","type":"sentiment","z":"ccc0d28.d6bdb3","name":"sentiment","x":570.5,"y":217.19992065429687,"wires":[["2bb90b41.2558c4","42569415.304dec"]]},{"id":"a13c1beb.2658d","type":"comment","z":"ccc0d28.d6bdb3","name":"ReadMe","info":"Change Get Tweets to all for a lot of data\n\nSample string: DELOS,WELLCertified,WELLBuilding","x":192.19000244140625,"y":160.659912109375,"wires":[]},{"id":"8e650350.632cf8","type":"twitter in","z":"ccc0d28.d6bdb3","twitter":"","tags":"#help","user":"false","name":"Get Tweets","topic":"tweets","x":128.49998474121094,"y":273.1999053955078,"wires":[["cd2be9bb.6695d","e63633ca.751c3"]]},{"id":"5dbbf4b8.2611dc","type":"cloudant out","z":"ccc0d28.d6bdb3","name":"","cloudant":"","database":"tweet_map","service":"hackig-cloudantNoSQLDB","payonly":false,"operation":"insert","x":954.5,"y":160,"wires":[]},{"id":"e63633ca.751c3","type":"debug","z":"ccc0d28.d6bdb3","name":"","active":true,"console":"false","complete":"false","x":450,"y":120,"wires":[]},{"id":"f97b2f53.bbc41","type":"websocket-listener","z":"","path":"/ws/location","wholemsg":"false"}] |
Author
imv7
commented
Oct 31, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment