Presidential Elections, Processing Historical Data
We are approaching a new presidential election here in the US,
and many are very excited to follow the evolving political trends. The
election results are very important public records which allow anyone to verify
the transparency of the core process for any modern democracy.
In this article we explore how to extract election historical
data, stored in a variety of data sources and use Stylus Studio in a creative
We start with the 2004 election result which we have found
in the text format. In the following screenshot, we see the raw flat file.
We can now convert the data using the Convert to XML module which
allows us to generate an XML document with a few clicks. We use the first line
in the file to create the element names. The preview window shows the
Once the data is converted to XML we can open the document
using the Stylus Studio XML editor; switching to the Grid view allows us to
easily sort the grid content using any of the column headers (right click->
Now that we have full control on the data for the 2004 election
results, we can move to the 2008 election. This data has been stored in a
relation database; the simple diagram below illustrates the relationship
between the “States” table and the “Election2008” table.
Our goal is to query the database and to generate an XML
document which will have a similar structure to the previously converted flat
file. For this task we are going to use the DataDirect XQuery engine which
allows for joining the table’s data and returning an XML document.
In the following screenshot you can see how the XQuery
mapping tool has been used to build a “for” statement and the collection
function calls are used to access the database tables. The equal operator
matches the records where the StateID is the same.
The preview window which captures the query result has been
undocked to reduce the real-estate.
If you are wondering how such an approach can scale with a
large database, take a peek at the query plan to discover what happens under
the cover. The following screenshot reveals that the query has been translated
into a SQL SELECT and it runs as fast as native SQL query.
In the next step, we build a report which compares the
results between the two presidential candidates state by state. The background
color indicates the party who won the state.
The final step consists of chaining together what we have
designed in a pipeline, which can be executed as a single unit.
We hope you enjoyed reading this article. If you have any
questions, do not hesitate to contact us.
You can download the Project Zip file by clicking
- Stylus Studio Team
Follow us on Twitter
Connect on Facebook