Hackaton

Hackaton

[{"id":"e62cd3e4.54585","type":"function","z":"45821715.765ae","name":"Find Top Tone Score","func":"if(msg.response.document_tone) {\n    \n    // Get the Social Summary tones.\n    var tones = msg.response.document_tone.tone_categories[0].tones;\n    var score = 0;\n    \n    // Find the highest tone.\n    for(var i in tones) {\n        if(tones[i].score > score) {\n            msg.toptone = tones[i].tone_id;   \n            score = tones[i].score;\n        }\n    }\n    \n    // Update the scoreboard, adding one to the category with the highest tone.\n    context.global.scores[msg.toptone]++;\n    \n    return msg;\n}","outputs":1,"noerr":0,"x":472,"y":296.5,"wires":[["7daf6a48.9d3efc","6df7454e.5f8b64"]]},{"id":"6a7056fe.c09d6","type":"inject","z":"45821715.765ae","name":"Trigger Each Minute","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":125.5,"y":475,"wires":[["d6d9b36.b0cfed"]]},{"id":"b7299a15.47fec","type":"function","z":"45821715.765ae","name":"Update State in DB","func":"msg.payload.lastMinute = {\n    openness_big5: 0,\n    conscientiousness_big5: 0,\n    extraversion_big5: 0,\n    agreeableness_big5: 0,\n    neuroticism_big5: 0\n};\n\n// Add to all time stats\nfor(var i in context.global.scores) {\n    context.global.allTime[i] += context.global.scores[i];\n    msg.payload.lastMinute[i] = context.global.scores[i];\n}\n\n// Add to hourly stats\ncontext.global.history.push(context.global.scores);\n\nif(context.global.history.length > 60) {\n    context.global.history.shift();\n}\n\nmsg.payload.lastHour = {\n    openness_big5: 0,\n    conscientiousness_big5: 0,\n    extraversion_big5: 0,\n    agreeableness_big5: 0,\n    neuroticism_big5: 0\n};\n\n// Condense last hour's stats\nfor(var r in context.global.history) {\n    for(var i in context.global.history[r]) {\n        msg.payload.lastHour[i] += context.global.history[r][i];\n    }\n}\n\nmsg.payload.allTime = context.global.allTime;\nmsg.payload.history = context.global.history;\n\ncontext.global.scores = {\n    openness_big5: 0,\n    conscientiousness_big5: 0,\n    extraversion_big5: 0,\n    agreeableness_big5: 0,\n    neuroticism_big5: 0\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":710.5,"y":475,"wires":[["6c26cf47.23cdd8"]]},{"id":"6c26cf47.23cdd8","type":"cloudant out","z":"45821715.765ae","name":"Save Updated State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","payonly":true,"operation":"insert","x":943,"y":475.5,"wires":[]},{"id":"2ea2c614.094302","type":"cloudant in","z":"45821715.765ae","name":"Get State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":518.5,"y":475,"wires":[["b7299a15.47fec"]]},{"id":"d6d9b36.b0cfed","type":"function","z":"45821715.765ae","name":"Set Doc ID = state","func":"msg.payload = 'state';\nreturn msg;","outputs":1,"noerr":0,"x":325.5,"y":475,"wires":[["2ea2c614.094302","e438088e.0e018"]]},{"id":"e438088e.0e018","type":"function","z":"45821715.765ae","name":"Log Last Minute Scores","func":"msg.payload = context.global.scores;\nmsg.payload.time = new Date();\nreturn msg;","outputs":1,"noerr":0,"x":545.5,"y":522,"wires":[["32564758.0d2de","f681e93c.3f1c58"]]},{"id":"7daf6a48.9d3efc","type":"switch","z":"45821715.765ae","name":"If Save Tweets On","property":"settings.saveTweets","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","outputs":1,"x":681.5,"y":297.5,"wires":[["f89b2135.ce5998"]]},{"id":"f51302bf.51d8a8","type":"cloudant out","z":"45821715.765ae","name":"Store Tweet in DB","cloudant":"","database":"tweets","service":"tonepin-cloudantNoSQLDB","payonly":true,"operation":"insert","x":1104.5,"y":297.5,"wires":[]},{"id":"ecded5c3.e75d2","type":"comment","z":"45821715.765ae","name":"Fetch Tweets","info":"","x":77,"y":259,"wires":[]},{"id":"462c299f.c4711","type":"comment","z":"45821715.765ae","name":"Tone Analyze Tweets","info":"","x":255,"y":259,"wires":[]},{"id":"e8c30f4b.8b0288","type":"comment","z":"45821715.765ae","name":"Find prevalent tone, count tweet","info":"","x":499,"y":259,"wires":[]},{"id":"df1fc6f7.a29be8","type":"comment","z":"45821715.765ae","name":"Update All Time and Last Minute Stats","info":"","x":160,"y":435,"wires":[]},{"id":"93d6fe8a.fcfb88","type":"comment","z":"45821715.765ae","name":"Update State","info":"","x":690,"y":434,"wires":[]},{"id":"32564758.0d2de","type":"cloudant out","z":"45821715.765ae","name":"Save Last Minute Score In DB","cloudant":"","database":"historical","service":"tonepin-cloudantNoSQLDB","payonly":true,"operation":"insert","x":821,"y":522.5,"wires":[]},{"id":"2c6c60de.9b24d8","type":"http response","z":"45821715.765ae","name":"","x":771,"y":701,"wires":[]},{"id":"711d8e0a.f66158","type":"cloudant in","z":"45821715.765ae","name":"Get State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":422,"y":701,"wires":[["89133899.616fd8"]]},{"id":"1bc9bb11.ad9fbd","type":"function","z":"45821715.765ae","name":"Set Doc ID = state","func":"msg.payload._id = 'state';\nmsg.settings = context.global.settings;\nreturn msg;","outputs":1,"noerr":0,"x":227.5,"y":700.5,"wires":[["711d8e0a.f66158"]]},{"id":"69f83ec5.8c748","type":"http in","z":"45821715.765ae","name":"","url":"/","method":"get","swaggerDoc":"","x":67,"y":700,"wires":[["1bc9bb11.ad9fbd"]]},{"id":"89133899.616fd8","type":"template","z":"45821715.765ae","name":"Report HTML","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n  <head>\n      <title> Watson Tone Analyzer : #{{settings.hashTag}} </title>\n      <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\n      <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js\"> </script>\n      <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\" integrity=\"sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==\" crossorigin=\"anonymous\"></script>\n      <script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>\n      <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\" type=\"text/css\">\n      <link href=\"css/styles.css\" rel=\"stylesheet\">\n      <script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>\n      <script type=\"text/javascript\">\n      google.charts.load('current', {'packages':['corechart']});\n      google.charts.setOnLoadCallback(drawChart);\n      function drawChart() {\n\n        var allTimeData = google.visualization.arrayToDataTable([\n          ['Tone', '# Tweets'],\n          ['Openness',     {{payload.allTime.openness_big5}}],\n          ['Conscientiousness',     {{payload.allTime.conscientiousness_big5}}],\n          ['Extraversion',     {{payload.allTime.extraversion_big5}}],\n          ['Agreeableness',     {{payload.allTime.agreeableness_big5}}],\n          ['Emotional Range',     {{payload.allTime.neuroticism_big5}}],\n        ]);\n\n        var allTimeChart = new google.visualization.PieChart(document.getElementById('alltimechart'));\n\n        allTimeChart.draw(allTimeData, {\n          title: 'All Time (# of Tweets)',\n          colors: [\n              '{{settings.chartColors.openness_big5}}', \n              '{{settings.chartColors.conscientiousness_big5}}',\n              '{{settings.chartColors.extraversion_big5}}',\n              '{{settings.chartColors.agreeableness_big5}}',\n              '{{settings.chartColors.neuroticism_big5}}'\n          ],\n          pieSliceTextStyle: {color: 'darkgrey'},\n          legend: {position: 'none'},\n          chartArea: {left: 10, top: 30, width: 250, height: 250}\n        });\n        \n        var lastMinuteData = google.visualization.arrayToDataTable([\n          ['Tone', '# Tweets'],\n          ['Openness',     {{payload.lastMinute.openness_big5}}],\n          ['Conscientiousness',     {{payload.lastMinute.conscientiousness_big5}}],\n          ['Extraversion',     {{payload.lastMinute.extraversion_big5}}],\n          ['Agreeableness',     {{payload.lastMinute.agreeableness_big5}}],\n          ['Emotional Range',     {{payload.lastMinute.neuroticism_big5}}],\n        ]);\n\n        var lastMinuteChart = new google.visualization.PieChart(document.getElementById('lastminutechart'));\n\n        lastMinuteChart.draw(lastMinuteData, {\n          title: 'Last Minute (# of Tweets)',\n          colors: [\n              '{{settings.chartColors.openness_big5}}', \n              '{{settings.chartColors.conscientiousness_big5}}',\n              '{{settings.chartColors.extraversion_big5}}',\n              '{{settings.chartColors.agreeableness_big5}}',\n              '{{settings.chartColors.neuroticism_big5}}'\n          ],\n          pieSliceTextStyle: {color: 'darkgrey'},\n          legend: {position: 'none'},\n          chartArea: {left: 10, top: 30, width: 250, height: 250}\n        });        \n      }\n    </script>\n  </head>\n\n  <body style=\"background-color: 233949\">\n    <div class=\"container\">\n      <div id=\"heading\"  class=\"jumbotron\" style=\"background-color: #233949; margin-top: 15px\">\n        <table style=\"width: 100%;\">\n          <tr>\n            <td>\n              <h3 style=\"color: #FFF\"> Watson Tone Analyzer : #{{settings.hashTag}} </h3>\n              <h4 style=\"color: #41D6C3;\"> A cognitive computing experiment to analyze an audience's collective tone of voice </h4>\n            </td>\n          </tr>\n        </table>\n        </div>\n\n      <!-- Table for intro. -->\n      <div id=\"intro\">\n        <h4> What is it? </h4>\n        <div class=\"panel panel-default\">\n        <div class=\"panel-body row\">\n          <div class=\"col-sm-4 text-justify\">\n            <p>In this fun cognitive computing experiment, Watson is analyzing the tone of voice of your collective tweets. </p>\n            <a href=\"https://twitter.com/intent/tweet?text={{settings.hashTag}}\" class=\"btn btn-danger\" role=\"button\" target=\"_blank\">#{{settings.hashTag}} 'n' see pin change color!</a>\n            <br><br>\n            <p> The pin was designed by artist <a href=\"https://twitter.com/zengirl2\">Leslie Birch</a> and IBM Bluemix Technical Evangelist <a href=\"https://twitter.com/dothewww\">JeanCarl Bisson</a>.</p>\n            <p>IBM Watson Tone Analyzer helps us analyze email messages, presentations, tweets, and other communications before sending them out. It examines how others might perceive our tone in written messages and helps us understand the potential impact of our words. To try out the Tone Analyzer yourself and to view other Cognitive Computing services, click <a href=\"https://bit.ly/WatsonServices\">here</a>. </p>\n          </div>\n          <div class=\"col-sm-4\">\n            <div id=\"alltimechart\" style=\"width: 300px; height: 300px;\"></div>\n          </div>\n          <div class=\"col-sm-4\">\n            <div id=\"lastminutechart\" style=\"width: 300px; height: 300px;\"></div>\n          </div>\n        </div>\n      </div>\n    </div>\n\n      <div id=\"shield\">\n          <h4> Wearable </h4>\n          <div class=\"panel panel-default\">\n            <div class=\"panel-body row\">\n              <div class=\"col-sm-4 text-justify\">\n                <p> An Arduino compatible microcontroller with WiFi capability and a RGB LED shield display the aggregated statistics. The NeoPixel ring is connected to Watson IoT Platform, receiving updated stats each minute. The 24 LEDs, illuminated with a tiny Lithium Polymer battery mounted on the back, change colors to represent the tone of the tweets. </p>\n              </div>\n              <div class=\"col-sm-8\">\n                <img style=\"width:100%\" class=\"img-responsive\" src=\"/images/pin.png\" alt=\"Cloudant logo\"/>\n              </div>\n            </div>\n          </div>\n      </div>\n\n      <div id=\"working\">\n        <h4>How does it work?</h4>\n        <div class=\"panel panel-default\">\n        <div class=\"panel-body text-justify\">\n          <div class=\"tab-pane fade active in\" id=\"workinginfo\">\n            <p> The IBM Watson Tone Analyzer Service uses linguistic analysis to detect three types of tones from written text: Emotions, Social Tendencies, and Writing Style. In this demo, we use identified social tones that infer the personality of the individual reflected in tweets around a search query. </p>\n\n            <p>\n            Tone Analyzer currently infers five different social tones: Openness, Conscientiousness, Extraversion, Agreeableness, and Emotional Range (alternatively Neuroticism). These five social tones are adopted from the Big-five personality model.\n\n              <ul>\n                <li>Agreeableness is a person's tendency to be compassionate and cooperative toward others.</li>\n                <li>Conscientiousness is a person's tendency to act in an organized or thoughtful way.</li>\n                <li>Extraversion is a person's tendency to seek stimulation in the company of others.</li>\n                <li>Emotional Range, also referred to as Neuroticism or Natural Reactions, is the extent to which a person's emotions are sensitive to the individual's environment.</li>\n                <li>Openness, or Open to Experience, is the extent to which a person is open to experiencing a variety of activities.</li>\n              </ul>\n\n            </p>\n            <p>\n            Each tweet is analyzed individually and categorized with the tone that ranks highest. The tweet is then aggregated together with others that share the same tone. </p>\n          </div>\n        </div>\n      </div>\n      </div>\n\n\n      <div id=\"nodered\">\n        <h4>Node-RED</h4>\n        <div class=\"panel panel-default\">\n          <div class=\"panel-body row\">\n            <div class=\"col-sm-4 text-justify\">\n              <p>Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click. Using IBM Watson's Tone Analyzer, tweets are processed for prominent tone and aggregated every minute.</p>\n            </div>\n            <div class=\"col-sm-8\">\n              <img style=\"width:100%\" class=\"img-responsive\" src=\"/images/nodered.png\" alt=\"Cloudant logo\"/>\n            </div>\n          </div>\n        </div>\n      </div>\n    </div>\n  </body>\n</html>\n","x":619,"y":701,"wires":[["2c6c60de.9b24d8"]]},{"id":"da433286.93eb78","type":"comment","z":"45821715.765ae","name":"Website Endpoint","info":"These endpoints are exposed to provide data about tweets over specified time periods.","x":95,"y":659,"wires":[]},{"id":"d03bc4ad.417538","type":"comment","z":"45821715.765ae","name":"Get Stats from DB","info":"These endpoints are exposed to provide data about tweets over specified time periods.","x":383,"y":661,"wires":[]},{"id":"91a08c89.3e20b8","type":"comment","z":"45821715.765ae","name":"Build Webpage with Stats","info":"These endpoints are exposed to provide data about tweets over specified time periods.","x":600,"y":660,"wires":[]},{"id":"733cf623.fec618","type":"twitter in","z":"45821715.765ae","twitter":"","tags":"ibm","user":"false","name":"","topic":"tweets","x":57,"y":297,"wires":[["28a9a041.dfa4c8","3ff037dd.09fdd8"]]},{"id":"f89b2135.ce5998","type":"function","z":"45821715.765ae","name":"Combine tweet/tone","func":"msg.payload = {\n    tweet: msg.tweet, \n    tone: msg.response\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":893.5,"y":297.5,"wires":[["f51302bf.51d8a8"]]},{"id":"28a9a041.dfa4c8","type":"debug","z":"45821715.765ae","name":"Toggle to show tweets","active":false,"console":"false","complete":"tweet.text","x":227.5,"y":341,"wires":[]},{"id":"a7981d36.e37608","type":"function","z":"45821715.765ae","name":"Initialize DB","func":"context.global.scores = context.global.allTime = context.global.lastHour = context.global.lastMinute = {\n             openness_big5: 0,\n    conscientiousness_big5: 0,\n         extraversion_big5: 0,\n        agreeableness_big5: 0,\n          neuroticism_big5: 0\n};\n\ncontext.global.history = [];\n\n// Create a document with these settings\nmsg.payload = {};\nmsg.payload['_id'] = 'state';\nmsg.payload.allTime = context.global.allTime;\nmsg.payload.lastHour = context.global.lastHour;\nmsg.payload.lastMinute = context.global.lastMinute;\nmsg.payload.history = context.global.history;\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":246,"y":114,"wires":[["75f8594f.8c76f8"]]},{"id":"75f8594f.8c76f8","type":"cloudant out","z":"45821715.765ae","name":"Save State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","payonly":true,"operation":"insert","x":460.5,"y":114,"wires":[]},{"id":"2b1ea424.34ee84","type":"inject","z":"45821715.765ae","name":"Setup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":82,"y":114,"wires":[["a7981d36.e37608"]]},{"id":"37b921a9.19ea2e","type":"comment","z":"45821715.765ae","name":"First Time Setup: Adds a blank state object to DB","info":"","x":185,"y":76,"wires":[]},{"id":"606d43a3.f0ec54","type":"inject","z":"45821715.765ae","name":"On Startup ","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":94,"y":204,"wires":[["5f364dba.d2ddb4"]]},{"id":"8c9942f9.a0c03","type":"cloudant in","z":"45821715.765ae","name":"Get State from DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":465,"y":204,"wires":[["a91437d1.a4138"]]},{"id":"5f364dba.d2ddb4","type":"function","z":"45821715.765ae","name":"Customize Settings","func":"// Settings used throughout application.\ncontext.global.settings = {\n    // Hashtag for the webpage\n    hashTag: 'IBM',\n    \n    // Colors to display in the webpage pie charts\n    chartColors: {\n                 'openness_big5': 'lightpink', \n        'conscientiousness_big5': 'lightgreen',\n             'extraversion_big5': 'LightCoral', \n            'agreeableness_big5': 'LightYellow',\n              'neuroticism_big5': 'lightblue'          \n    },\n    \n    // Colors to display on pin\n    pinColors: {\n                 'openness_big5': 'p', \n        'conscientiousness_big5': 'g',\n             'extraversion_big5': 'r', \n            'agreeableness_big5': 'y',\n              'neuroticism_big5': 'b'            \n    },\n    \n    // Save tweets along with tone analyzer results?\n    saveTweets: false,\n    \n    // Number of LED lights\n    numberOfLEDLights: 24\n};\n\ncontext.global.normalize = function(scores) {\n    var total = 0;\n    for(var i in scores) {\n        if(Number.isInteger(scores[i])) {\n            total += scores[i];\n        }\n    }    \n    \n    var normalized = {};\n    \n    for(var j in scores) {\n        if(Number.isInteger(scores[j])) {\n            normalized[j] = total == 0 ? 0 : Math.floor((scores[j]/total)*100);\n        }\n    }\n    \n    return normalized;\n}\n\nmsg.payload = 'state';\nreturn msg;","outputs":1,"noerr":0,"x":264,"y":204,"wires":[["8c9942f9.a0c03"]]},{"id":"a91437d1.a4138","type":"function","z":"45821715.765ae","name":"Load Previous State","func":"context.global.scores = {\n             openness_big5: 0,\n    conscientiousness_big5: 0,\n         extraversion_big5: 0,\n        agreeableness_big5: 0,\n          neuroticism_big5: 0\n};\n\ncontext.global.history = msg.payload.history;\ncontext.global.allTime = msg.payload.allTime;\ncontext.global.lastMinute = msg.payload.lastMinute;\ncontext.global.lastHour = msg.payload.lastHour;","outputs":1,"noerr":0,"x":674.5,"y":203.5,"wires":[[]]},{"id":"55cf5056.25eab","type":"comment","z":"45821715.765ae","name":"Load System State","info":"","x":97,"y":168.5,"wires":[]},{"id":"f681e93c.3f1c58","type":"function","z":"45821715.765ae","name":"Send Stats to Pin","func":"var lastMinuteNormalized = context.global.normalize(context.global.scores);\n\nmsg.payload = '';\n\nfor(var i in context.global.settings.pinColors) {\n    for(var c=0; c<Math.round(context.global.settings.numberOfLEDLights*lastMinuteNormalized[i]/100); c++) \n        msg.payload += context.global.settings.pinColors[i];\n}\n\nif(msg.payload.length < context.global.settings.numberOfLEDLights) {\n    for(var c=msg.payload.length; c<context.global.settings.numberOfLEDLights; c++) \n        msg.payload += msg.payload.slice(-1);\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":779,"y":561.7667236328125,"wires":[["a5e5f702.cd09d8"]]},{"id":"43250a87.ff2974","type":"switch","z":"45821715.765ae","name":"If Connected","property":"payload.Action","propertyType":"msg","rules":[{"t":"eq","v":"Connect","vt":"str"}],"checkall":"true","outputs":1,"x":300.5333251953125,"y":563.2000427246094,"wires":[["d4da66c5.e6c9b8"]]},{"id":"d4da66c5.e6c9b8","type":"delay","z":"45821715.765ae","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":478.5333251953125,"y":563,"wires":[["f681e93c.3f1c58"]]},{"id":"b48c8796.d52c18","type":"comment","z":"45821715.765ae","name":"Update Device on Connection","info":"","x":174,"y":599.2667236328125,"wires":[]},{"id":"92cd3057.f54ee","type":"comment","z":"45821715.765ae","name":"Send Stats to IoT Pin","info":"","x":1011,"y":600.2667236328125,"wires":[]},{"id":"a5e5f702.cd09d8","type":"debug","z":"45821715.765ae","name":"Toggle to show IoT command","active":true,"console":"false","complete":"true","x":985.5,"y":641.2667236328125,"wires":[]},{"id":"6df7454e.5f8b64","type":"debug","z":"45821715.765ae","name":"Toggle to show top tone category","active":true,"console":"false","complete":"toptone","x":728.5000610351562,"y":335,"wires":[]},{"id":"4aa486e5.6dbef8","type":"inject","z":"45821715.765ae","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":459,"y":614.5,"wires":[["f681e93c.3f1c58"]]},{"id":"cfe73a57.6b93","type":"inject","z":"45821715.765ae","name":"Reset stats","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100.36669921875,"y":793.0333251953125,"wires":[["69379e77.316a68"]]},{"id":"ab67e05c.a80bc","type":"function","z":"45821715.765ae","name":"Reset State","func":"context.global.allTime = msg.payload.allTime = \ncontext.global.lastMinute = msg.payload.lastMinute = \ncontext.global.lastHour = msg.payload.lastHour = \ncontext.global.scores = {\n             openness_big5: 0,\n    conscientiousness_big5: 0,\n         extraversion_big5: 0,\n        agreeableness_big5: 0,\n          neuroticism_big5: 0\n};\n\ncontext.global.history = msg.payload.history = [];\n\n\nreturn msg;","outputs":1,"noerr":0,"x":644.36669921875,"y":793.0333251953125,"wires":[["bc9a78bb.cdea68"]]},{"id":"bc9a78bb.cdea68","type":"cloudant out","z":"45821715.765ae","name":"Save Updated State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","payonly":true,"operation":"insert","x":858.86669921875,"y":792.5333251953125,"wires":[]},{"id":"6bf96ea.221349","type":"cloudant in","z":"45821715.765ae","name":"Get State in DB","cloudant":"","database":"application","service":"tonepin-cloudantNoSQLDB","search":"_id_","design":"","index":"","x":468.3666687011719,"y":793.0333251953125,"wires":[["ab67e05c.a80bc"]]},{"id":"69379e77.316a68","type":"function","z":"45821715.765ae","name":"Set Doc ID = state","func":"msg.payload = 'state';\nreturn msg;","outputs":1,"noerr":0,"x":276.36669921875,"y":793.0333251953125,"wires":[["6bf96ea.221349"]]},{"id":"1a439f0d.31e031","type":"comment","z":"45821715.765ae","name":"Reset stats to zero","info":"","x":103.36666870117188,"y":753.0999755859375,"wires":[]},{"id":"3ff037dd.09fdd8","type":"watson-tone-analyzer","z":"45821715.765ae","name":"Tone Analyzer","tones":"social","sentences":"true","x":244.4000244140625,"y":296.54998779296875,"wires":[["e62cd3e4.54585","ae553cf7.91b12"]]},{"id":"ae553cf7.91b12","type":"debug","z":"45821715.765ae","name":"Toggle to show tone category scores","active":true,"console":"false","complete":"response.document_tone.tone_categories","x":516.4000244140625,"y":371.4666748046875,"wires":[]}]
melwinoro

Flow Info

created 4 months, 3 weeks ago

Node Types

Core
  • comment (x13)
  • debug (x4)
  • delay (x1)
  • function (x12)
  • http in (x1)
  • http response (x1)
  • inject (x5)
  • switch (x2)
  • template (x1)
  • twitter in (x1)
Other

Tags

Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option