Trendrr is a service to track, compare and share data. You can track data from sources that are supported by Trendrr or you can add your own dataset. You can have multiple data sets and you can lay them on top of each other to compare these data sets. Plus, you can export your data set in a visual graph or raw data in XML, json or as an excel spreadsheet.
This recipe demos how you can use Daylife's APIs to get news coverage about any topic and then send that data to Trendrr on periodic basis using their API. The end result is a trending graph that you can share with anyone for news converage about any topic.
Below are trend graphs for Hillary Clinton, Barack Obama and John McCain in three different visual formats.
We have hosted a script for you to create your trendrr graphs (more details below) or download it to customize the data. Read below how you can create similar graphs using Daylife and Trendrr Services.
The Trendrr API is a simple HTTP GET request with a very few parameters sent in the query string. A sample URL looks like this:
http://www.trendrr.com/api/simple?key=<your trendrr key for the graph>&value=<value you want to graph on the y-axis>&date=<time in microseconds since the epoch on the x-axis>
Here is the step-by step process that I followed to create my mashup: a. From trendrr home page:
b. Fill in 'Data Set Title' and 'Legend Text'. In this case I used:
Data Set Title = 'Hillary Clinton' Legend Text = 'Number of mentions in news for Hillary Clinton
c. Select the time scale for your graph. I left the it to be the default 2 weeks. Once you have submitted this information, you get an API key for this particular graph/dataset. You then use this key in the API call above.
d. Collect your data. I wrote a php script that would take 'Hillary Clinton' (or any other topic) as an input and get the number of mentions for her in news per day in the last 14 days from the Daylife API.
e. Send that data to trendrr to track on the graph I just created for Hillary by calling the trendrr API. So now I have a trend graph for Hillary's coverage in news in the last 2 weeks.
Here is my script that you can use to create your own trends using the Daylife API:
http://demos.daylife.com/demos/trendrr/trendrr.php?query=Hillary+Clinton&trendrr_key=<your trendrr key>&days_back=14&interval_days=1
As you can see the script accepts the following parametrs:
i. query - the topic in news that you want to track
ii. trendrr_key - your key for the trendrr graph that you want to track this data on
iii. days_back - number of days in past that the data was sent to trendrr.
iv. interval_days - number of days over which the mentions were counted for every data point sent to trendrr
The URL above sends number of mentions for Hillary Clinton per day in the last 14 days to trendrr.
If you want to send number of mentions for Hillary Clinton every 3 days in the last 21 days to trendrr, you call my script as follows:
http://demos.daylife.com/demos/trendrr/trendrr.php?query=Hillary+Clinton&trendrr_key=<your trendrr key>&days_back=21&interval_days=3
f. I then scheduled a cron job to call the following URL once every day:
http://demos.daylife.com/demos/trendrr/trendrr.php?query=Hillary+Clinton&trendrr_key=<your trendrr key>
Remember, if you are trying to trend data every X days, you schedule the job every X days and provide interval_days=X in the URL above for the job.
If you do not know how to schedule a cron job or do not have access to your server, use Webcron
g. Make the graph public from the trendrr site by going to My Graphs. You can then pick the embed code or the Permalink to distribute your graph.
| Attachment | Size |
|---|---|
| trendrr.zip | 2.1 KB |