Skip to content
Permalink
Browse files

fix basic statistics calculation ( mean no longer always 0.00! )

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10848 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer
cfarmer committed May 25, 2009
1 parent cc5de98 commit aa039cb83c1f588b747da3d142651ea9fdbf926f
Showing with 10 additions and 13 deletions.
  1. +10 −13 python/plugins/fTools/tools/doVisual.py
@@ -174,11 +174,11 @@ def basic_statistics( self, vlayer, myField ):
fields = vprovider.fields()
index = vprovider.fieldNameIndex( myField )
feat = QgsFeature()
sumVal = 0
meanVal = 0
stdVal = 0
cvVal = 0
nVal = 0
sumVal = 0.0
meanVal = 0.0
stdVal = 0.0
cvVal = 0.0
nVal = 0.0
values = []
first = True
nFeat = vprovider.featureCount()
@@ -196,20 +196,17 @@ def basic_statistics( self, vlayer, myField ):
if value < minVal: minVal = value
if value > maxVal: maxVal = value
values.append( value )
sumVal = sumVal + value
sumVal = float( sumVal + value )
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
nVal= float( len( values ) )
print "to here"
if not nVal > 0.00:
print "then here"
if nVal > 0.00:
meanVal = float( sumVal ) / nVal
if not meanVal == 0.00:
for val in values:
stdVal += ( ( val - meanVal ) * ( val - meanVal ) )
print "finally here"
stdVal = math.sqrt( stdVal / nVal )
cvVal = stdVal / meanVal
stdVal += float( ( val - meanVal ) * ( val - meanVal ) )
stdVal = float( math.sqrt( stdVal / nVal ) )
cvVal = float( stdVal / meanVal )
lstStats = []
lstStats.append( "Mean : " + unicode( meanVal ) )
lstStats.append( "StdDev : " + unicode( stdVal ) )

0 comments on commit aa039cb

Please sign in to comment.
You can’t perform that action at this time.