Skip to Content

Part 1: Setup HCP account and IDE, twitter account and download first tweets


As a student in SAP HANA Product Management I had to explore what can be done on HCP trial landscape, what runs out-of-the-box, which SAP HANA features are available – and which business needs can be met, in the end? So, here are the results.


In this series of blogs I am going to explain how to build an real-time social media analytic application using the SAP HANA cloud platform (HCP). I wanted to make use of predictive algorithms. A hotspot for predictive is marketing. Therefore, I chose this topic. Of course, it is not ready-to-use, like a product. But it is “ready-to-copy-and-learn” and I named it SmartApp. While digging deeper and deeper, of course I learnt a lot through a multitude of other blogs and SAP HANA Academy videos. Thanks to all of you! (I do mention them below.)


It is an application that you can follow along yourself. However first let’s have a quick look at the overall scenario of the SmartApp. We are going to access some real-time social media information. I would like to take twitter as the example so we can get information on specific tweets that we want to look for and will pull those tweets out in real-time using the twitter API. The idea for this use was fueled by a nice blog from a Chinese colleague of mine, Wenjun Zhou:http://scn.sap.com/community/developer-center/hana/blog/2014/11/23/real-time-sentiment-rating-of-movies-on-sap-hana-part-6–wrap-up-and-looking-ahead– kudos to you for this work!


We will process those tweets and load them in real-time into the HANA database. However the database is hosted on HCP. It was my ambition to use an HCP developer trial edition for as long as possible (until I need a feature that is only available on a dedicated HANA instance). Once we loaded the data into the database then we can do some further analysis on how to group or segment the different types of tweeters, maybe we to group similar people together, for example the group of people expressing positive or negative sentiments towards the product or company, and it would also make sense to differentiate whether they are influential because a lot of people follow them and their tweets get retweeted. We could identify that group so we can target some education program or reach-out program to those people. So, the idea was to do some predictive analysis in HANA itself in order to segment, cluster or to group similar kinds of people sending tweets. And finally, I wanted to make the results available through web services i.e., OData, XSJS native web services within the HANA platform in order to build a HTML5 application that could run on desktop and mobile devices to look at the analysis results. That’s the overall scenario of the SmartApp.


I don’t want this blog to stretch like a chewing gum, so I divided the whole story into 3 parts:

  

1. Setup HCP account and IDE, twitter account and download first tweets

2. Refine processing of tweets with text Analysis, building web services and setting HANA Cloud Connector – this is the “heavy lifting” on SAP HANA from my point of view!

3. Do the UX work – use Analytics tools – make it nice 🙂



In the following sections, of course there is a lot of overlap with many existing blogs out there. Thank you to everybody I learnt from. Here are just a few of them:


Prerequisites


Before we start to build the application, we need to register for HCP trial developer account and create Hana instance within the trial account (recommended to give instance name as “dev” and Database system as HANA XS (shared)since we can refer it in many applications).

Open SAP HANA Administration console perspective by clicking top right cornerCapture 11.PNGof eclipse.


Find API keys



SET SCHEMA


First, identify the schema name to put application specific artifacts like tables, views:

To Identify and set Application schema keep DEV_xxx schema selected and hit onSQLSnip.PNGSQL button.

schema.PNG

Make sure to set the database connection by clicking ondbconnection.PNG.


Copy the following statements to the sql console in eclipse:

To Identify application schema,copy:

SELECT SCHEMA_NAME FROM “HCP”.”HCP_DEV_METADATA”;


To Identify current user,copy:

SELECT CURRENT_USER FROM DUMMY;


To Verify predictive analysis library is available,copy:

SELECT * FROM SYS.AFL_FUNCTIONS WHERE PACKAGE_NAME=’PAL’;


To Set application schema – paste in value below,copy:

SET SCHEMA NEO_;

Select & Run the statement to identify application schema:

SELECT SCHEMA_NAME FROM “HCP”.”HCP_DEV_METADATA”;  execute by clicking executionsnip.PNG.  As a result, the schema name is shown.


Then right click on the schema name and copy the cells. To set application schema – Paste the value below as

SET SCHEMA NEO_xxxxxxxxxxx; execute it to activate the schema.


Create Tweets table executing the below code:

CREATE COLUMN TABLE “Tweets” (

           

             “id” VARCHAR(256) NOT NULL,

           

              “created” TIMESTAMP,

           

               “text” NVARCHAR(256),

           

               “lang” VARCHAR(256),

           

               “user” VARCHAR(256),

           

               “replyUser” VARCHAR(256),

          

               “retweetedUser” VARCHAR(256),

           

               “lat” DOUBLE,

       

               “lon” DOUBLE,

          

                PRIMARY KEY (“id”)

);


Now we can find the tweets table in the schema (NEO_xxxxxxx) that we set initially.

tweetstable.PNG


Now install node.js to access both twitter API and HANA Database very easily that connects together.


To download the code of SmartApp from Git hub please click here.


Open downloaded SmartApp -> nodejs-> app.js in the editor may be notepad++.


In the code snippet we can see a variable called twitter where we actually specify the consumer_key, consumer_secret, access_token_key, access_token_secret. If you remember we already got this information when we registered our application in twitter. Now copy and paste the consumer_key into our file. Similarly do the same for other values also as shown below.


var twitter = new twitter({

       consumer_key: ‘xxxxxxxx’,


      consumer_secret: ‘xxxxxxxxxxx’,


      access_token_key: ‘xxxxxxxxxxx’,


       access_token_secret: ‘xxxxxxxxxxx’


We have a second file called package.json in the nodejs with the list of dependencies like express, request, oauth, twitter, hdb that are used in our application. Now we can install all these with an npm and node installation command. Now click shift+rightmouse button on the nodejs folder in the SmartApp to open a command prompt in that nodejs folder then use “npm install” command to install all the dependencies that we needed in our application.


Then Restart the system (computer) so that nodejs could run without errors.

nodejs command.PNG

npm install.PNG

Go to nodejs folder should be able to see node_modules folder which actually consists the code for the modules setup and installed.


Setup the Tunnel


Let us setup the Database tunnel to connect directly to the HANA database using p-number trial id (pxxxxtrial). In order to setup the database tunnel open a command prompt on the tools folder in neo-java-web-sdk by shift+right click mouse button. Now execute the command “neo open-db-tunnel –h hanatrial.ondemand.com –i dev –a pxxxtrial –u pxxxx” (please enter the command manually don’t copy!) by replacing the account name with your pxxxxxtrial account and username with the pxxxx number.


After executing the command enter the password that you gave during the trial account creation. The tunnel opened and gives us the properties to connect to the schema.

Capture.PNG

Now go to the app.js file, edit the port as 30115 then copy the user, password, Schema name properties and paste in the app.js file respectively as shown below.


var hdb = hdb.createClient({

            host     : ‘localhost’,

            port     : 30115,

            user     : ‘DEV_xxxxxxxxxxxxxxxxx’,

            password : ‘xxxxxxxxxxxxxx’

});

var hdb_schema = “NEO_xxxxxxxxxxxxxx”;


Now let’s start the application by simply going into command prompt running in the nodejs folder. Goto the downloaded smartApp -> nodejs folder then shift+right click then select open command window.Type “node app.js” as command, application will run and we can see two messages as shown below.

nodeapp.PNG

Goto the Chrome browser enter “localhost:8888/do/start?track = productname or companyname”. 


Note: Enter the product or company name that you would like to track or make analysis. 

Now we can see in nodejs command prompt that tweets are loading into HANA database. Go to the tweets table in eclipse and refresh by clicking on top right corner. We can see some tweets that are loaded in to table.

tweetloaded.PNG

If you want to stop loading the tweets go back to chrome browser then type “localhost:8888/do/stop”.


Note: While working with tunnel it must remain open for nodejs in order to be connect to the Hana instance. Since it’s a trial account this tunnel only lasts for 24 hours at that time you need to reopen it. However it’s fine for development and testing purposes. When using Productive HCP able to let things run 24/7.


Thanks for reading. Hope you enjoyed the blog…. 🙂


Next Steps

In the next blog will perform some text analysis on Tweets data, Setup SAP HANA Cloud Connector and Configurations, Building web services using HANA Native development and setup authorizations. I will insert the link in here as soon as it is available!

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Luca Manassero

    Hi Vikram,

    thank you!

    With Live3 being now private due to the many changes in the trial version of SAP HANA, your tutorial is probably the best one I was able to find and… it actually works.

    I was able to go through it (1st part) in an afternoon on a mac (so running Mac OS X 10.11, also known as “El Capitan”) and have a lot of fun.

    All the best,

    Luca

    (0) 

Leave a Reply