Tag Archives: election data hackathon

How to Make an Election Interactive

So I created an interactive for Wionews.com (embedded below) on the assembly elections taking place in five states. This write-up goes into how I did the interactive and the motivations behind it.


The Interactive is embedded below. Click on Start to begin.


The interactive looks at three things:

  • where each party won in the last assembly election in 2012 in each of the five states, visualised with a map.
  • where each party won in the last Lok Sabha (LS) election in 2014, if the LS seats were broken up into assembly seats. This was also done with a map.
  • the share of seats won by each major party in previous assembly elections, done with a line chart.

I got all my data from the Election commission website and the Datameet repositories, specifically the repositories with the assembly constituency shapefiles and historical assembly election results.

Now these files have a lot of information in them, but since I was making this interactive specifically for mobile screens and there wouldn’t be much space to play with, I made a decision to focus just on which party won where.

As mundane as that may seem, there’s still some interesting things you get to see. For example, from the break-up of the 2014 Lok Sabha results, you find out where the Aam Aadmi Party has gained influence in Punjab since the last assembly elections in 2012, when they weren’t around.

The interactive page on the AAP in Punjab, 2014
The interactive page on the AAP in Punjab, 2014

ANALYSING THE DATA

While I got the 2012 election results directly from the election commission’s files, the breakdown of the 2014 Lok Sabha results by assembly seat needed a little more work with some data analysis in python (see code below) and manual cross-checking with other election commission files.

Some of the python code used to break down the 2014 LS results by assembly seat.
Some of the python code used to break down the 2014 LS results by assembly seat. You can see all of it here.

For calculating the percentages of seats won by major parties in the past, I had to do some analysis in python of Datameet’s assembly election results file.

Some of the python code used to calculate historical seat shares of parties.
Some of the python code used to calculate historical seat shares of parties. You can see all of it here.

PUTTING IT ALL ONTO A MAP

The next thing to do was put the data of which party won where onto an assembly seat map for each state.

To get the assembly seat maps, I downloaded the assembly constituency shapefile from the datameet repository and used the software QGIS to create five separate shapefiles for each of the states. (Shapefiles are what geographers and cartographers use to make maps.)

A screenshot of the <a href="https://www.qgis.org" target="_blank">QGIS</a> software separating the India shapefile into separate ones for the states.
A screenshot of the QGIS software separating the India shapefile into separate ones for the states.

The next task is to make sure the assembly constituency names in the shapefiles match the constituency names in the election results. For example, in the shapefile, one constituency in Uttar Pradesh is spelt as Bishwavnathganj while in the election results, it’s spelt as Vishwanathganj. These spellings need to be made consistent for the map to work properly.

I did this with the OpenRefine software which has a lot of inbuilt tools to detect and correct these kinds of inconsistencies.

The purist way would have been to do all this with code, but I’ve been using OpenRefine, a graphical tool, for a while now and it’s just easier for me this way. Please don’t judge me! (Using graphical tools such as OpenRefine and QGIS make it harder for others to reproduce your exact results and is less transparent, which is why purists look down on a workflow that is not entirely in code.)

After the data was cleaned, I merged or ‘joined’ the 2012 and 2014 election results with the shapefile in QGIS, I then converted the shapefile into the geojson format, which is easier to visualise with javascript libraries such as D3.js.

I then chose the biggest three or four political parties in the 2012 assembly and 2014 LS election results for each state, and created icons for them using the tool Inkscape. This can be done by tracing the party symbols available in various election commission documents.

Some of the party icons designed for the interactive
Some of the party icons designed for the interactive

HOW IT’S ALL VISUALISED

The way the interactive would work is if you click on the icon for a party, it downloads the geojson file which, to crudely put it, has the boundaries of the assembly seats and the names of the party that’s won each seat.

The interactive map showing the NPF in Manipur in 2014
The interactive map showing the NPF in Manipur in 2014

You then get a map with the seats belonging to that party coloured in yellow. And each time you click on a different party icon, a new map is generated. (If I’ve understood the process wrong, do let me know in the comments!)

Here’s some of the d3 code used:

    map2
        .append("svg:image")  //put an image onto the canvas
        .attr("xlink:href","../exp_buttons/bharatiya_janta_party_75.png")  //take the image from the exp_buttons folder
        .attr('height', '75')
        .attr('width', '75')
        .attr('class','shadow partyButton')
        .attr('id','bjpButton')
        .attr("x", 30)             
        .attr("y", 0)    
        .on("click", function(){
            map
              .append("svg:g")         //create the map
              .style("fill","#4f504f")  //fill the map with this black color
              .selectAll("path")
              .data(json.features)
              .enter()
              .append("path")
                  .attr("d", pathx)
                  .style("stroke", "#fdd928")  //create yellow borders
                  .style("opacity","1")
                  .style("stroke-width", "1")
                  .style("fill",colorParty);      //colorparty is determined by the function below

		 //fill the seats with yellow if they were won by the “Bharatiya Janta Party”
		//and if they were won by someone else, make them black
					                
                function colorParty(d) {
                   if (d.properties.uttarakhand_2012_2012_1 == "Bharatiya Janta Party") {
                      return "#fdd928"
                } else {
                      return "#4f504f";
                    }
                };
              });

I won’t go into the nitty gritty of how the line chart works, but essentially every time you click on one of these icons, it changes the opacity of the line representing the party into 1 making it visible while the opacity of every other line is reduced to 0 making them invisible.

The historical performance of the MGP in Goa.
The historical performance of the MGP in Goa.

Here’s some of the relevant d3 code:

svg
	.append("svg:image")                                                             //this tells D3 to put an image onto the canvas
	.attr("xlink:href","../exp_buttons/bharatiya_janta_party_75.png")   //and this will be the bjp image located in the exp_buttons folder
	.attr('height', '75')
	.attr('width', '75')
	.attr('class','shadow partyButton')       //this is what gives a button the shadow, attributes derived from css 
	.attr('id','bjpButton')			     
	.attr("x", 0)             
	.attr("y", height + margin.top + 20)    
	.on("click", function(){
			d3.selectAll(".line:not(.bjpLine)").style("opacity", "0");  //make all other lines invisible
			d3.selectAll(".bjpLine").style("opacity", "1");                   //make the BJP line visible
			d3.select(this).classed({'shadow': false});		//remove the drop shadow from the BJP button 
											//so that people know it’s active
			d3.selectAll('.partyButton:not(#bjpButton)').classed({'shadow': true});  //this puts a drop shadow onto other buttons
													   //in case they were active
			
			});

I then put everything into a repository on Github and used Github pages to ‘serve’ the interactive to users.

Now I haven’t gone into the complexity of much of what’s been done. For example, if you see those party symbols and the tiny little shadows under them (they’re called drop shadows), it took me at least two days to make that happen.

It took two days to get these drop shadows!
It took two days to get these drop shadows!

MOTIVATIONS BEHIND THE INTERACTIVE

As for the design, I wanted something that people would just click/swipe through, that they wouldn’t have to scroll through, and also limit the data on display, giving only as much as someone can absorb at a glance.

My larger goal was to try and start doing data journalism that’s friendlier and more approachable than the stuff I’ve been doing in the past such as this blogpost on the Jharkhand elections.

I actually read a lot on user interface design, after which I made sure that the icons people tap on their screen are large enough for their thumbs, that icons were placed in the lower half of the screen so that their thumbs wouldn’t have to travel as much to tap on them, and adopted flat design with just a few drop shadows and not too many what-are-called skeumorphic effects.

Another goal was to allow readers to get to the information they’re most interested in without having to wade through paras of text by just tapping on various options.

The sets of options available to the user while in the interactive
The sets of options available to the user while in the interactive

I hacked a lot of D3.js examples on bl.ocks.org and stackoverflow.com to arrive at the final interactive, I’m still some way away from writing d3 code from scratch, but I hope to get there soon.

Because I’m not a designer, web developer, data scientist or a statistician, I may have violated lots of best practices in those fields. So if you happen to come across some noobie mistake, do let me know in the comments, I’m here to learn, thanks! 🙂


Shijith Kunhitty is a data journalist at WION and former deputy editor of IndiaSpend. He is an alumnus of Washington University, St. Louis and Hindu College, Delhi.

Notes from DataMeet-Up in Delhi, 22 November 2013

We had DataMeet-Up on Friday, November 22, 2013, at the Akvo office in Yususf Sarai Community Centre, Delhi.

Here are the notes from the meet-up [additional information in square brackets]:

Election Data Hackathon

  • We will undertake a collaborative mapping of datasets relevant for election data hackathon, using GitHub and Google Drive. More details about this below.
  • Datasets that we are trying to locate include: election results data (total vote count, vote count per party/candidate, etc), total utilisation and composition of utilisation of MP Local Area Development funds, parliamentary activities of MPs (presence/absence, questions asked, bill discussed, committees joined. etc), crime data corresponding to constituencies, etc.
  • We will identify organisations who might hold additional relevant data, such as PRS Legislative Research, Association for Democratic Reforms (and MyNeta.info), Gramener, and Hindustan Times [Anika used to work at HT].
  • Two caveats: (1) we may not get unique and standard identifiers across datasets, and (2) calculations may get difficult in case of by-elections [Lok Sabha Secretariat will have details of all by-elections, which can be accessed through RTI request].

Hack for Change on Women’s Rights

  • Shobha, Breakthrough.tv, led the discussion on the planned Hack for Change event being organised by Breakthrough and Hacks/Hackers, as part of the 16 days of activism against violence against women.
  • The hackathon is organised around urban safety data from Whypoll , multimedia evidences of early marriage practices in Bihar and Jharkhand gathered by Gramvaani , etc. It will also include a Wikipedia Edit-athon facilitated by Noopur Raval.
  • There were multi-directional discussions around other datasets of relevance for the hack event, which I have not kept track of very well. Overall, there were discussions around datasets available from , those published by National Crime Records Bureau, FIR and call database of Delhi police (and how to access that), and data on violence against women gathered by Tata Institute of Social Sciences from police stations across seven states.

Presentation on iPython

  • Konark Modi presented a detailed introduction to using iPython to undertake data cleaning in a very organised manner, as well collaboration features/workflow of iPython.
  • There emerged a demand for a tutorial on OpenRefine (previously Google Refine), which will be organised in a later meeting.

Mapping Indian Election Data

  • We will start documenting publicly available datasets relevant for studying past General Assembly (Lok Sabha) elections in India and the activities of the elected members at present. One can contribute to this mapping exercise in two ways, as mentioned below.
  • GitHub: We have created a repository for this data mapping exercise under the DataMeet organisation at GitHub. The organisation page can be accessed here, and the (india-election-data) repository can be accessed here. In the repository, I have created a draft format for documenting the identified datasets. This draft format can be accessed here. Please feel free to suggest changes to the draft format by opening an issue.
  • To document a dataset, use the format given in the repository, fill up the details, and rename the file according to the dataset’s name, such as “election-results-delhi-1995.md”. Then if you notice any requirement of data cleaning/reorganisation or lack of clarity regarding the dataset, open an issue (where the name of the dataset is mentioned) to note that task.
  • Google Drive spreadsheet: Alternatively, you can access this spreadsheet on Google Drive and add the relevant information about the dataset documented by you.

Please comment here or post to the DataMeet mailing list for any clarifications and suggestions.

DataMeet-Up in Delhi, Friday, November 22

After a hiatus, the Delhi DataMeet-Up is back. We are meeting today, Friday, November 22, at Akvo Foundation office, at 5:00 pm.

Here is the tentative agenda of the meeting:

  • Updates: Sharing news across the network.
  • Discussion: Discussing how we can support Hack for Change around women’s rights being organised by Breakthrough.tv and Hacks/Hackers New Delhi. Shobha and Anika would begin the discussion by talking about the planned event.
  • Discussion: Beginning a discussion towards a election data hackathon. It will be led by Satyakam and Surendran.
  • Presentation: Using iPython for exploratory data visualisation – Konark Modi, MakeMyTrip.com.
  • Discussion: Brief chat about the overall agenda of the Delhi chapter of DataMeet.

Location: Akvo Foundation, 3rd Floor, Ramnath House, Plot #18, Yusuf Sarai Community Centre, Yusuf Sarai. Nearest metro is Green Park.

loading map - please wait...

Akvo Foundation 28.557765, 77.208158 Akvo Foundation 3rd Floor, Ramnath House Plot #18, Yusuf Sarai Community Centre Yusuf Sarai She was thinking Only the when to take vigrx plus pills last two hours magna rx plus side effects of patrolling in the street were available, and I could survive. Shakes continued. viagra with alcohol The first time she felt uneasy this morning as she walked when to take vigrx plus pills into a bush. magna rx plus side effects Someone is viagra with alcohol watching me. The hot wind blew through the viagra with alcohol dry bushes and made the rustling sound. A car truck ran full steam ahead of the Lincoln Tunnel. She remembered one thing the patrolmen would often when to take vigrx plus pills think of the city was so noisy that I could not testogen customer reviews detect magna rx plus side effects if someone came back to viagra with alcohol me behind me and walked to lift when to take vigrx plus pills me up with a knife. Or take my back as viagra with alcohol a testofuel recommended dosage target She turned quickly. Nothing except leaves, rusty machines and https://briansky.org/extenze-review-2020/ rubbish. When climbing a pile of stones, the knee pain so she could not help but shrink body. Emily Shakes, 31, is afflicted with joint inflammation - testogen customer reviews her mother when to take vigrx plus pills https://briansky.org/extenze-review-2020/ often says youre 31 It is inherited from her grandfather, just as testofuel recommended dosage she inherited her mothers good figure, her fathers good looks and occupation as long as the red hair no one can say it. She slowly passed through a cluster of testofuel recommended dosage dead shrubs, a sharp pain testogen customer reviews on her knees. Thanks to her prompt closing, she did not drop a steep 30-foot deep slope. Below her was a gloomy gorge that cut deeply through the bottom of the testogen customer reviews West testofuel recommended dosage End. The railroad tracks when to take vigrx plus pills of the U.S. Railroad Passenger when to take vigrx plus pills Transport Company viagra with alcohol run through the canyon and the train goes https://briansky.org/extenze-review-2020/ to the north. She narrowed her eyes and looked to testogen customer reviews the bottom of the canyon not far from the tracks. what is that viagra with alcohol testofuel recommended dosage Is inserted in a circle of soil has been turned over the twigs It looks like Europe, my testofuel recommended dosage god The sight of her testofuel recommended dosage made her shiver. Nausea suddenly rose, burning like a flame burning her skin. For a moment she really wanted to https://briansky.org/extenze-review-2020/ turn viagra with alcohol around and escape, pretended nothing was seen. But she tried hard to suppress the idea in my heart. He hopes the victim is dead. This is the best. She runs to an iron staircase that leads from the sidewalk to the canyon. She viagra with alcohol stopped in time as she viagra with alcohol grabbed the magna rx plus side effects testogen customer reviews https://briansky.org/extenze-review-2020/ balustrade of the iron when to take vigrx plus pills staircase. bad The murderer has escaped in all likelihood, and is likely to have left the ladder. If she touches testofuel recommended dosage the railings, she may undermine the mark he left behind when he ran https://briansky.org/extenze-review-2020/ away. Okay, then well waste something. She took a deep breath and held back the pain magna rx plus side effects of the knee joint. She inserted the deliberately polished bright boot into the crevice of the stone on the first day of her new job and began to climb down the https://briansky.org/extenze-review-2020/ testofuel recommended dosage rock wall. She was still four feet off the ground and jumped testogen customer reviews straight testofuel recommended dosage to the place where it was buried. My God It is not a branch that extends from under the ground it https://briansky.org/extenze-review-2020/ is a mans hand. testogen customer reviews The body of this man was buried vertically in the earth, leaving magna rx plus side effects only the arm, magna rx plus side effects wrist and testogen customer reviews palm left outside. She stared at the ring finger of the https://briansky.org/extenze-review-2020/ hand all testofuel recommended dosage https://briansky.org/extenze-review-2020/ the muscles had been cut off, the red of the bones of the fingers, set with https://briansky.org/extenze-review-2020/ a huge female diamond ring. Shakes knelt on the when to take vigrx plus pills ground, began digging down. The soil fluttered under her hands as a dog. She https://briansky.org/extenze-review-2020/ found that those https://briansky.org/extenze-review-2020/ fingers testofuel recommended dosage that had not been cut were wide open, pointing in the direction that their fingers testofuel recommended dosage would not normally bend. This shows that the victim was still alive when the last shovel of mud buried his face. Maybe its still alive now. Shakes desperately dug soft soil, her hands magna rx plus side effects testofuel recommended dosage were shattered by pieces of https://briansky.org/extenze-review-2020/ glass, dark red blood and dark red soil mixed together. This persons hair is exposed, followed by a bluish, gray forehead due testogen customer reviews when to take vigrx plus pills to lack of viagra with alcohol oxygen. She continued digging until she saw the dull eyes and mouth of the man. The testofuel recommended dosage mans mouth testogen customer reviews twisted into horrible curvature, indicating that in the last few seconds of magna rx plus side effects life testogen customer reviews the victim struggled to keep his mouth through magna rx plus side effects the rising when to take vigrx plus pills black soil. This is not a woman. Despite the finger on the viagra with alcohol set of a diamond ring. He was a big man in his fifties and was as angry as magna rx plus side effects the soil surrounding him. She when to take vigrx plus pills took testogen customer reviews a few steps back, her gaze testogen customer reviews never leaving that person, almost tripped over by the tracks behind her. For a while, her mind was empty and viagra with alcohol could not think of anything, only knowing that magna rx plus side effects a man was buried to die like this. Then she testofuel recommended dosage reminded testogen customer reviews herself Be strong, baby. In front of you is when to take vigrx plus pills the testogen customer reviews scene of a homicide together, and magna rx plus side effects you are the magna rx plus side effects first police officer present. https://briansky.org/extenze-review-2020/ You know what to do ADAPT, https://briansky.org/extenze-review-2020/ adapt. A is the current arrest of Arrest. D is a magna rx plus side effects major eyewitness and suspect to Detain. A is Assess murder scene. P when to take vigrx plus pills is P what is it She bowed her head towards the walkie-talkie Patrolman 5885 viagra with alcohol calls headquarters. ExtenZe - Longest Lasting Sex Pills Prime Male Vs. Nugenix (Researched & Tested) - magna rx plus side effects Prime Male and viagra with alcohol Nugenix are both dietary when to take vigrx plus pills supplements designed to boost testosterone levels naturally and safely.Prime Male addresses three main barriers to testosterone production in the when to take vigrx plus pills body, the luteinizing hormone, SHBG, and female hormones.Nugenix, on the other hand, focuses on increasing the levels of free testosterone.When it comes to ingredients, Nugenix relies on a proprietary blend.Unfortunately, proprietary blends do not inspire much confidence because they beg the question- what is the manufacturer hiding? With such a blend, it is impossible to know the exact ingredient amounts used, so we cannot ascertain their effectiveness. viagra with alcohol