def get_time_sorted_events_list(df, n_states):
    """
    Given a dataframe returns a list of events, ordered by timestamp.
    """
    end_event = n_states - 1
    beginning_event = n_states - 2

    events_list = list([beginning_event])

    events_list.extend(df.reset_index()
                         .set_index("timestamp")
                         .sort_index()
                         ['event'].values)

    events_list.append(end_event)

    return events_list