コード例 #1
0
    def boot_strap_and_write_overall_lists(dictionary_of_lists, csv_title):
        
        if not os.path.exists(Writing_Path):
            os.makedirs(Writing_Path)   
        
        print "Boot Strapping and Writing " + csv_title + " to file"
        
        header = ['IPEDS', 'School', '25th Percentile Pay', 'Median Pay', '75th Percentile Pay',
                  'Confidence Level on the Median', "Report or Don't Report",'Lower Bound 90% CI(25th)',
                  'Upper Bound 90% CI(25th)', 'Lower Bound 90% CI(50th)','Upper Bound 90% CI(50th)',
                  'Lower Bound 90% CI(75th)','Upper Bound 90% CI(75th)']        
                
        with open(Writing_Path + todaysdateAlt + " " + csv_title, 'wb') as f:
            writer = csv.writer(f, delimiter="|", lineterminator='\n')
            writer.writerow(header)
            
            counter = 0
               
            for Keys in dictionary_of_lists:
                
                counter += 1

                print "Boot Strapping " + Keys + " which is %s of 1055" % counter
                
                Schools = Keys
                
                IPEDS = IPEDS_Mapping[Schools]
                
                Twenty_Fifth = aequitas_functions.boot_strap(dictionary_of_lists[Keys],1000,25)
                Fiftieth = aequitas_functions.boot_strap(dictionary_of_lists[Keys],1000,50)
                Seventy_Fifth = aequitas_functions.boot_strap(dictionary_of_lists[Keys],1000,75)
                            
                
                Twenty_Five, TFerror, TFTenth, TFNinetieth, TFDistance = Twenty_Fifth
                Median, Merror, MTenth, MNinetieth, MDistance = Fiftieth
                Seventy_Five, SFerror, SFTenth, SFNinetieth, SFDistance = Seventy_Fifth
                
                if Merror in ['Low Data','Very Low']:
                    Report = "Don't Report"
                    
                if Merror in ['No Data','N/R']:
                    continue

                if Merror not in ['Low Data','No Data','N/R','Very Low']:
                    Report = "Report"             

                if Median == Twenty_Five or Median == Seventy_Five:
                    Twenty_Five = 'Low Data'
                    Seventy_Five = 'Low Data'
                    
                if Median == 'No Data':
                    Twenty_Five = 'No Data'
                    Seventy_Five = 'No Data'    
                    
                if Merror == 'Low Data':
                    Twenty_Five = 'Low Data'
                    Seventy_Five = 'Low Data'        

                Final = IPEDS, Schools, Twenty_Five, Median, Seventy_Five, Merror, Report, TFTenth, TFNinetieth, MTenth, \
                        MNinetieth, SFTenth, SFNinetieth
                        
                writer.writerow(Final)
コード例 #2
0
    def boot_strap_and_write_lists(self, dictionary_of_lists, csv_title):
        
        if not os.path.exists(Writing_Path):
            os.makedirs(Writing_Path)   
            
        dict_keys = dictionary_of_lists.keys()
        
        print "Boot Strapping and Writing " + csv_title + " to file"
        
        header = ['IPEDS ID', 'School', 'Major', 'CIP Code', '25th Percentile Pay', 'Median Pay', '75th Percentile Pay',
                  'Confidence Level on the Median', "Report or Don't Report", 'Lower Bound 90% CI(25th)',
                  'Upper Bound 90% CI(25th)', 'Lower Bound 90% CI(50th)', 'Upper Bound 90% CI(50th)',
                  'Lower Bound 90% CI(75th)', 'Upper Bound 90% CI(75th)']
                
        with open(Writing_Path + todaysdateAlt + " " + csv_title, 'wb') as f:
            writer = csv.writer(f, delimiter="|", lineterminator='\n')
            writer.writerow(header)
        
            for i, keys in enumerate(dict_keys):
                print "Boot Strapping the " + keys + " CIP Code"
                counter = 0
                for Schools in dictionary_of_lists[keys]:
                    counter += 1
                    
                    if counter % 50 == 0:
                        print "Bootstrapped %s Schools" % counter
                        
                    ipeds_id = IPEDS_Mapping[Schools]
                    cip_code = keys
                    Major = CIP_Mapping[keys]

                    if self.reality_check(ipeds_id, cip_code) is False:
                        
                        self.bad_reports(ipeds_id, Schools, cip_code, Major, "Reality Check", Bad_Report_List)
                        continue

                    else:
                        
                        twenty_fifth = aequitas_functions.boot_strap(dictionary_of_lists[keys][Schools], 1000, 25)
                        fiftieth = aequitas_functions.boot_strap(dictionary_of_lists[keys][Schools], 1000, 50)
                        seventy_fifth = aequitas_functions.boot_strap(dictionary_of_lists[keys][Schools], 1000, 75)
                        
                        twenty_five, t_f_error, t_f_tenth, t_f_ninetieth, t_f_distance = twenty_fifth
                        median, m_error, m_tenth, m_ninetieth, m_distance = fiftieth
                        seventy_five, s_f_error, s_f_tenth, SFNinetieth, SFDistance = seventy_fifth

                        report = "Don't Report"
                        
                        if m_error in ['Low Data', 'Very Low', 'No Data']:
                            report = "Don't Report"

                        elif m_error not in ['Low Data', 'No Data', 'N/R', 'Very Low']:
                            report = "Report"
                            
                        if m_error == 'No Data':
                            self.bad_reports(ipeds_id, Schools, cip_code, Major, "No Data or less than 5",
                                             Bad_Report_List)
                            continue
                            
                        if m_error == 'N/R':
                            self.bad_reports(ipeds_id, Schools, cip_code, Major, "High Variability", Bad_Report_List)
                            continue

                        if median == twenty_five or median == seventy_five:
                            twenty_five = 'Low Data'
                            seventy_five = 'Low Data'
                            
                        if median == 'No Data':
                            twenty_five = 'No Data'
                            seventy_five = 'No Data'
                            
                        if m_error == 'Low Data':
                            twenty_five = 'Low Data'
                            seventy_five = 'Low Data'

                        final = ipeds_id, Schools, Major, cip_code, twenty_five, median, seventy_five, m_error, \
                                report, t_f_tenth, t_f_ninetieth, m_tenth, m_ninetieth, \
                                s_f_tenth, SFNinetieth
                                
                        writer.writerow(final)