diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2020-11-01 17:00:45 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2020-11-01 17:00:45 +0100 |
commit | d6c5dbc925e63bebc048356c4a54a1ad6b364014 (patch) | |
tree | 31313bb87d7ec4ab256758404ee9e3d48857858f /lulua/report.py | |
parent | 6a2262a7f9bf2ab16ecfdfc52e548ef010c76e00 (diff) | |
download | lulua-d6c5dbc925e63bebc048356c4a54a1ad6b364014.tar.gz lulua-d6c5dbc925e63bebc048356c4a54a1ad6b364014.tar.bz2 lulua-d6c5dbc925e63bebc048356c4a54a1ad6b364014.zip |
Explain design decisions
Fixes #10.
Diffstat (limited to 'lulua/report.py')
-rw-r--r-- | lulua/report.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lulua/report.py b/lulua/report.py index 8a50681..b25201d 100644 --- a/lulua/report.py +++ b/lulua/report.py @@ -21,6 +21,7 @@ import sys, argparse, logging, pickle, math from gettext import GNUTranslations, NullTranslations from decimal import Decimal +from fractions import Fraction import yaml from jinja2 import Environment, PackageLoader @@ -40,6 +41,11 @@ def approx (i, lang='en'): units.pop (0) return round (i, 1), units[0] +def fraction (n, maxdenom=10): + """ Turn floating number n into a human-digestable fraction """ + f = Fraction (n).limit_denominator (maxdenom) + return f'{f.numerator}\u2044{f.denominator}' + def numspace (s): """ Replace ordinary spaces with unicode FIGURE SPACE """ return s.replace (' ', '\u2007') @@ -83,6 +89,7 @@ def render (): env.filters['numspace'] = numspace env.filters['arabnum'] = arabnum env.filters['blendn'] = blendn + env.filters['fraction'] = fraction corpus = [] for x in args.corpus: |