Skip to content
Permalink
Browse files

[processing] correctly handle zero in Basic statistics alg (fix #14331)

  • Loading branch information
alexbruy committed Feb 18, 2016
1 parent a0da85f commit d8a5e0fc458538af3456d4b7989488ac0a6c0d94
Showing with 10 additions and 4 deletions.
  1. +10 −4 python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
@@ -57,6 +57,7 @@ class BasicStatisticsNumbers(GeoAlgorithm):
MAJORITY = 'MAJORITY'
FIRSTQUARTILE = 'FIRSTQUARTILE'
THIRDQUARTILE = 'THIRDQUARTILE'
NULLVALUES = 'NULLVALUES'
IQR = 'IQR'

def defineCharacteristics(self):
@@ -86,6 +87,7 @@ def defineCharacteristics(self):
self.addOutput(OutputNumber(self.MAJORITY, self.tr('Majority (most frequently occurring value)')))
self.addOutput(OutputNumber(self.FIRSTQUARTILE, self.tr('First quartile')))
self.addOutput(OutputNumber(self.THIRDQUARTILE, self.tr('Third quartile')))
self.addOutput(OutputNumber(self.NULLVALUES, self.tr('NULL (missed) values')))
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))

def processAlgorithm(self, progress):
@@ -95,8 +97,6 @@ def processAlgorithm(self, progress):

outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)

index = layer.fieldNameIndex(fieldName)

cvValue = 0
minValue = 0
maxValue = 0
@@ -108,6 +108,7 @@ def processAlgorithm(self, progress):
majority = 0
firstQuartile = 0
thirdQuartile = 0
nullValues = 0
iqr = 0

isFirst = True
@@ -117,8 +118,11 @@ def processAlgorithm(self, progress):
count = len(features)
total = 100.0 / float(count)
for current, ft in enumerate(features):
if ft.attributes()[index]:
values.append(float(ft.attributes()[index]))
value = ft[fieldName]
if value or value == 0:
values.append(float(value))
else:
nullValues += 1

progress.setPercentage(int(current * total))

@@ -159,6 +163,7 @@ def processAlgorithm(self, progress):
data.append('Majority (most frequently occurring value): ' + unicode(majority))
data.append('First quartile: ' + unicode(firstQuartile))
data.append('Third quartile: ' + unicode(thirdQuartile))
data.append('NULL (missed) values: ' + unicode(nullValues))
data.append('Interquartile Range (IQR): ' + unicode(iqr))

self.createHTML(outputFile, data)
@@ -176,6 +181,7 @@ def processAlgorithm(self, progress):
self.setOutputValue(self.MAJORITY, majority)
self.setOutputValue(self.FIRSTQUARTILE, firstQuartile)
self.setOutputValue(self.THIRDQUARTILE, thirdQuartile)
self.setOutputValue(self.NULLVALUES, nullValues)
self.setOutputValue(self.IQR, iqr)

def createHTML(self, outputFile, algData):

0 comments on commit d8a5e0f

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