Skip to content

Commit da319b7

Browse files
committed
htmlreport: stats: sort primary by occurrences but if several IDs occur equally often, sort them alphabetically.
1 parent 65e9085 commit da319b7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

htmlreport/cppcheck-htmlreport

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,21 @@ if __name__ == '__main__':
417417
stats.append(error['id']) # get the stats
418418

419419
stat_html = []
420-
for _id, _number in Counter(stats).most_common():
421-
stat_html.append(" " + str(_number) + " " + str(_id) + "<br/>\n")
420+
# the following lines sort the stat primary by value (occurrences),
421+
# but if two IDs occur equally often, then we sort them alphabetically by warning ID
422+
try:
423+
cnt_max = Counter(stats).most_common()[0][1]
424+
except IndexError:
425+
cnt_max = 0
426+
427+
try:
428+
cnt_min = Counter(stats).most_common()[-1][1]
429+
except IndexError:
430+
cnt_min = 0
431+
432+
for occurrences in reversed(range(cnt_min, cnt_max+1)):
433+
for _id in[ k for k,v in sorted(Counter(stats).items()) if v == occurrences ]:
434+
stat_html.append(" " + str(dict(Counter(stats).most_common())[_id]) + " " + str(_id) + "<br/>\n")
422435

423436
output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defect list", "Defect summary", 1) % (options.title, '', options.title, ''))
424437
output_file.write(' <p>\n' + ''.join(stat_html) + ' </p>')

0 commit comments

Comments
 (0)