Skip to content
Permalink
Browse files

[processing] fix handling of NULLs is Basic statistics for text fields

  • Loading branch information
alexbruy committed Feb 22, 2016
1 parent 847f1c0 commit d3852e481e435b283a92c0c73a7c904d501f2914
@@ -84,8 +84,8 @@ def processAlgorithm(self, progress):
minValue = 0
maxValue = 0
meanValue = 0
countEmpty = 0
countFilled = 0
nullValues = 0
filledValues = 0

isFirst = True
values = []
@@ -94,7 +94,14 @@ def processAlgorithm(self, progress):
count = len(features)
total = 100.0 / count
for current, ft in enumerate(features):
length = float(len(ft.attributes()[index]))
value = ft[fieldName]
if value:
length = float(len(value))
filledValues += 1
else:
nullValues += 1
progress.setPercentage(int(current * total))
continue

if isFirst:
minValue = length
@@ -106,11 +113,6 @@ def processAlgorithm(self, progress):
if length > maxValue:
maxValue = length

if length != 0.00:
countFilled += 1
else:
countEmpty += 1

values.append(length)
sumValue += length

@@ -128,8 +130,8 @@ def processAlgorithm(self, progress):
data.append('Minimum length: ' + unicode(minValue))
data.append('Maximum length: ' + unicode(maxValue))
data.append('Mean length: ' + unicode(meanValue))
data.append('Filled: ' + unicode(countFilled))
data.append('Empty: ' + unicode(countEmpty))
data.append('Filled values: ' + unicode(filledValues))
data.append('NULL (missed) values: ' + unicode(nullValues))
data.append('Count: ' + unicode(count))
data.append('Unique: ' + unicode(uniqueValues))

@@ -138,8 +140,8 @@ def processAlgorithm(self, progress):
self.setOutputValue(self.MIN_LEN, minValue)
self.setOutputValue(self.MAX_LEN, maxValue)
self.setOutputValue(self.MEAN_LEN, meanValue)
self.setOutputValue(self.FILLED, countFilled)
self.setOutputValue(self.EMPTY, countEmpty)
self.setOutputValue(self.FILLED, filledValues)
self.setOutputValue(self.EMPTY, nullValues)
self.setOutputValue(self.COUNT, count)
self.setOutputValue(self.UNIQUE, uniqueValues)

@@ -63,6 +63,7 @@ tests:
OUTPUT:
name: expected/polys_to_lines.gml
type: vector

- algorithm: qgis:basicstatisticsfornumericfields
name: Test (qgis:basicstatisticsfornumericfields)
params:
@@ -73,3 +74,14 @@ tests:
OUTPUT_HTML_FILE:
name: expected/basic_statistics_numeric_float.html
type: file

- algorithm: qgis:basicstatisticsfortextfields
name: Test (qgis:basicstatisticsfortextfields)
params:
- name: multipolys.gml
type: vector
- 'Bname'
results:
OUTPUT_HTML_FILE:
name: expected/basic_statistics_string.html
type: file
@@ -0,0 +1,12 @@
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>
<p>Analyzed layer: multipolys.gml</p>
<p>Analyzed field: Bname</p>
<p>Minimum length: 4.0</p>
<p>Maximum length: 4.0</p>
<p>Mean length: 4.0</p>
<p>Filled values: 3</p>
<p>NULL (missed) values: 1</p>
<p>Count: 4</p>
<p>Unique: 2</p>
</body></html>

2 comments on commit d3852e4

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Feb 24, 2016

Thanks Alex.

Any thoughts from your side about the testing infrastructure?

@alexbruy

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Feb 24, 2016

It looks great. And in the same time easy to use and understand. Hope we will be able to cover with test most important parts of Processing soon.

Thanks for your hard work!

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