# Path: sktracker/utils/progress.py
# def print_progress(progress, message=None, out=None):
#     """Display a progress bar filled with a variable value. print_progress
#     also works under IPython notebook.
# 
#     Set `progress` to -1 to remove the progress bar.
# 
#     Parameters
#     ----------
#     progress: int
#         Variable value use to fill the progress bar. Should be between 0
#         and 100.
#     out: OutStream
#         Where to stream progress bar. None will redirect output to `sys.stdout`.
# 
#     Returns
#     -------
#     None. Display the progress bar.
# 
#     Examples
#     --------
#     >>> import time
#     >>> from sktracker.utils import print_progress
# 
#     >>> n = 5
#     >>> for i in range(n):
#     >>>     time.sleep(1)
# 
#     >>>     print_progress((i + 1) * 100 / n)
#     100% [=================================================>]
#     >>> print_progress(-1)
# 
#     """
# 
#     if out is None:
#         out = sys.stdout
# 
#     # If process is finished
#     if progress == -1:
#         out.write("\r" + " " * 80 + "\r\r")
#         out.flush()
#         return
# 
#     # Size of the progress bar
#     size = 50
# 
#     # Compute current progress
#     progress_bar = (progress) * size / 100
# 
#     # Build progress bar
#     bar = "["
#     for i in range(int(progress_bar - 1)):
#         bar += "="
#     bar += ">"
#     for i in range(int(size - progress_bar)):
#         bar += " "
#     bar += "]"
# 
#     if message:
#         bar = " ".join([bar, message])
# 
#     # Write progress bar
#     bar_str = "\r%d%% " % (progress) + bar
#     out.write(bar_str)
#     out.flush()


import logging
import numpy as np
from ...utils import print_progress
from ..matrix import CostMatrix
from ..cost_function import AbstractCostFunction
from ..cost_function.brownian import BrownianLinkCostFunction
from ..cost_function.diagonal import DiagonalCostFunction
from ..cost_function.directed import BasicDirectedLinkCostFunction
from . import AbstractSolver
        """

        Returns
        -------
        self.trajs : :class:`pandas.DataFrame`
        progress_bar : bool
            Display progress bar
        progress_bar_out : OutStream
            For testing purpose only
        """

        log.info('Initiating frame by frame tracking.')

        old_labels = self.trajs.index.get_level_values('label').values
        self.trajs['new_label'] = old_labels.astype(np.float)
        ts_in = self.trajs.t_stamps[:-1]
        ts_out = self.trajs.t_stamps[1:]

        n_labels_before = len(self.trajs.labels)

        n = len(ts_in)
        for i, (t_in, t_out) in enumerate(zip(ts_in, ts_out)):
            if progress_bar:
                progress = i / n * 100
                message = "t_in : {} | t_out {}".format(t_in, t_out)
                print_progress(progress, message=message, out=progress_bar_out)

            self.one_frame(t_in, t_out)

        if progress_bar:

# Path: sktracker/utils/progress.py
# def print_progress(progress, message=None, out=None):
#     """Display a progress bar filled with a variable value. print_progress
#     also works under IPython notebook.
# 
#     Set `progress` to -1 to remove the progress bar.
# 
#     Parameters
#     ----------
#     progress: int
#         Variable value use to fill the progress bar. Should be between 0
#         and 100.
#     out: OutStream
#         Where to stream progress bar. None will redirect output to `sys.stdout`.
# 
#     Returns
#     -------
#     None. Display the progress bar.
# 
#     Examples
#     --------
#     >>> import time
#     >>> from sktracker.utils import print_progress
# 
#     >>> n = 5
#     >>> for i in range(n):
#     >>>     time.sleep(1)
# 
#     >>>     print_progress((i + 1) * 100 / n)
#     100% [=================================================>]
#     >>> print_progress(-1)
# 
#     """
# 
#     if out is None:
#         out = sys.stdout
# 
#     # If process is finished
#     if progress == -1:
#         out.write("\r" + " " * 80 + "\r\r")
#         out.flush()
#         return
# 
#     # Size of the progress bar
#     size = 50
# 
#     # Compute current progress
#     progress_bar = (progress) * size / 100
# 
#     # Build progress bar
#     bar = "["
#     for i in range(int(progress_bar - 1)):
#         bar += "="
#     bar += ">"
#     for i in range(int(size - progress_bar)):
#         bar += " "
#     bar += "]"
# 
#     if message:
#         bar = " ".join([bar, message])
# 
#     # Write progress bar
#     bar_str = "\r%d%% " % (progress) + bar
#     out.write(bar_str)
#     out.flush()


# Path: sktracker/tracker/solver/by_frame_solver.py
import logging
import numpy as np
from ...utils import print_progress
from ..matrix import CostMatrix
from ..cost_function import AbstractCostFunction
from ..cost_function.brownian import BrownianLinkCostFunction
from ..cost_function.diagonal import DiagonalCostFunction
from ..cost_function.directed import BasicDirectedLinkCostFunction
from . import AbstractSolver

        """

        Returns
        -------
        self.trajs : :class:`pandas.DataFrame`
        progress_bar : bool
            Display progress bar
        progress_bar_out : OutStream
            For testing purpose only
        """

        log.info('Initiating frame by frame tracking.')

        old_labels = self.trajs.index.get_level_values('label').values
        self.trajs['new_label'] = old_labels.astype(np.float)
        ts_in = self.trajs.t_stamps[:-1]
        ts_out = self.trajs.t_stamps[1:]

        n_labels_before = len(self.trajs.labels)

        n = len(ts_in)
        for i, (t_in, t_out) in enumerate(zip(ts_in, ts_out)):
            if progress_bar:
                progress = i / n * 100
                message = "t_in : {} | t_out {}".format(t_in, t_out)
                print_progress(progress, message=message, out=progress_bar_out)

            self.one_frame(t_in, t_out)

        if progress_bar:

            print_progress(-1)