''' Created on May 11, 2020 @author: Brett Paufler Copyright Brett Paufler Finished: 2020-06-02 As I start the next file/page, I will make note that the incremental nature of the task makes it more fun I'm not doing multi-hour sprints Nor is the problem set particularly complex So, it's an easy relaxing sort of task It doesn't hurt that the bugs have been minor My way rather direct and straightforward ''' 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_my_agreement_with_justices(): '''Given an Opinion, Do I agree? +1 Agree -1 Disagree ''' 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 for case in all_cases(): for opinion in case.Opinions: #print opinion num_opinions += 1 if opinion.good == 'Yes': #print 'Yes', opinion agree += 1 agree_authored_only[opinion.author] += 1 agree_authored_and_joined[opinion.author] += 1 for joining in opinion.joining: num_joining += 1 agree_authored_and_joined[joining] += 1 elif opinion.good == 'No': #print 'No', opinion agree -= 1 agree_authored_only[opinion.author] -= 1 agree_authored_and_joined[opinion.author] -= 1 for joining in opinion.joining: num_joining += 1 agree_authored_and_joined[joining] -= 1 else: assert 'Should Never Get Here' == 'Clear Error' #for joining in opinion.joining #Output Looks Good #print 'num_opinions', num_opinions #print 'agree', agree #To Make Graphs Equal Lengths, Easier to Compare #Add None to Authored agree_authored_only['None'] = 0 print 'num_opinions', num_opinions #168 agrees with previous print 'sum agree authored only', sum(agree_authored_only.values()) print 'num_joining WRONG', num_joining #576 print 'num_joining LESS None', num_joining - abs(agree_authored_and_joined['None']) 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 #Ratio Join/Opin 3.375 #If desire to normalize graphs #Does Not include None on Joining join_opin_ratio = ( float(num_joining - abs(agree_authored_and_joined['None'])) / float(num_opinions)) print 'join_opin_ratio', join_opin_ratio norm_agree_joining = Bag_O_Judges() for k in agree_authored_only.keys(): norm_agree_joining[k] = agree_authored_and_joined[k] / join_opin_ratio print norm_agree_joining # # From Here, Might Just Be Bar Graphs # # GRAPH # Agree Authored Only # Agree & Joining Normed print 'Start 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 Agreement with Opinions Authored') #plt.xlabel('Opinion Page Length') plt.ylabel('+1 Agree / -1 Disagree') #plt.show() plt.savefig('./output/2018_A4_authored_agree.png') plt.clf() print 'Start 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 Agreement with Opinions Authored or Joined') #plt.xlabel('Opinion Page Length') plt.ylabel('+1 Agree / -1 Disagree') #plt.show() plt.savefig('./output/2018_A4_authored_join_agree.png') plt.clf() graph_my_agreement_with_justices() ######################## # # Printed Output Follows # ######################## ''' num_opinions 168 sum agree authored only 0 num_joining WRONG 576 num_joining LESS None 567 sum joining all 70 agree 0 Authored OrderedCounter(OrderedDict([('Roberts', -2), ('Thomas', -6), ('Ginsburg', 12), ('Breyer', -2), ('Alito', 2), ('Sotomayor', 0), ('Kagan', 0), ('Gorsuch', 2), ('Kavanaugh', -4), ('Per Curiam', -2), ('None', 0)])) Authored & Joining OrderedCounter(OrderedDict([('Roberts', 7), ('Thomas', -1), ('Ginsburg', 17), ('Breyer', 11), ('Alito', 18), ('Sotomayor', 5), ('Kagan', 7), ('Gorsuch', 6), ('Kavanaugh', 11), ('Per Curiam', -2), ('None', -9)])) join_opin_ratio 3.375 OrderedCounter(OrderedDict([('Roberts', 2.074074074074074), ('Thomas', -0.2962962962962963), ('Ginsburg', 5.037037037037037), ('Breyer', 3.259259259259259), ('Alito', 5.333333333333333), ('Sotomayor', 1.4814814814814814), ('Kagan', 2.074074074074074), ('Gorsuch', 1.7777777777777777), ('Kavanaugh', 3.259259259259259), ('Per Curiam', -0.5925925925925926), ('None', -2.6666666666666665)])) Start Agree Graph ('Roberts', 'Thomas', 'Ginsburg', 'Breyer', 'Alito', 'Sotomayor', 'Kagan', 'Gorsuch', 'Kavanaugh', 'Per Curiam', 'None') (-2, -6, 12, -2, 2, 0, 0, 2, -4, -2, 0) Start Agree Authored or Joining Graph ('Roberts', 'Thomas', 'Ginsburg', 'Breyer', 'Alito', 'Sotomayor', 'Kagan', 'Gorsuch', 'Kavanaugh', 'Per Curiam', 'None') (7, -1, 17, 11, 18, 5, 7, 6, 11, -2, -9) '''