def count_intervals(dat):
    """
    We will have instances of continuous downtimes being split into different
    state transitions. For example, if a 2 out of 3 system transitions
    from 2 down to 3 down and then back to 2 down, we want to treat those
    three transitions as a single DOWN event for the system. This method helps with
    that.
    """
    prev_start = 0
    prev_end = 0
    intervals = 0
    for _, row in dat.iterrows():
        curr_start = row['start']
        curr_end = row['end']
        if curr_start > prev_end:
            intervals += 1
        prev_start = curr_start
        prev_end = curr_end
    return intervals
