Database Reference
In-Depth Information
Listing 5.4
Extracting the time-series of the volume of Tweets
// Time pattern used to count the volume of Tweets
final SimpleDateFormat SDM = new SimpleDateFormat( "dd MMM yyyy
HH:mm" );
public JSONArray GenerateDataTrend(String inFilename) {
HashMap<String,Integer> datecount = new HashMap<String,
Integer>();
// Step 1: Parse the time of publication of each Tweet and
count the number of Tweets using SDM
...
/ ** DateInfo consists of a date string and the
corresponding count.
* It also implements a Comparator for sorting by time
* /
ArrayList<DateInfo> dinfos = new ArrayList<DateInfo>();
Set<String> keys = datecount.keySet();
for(String key:keys) {
DateInfo dinfo = new DateInfo();
try {
dinfo.d = SDM.parse(key);
} catch (ParseException ex) {
ex.printStackTrace();
continue;
}
dinfo.count = datecount.get(key);
dinfos.add(dinfo);
}
// Step 2: Sort the counts in the increasing order of
the time
Collections.sort(dinfos);
// Format and return the date string and the
corresponding count
...
}
Source: Chapter5/trends/ExtractDatasetTrend.java
An example of the two actions described above can be seen in Fig. 5.5 . Initially
the trend lines/views present the same overview of the trend as in Fig. 5.4 . Brushing
a region in the trendline at the bottom selects a time range. Since the two views are
linked, this action causes the series on the top to focus into the selected time range,
which in this case is 12-3 PM. The user can then observe the information in greater
detail and identify finer patterns in the data. Removing the brushed region causes
the original trend to re-appear and present the context. This helps a user analyze the
overview of the time-series all the time and obtain details when necessary, which
can be useful when investigating time-series data over extended periods of time.
This visualization can be implemented using the function summarized in Listing 5.5 ,
which is defined in TrendLine.js .
 
Search WWH ::




Custom Search