Package client :: Package Dock :: Module Statistics
[hide private]
[frames] | no frames]

Source Code for Module client.Dock.Statistics

  1  import PyQt4.QtCore 
  2  import PyQt4.QtGui 
  3   
  4  import Constants 
  5  import Widget 
  6  import Holders 
  7   
8 -class AbstractStatistics (Widget.DockWidget):
9 - def __init__ (self, parent, bridge):
10 self._type = "Statistics" 11 Widget.DockWidget.__init__ (self, parent, bridge)
12
13 - def _addCommands (self):
14 box = PyQt4.QtGui.QGroupBox ("Commands") 15 layout = PyQt4.QtGui.QHBoxLayout (box) 16 17 transformButton = Constants.BQPushButton ("Execute", layout) 18 PyQt4.QtCore.QObject.connect (transformButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.execute) 19 20 clearButton = Constants.BQPushButton ("Clear", layout) 21 PyQt4.QtCore.QObject.connect (clearButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.clear) 22 23 return box
24
25 - def _addDataSelection (self):
26 outline = PyQt4.QtGui.QGroupBox ("Data Selection") 27 self.list = Holders.FreeHolderGroup (self._bridge, self._inList, self._outList) 28 layout = self.list.layout 29 outline.setLayout (layout) 30 return outline
31
32 - def clear (self):
33 self.list.clear () 34 for holder in self.list._inList: 35 holder.clear () 36 for holder in self.list._outList: 37 holder.clear ()
38
39 - def DoubleClicked (self, attr = None):
40 if attr == None: 41 attr = self._bridge._regionViewer.getSingleSelectedItem () 42 43 if attr.Type () == "ALIAS": 44 attr = attr._item 45 46 if attr.Type () == "ATTRIBUTE" or \ 47 (attr.Type () == "VALUE" and attr._type == "_basin.Attribute"): 48 for holder in self.list._inList: 49 if holder.SetItem (attr, clobber = False) == True: 50 return 51 elif attr.Type () == "LIST": 52 if self.list.text () == "None": 53 self.list.setText (attr.text (0)) 54 self.list._shellAccess = attr._shellAccess
55
56 - def setOutput (self, state):
57 self.clear () 58 if state == 0: 59 self.list.setEnabled (False) 60 elif state == 2: 61 self.list.setEnabled (True)
62
63 - def execute (self):
64 if not ( self._bridge._connected == True and self._bridge._parallel == True): 65 return False 66 67 inAttributes = "" 68 result = self.list.getInAccesses () 69 if result == False: 70 return 71 for attr in result: 72 inAttributes = str (attr) 73 outAttributes = "" 74 result = self.list.getOutNames () 75 if result == False: 76 return 77 for attr in result: 78 outAttributes = str (attr) 79 80 commands = [] 81 for out in self.list.getOutNames (): 82 commands.append (str (out) + " = Attribute ()") 83 84 commands.append (outAttributes + " = " + \ 85 self._funcName + " (" + inAttributes + ")") 86 87 self._bridge._ipyShell.BatchCommands (commands, True) 88 89 for holder in self.list._inList: 90 holder.clear () 91 for holder in self.list._outList: 92 holder.clear () 93 self.list.clear ()
94 95
96 -class Mean (AbstractStatistics):
97 - def __init__ (self, parent, bridge):
98 self._funcName = "mean" 99 self._displayName = "Mean" 100 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/statistics/mean.png") 101 self._description = "Simply place an attribute in the `in` holder. The `mask` holder is optional. " + \ 102 "Clicking the `Execute` will create a new free variable!" 103 self._inList = ["in", "mask"] 104 self._outList = ["out"] 105 AbstractStatistics.__init__ (self, parent, bridge)
106
107 - def execute (self):
108 if not ( self._bridge._connected == True and self._bridge._parallel == True): 109 return False 110 _in = self.list.getInAccesses (False) 111 _out = self.list.getOutNames (False) 112 if len (_in) == 0 or len (_out) == 0: 113 return False 114 115 begin = _out[0] + " = " + self._funcName + "(" + _in[0] 116 117 commands = [] 118 if len (_in) == 1: 119 commands.append (begin + ")") 120 elif len (_in) == 2: 121 commands.append (begin + ", " + _in[1] + ")") 122 self._bridge._ipyShell.BatchCommands (commands, True) 123 124 for holder in self.list._inList: 125 holder.clear () 126 for holder in self.list._outList: 127 holder.clear () 128 self.list.clear ()
129 130
131 -class StandardDeviation (AbstractStatistics):
132 - def __init__ (self, parent, bridge):
133 self._funcName = "stdev" 134 self._displayName = "Standard Deviation" 135 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/statistics/stddev.png") 136 self._description = "Simply place an attribute in the `in` holder. The `mask` holder is optional. Clicking the `Execute` will create a new free variable!" 137 self._inList = ["in", "mask"] 138 self._outList = ["out"] 139 AbstractStatistics.__init__ (self, parent, bridge)
140
141 - def execute (self):
142 if not ( self._bridge._connected == True and self._bridge._parallel == True): 143 return False 144 _in = self.list.getInAccesses (False) 145 _out = self.list.getOutNames (False) 146 if len (_in) == 0 or len (_out) == 0: 147 return False 148 149 begin = _out[0] + " = " + self._funcName + "(" + _in[0] 150 151 commands = [] 152 if len (_in) == 1: 153 commands.append (begin + ")") 154 elif len (_in) == 2: 155 commands.append (begin + ", " + _in[1] + ")") 156 self._bridge._ipyShell.BatchCommands (commands, True) 157 158 for holder in self.list._inList: 159 holder.clear () 160 for holder in self.list._outList: 161 holder.clear () 162 self.list.clear ()
163 164
165 -class Histogram (AbstractStatistics):
166 - def __init__ (self, parent, bridge):
167 self._funcName = "histogram" 168 self._displayName = "Histogram" 169 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/statistics/histogram.png") 170 self._description = "Simply place an attribute in the `in` holder. The `mask` holder is optional. " + \ 171 "Clicking the `Execute` will create a new free variable!" 172 self._inList = ["in"] 173 self._outList = ["out"] 174 AbstractStatistics.__init__ (self, parent, bridge) 175 176 self._binmin = PyQt4.QtGui.QDoubleSpinBox () 177 self._binmin.setRange (-999999999.9, 999999999.9) 178 self._dbin = PyQt4.QtGui.QDoubleSpinBox () 179 self._dbin.setRange (0.0, 999999999.9) 180 self._nbins = PyQt4.QtGui.QSpinBox () 181 self._nbins.setRange (1, 999999999) 182 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("bin min:"), 2, 0, PyQt4.QtCore.Qt.AlignRight) 183 self.list.layout.addWidget (self._binmin, 2, 1, PyQt4.QtCore.Qt.AlignLeft) 184 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("d bin:"), 3, 0, PyQt4.QtCore.Qt.AlignRight) 185 self.list.layout.addWidget (self._dbin, 3, 1, PyQt4.QtCore.Qt.AlignLeft) 186 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("n bins:"), 4, 0, PyQt4.QtCore.Qt.AlignRight) 187 self.list.layout.addWidget (self._nbins, 4, 1, PyQt4.QtCore.Qt.AlignLeft)
188
189 - def execute (self):
190 if not ( self._bridge._connected == True and self._bridge._parallel == True): 191 return False 192 _in = self.list.getInAccesses (False) 193 _out = self.list.getOutNames (False) 194 if len (_in) == 0 or len (_out) == 0: 195 return False 196 197 begin = _out[0] + " = " + self._funcName + "(" + _in[0] 198 199 commands = [] 200 commands.append (begin + ", " + str (self._binmin.value ()) + \ 201 ", " + str (self._dbin.value ()) + ", " + str (self._nbins.value ()) + ")") 202 self._bridge._ipyShell.BatchCommands (commands, True) 203 204 for holder in self.list._inList: 205 holder.clear () 206 for holder in self.list._outList: 207 holder.clear () 208 self.list.clear ()
209