/Purdue-Photography-Contest

Code for Google App Script for the Purdue Photography Contest

Primary LanguageJavaScript

Purdue Photography Contest

As President of the Purdue Photography Club, I ended up in charge of running our photo contest which we moved online during to the current pandemic.

The Problem

  1. We had 179 total photos entered on our website, and we had the data to be self populated into a Google Sheets file. We then had two Google Docs, one for each of our two judges, to record their scores and write down their comments. That is a total 2685 individual data points that we have to copy and verify which is way too much to do manually. Then, we would have to send an email to each individual who entered with their specific scoring reports and judges comments. We could have just shared the Google Sheets file, and let everyone look at their scores. However, that would not be very secure or appropriate way of doing it.

  2. Additionally, we had a viewer's choice award where the photo with the highest score wins that award. A photo would get 14 points for a first place vote and 9 through 3 points for second through eighth place votes respectively (just like how the MLB scores their votes for season awards). All of the votes where cast on our website and auto populated in a Google Sheets file. Like tallying the judges scores and comments, calculating the photo with the highest point total would be too much to do manually. In addition to just calculating the scores, we also want to check so someone cannot vote for their own photo, cannot vote twice, verify the photo ID, etc.

The Solution

  1. I wrote this code running on Google Apps Script to do all of that automatically. First, there is a function to read all the raw judging data from the two separate Google Docs. Then, we pass all that data to be inputed into our Google Sheets file while verifying that we are indeed entering it into the correct record. One key optimization is that both the Google Docs and Google Sheets file were sorted alphabetically on the Photo ID beforehand so our run time to update all the records is O(n) versus O(n2) where n is the number of records (photo entries). Then, we loop over all the records in the Google Sheets file to send the emails out. There is the email function template which takes all the input data from each row and formats it into an email. I also wrote a couple helper functions to add paragraph spaces between paragraphs and format the scoring table.

  2. Once again, I wrote code running on Google Apps Script by reading from both the votes sheet file and the photo submissions sheets file. The key data structures that were used in this were dictionaries and sets. For example, this allows us to check from the submissions table whether someone is voting for their own photo in constant time instead of looping through the submissions table for each vote entry. Additionally, sets enabled the ability to check for duplicate voters or duplicate votes of the same photo.