diff --git a/core/utils.py b/core/utils.py index 8a450a92..8a55a8a4 100644 --- a/core/utils.py +++ b/core/utils.py @@ -33,12 +33,6 @@ def duration_string(duration): return duration -def duration_string_short(duration): - """Format hours, minutes and seconds as a short string (e.g. "0h2m35s").""" - h, m, s = duration_parts(duration) - return '{}h{}m{}s'.format(h, m, s) - - def duration_parts(duration): """Get hours, minutes and seconds from a timedelta.""" if not isinstance(duration, timezone.timedelta): @@ -46,4 +40,4 @@ def duration_parts(duration): h, remainder = divmod(duration.seconds, 3600) h += duration.days * 24 m, s = divmod(remainder, 60) - return h, m, s \ No newline at end of file + return h, m, s diff --git a/reports/graphs.py b/reports/graphs.py index 3bd13150..a0344d2c 100644 --- a/reports/graphs.py +++ b/reports/graphs.py @@ -12,7 +12,7 @@ import plotly.offline as plotly import plotly.graph_objs as go from core.models import DiaperChange, Feeding, Sleep, TummyTime -from core.utils import duration_string, duration_string_short +from core.utils import duration_string, duration_parts from .utils import default_graph_layout_options, split_graph_output @@ -87,7 +87,7 @@ def sleep_totals(child): y=[td.seconds/3600 for td in totals.values()], hoverinfo='text', textposition='outside', - text=[duration_string_short(td) for td in totals.values()] + text=[_duration_string_short(td) for td in totals.values()] ) layout_args = default_graph_layout_options() @@ -104,6 +104,13 @@ def sleep_totals(child): return split_graph_output(output) +def _duration_string_short(duration): + """Format a "short" duration string without seconds precision. This is + intended to fit better in smaller spaces on a graph.""" + h, m, s = duration_parts(duration) + return '{}h{}m'.format(h, m) + + def sleep_pattern(child): """Create a graph showing blocked out periods of sleep during each day.""" # TODO: Simplify this using the bar charts "base" property.