How to exploit Twitter data with Dashboards?
Introduction
In this article, we are going to exploit data stored in Platform Entities received from Twitter with the Dashboards.
For this article, we assume that the data is already stored in the Platform, as described in this article:
How to work with Twitter from the FlowEngine?
Data analysis
With the Twitter data already obtained directly from the Twitter API and stored in the platform's TweetsFromFlowEngine entity, you are going to proceed to exploit them.
As already shown in the previous article, you are going to use the Query Tool in TOOLS>Query Tool, with which you can launch different queries on the data.
You can use both the SQL language and the native language (in this case, the MongoDB query language). For this tutorial, you will use the SQL language, which is the standard query language provided by the platform.
You are going to launch queries on the data you have, in order to have a base on which to build your analytical dashboard.
If you do not change the query that is generated, you will see that the default query retrieves three records of the entity.
SELECT * FROM TweetsFromFlowEngine AS c LIMIT 3
With the following query, you will obtain the total number of records loaded in the entity.
SELECT count(*) FROM TweetsFromFlowEngine AS c
Using the lang field, you can group your data and get the number of tweets per language
SELECT lang, count(*) as cc FROM TweetsFromFlowEngine AS c group by lang
A similar but more interesting query would be to order these languages by descending number of occurrences, with which you will obtain a ranking by language.
SELECT lang, count(*) as cc FROM TweetsFromFlowEngine AS c group by lang order by cc desc
In this case, you have used the table display that will make it easier for you to compress the flat data using the button on the right of the screen.
Another interesting field is the location. You can obtain the tweets by this field.
SELECT location.place, count(*) as conteoporlugar FROM TweetsFromFlowEngine AS c group by location.place order by conteoporlugar desc
We see that there is a lot of uncategorized data. This is because it is data without location. If you look closely, you will also see that the tweet.geo field is always null. This is because most users deactivate this location and the information does not arrive. You can modify the previous query to avoid null data.
SELECT location.place, count(*) as conteoporlugar FROM TweetsFromFlowEngine AS c group by location.place where location.place is not null order by conteoporlugar desc
Dashboard Building
Now you are going to use queries similar to the previous ones to set up an analytical dashboard on Twitter data.
The first thing to do is generate a new dashboard. To do this, go to the menu:
And enter My Dashboards. There, you will see the dashboards of your user, and you can create a new one with the “+” button.
By clicking on it, the dashboard creation form will appear, as well as different settings. At this point, give your dashboard a name, include a description and mark the Default Style from 2.2
… Finally, click on the “Create” button.
Inside you can see the canvas on which you can place the gadgets:
To add your first gadget, click on the “+” button, which will make a panel appear, where which you can drag elements.
The first gadget that you are going to create will be a table with the different tweets. To do this, drag the Table icon on the canvas and drop it. This will make a popup appear, where you are to specify what you want to do.
Click on New Gadget, since you want to create a new one.
Give your table gadget a name, and select the TweetsFromFlowEngine entity.
Now you can enter the access query. In this case, leave the one that comes by default.
Click Continue and select the fields: Tweet.id_str, Tweet.user.name, Tweet.user.location, Tweet.text
You will see a preview of the gadget and you can click Create to generate it
Now you are going to generate a bar graph to be able to see how many Tweets there are by language. In this case, drag the “Bar Chart” Icon and click on New Gadget. In this case you will use the query:
SELECT lang, count(*) as cc FROM TweetsFromFlowEngine AS c group by lang order by cc desc
Click Continue and uncheck “Sort”, since this field would order the display along the X axis, which is not what you want.
And leave the Y axis without a maximum so that it is automatically recalculated.
Now use lang for xaxis and cc for yaxis. You can use some additional styles if you deem it necessary.
Click Create and you will have created your gadget.
Now you are going to create a pie-type gadget with the location information. The query will be the following:
SELECT location.place, count(*) as conteoporlugar FROM TweetsFromFlowEngine AS c where location.place is not null group by location.place order by conteoporlugar desc
You will use as the axes place and conteoporlugar ("count by place").
Now you are going to connect the gadgets, so that you can filter by lang from the bar gadget. To do this, use the datalink button.
Select the table gadget and the lang field as the source, and both the gadgets and the lang field as the destination. In this case, you will have to explicitly write lang in the destination, as it is a field that the query does to provide.
With both connections added, you will have something like this:
Click Close and you can confirm that, by pressing the bars of the first gadget, we will be able to filter the other two:
This is a good time to save the dashboard and avoid losing the work done with the button:
Finally, using different dashboard options, you can style it to have a more attractive presentation: