def build_timeseries(timepoints, timestamp_to_timepoints):
    """Add extra information to ``timeseries``, based on the information in
    ``timestamp_to_timepoints`` and ``timepoints``.

    :param pandas.DataFrame timepoints: data frame, indexed by timepoint_id, with
        columns: 'timestamp', 'timeseries', 'ts_period', and 'ts_duration_of_tp'.
    :param pandas.Series timestamp_to_timepoints: timepoints (values) of each timestamp
        (index).
    :return: (*pandas.DataFrame*) -- data frame containing all timeseries information.
    """
    timeseries = timepoints.groupby("timeseries").first().drop(columns="timestamp")
    timeseries["ts_num_tps"] = timepoints.value_counts("timeseries")
    # Count the number of hours mapped to each timeseries (via the timepoints)
    hours = timestamp_to_timepoints.value_counts().groupby(timepoints.timeseries).sum()
    timeseries["ts_scale_to_period"] = hours / (
        timeseries["ts_duration_of_tp"] * timeseries["ts_num_tps"]
    )
    timeseries.index.name = "TIMESERIES"
    timeseries.reset_index(inplace=True)
    return timeseries