Skip to content

Commit

Permalink
[processing] Make batch processing HTML report more useful
Browse files Browse the repository at this point in the history
Include the input parameter values in the report, otherwise the
results are just a meaningless list of values which can't be
associated with any particular set of inputs

Also correctly handle boolean and other output types
  • Loading branch information
nyalldawson committed Jun 11, 2019
1 parent d10db05 commit e0eedc5
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions python/plugins/processing/gui/BatchAlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def runAlgorithm(self):
feedback.pushInfo(self.tr('Results:'))
feedback.pushCommandInfo(pformat(results))
feedback.pushInfo('')
algorithm_results.append(results)
algorithm_results.append({'parameters': parameters, 'results': results})
else:
break

Expand All @@ -151,7 +151,7 @@ def runAlgorithm(self):

def finish(self, algorithm_results):
for count, results in enumerate(algorithm_results):
self.loadHTMLResults(results, count)
self.loadHTMLResults(results['results'], count)

self.createSummaryTable(algorithm_results)
self.mainWidget().setEnabled(True)
Expand All @@ -176,12 +176,24 @@ def createSummaryTable(self, algorithm_results):

outputFile = getTempFilename('html')
with codecs.open(outputFile, 'w', encoding='utf-8') as f:
for res in algorithm_results:
f.write('<hr>\n')
for i, res in enumerate(algorithm_results):
results = res['results']
params = res['parameters']
if i > 0:
f.write('<hr>\n')
f.write(self.tr('<h3>Parameters</h3>\n'))
f.write('<table>\n')
for param in self.algorithm().parameterDefinitions():
if not param.isDestination():
if param.name() in params:
f.write('<tr><th>{}</th><td>{}</td></tr>\n'.format(param.description(), params[param.name()]))
f.write('</table>\n')
f.write(self.tr('<h3>Results</h3>\n'))
f.write('<table>\n')
for out in self.algorithm().outputDefinitions():
if isinstance(out, (QgsProcessingOutputNumber, QgsProcessingOutputString)) and out.name() in res:
f.write('<p>{}: {}</p>\n'.format(out.description(), res[out.name()]))
f.write('<hr>\n')
if out.name() in results:
f.write('<tr><th>{}</th><td>{}</td></tr>\n'.format(out.description(), results[out.name()]))
f.write('</table>\n')

resultsList.addResult(icon=self.algorithm().icon(),
name='{} [summary]'.format(self.algorithm().name()), timestamp=time.localtime(),
Expand Down

0 comments on commit e0eedc5

Please sign in to comment.