From 347a6ef8bcb6d37fe166a5f6988a6c0e7ec6eee1 Mon Sep 17 00:00:00 2001 From: Eva Schiffer <evas@ssec.wisc.edu> Date: Mon, 8 Nov 2021 10:59:37 -0600 Subject: [PATCH] three column stats on gui comparisons --- pyglance/glance/gui_statsprovider.py | 15 ++++++--- pyglance/glance/report.py | 46 ++-------------------------- pyglance/glance/stats.py | 43 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/pyglance/glance/gui_statsprovider.py b/pyglance/glance/gui_statsprovider.py index b58c72b..c15021e 100644 --- a/pyglance/glance/gui_statsprovider.py +++ b/pyglance/glance/gui_statsprovider.py @@ -101,10 +101,12 @@ class GlanceGUIStats (object) : epsilon=self.dataModel.getEpsilon(), epsilon_percent=self.dataModel.getEpsilonPercent()) # package up the data for the report - tempInfo = { constants.VARIABLE_TECH_NAME_KEY: aVarName, - constants.VARIABLE_B_TECH_NAME_KEY: bVarName } - kwargs = { constants.RUN_INFO_DICT_KEY: tempInfo, - constants.STATS_INFO_DICT_KEY: tempAnalysis.dictionary_form() } + tempStatsDict = tempAnalysis.dictionary_form() + tempInfo = { constants.VARIABLE_TECH_NAME_KEY: aVarName, + constants.VARIABLE_B_TECH_NAME_KEY: bVarName } + kwargs = { constants.RUN_INFO_DICT_KEY: tempInfo, + constants.STATS_INFO_DICT_KEY: tempStatsDict, + constants.GROUPED_STATS_INFO_DICT_KEY: stats.group_stats_by_file(tempStatsDict), } # use a mako template to render an html verion of the stats for display templateLookup = TemplateLookup(directories=[resource_filename(__name__, ".")]) @@ -125,9 +127,12 @@ class GlanceGUIStats (object) : # do the statistical analysis and collect the data that will be needed to render it nicely tempAnalysis = stats.StatisticalInspectionAnalysis.withDataObjects(dataObject) # package up the data for the report + tempStatsDict = tempAnalysis.dictionary_form() tempInfo = { constants.VARIABLE_TECH_NAME_KEY: varName } kwargs = { constants.RUN_INFO_DICT_KEY: tempInfo, - constants.STATS_INFO_DICT_KEY: tempAnalysis.dictionary_form() } + constants.STATS_INFO_DICT_KEY: tempStatsDict, + #constants.GROUPED_STATS_INFO_DICT_KEY: stats.group_stats_by_file(tempStatsDict), # FUTURE, we may want to do this some day, but it looks awful now + } # use a mako template to render an html verion of the stats for display templateLookup = TemplateLookup(directories=[resource_filename(__name__, ".")]) diff --git a/pyglance/glance/report.py b/pyglance/glance/report.py index d3cea10..429665b 100644 --- a/pyglance/glance/report.py +++ b/pyglance/glance/report.py @@ -18,6 +18,7 @@ import shutil as shutil import locale from glance.constants import * +import glance.stats as stats LOG = logging.getLogger(__name__) @@ -212,49 +213,6 @@ def generate_and_save_doc_page(definitions, outputPath) : return -def group_stats_by_file(statGroups): - """ Group statistics by file - - Where there are pairs of statistics in the form *_[ab] or [ab]_*, group - them together. So given - - { 'General Statistics': { - 'min_a': -1, - 'min_b': -10 - 'epsilon': 3 - } - } - - returns - - { 'General Statistics': { - 'min': { 'a': -1. b: -10 }, - 'epsilon': { 'both':3 } - } - } - - """ - - def id_file(varname): - if varname[1] == "_": - return (varname[2:], varname[0]) - if varname[-2] == "_": - return (varname[:-2], varname[-1]) - return (varname, "both") - - ret = {} - - for groupname, group in statGroups.items(): - ret[groupname] = {} - for var, val in group.items(): - justvar, file = id_file(var) - #sys.stderr.write("{0} -> {1} {2}\n".format(var, justvar, file)) - if justvar not in ret[groupname]: - ret[groupname][justvar] = { 'a':'', 'b':'', 'both':''} - ret[groupname][justvar][file] = val - - return ret - def generate_and_save_concise_report(outputPath, reportFileName, summaryInfo,): """ @@ -460,7 +418,7 @@ def generate_and_save_variable_report(files, runInfo = generalRunInfo.copy() runInfo.update(variableRunInfo) - groupedStats = group_stats_by_file(statGroups) + groupedStats = stats.group_stats_by_file(statGroups) # put all the info together in the kwargs kwargs = { diff --git a/pyglance/glance/stats.py b/pyglance/glance/stats.py index ee3b5b4..04505d5 100644 --- a/pyglance/glance/stats.py +++ b/pyglance/glance/stats.py @@ -1112,6 +1112,49 @@ def get_comparison_doc_string ( ) : def get_inspection_doc_string ( ) : return '\n'.join( '%s:\n %s' % x for x in sorted(list(StatisticalInspectionAnalysis.doc_strings().items())) ) + '\n' +def group_stats_by_file(statGroups): + """ Group statistics by file + + Where there are pairs of statistics in the form *_[ab] or [ab]_*, group + them together. So given + + { 'General Statistics': { + 'min_a': -1, + 'min_b': -10 + 'epsilon': 3 + } + } + + returns + + { 'General Statistics': { + 'min': { 'a': -1. b: -10 }, + 'epsilon': { 'both':3 } + } + } + + """ + + def id_file(varname): + if varname[1] == "_": + return (varname[2:], varname[0]) + if varname[-2] == "_": + return (varname[:-2], varname[-1]) + return (varname, "both") + + ret = {} + + for groupname, group in statGroups.items(): + ret[groupname] = {} + for var, val in group.items(): + justvar, file = id_file(var) + #sys.stderr.write("{0} -> {1} {2}\n".format(var, justvar, file)) + if justvar not in ret[groupname]: + ret[groupname][justvar] = { 'a':'', 'b':'', 'both':''} + ret[groupname][justvar][file] = val + + return ret + if __name__=='__main__': import doctest doctest.testmod() -- GitLab