Skip to content

Instantly share code, notes, and snippets.

@hlian
Created March 8, 2010 04:48
Show Gist options
  • Save hlian/324879 to your computer and use it in GitHub Desktop.
Save hlian/324879 to your computer and use it in GitHub Desktop.
i saved oscars night
import codecs
import csv
import os
import sys
from collections import defaultdict
from operator import itemgetter
from pprint import pprint
KEYS = ['Timestamp',
'name',
'netid',
'college',
"Don't you wish you lived in Mathey?",
'Performance by an actor in a leading role',
'Performance by an actor in a supporting role',
'Performance by an actress in a leading role ',
'Performance by an actress in a supporting role ',
'Best animated feature film of the year ',
'Achievement in art direction ',
'Achievement in cinematography ',
'Achievement in costume design ',
'Achievement in directing ',
'Best documentary feature ',
'Best documentary short subject ',
'Achievement in film editing ',
'Best foreign language film of the year ',
'Achievement in makeup ',
'Achievement in music written for motion pictures (Original score) ',
'Achievement in music written for motion pictures (Original song) ',
'Best motion picture of the year ',
'Best animated short film ',
'Best live action short film ',
'Achievement in sound editing ',
'Achievement in sound mixing ',
'Achievement in visual effects ',
'Adapted screenplay ',
'Original screenplay ']
WINNERS = {
'Performance by an actor in a leading role': 'Jeff Bridges in "Crazy Heart" (Fox Searchlight)',
'Performance by an actor in a supporting role': 'Christoph Waltz in "Inglourious Basterds" (The Weinstein Company)',
'Performance by an actress in a leading role ': 'Sandra Bullock in "The Blind Side" (Warner Bros.)',
'Performance by an actress in a supporting role ': 'Mo\'Nique in "Precious: Based on the Novel \'Push\' by Sapphire" (Lionsgate) ',
'Best animated feature film of the year ': '"Up" (Walt Disney)\tPete Docter ',
'Achievement in art direction ': '"Avatar" (20th Century Fox)\tArt Direction: Rick Carter and Robert Stromberg Set Decoration: Kim Sinclair ',
'Achievement in cinematography ': '"Avatar" (20th Century Fox)\tMauro Fiore ',
'Achievement in costume design ': '"The Young Victoria" (Apparition)\tSandy Powell ',
'Achievement in directing ': '"The Hurt Locker" (Summit Entertainment)\tKathryn Bigelow ',
'Best documentary feature ': '"The Cove" (Roadside Attractions) An Oceanic Preservation Society Production\tNominees to be determined ',
'Best documentary short subject ': '"Music by Prudence" An iThemba Production\tRoger Ross Williams and Elinor Burkett ',
'Achievement in film editing ': '"The Hurt Locker" (Summit Entertainment)\tBob Murawski and Chris Innis ',
'Best foreign language film of the year ': '"El Secreto de Sus Ojos" (Sony Pictures Classics) A Haddock Films Production\tArgentina ',
'Achievement in makeup ': '"Star Trek" (Paramount and Spyglass Entertainment)\tBarney Burman, Mindy Hall and Joel Harlow ',
'Achievement in music written for motion pictures (Original score) ': '"Up" (Walt Disney)\tMichael Giacchino ',
'Achievement in music written for motion pictures (Original song) ': '"The Weary Kind (Theme from Crazy Heart)" from "Crazy Heart" (Fox Searchlight)\tMusic and Lyric by Ryan Bingham and T Bone Burnett ',
'Best motion picture of the year ': '"The Hurt Locker" (Summit Entertainment) A Voltage Pictures Production\tNominees to be determined ',
'Best animated short film ': '"Logorama" (Autour de Minuit) An Autour de Minuit Production\tNicolas Schmerkin ',
'Best live action short film ': '"The New Tenants" A Park Pictures and M & M Production\tJoachim Back and Tivi Magnusson ',
'Achievement in sound editing ': '"The Hurt Locker" (Summit Entertainment)\tPaul N.J. Ottosson ',
'Achievement in sound mixing ': '"The Hurt Locker" (Summit Entertainment)\tPaul N.J. Ottosson and Ray Beckett ',
'Achievement in visual effects ': '"Avatar" (20th Century Fox)\tJoe Letteri, Stephen Rosenbaum, Richard Baneham and Andrew R. Jones ',
'Adapted screenplay ': '"Precious: Based on the Novel \'Push\' by Sapphire" (Lionsgate)\tScreenplay by Geoffrey Fletcher ',
'Original screenplay ': '"The Hurt Locker" (Summit Entertainment)\tWritten by Mark Boal ',
}
SCORES = defaultdict(int)
DUPLICATES = defaultdict(int)
def main(f):
for line in f:
# Convert into Unicode.
line = map(lambda x: x.decode('utf8'), line)
# Convert a line of CSV into a dictionary of keys and values.
person = dict(zip(KEYS, line))
DUPLICATES[(person['netid'], person['name'])] += 1
# For each choice, see if the person is right.
for key in person:
# If the person is right, add one to his or her score.
if WINNERS.get(key) == person[key]:
SCORES[(person['netid'], person['name'])] += 1
if __name__ == '__main__':
# Open up a file, pass it to the CSV module, pass the stream to main().
main(csv.reader(open(sys.argv[1], 'rb')))
# Sort by value (score) and print everything out.
pprint(sorted(SCORES.items(), key=itemgetter(1), reverse=True))
for key in DUPLICATES:
if DUPLICATES[key] > 1:
print(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment