Combines consecutive 'self time' frames
484828
def merge_consecutive_self_time(frame, options):
    '''
    
    '''
    if frame is None:
        return None

    previous_self_time_frame = None

    for child in frame.children:
        if isinstance(child, SelfTimeFrame):
            if previous_self_time_frame:
                # merge
                previous_self_time_frame.self_time += child.self_time
                child.remove_from_parent()
            else:
                # keep a reference, maybe it'll be added to on the next loop
                previous_self_time_frame = child
        else:
            previous_self_time_frame = None
    
    for child in frame.children:
        merge_consecutive_self_time(child, options=options)
    
    return frame
752451
def time_segments_aggregate(X, interval, time_column, method=['mean']):
    """"""
    if isinstance(X, np.ndarray):
        X = pd.DataFrame(X)

    X = X.sort_values(time_column).set_index(time_column)

    if isinstance(method, str):
        method = [method]

    start_ts = X.index.values[0]
    max_ts = X.index.values[-1]

    values = list()
    index = list()
    while start_ts <= max_ts:
        end_ts = start_ts + interval
        subset = X.loc[start_ts:end_ts - 1]
        aggregated = [
            getattr(subset, agg)(skipna=True).values
            for agg in method
        ]
        values.append(np.concatenate(aggregated))
        index.append(start_ts)
        start_ts = end_ts

    return np.asarray(values), np.asarray(index)
135799
def lerp(vec1, vec2, time):
        """"""
        if isinstance(vec1, Vector2) \
                and isinstance(vec2, Vector2):
            # Clamp the time value into the 0-1 range.
            if time < 0:
                time = 0
            elif time > 1:
                time = 1

            x_lerp = vec1[0] + time * (vec2[0] - vec1[0])
            y_lerp = vec1[1] + time * (vec2[1] - vec1[1])
            return Vector2(x_lerp, y_lerp)
        else:
            raise TypeError("Objects must be of type Vector2")
519183
def previous(time, base)
      current = time
      until match?(current, base) && current < time
        pot_prev = align(potential_previous(current, base), base)
        pot_prev -= min_step if pot_prev == current

        current = pot_prev
      end

      current
    end
927328
function (skeleton, lastTime, time, firedEvents, alpha) {
		if (!firedEvents) return;

		var frames = this.frames;
		var frameCount = frames.length;

		if (lastTime > time) { // Fire events after last time for looped animations.
			this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha);
			lastTime = -1;
		} else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
			return;
		if (time < frames[0]) return; // Time is before first frame.

		var frameIndex;
		if (lastTime < frames[0])
			frameIndex = 0;
		else {
			frameIndex = spine.Animation.binarySearch1(frames, lastTime);
			var frame = frames[frameIndex];
			while (frameIndex > 0) { // Fire multiple events with the same frame.
				if (frames[frameIndex - 1] != frame) break;
				frameIndex--;
			}
		}
		var events = this.events;
		for (; frameIndex < frameCount && time >= frames[frameIndex]; frameIndex++)
			firedEvents.push(events[frameIndex]);
	}
864312
def record_entering(self, time, code, frame_key, parent_stats):
        """"""
        stats = parent_stats.ensure_child(code, RecordingStatistics)
        self._times_entered[(code, frame_key)] = time
        stats.own_hits += 1
149182
function merge(prev, current, next) {
  return prev
    .concat()
    .reverse()
    .concat([current], next)
}
1117971
def timelines(fig, y, xstart, xstop, color='b'):
    """"""
    fig.hlines(y, xstart, xstop, color, lw=4)
    fig.vlines(xstart, y+0.03, y-0.03, color, lw=2)
    fig.vlines(xstop, y+0.03, y-0.03, color, lw=2)
1062888
def _read_next_timestep(self, ts=None):
    """"""

    if self.ts.frame >= self.n_frames-1:
        raise IOError(errno.EIO, 'trying to go over trajectory limit')
    if ts is None:
        ts = self.ts
    ts.frame += 1

    self.zdock_inst._set_pose_num(ts.frame+1)
    ts._pos = self.zdock_inst.static_mobile_copy_uni.trajectory.ts._pos

    return ts
572477
def at(time)
      add_tracks if ! @tracks_added

      if time.is_a?(String)
        time = Time.parse(time)
      end
      time = time.to_i

      location = nil

      @tracks.each do |track|
        location = track.at(time)
        break if location
      end

      if ! location
        case @intersegment_behavior
        when :interpolate then
          @intersegments.each do |track|
            location = track.at(time)
            break if location
          end
        when :nearest then
          # hash is sorted in ascending time order.
          # all start/end points for all segments
          points = {}
          @tracks.each do |t|
            points[t.start_time.to_i] = t.start_location
            points[t.end_time.to_i] = t.end_location
          end

          last_diff = Infinity
          last_time = -1
          points.each do |p_time,p_location|
            this_diff = (p_time.to_i - time).abs

            # as long as the differences keep getting smaller, we keep going
            # as soon as we see a larger one, we step back one and use that value.
            if this_diff > last_diff
              l = points[last_time]
              location = Track.array_to_hash(points[last_time])
              break
            else
              last_diff = this_diff
              last_time = p_time
            end
          end

          # if we got here, time is > the end of the last segment
          location = Track.array_to_hash(points[last_time])
        end
      end

      # each segment has a begin and end time.
      # which one is this time closest to?
      # array of times in order. compute abs diff between time and each point.
      # put times in order. abs diff to each, until we get a larger value or we run out of points. then back up one and use that.
      # {time => [lat, lon, elev], time => [lat, lon, elev]}

      location
    end
843853
function createLinkedTimelines() {
    const tl1 = createTimeline();
    const tl2 = createTimeline();
    tl1.setNeighbouringTimeline(tl2, EventTimeline.FORWARDS);
    tl2.setNeighbouringTimeline(tl1, EventTimeline.BACKWARDS);
    return [tl1, tl2];
}
400472
def _set_time(self, time):
        
        if len(self.time) == 0 :
            self.time = np.array(time)
            if self.h5 is not None:
                self.h5.create_dataset('time', self.time.shape, dtype=self.time.dtype, data=self.time, compression="gzip", shuffle=True, scaleoffset=3)
        else:
            if(len(time) != len(self.time)):
                raise AssertionError("\nTime or number of frame mismatch in input files.\n Exiting...\n")
575687
def i2repr(self, pkt, packed_seconds):
        """"""
        time_struct = time.gmtime(self._convert_seconds(packed_seconds))
        return time.strftime("%a %b %d %H:%M:%S %Y", time_struct)
952331
function createTimeline(numEvents, baseIndex) {
    if (numEvents === undefined) {
        numEvents = 3;
    }
    if (baseIndex === undefined) {
        baseIndex = 1;
    }

    // XXX: this is a horrid hack
    const timelineSet = { room: { roomId: ROOM_ID }};
    timelineSet.room.getUnfilteredTimelineSet = function() {
        return timelineSet;
    };

    const timeline = new EventTimeline(timelineSet);

    // add the events after the baseIndex first
    addEventsToTimeline(timeline, numEvents - baseIndex, false);

    // then add those before the baseIndex
    addEventsToTimeline(timeline, baseIndex, true);

    expect(timeline.getBaseIndex()).toEqual(baseIndex);
    return timeline;
}
1005389
def temporal_segmentation(segments, min_time):
    
    final_segments = []
    for segment in segments:
        final_segments.append([])
        for point in segment:
            if point.dt > min_time:
                final_segments.append([])
            final_segments[-1].append(point)

    return final_segments
351862
def merge_datetime(date, time='', date_format='%d/%m/%Y', time_format='%H:%M'):
    """"""
    day = datetime.strptime(date, date_format)
    if time:
        time = datetime.strptime(time, time_format)
        time = datetime.time(time)
        day = datetime.date(day)
        day = datetime.combine(day, time)
    return day
977412
private Timestamp plus(long secondsToAdd, long nanosToAdd) {
    if ((secondsToAdd | nanosToAdd) == 0) {
      return this;
    }
    long epochSec = TimeUtils.checkedAdd(getSeconds(), secondsToAdd);
    epochSec = TimeUtils.checkedAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
    nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
    long nanoAdjustment = getNanos() + nanosToAdd; // safe int + NANOS_PER_SECOND
    return ofEpochSecond(epochSec, nanoAdjustment);
  }