def _preprocess_trials(trial_gen):
    """Preprocess trials


    Add level and tooltip to trials

    Return:
    trials -- preprocessed trials
    ids -- preprocessed trial ids
    tmap -- map trial.id to trial


    Arguments:
    trial_gen -- trial generator
    """
    trials = []
    ids = []
    tmap = {}
    for trial in trial_gen:
        trial.level = 0
        trial.tooltip = (
            """
            <b>{0.script}</b><br>
            {status}<br>
            Start: {0.start}<br>
            Finish: {0.finish}
            """
            .format(trial, status=trial.status.capitalize()))
        if trial.finish:
            trial.tooltip += (
                """
            <br>
            Duration: {duration}
            """
                .format(duration=trial.duration_text))
        tmap[trial.id] = trial
        trials.append(trial)
        ids.append(trial.id)
    return trials, ids, tmap
