# Path: pydlm/base/tools.py
# def getInterval(means, var, p):
#     alpha = abs(normal_CDF_inverse(min(1 - p, p) / 2))
#     upper = [0] * len(means)
#     lower = [0] * len(means)
#     for i in range(0, len(means)):
#         upper[i] = means[i] + alpha * math.sqrt(var[i])
#         lower[i] = means[i] - alpha * math.sqrt(var[i])
# 
#     return (upper, lower)


import matplotlib.pyplot as plt
from pydlm.base.tools import getInterval

# =========================== plot for main data ============================


def plotInOneFigure(time, data, result, options):
    """
    Plot the dlm results in one figure

    Args:
        time: the time label
        data: the original data
        result: the fitted result from dlm class
        options: options for the plot, for details please refer to @dlm
    """
    # plot the original data
    plotData(time=time, data=data,
             showDataPoint=options.showDataPoint, color=options.dataColor,
             label='time series')

    # plot fitered results if needed
    if options.plotFilteredData:
        start = result.filteredSteps[0]
        end = result.filteredSteps[1] + 1
        plotData(time=time[start:end],
                 data=to1dArray(result.filteredObs[start:end]),
                 showDataPoint=options.showFittedPoint,
                 color=options.filteredColor,
                 label='filtered series')

        if options.showConfidenceInterval:

# Path: pydlm/base/tools.py
# def getInterval(means, var, p):
#     alpha = abs(normal_CDF_inverse(min(1 - p, p) / 2))
#     upper = [0] * len(means)
#     lower = [0] * len(means)
#     for i in range(0, len(means)):
#         upper[i] = means[i] + alpha * math.sqrt(var[i])
#         lower[i] = means[i] - alpha * math.sqrt(var[i])
# 
#     return (upper, lower)


# Path: pydlm/plot/dlmPlot.py
import matplotlib.pyplot as plt
from pydlm.base.tools import getInterval


# =========================== plot for main data ============================


def plotInOneFigure(time, data, result, options):
    """
    Plot the dlm results in one figure

    Args:
        time: the time label
        data: the original data
        result: the fitted result from dlm class
        options: options for the plot, for details please refer to @dlm
    """
    # plot the original data
    plotData(time=time, data=data,
             showDataPoint=options.showDataPoint, color=options.dataColor,
             label='time series')

    # plot fitered results if needed
    if options.plotFilteredData:
        start = result.filteredSteps[0]
        end = result.filteredSteps[1] + 1
        plotData(time=time[start:end],
                 data=to1dArray(result.filteredObs[start:end]),
                 showDataPoint=options.showFittedPoint,
                 color=options.filteredColor,
                 label='filtered series')

        if options.showConfidenceInterval:

            upper, lower = getInterval(result.filteredObs[start:end],