CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Member Functions

dirstructure::Directory Class Reference

Inheritance diagram for dirstructure::Directory:
dirstructure::Weighted

List of all members.

Public Member Functions

def __init__
def __repr__
def calcStats
def get_fail_rate
def get_null_rate
def get_skiped_rate
def get_subdirs_dict
def get_subdirs_names
def get_success_rate
def get_summary_chart_ajax
def get_summary_chart_name
def is_empty
def print_report
def prune

Public Attributes

 comparisons
 do_pngs
 draw_success
 meta
 mother_dir
 n_comp_fails
 n_comp_nulls
 n_comp_skiped
 n_comp_successes
 n_fails
 n_nulls
 n_skiped
 n_successes
 rank_histo
 stats_calculated
 subdirs
 weight

Private Member Functions

def __create_on_disk
def __create_pie_image
def __get_full_path

Detailed Description

Definition at line 61 of file dirstructure.py.


Constructor & Destructor Documentation

def dirstructure::Directory::__init__ (   self,
  name,
  mother_dir = "",
  meta = CompInfo(),
  draw_success = False,
  do_pngs = False 
)

Definition at line 62 of file dirstructure.py.

00063                                                                                         :
00064     self.mother_dir=mother_dir
00065     self.meta=meta
00066     self.subdirs=[]
00067     self.comparisons=[]   
00068     self.n_fails=0
00069     self.n_successes=0
00070     self.n_nulls=0
00071     self.n_skiped = 0
00072     self.n_comp_skiped = 0
00073     self.n_comp_fails=0
00074     self.n_comp_successes=0
00075     self.n_comp_nulls=0 
00076     self.weight=0
00077     self.stats_calculated=False
00078     Weighted.__init__(self,name)
00079     self.draw_success=draw_success
00080     self.do_pngs=do_pngs
00081     self.rank_histo=TH1I("rh%s"%name,"",50,-0.01,1.001)
00082     self.rank_histo.SetDirectory(0)


Member Function Documentation

def dirstructure::Directory::__create_on_disk (   self) [private]

Definition at line 211 of file dirstructure.py.

00212                             :
00213     if not exists(self.mother_dir) and len(self.mother_dir)!=0:
00214       makedirs(self.mother_dir)
00215     full_path=self.__get_full_path()    
00216     if not exists(full_path) and len(full_path)>0:
00217       makedirs(full_path)

def dirstructure::Directory::__create_pie_image (   self) [private]

Definition at line 221 of file dirstructure.py.

00222                               :
00223     self.__create_on_disk()
00224     vals=[]
00225     colors=[]
00226     for n,col in zip((self.n_fails,self.n_nulls,self.n_successes,self.n_skiped),(kRed,kYellow,kGreen,kBlue)):
00227       if n!=0:
00228         vals.append(n)
00229         colors.append(col)
00230     valsa=array('f',vals)
00231     colorsa=array('i',colors)
00232     can = TCanvas("cpie","TPie test",100,100);
00233     try:
00234       pie = TPie("ThePie",self.name,len(vals),valsa,colorsa);
00235       label_n=0
00236       if self.n_fails!=0:
00237         pie.SetEntryLabel(label_n, "Fail: %.1f(%i)" %(self.get_fail_rate(),self.n_fails) );
00238         label_n+=1
00239       if self.n_nulls!=0:
00240         pie.SetEntryLabel(label_n, "Null: %.1f(%i)" %(self.get_null_rate(),self.n_nulls) );      
00241         label_n+=1
00242       if self.n_successes!=0:
00243         pie.SetEntryLabel(label_n, "Success: %.1f(%i)" %(self.get_success_rate(),self.n_successes) );
00244       if self.n_skiped!=0:
00245         pie.SetEntryLabel(label_n, "Skipped: %.1f(%i)" %(self.get_skiped_rate(),self.n_skiped));
00246       pie.SetY(.52);
00247       pie.SetAngularOffset(0.);    
00248       pie.SetLabelsOffset(-.3);
00249       #pie.SetLabelFormat("#splitline{%val (%perc)}{%txt}");
00250       pie.Draw("3d  nol");
00251       can.Print(self.get_summary_chart_name());    
00252     except:
00253       print "self.name = %s" %self.name
00254       print "len(vals) = %s (vals=%s)" %(len(vals),vals)
00255       print "valsa = %s" %valsa
00256       print "colorsa = %s" %colorsa

def dirstructure::Directory::__get_full_path (   self) [private]

Definition at line 205 of file dirstructure.py.

00206                            :
00207     #print "Mother is %s" %self.mother_dir
00208     if len(self.mother_dir)==0:
00209       return self.name
00210     return join(self.mother_dir,self.name)
    
def dirstructure::Directory::__repr__ (   self)

Definition at line 301 of file dirstructure.py.

00302                     :
00303     if self.is_empty():
00304       return "%s seems to be empty. Please check!" %self.name
00305     content="%s , Rates: Success %.2f%%(%s) - Fail %.2f%%(%s) - Null %.2f%%(%s)\n" %(self.name,self.get_success_rate(),self.n_successes,self.get_fail_rate(),self.n_fails,self.get_null_rate(),self.n_nulls)   
00306     for subdir in self.subdirs:
00307       content+=" %s\n" % subdir
00308     for comp in self.comparisons:
00309       content+=" %s\n" % comp
00310     return content
00311     
#-------------------------------------------------------------------------------
def dirstructure::Directory::calcStats (   self,
  make_pie = True 
)
Walk all subdirs and calculate weight,fails and successes.
Moreove propagate the sample and releases names.

Definition at line 88 of file dirstructure.py.

00089                                    :
00090     '''Walk all subdirs and calculate weight,fails and successes.
00091     Moreove propagate the sample and releases names.
00092     '''
00093     if self.stats_calculated:
00094       return 0
00095     
00096     self.n_fails=0
00097     self.n_successes=0
00098     self.n_nulls=0
00099     self.n_comp_fails=0
00100     self.n_comp_successes=0
00101     self.n_comp_nulls=0  
00102     self.weight=0
00103     
00104     self.n_skiped = 0
00105     self.n_comp_skiped = 0
00106     
00107     # clean from empty dirs    
00108     self.subdirs = filter(lambda subdir: not subdir.is_empty(),self.subdirs)    
00109     
00110     for comp in self.comparisons:
00111       if comp.status == SKIPED: #in case its in black list & skiped 
00112           self.n_skiped += 1
00113           self.n_comp_skiped += 1
00114           self.weight+=1
00115       else: #else original code -> to check for Fails and Successes
00116           self.rank_histo.Fill(comp.rank)
00117           self.weight+=1
00118           if comp.status == FAIL:
00119               self.n_fails+=1
00120               self.n_comp_fails+=1
00121           elif comp.status == SUCCESS:
00122               self.n_successes+=1
00123               self.n_comp_successes+=1
00124           else:
00125               self.n_nulls+=1
00126               self.n_comp_nulls+=1
00127 
00128     for subdir in self.subdirs:
00129       subdir.mother_dir=join(self.mother_dir,self.name)
00130       subdir.calcStats(make_pie)
00131       subdir.meta=self.meta 
00132       self.weight+=subdir.weight
00133       self.n_fails+=subdir.n_fails
00134       self.n_successes+=subdir.n_successes
00135       self.n_nulls+=subdir.n_nulls
00136       
00137       self.n_skiped+=subdir.n_skiped
00138       
00139       self.rank_histo.Add(subdir.rank_histo)
00140 
00141     self.stats_calculated=True 
00142     #if make_pie:
00143       #self.__create_pie_image()

def dirstructure::Directory::get_fail_rate (   self)

Definition at line 193 of file dirstructure.py.

00194                          :
00195     if self.weight == 0:return 0
00196     return 100.*self.n_fails/self.weight
    
def dirstructure::Directory::get_null_rate (   self)

Definition at line 201 of file dirstructure.py.

00202                          :
00203     if self.weight == 0:return 0    
00204     return 100.*self.n_nulls/self.weight

def dirstructure::Directory::get_skiped_rate (   self)

Definition at line 190 of file dirstructure.py.

00191                            :
00192     if self.weight == 0: return 0
    return 100.*self.n_skiped/self.weight
def dirstructure::Directory::get_subdirs_dict (   self)

Definition at line 144 of file dirstructure.py.

00145                             :
00146     subdirdict={}
00147     for subdir in self.subdirs:
00148       subdirdict[subdir.name]=subdir
00149     return subdirdict

def dirstructure::Directory::get_subdirs_names (   self)

Definition at line 150 of file dirstructure.py.

00151                              :
00152     subdirnames=[]
00153     for subdir in self.subdirs:
00154       subdirnames.append(subdir.name)
00155     return subdirnames

def dirstructure::Directory::get_success_rate (   self)

Definition at line 197 of file dirstructure.py.

00198                             :
00199     if self.weight == 0:return 1    
00200     return 100.*self.n_successes/self.weight
    
def dirstructure::Directory::get_summary_chart_ajax (   self,
  w = 400,
  h = 300 
)
Emit the ajax to build a pie chart using google apis...

Definition at line 156 of file dirstructure.py.

00157                                               :
00158     """Emit the ajax to build a pie chart using google apis...
00159     """
00160     url = "https://chart.googleapis.com/chart?"
00161     url+= "cht=p3" # Select the 3d chart
00162     #url+= "&chl=Success|Null|Fail" # give labels
00163     url+= "&chco=00FF00|FFFF00|FF0000|7A7A7A" # give colours to labels
00164     url+= "&chs=%sx%s" %(w,h)
00165     #url+= "&chtt=%s" %self.name
00166     url+= "&chd=t:%.2f,%.2f,%.2f,%.2f"%(self.get_success_rate(),self.get_null_rate(),self.get_fail_rate(),self.get_skiped_rate())
00167     
00168     return url

def dirstructure::Directory::get_summary_chart_name (   self)

Definition at line 218 of file dirstructure.py.

00219                                   :
00220     return join(self.__get_full_path(),"summary_chart.png") 

def dirstructure::Directory::is_empty (   self)

Definition at line 83 of file dirstructure.py.

00084                     :
00085     if len(self.subdirs)==0 and len(self.comparisons)==0:
00086       return True
00087     return False
  
def dirstructure::Directory::print_report (   self,
  indent = "",
  verbose = False 
)

Definition at line 169 of file dirstructure.py.

00170                                                 :
00171     if len(indent)==0:
00172       self.calcStats(make_pie=False)
00173     # print small failure report
00174     if verbose:
00175       fail_comps=filter(lambda comp:comp.status==FAIL,self.comparisons)
00176       fail_comps=sorted(fail_comps,key=lambda comp:comp.name )    
00177       if len(fail_comps)>0:
00178         print indent+"* %s/%s:" %(self.mother_dir,self.name)
00179         for comp in fail_comps:
00180           print indent+" - %s: %s Test Failed (pval = %s) " %(comp.name,comp.test_name,comp.rank)
00181       for subdir in self.subdirs:
00182         subdir.print_report(indent+"  ",verbose)
00183     
00184     if len(indent)==0:
00185       print "\n%s - summary of %s tests:" %(self.name,self.weight)
00186       print " o Failiures: %.2f%% (%s/%s)" %(self.get_fail_rate(),self.n_fails,self.weight)
00187       print " o Nulls: %.2f%% (%s/%s) " %(self.get_null_rate(),self.n_nulls,self.weight)
00188       print " o Successes: %.2f%% (%s/%s) " %(self.get_success_rate(),self.n_successes,self.weight)
00189       print " o Skipped: %.2f%% (%s/%s) " %(self.get_skiped_rate(),self.n_skiped,self.weight)

def dirstructure::Directory::prune (   self,
  expandable_dir 
)
Eliminate from the tree the directory the expandable ones.

Definition at line 257 of file dirstructure.py.

00258                                 :
00259     """Eliminate from the tree the directory the expandable ones.
00260     """
00261     #print "pruning %s" %self.name
00262     exp_index=-1
00263     counter=0
00264     for subdir in self.subdirs:      
00265       # Eliminate any trace of the expandable path in the mother directories
00266       # for depths higher than 1
00267       subdir.mother_dir=subdir.mother_dir.replace("/"+expandable_dir,"")
00268       if subdir.name==expandable_dir:        
00269         exp_index=counter
00270       counter+=1
00271     
00272     # Did we find an expandable?
00273     if exp_index>=0:
00274       exp_dir=self.subdirs[exp_index]
00275       for subsubdir in exp_dir.subdirs:
00276         #print "*******",subsubdir.mother_dir,
00277         subsubdir.mother_dir=subsubdir.mother_dir.replace("/"+expandable_dir,"")
00278         while "//" in subsubdir.mother_dir:
00279           print subsubdir.mother_dir
00280           subsubdir.mother_dir=subsubdir.mother_dir.replace("//","/") 
00281         #print "*******",subsubdir.mother_dir
00282         self.subdirs.append(subsubdir)
00283           
00284         for comp in exp_dir.comparisons:
00285           comp.mother_dir=comp.mother_dir.replace("/"+expandable_dir,"")        
00286           while "//" in comp.mother_dir:
00287               comp.mother_dir
00288               comp.mother_dir=comp.mother_dir.replace("/")
00289           if not comp in self.comparisons:  #in case not to  append same comparisons few times
00290               self.comparisons.append(comp)  # add a comparison
00291               self.n_comp_fails = exp_dir.n_comp_fails  #copy to-be removed directory
00292               self.n_comp_nulls = exp_dir.n_comp_nulls  # numbers to parent directory
00293               self.n_comp_successes = exp_dir.n_comp_successes
00294               self.n_comp_skiped = exp_dir.n_comp_skiped
00295         
00296       del self.subdirs[exp_index]
00297       self.prune(expandable_dir)
00298     
00299     for subdir in self.subdirs:
00300       subdir.prune(expandable_dir)


Member Data Documentation

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Definition at line 62 of file dirstructure.py.

Reimplemented from dirstructure::Weighted.

Definition at line 62 of file dirstructure.py.