def report_messages_by_module_stats(sect, stats, _):
if len(stats["<STR_LIT>"]) == <NUM_LIT:1>:<EOL><INDENT>raise exceptions.EmptyReportError()<EOL><DEDENT>by_mod = collections.defaultdict(dict)<EOL>for m_type in ("<STR_LIT>", "<STR_LIT:error>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>total = stats[m_type]<EOL>for module in stats["<STR_LIT>"].keys():<EOL><INDENT>mod_total = stats["<STR_LIT>"][module][m_type]<EOL>if total == <NUM_LIT:0>:<EOL><INDENT>percent = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>percent = float((mod_total) * <NUM_LIT:100>) / total<EOL><DEDENT>by_mod[module][m_type] = percent<EOL><DEDENT><DEDENT>sorted_result = []<EOL>for module, mod_info in by_mod.items():<EOL><INDENT>sorted_result.append(<EOL>(<EOL>mod_info["<STR_LIT:error>"],<EOL>mod_info["<STR_LIT>"],<EOL>mod_info["<STR_LIT>"],<EOL>mod_info["<STR_LIT>"],<EOL>module,<EOL>)<EOL>)<EOL><DEDENT>sorted_result.sort()<EOL>sorted_result.reverse()<EOL>lines = ["<STR_LIT>", "<STR_LIT:error>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>for line in sorted_result:<EOL><INDENT>if all(entry == <NUM_LIT:0> for entry in line[:-<NUM_LIT:1>]):<EOL><INDENT>continue<EOL><DEDENT>lines.append(line[-<NUM_LIT:1>])<EOL>for val in line[:-<NUM_LIT:1>]:<EOL><INDENT>lines.append("<STR_LIT>" % val)<EOL><DEDENT><DEDENT>if len(lines) == <NUM_LIT:5>:<EOL><INDENT>raise exceptions.EmptyReportError()<EOL><DEDENT>sect.append(report_nodes.Table(children=lines, cols=<NUM_LIT:5>, rheaders=<NUM_LIT:1>))<EOL>
make errors / warnings by modules report