Commits

Amela Rakanovic  committed daae64e

Refactored OWIndContinuousQt

  • Participants
  • Parent commits 35278c5
  • Branches widgets-statistics

Comments (0)

Files changed (2)

File Orange/OrangeWidgets/Statistics/OWComparisonQt.py

     ow = OWComparisonQt()
     ow.show()
     # /home/ami/orange/Orange/doc/datasets
-    dataset = orange.ExampleTable('../doc/datasets/heart_disease.tab')
+    dataset = orange.ExampleTable('heart_disease.tab')
     ow.data(dataset)
     appl.exec_()

File Orange/OrangeWidgets/Statistics/OWIndContinuousQt.py

 from OWScatterPlotGraphQt import *
 
 """
- Statistics: Correlation between continuous variable
+ Statistics: Correlation between continuous variables
 """
 
 class OWIndContinuousQt(OWWidget):
-    settingsList=["grouping_select","test_select", "attributes", "slider_intervals"]
+    settingsList=["test_select"]
    
     def __init__(self, parent=None, signalManager=None):
         OWWidget.__init__(self, parent, signalManager, 'Indenpendance/Correlation between continuous variables')
         self.infot1 = OWGUI.widgetLabel(e, "<center>No test results.<center>")       
     
     def get_color(self, data, maxdata, mindata):
-        """ Calculates color for cells in table based on data """    
+        """Calculates color for cells in table based on data in it
+            Usage::
+                self.get_color(self.correlation_np[a][i], 1, -1)
+
+            return: QColor for selected cell
+        """    
         
         if data != data: #check if NaN
             return Qt.black
             return QColor((1-abs(data/maxdata)*0.75)*255, 1*255, (1-abs(data/maxdata)*0.75)*255)
     
     def set_table(self):
-        """ Sets table for basic statistics """                
+        """Draw appropriate data and look to table"""                
         
         len_attrs = len(self.attributes)
 
-        self.table.setColumnCount(0)
+        #self.table.setColumnCount(0)
         self.table.setColumnCount(len_attrs)
         self.table.setRowCount(len_attrs)
 
         self.table.selectionModel().selectionChanged.connect(self.to_graph)
         
     def to_graph(self):
-        """ Draw appropriate attributes to graph """
+        """ Draw appropriate attributes to graph"""
         
         self.graph.setData(self.ddataset)
         
         if not self.attributes:
             return
         
-        if not (0 <= self.table.currentRow() < self.table.rowCount and 0 <= self.table.currentColumn() < self.table.columnCount):
-            self.table.setCurrentCell(0,0) 
-
+        if not (0 <= self.table.currentRow() < len(self.attributes) and 0 <= self.table.currentColumn() < len(self.attributes)):
+            self.table.setCurrentCell(0,0)
+            
+       
         self.graph.updateData(self.attributes[self.table.currentColumn()].name, self.attributes[self.table.currentRow()].name, "")
-        
+    
         k = self.linear_array_slope[self.table.currentColumn()][self.table.currentRow()]
         n = self.linear_array_intersect[self.table.currentColumn()][self.table.currentRow()]
         tabx = data_to_npcol(self.ddataset, self.attributes[self.table.currentColumn()].name)
         minn = np.min(tabx)
         maxx = np.max(tabx)
-        XX = self.graph.add_curve('test', xData = [minn, maxx], yData = [minn*k+n, maxx*k+n], enableLegend = False, autoScale=0, penColor = Qt.red)
-        XX.set_style(OWCurve.Lines)
+        lin_curve = self.graph.add_curve('test', xData = [minn, maxx], yData = [minn*k+n, maxx*k+n], enableLegend = False, autoScale=0, penColor = Qt.red)
+        lin_curve.set_style(OWCurve.Lines)
         self.infot1.setText("<center>Linear regression: f(x) = %.2f * x + %.2f</center>" % (k, n))
         
         self.graph.set_axis_title(yLeft, self.attributes[self.table.currentRow()].name)
         
         self.graph.set_show_axis_title(yLeft, 1)
         self.graph.set_show_axis_title(xBottom, 1)
-        
+            
         self.graph.replot()
     
     def run_selected_test(self):  
-        """ Runs selected tests """
+        """Runs from UI selected tests"""
         
+        #Linear regression
         if self.linregression_dirty == 0:
             self.linregression_dirty = 1
             self.linear_array_slope, self.linear_array_intersect = [], []
             self.linear_array_slope, self.linear_array_intersect = fun_statistics(self.ddataset, self.attributes, stats.linregress)
         
+        #Pearson test
         if self.test_select == 0:
             if self.pearson_dirty == 0:
                 print 'Running Pearson'
             
             else:
                 self.set_table_graph(self.pearson_array)
-            
+        
+        #Spearman test    
         elif self.test_select == 1:
             if self.spearman_dirty == 0:
                 print 'Running Spearman'
                 self.spearman_array = []
                 self.spearman_array = fun_statistics(self.ddataset, self.attributes, stats.spearmanr)[0]
                     
-                self.set_table_graph(sself.spearman_array)
+                self.set_table_graph(self.spearman_array)
             
             else:
-                self.set_table_graph(sself.spearman_array)
+                self.set_table_graph(self.spearman_array)
+        
+        #Error
         else:
             print 'Error'
 
     def set_table_graph(self, test_array):
+        """Runns functions to redraw table and graph, based on selected options in UI"""
+
         self.correlation_np = np.array(test_array)
         self.set_table()
         self.to_graph()
                  
     def data(self, dataset):
-        
+        """Read data from imported dataset"""
+
+        #*_dirty for not recalculating already calculated stuff 
         self.data_dirty = 0
         self.linregression_dirty = 0
         self.pearson_dirty = 0
+        self.spearman_dirty = 0
+        
+        self.attributes = []
+
         if dataset:
             self.ddataset = dataset
            
-            self.attributes = []
-            
             for attr in dataset.domain:
                 if attr.varType == orange.VarTypes.Continuous:
                     self.attributes.append(attr)
             self.run_selected_test()
                    
         else:
-            self.attributes = []
             self.run_selected_test()
             self.table.clear()
             self.graph.clear()
         pass
                     
     def reset_all_data(self):
-        self.test_select = 0          
-        self.attributes = []
-        self.slider_intervals = 1
+        #self.test_select = 0  
+        pass        
 
 # ***************************************************************************
 # ***************************************************************************
     :param attrs:    list of attribute strings or positions
     :return:         list of numpy columns
     """
+    
     is_single = False
     if not isinstance(attrs, list):
         is_single = True
     :param dataset:     orange dataset - non filtered
     :parm attributes:   continuous attributes
     :param alpha:       function to be runned
-    :return:            (table1, table2)
+    :return:            (table1, table2) - tables full of calculated statisics
     """  
+    
     table1 = []
     table2 = []