def diaperchange_intervals(changes):
    """
    Create a graph showing intervals of diaper changes.
    :param changes: a QuerySet of Diaper Change instances.
    :returns: a tuple of the graph's html and javascript.
    """

    changes = changes.order_by("time")
    intervals = []
    intervals_solid = []
    intervals_wet = []
    last_change = changes.first()
    for change in changes[1:]:
        interval = change.time - last_change.time
        if interval.total_seconds() > 0:
            intervals.append(interval)
            if change.solid:
                intervals_solid.append(interval)
            if change.wet:
                intervals_wet.append(interval)
        last_change = change

    trace_solid = go.Scatter(
        name=_("Solid"),
        line=dict(shape="spline"),
        x=list(changes.values_list("time", flat=True))[1:],
        y=[i.total_seconds() / 3600 for i in intervals_solid],
        hoverinfo="text",
        text=[_duration_string_hms(i) for i in intervals_solid],
    )

    trace_wet = go.Scatter(
        name=_("Wet"),
        line=dict(shape="spline"),
        x=list(changes.values_list("time", flat=True))[1:],
        y=[i.total_seconds() / 3600 for i in intervals_wet],
        hoverinfo="text",
        text=[_duration_string_hms(i) for i in intervals_wet],
    )

    trace_total = go.Scatter(
        name=_("Total"),
        line=dict(shape="spline"),
        x=list(changes.values_list("time", flat=True))[1:],
        y=[i.total_seconds() / 3600 for i in intervals],
        hoverinfo="text",
        text=[_duration_string_hms(i) for i in intervals],
    )

    layout_args = utils.default_graph_layout_options()
    layout_args["barmode"] = "stack"
    layout_args["title"] = "<b>" + _("Diaper Change Intervals") + "</b>"
    layout_args["xaxis"]["title"] = _("Date")
    layout_args["xaxis"]["type"] = "date"
    layout_args["xaxis"]["autorange"] = True
    layout_args["xaxis"]["autorangeoptions"] = utils.autorangeoptions(trace_total.x)
    layout_args["xaxis"]["rangeselector"] = utils.rangeselector_date()
    layout_args["yaxis"]["title"] = _("Interval (hours)")

    fig = go.Figure(
        {
            "data": [trace_solid, trace_wet, trace_total],
            "layout": go.Layout(**layout_args),
        }
    )
    output = plotly.plot(
        fig,
        output_type="div",
        include_plotlyjs=False,
        config={"locale": get_language()},
    )
    return utils.split_graph_output(output)

    Create a graph showing intervals of diaper changes.
    :param changes: a QuerySet of Diaper Change instances.
    :returns: a tuple of the graph's html and javascript.
    
reports/graphs/diaperchange_intervals.py