''' Created on Jun 2, 2020 @author: Brett Paufler Copyright Brett Paufler Finished: 2020-06-02 As per A4 only weighting the points Not +1 / -1 But 1-9 More Weight to Outliers 1 if everyone else joins 2 if only one does not join 8 if only one joins 9 if no one else joins Intended to highlight outlier opinions Do I agree or Disagree When they stand alone Or Disagree ''' import matplotlib.pyplot as plt #Cut And Paste From Previous from judges_utilities import CASE, OPINION from judges_utilities import Bag_O_Judges from judges_utilities import load_data def all_cases(): '''2018 Term Year Cases Remember to Call This Fresh for Each Graph''' return load_data() #all_cases() ############################################### # # Graph My Agreement # ############################################### def graph_weighted_agreement(): '''Given an Opinion, Do I agree? Weights: To Be Decided +Agree -Disagree 1/NumberAgree sum(Author, Joiners) ''' num_joining = 0 #A Running Total num_opinions = 0 #A Running Total agree = 0 #Running Total, +1 agree, -1 disagree agree_authored_only = Bag_O_Judges() #+1 agree, -1 disagree agree_authored_and_joined = Bag_O_Judges() #+1 agree, -1 disagree count_none_joining = 0 for case in all_cases(): for opinion in case.Opinions: #print opinion num_opinions += 1 #This is what is changing #Floats had error #So Reverse Integer Weighting #All Agree = 1 #None Agree = 9 count_none_joining if 'None' in opinion.joining: weight = 9 count_none_joining += 1 #print 'None Joining', count_none_joining #Previous Value per A3 was 45 #I get the same total here, so it checks elif opinion.author == 'Per Curiam': weight = 1 else: weight = 10 - (1 + len(opinion.joining)) weights_possible = range(1,10)#[1.0/x for x in range(1,10)] #print 'weights_possible', weights_possible #print opinion #print weight, weights_possible assert weight in weights_possible #Looking Good #Above are the major changes from A4 #Logic Stays the same, weight in lieu of 1 if opinion.good == 'Yes': #print 'Yes', opinion agree += 1 agree_authored_only[opinion.author] += weight agree_authored_and_joined[opinion.author] += weight for joining in opinion.joining: num_joining += 1 agree_authored_and_joined[joining] += weight elif opinion.good == 'No': #print 'No', opinion agree -= 1 agree_authored_only[opinion.author] -= weight agree_authored_and_joined[opinion.author] -= weight for joining in opinion.joining: num_joining += 1 agree_authored_and_joined[joining] -= weight else: assert 'Should Never Get Here' == 'Clear Error' #To Make Graphs Equal Lengths, Easier to Compare #Add None to Authored agree_authored_only['None'] = 0 print 'num_opinions', num_opinions #168 Yes, agrees with previous print 'sum agree authored only', sum(agree_authored_only.values()) print 'num_joining WRONG', num_joining #576, This agrees print 'num_joining LESS None', num_joining - abs(agree_authored_and_joined['None'])/9 #567 matches once normalized print 'sum joining all', sum(agree_authored_and_joined.values()) print 'agree', agree print 'Authored', agree_authored_only print 'Authored & Joining', agree_authored_and_joined # # From Here, Might Just Be Bar Graphs # # GRAPH - WEIGHTED # Agree Authored Only # Agree & Joining Normed print 'Start Weighted Agree Graph' judges, votes = zip(*agree_authored_only.items()) print judges print votes x_div = range(len(judges)) plt.subplots(figsize=(15,5)) plt.bar(x_div, votes) plt.xticks(x_div, judges) plt.title('Supreme Court: 2018 Term Year\nMy Weighted Agreement with Opinions Authored') #plt.xlabel('Opinion Page Length') plt.ylabel('10 - Number Judges Agreeing\nHighlights Outlier Opinions') #plt.show() plt.savefig('./output/2018_A4_author_weight_agree.png') plt.clf() print 'Start Weighted Agree Authored or Joining Graph' judges, votes = zip(*agree_authored_and_joined.items()) print judges print votes x_div = range(len(judges)) plt.subplots(figsize=(15,5)) plt.bar(x_div, votes) plt.xticks(x_div, judges) plt.title('Supreme Court: 2018 Term Year\nMy Weighted Agreement with Opinions Authored or Joined') #plt.xlabel('Opinion Page Length') plt.ylabel('10 - Number Judges Agreeing\nHighlights Outlier Opinions') #plt.show() plt.savefig('./output/2018_A4_author_join_weight_agree.png') plt.clf() graph_weighted_agreement() ######################## # # Printed Output Follows # ######################## ''' num_opinions 168 sum agree authored only -77 num_joining WRONG 576 num_joining LESS None 567 sum joining all -12 agree 0 Authored OrderedCounter(OrderedDict([('Roberts', -28), ('Thomas', -55), ('Ginsburg', 69), ('Breyer', -11), ('Alito', 12), ('Sotomayor', -14), ('Kagan', -19), ('Gorsuch', 4), ('Kavanaugh', -33), ('Per Curiam', -2), ('None', 0)])) Authored & Joining OrderedCounter(OrderedDict([('Roberts', -12), ('Thomas', -58), ('Ginsburg', 69), ('Breyer', 21), ('Alito', 57), ('Sotomayor', -7), ('Kagan', -2), ('Gorsuch', -21), ('Kavanaugh', 24), ('Per Curiam', -2), ('None', -81)])) Start Weighted Agree Graph ('Roberts', 'Thomas', 'Ginsburg', 'Breyer', 'Alito', 'Sotomayor', 'Kagan', 'Gorsuch', 'Kavanaugh', 'Per Curiam', 'None') (-28, -55, 69, -11, 12, -14, -19, 4, -33, -2, 0) Start Weighted Agree Authored or Joining Graph ('Roberts', 'Thomas', 'Ginsburg', 'Breyer', 'Alito', 'Sotomayor', 'Kagan', 'Gorsuch', 'Kavanaugh', 'Per Curiam', 'None') (-12, -58, 69, 21, 57, -7, -2, -21, 24, -2, -81) '''