| 619 | |
| 620 | |
| 621 | def render_summary(items, *, |
| 622 | groupby='kind', |
| 623 | sort=None, |
| 624 | showempty=None, |
| 625 | verbose=False, |
| 626 | ): |
| 627 | if groupby is None: |
| 628 | groupby = 'kind' |
| 629 | summary = summarize( |
| 630 | items, |
| 631 | groupby=groupby, |
| 632 | includeempty=showempty, |
| 633 | minimize=None if showempty else not verbose, |
| 634 | ) |
| 635 | |
| 636 | subtotals = summary['totals']['subs'] |
| 637 | bygroup = summary['totals']['bygroup'] |
| 638 | for outer, subtotal in subtotals.items(): |
| 639 | if bygroup: |
| 640 | subtotal = f'({subtotal})' |
| 641 | yield f'{outer + ":":20} {subtotal:>8}' |
| 642 | else: |
| 643 | yield f'{outer + ":":10} {subtotal:>8}' |
| 644 | if outer in bygroup: |
| 645 | for inner, count in bygroup[outer].items(): |
| 646 | yield f' {inner + ":":9} {count}' |
| 647 | total = f'*{summary["totals"]["all"]}*' |
| 648 | label = '*total*:' |
| 649 | if bygroup: |
| 650 | yield f'{label:20} {total:>8}' |
| 651 | else: |
| 652 | yield f'{label:10} {total:>9}' |
| 653 | |
| 654 | |
| 655 | _FORMATS = { |