Move "short" duration string function to graphs and exclude seconds.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-25 11:39:08 -04:00
parent 6562fa2390
commit 43edfddd82
2 changed files with 10 additions and 9 deletions

View File

@ -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):

View File

@ -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.