Given two 'members' elements from rs.status(),
            return lag between their optimes (in secs).
778260
def get_repl_lag(self, master_status):
        
        member_status = self.get_member_rs_status()

        if not member_status:
            raise MongoctlException("Unable to determine replicaset status for"
                                    " member '%s'" %
                                    self.id)

        return get_member_repl_lag(member_status, master_status)
1181639
function getLatency(emitter) {
    var start = Date.now();

    return emitter.request('time')
        .then(function (timestamp) {
          var end = Date.now();
          var latency = (end - start) / 2;
          var time = timestamp + latency;

          // apply the first ever retrieved offset immediately.
          if (isFirst) {
            isFirst = false;
            emitter.emit('change', time);
          }

          return latency;
        })
  }
125650
def moment2(self):
        """"""
        moment1 = self.moment1
        delays, response = self.delay_response_series
        return statstools.calc_mean_time_deviation(
            delays, response, moment1)
1355753
def membership_score(self, element):
        
        other = self.coerce(element)
        if self.value and other.value:
            return 1 - (self.value.delta_e(other.value, mode='cmc', pl=1, pc=1) / 200.0)
        else:
            return 0.0
1258068
def _is_healthiest_node(self, members, check_replication_lag=True):
        """"""

        _, my_wal_position = self.state_handler.timeline_wal_position()
        if check_replication_lag and self.is_lagging(my_wal_position):
            logger.info('My wal position exceeds maximum replication lag')
            return False  # Too far behind last reported wal position on master

        if not self.is_standby_cluster() and self.check_timeline():
            cluster_timeline = self.cluster.timeline
            my_timeline = self.state_handler.replica_cached_timeline(cluster_timeline)
            if my_timeline < cluster_timeline:
                logger.info('My timeline %s is behind last known cluster timeline %s', my_timeline, cluster_timeline)
                return False

        # Prepare list of nodes to run check against
        members = [m for m in members if m.name != self.state_handler.name and not m.nofailover and m.api_url]

        if members:
            for st in self.fetch_nodes_statuses(members):
                if st.failover_limitation() is None:
                    if not st.in_recovery:
                        logger.warning('Master (%s) is still alive', st.member.name)
                        return False
                    if my_wal_position < st.wal_position:
                        logger.info('Wal position of %s is ahead of my wal position', st.member.name)
                        return False
        return True
484187
def check_status(self, delay=0):
        
        if not self.item_id:
            while not self._request_status():
                # wait until _request_status returns True
                yield self.status, self.completion_percentage
                if self.item_id is None:
                    sleep(delay)
        else:
            yield self.status, self.completion_percentage
777086
def status(self):
        
        if self.request_list.conflict:
            return SolverStatus.failed

        if self.callback_return == SolverCallbackReturn.fail:
            # the solve has failed because a callback has nominated the most
            # recent failure as the reason.
            return SolverStatus.failed

        st = self.phase_stack[-1].status
        if st == SolverStatus.cyclic:
            return SolverStatus.failed
        elif len(self.phase_stack) > 1:
            if st == SolverStatus.solved:
                return SolverStatus.solved
            else:
                return SolverStatus.unsolved
        elif st in (SolverStatus.pending, SolverStatus.exhausted):
            return SolverStatus.unsolved
        else:
            return st
740265
def make_multi_lagger(lags, groupby_kwargs=None):
    
    laggers = [SingleLagger(l, groupby_kwargs=groupby_kwargs) for l in lags]
    feature_union = FeatureUnion([
        (repr(lagger), lagger) for lagger in laggers
    ])
    return feature_union
1223593
def _longer_than(segments, min_dur):
    """"""
    if min_dur <= 0.:
        return segments

    long_enough = []
    for seg in segments:

        if sum([t[1] - t[0] for t in seg['times']]) >= min_dur:
            long_enough.append(seg)

    return long_enough
80352
private boolean checkSync() {
        boolean sync = false;
        long last = lastSubmitTime;
        long now = Clock.currentTimeMillis();
        if (last + SYNC_DELAY_MS < now) {
            CONSECUTIVE_SUBMITS.set(this, 0);
        } else if (CONSECUTIVE_SUBMITS.incrementAndGet(this) % SYNC_FREQUENCY == 0) {
            sync = true;
        }
        lastSubmitTime = now;
        return sync;
    }
883552
private static void getStats(
      StatsSnapshot snapshot,
      AggregationData data,
      View view,
      ViewData.AggregationWindowData windowData) {
    if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_VIEW || view == RPC_SERVER_SERVER_LATENCY_VIEW) {
      snapshot.avgLatencyTotal = ((DistributionData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_MINUTE_VIEW
        || view == RPC_SERVER_SERVER_LATENCY_MINUTE_VIEW) {
      snapshot.avgLatencyLastMinute = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_HOUR_VIEW
        || view == RPC_SERVER_SERVER_LATENCY_HOUR_VIEW) {
      snapshot.avgLatencyLastHour = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ERROR_COUNT_VIEW || view == RPC_SERVER_ERROR_COUNT_VIEW) {
      snapshot.errorsTotal = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_MINUTE_VIEW
        || view == RPC_SERVER_ERROR_COUNT_MINUTE_VIEW) {
      snapshot.errorsLastMinute = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_HOUR_VIEW
        || view == RPC_SERVER_ERROR_COUNT_HOUR_VIEW) {
      snapshot.errorsLastHour = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_REQUEST_BYTES_VIEW || view == RPC_SERVER_REQUEST_BYTES_VIEW) {
      DistributionData distributionData = (DistributionData) data;
      snapshot.inputRateTotal =
          distributionData.getCount()
              * distributionData.getMean()
              / BYTES_PER_KB
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_REQUEST_BYTES_MINUTE_VIEW
        || view == RPC_SERVER_REQUEST_BYTES_MINUTE_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.inputRateLastMinute =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_REQUEST_BYTES_HOUR_VIEW
        || view == RPC_SERVER_REQUEST_BYTES_HOUR_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.inputRateLastHour =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_VIEW || view == RPC_SERVER_RESPONSE_BYTES_VIEW) {
      DistributionData distributionData = (DistributionData) data;
      snapshot.outputRateTotal =
          distributionData.getCount()
              * distributionData.getMean()
              / BYTES_PER_KB
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_MINUTE_VIEW
        || view == RPC_SERVER_RESPONSE_BYTES_MINUTE_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.outputRateLastMinute =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_HOUR_VIEW
        || view == RPC_SERVER_RESPONSE_BYTES_HOUR_VIEW) {
      AggregationData.MeanData meanData = (AggregationData.MeanData) data;
      snapshot.outputRateLastHour =
          meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_MINUTE_VIEW
        || view == RPC_SERVER_STARTED_COUNT_MINUTE_VIEW) {
      snapshot.countLastMinute = ((CountData) data).getCount();
      snapshot.rpcRateLastMinute = snapshot.countLastMinute / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_STARTED_COUNT_HOUR_VIEW
        || view == RPC_SERVER_STARTED_COUNT_HOUR_VIEW) {
      snapshot.countLastHour = ((CountData) data).getCount();
      snapshot.rpcRateLastHour = snapshot.countLastHour / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_CUMULATIVE_VIEW
        || view == RPC_SERVER_STARTED_COUNT_CUMULATIVE_VIEW) {
      snapshot.countTotal = ((CountData) data).getCount();
      snapshot.rpcRateTotal =
          snapshot.countTotal
              / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } // TODO(songya): compute and store latency percentiles.
  }
781267
function findLastCommonIndex(xs, ys) {
    for (let i = Math.min(xs.length, ys.length) - 1; i >= 0; --i) {
        if (xs[i] === ys[i]) {
            return i
        }
    }
    return -1
}
429885
void waitBetweenFrames(int transDelayMS, long lastTransactionTimestamp) {

        // If a fixed delay has been set
        if (transDelayMS > 0) {
            ModbusUtil.sleep(transDelayMS);
        }
        else {
            // Make use we have a gap of 3.5 characters between adjacent requests
            // We have to do the calculations here because it is possible that the caller may have changed
            // the connection characteristics if they provided the connection instance
            int delay = getInterFrameDelay() / 1000;

            // How long since the last message we received
            long gapSinceLastMessage = (System.nanoTime() - lastTransactionTimestamp) / NS_IN_A_MS;
            if (delay > gapSinceLastMessage) {
                long sleepTime = delay - gapSinceLastMessage;

                ModbusUtil.sleep(sleepTime);

                if (logger.isDebugEnabled()) {
                    logger.debug("Waited between frames for {} ms", sleepTime);
                }
            }
        }
    }
755425
def waiting_member_state(self, timeout=300):
        """"""
        t_start = time.time()
        while not self.check_member_state():
            if time.time() - t_start > timeout:
                return False
            time.sleep(0.1)
        return True
947372
private int timeSkewInSeconds(Date clientTime, Date serverTime) {
        ValidationUtils.assertNotNull(clientTime, "clientTime");
        ValidationUtils.assertNotNull(serverTime, "serverTime");

        long value = (clientTime.getTime() - serverTime.getTime()) / 1000;

        if ((int) value != value) {
            throw new IllegalStateException("Time is too skewed to adjust: (clientTime: " + clientTime.getTime() + ", " +
                                            "serverTime: " + serverTime.getTime() + ")");
        }
        return (int) value;
    }
1296061
private int compareStarts(Interval<T> other){
		if (start == null && other.start == null)
			return 0;
		if (start == null)
			return -1;
		if (other.start == null)
			return 1;
		int compare = start.compareTo(other.start);
		if (compare != 0)
			return compare;
		if (isStartInclusive ^ other.isStartInclusive)
			return isStartInclusive ? -1 : 1;
		return 0;
	}
1061814
private void logIfConnectionToEndpointIsMissing(long now, Member member) {
        long heartbeatTime = heartbeatFailureDetector.lastHeartbeat(member);
        if ((now - heartbeatTime) >= heartbeatIntervalMillis * HEART_BEAT_INTERVAL_FACTOR) {
            Connection conn = node.getEndpointManager(MEMBER).getOrConnect(member.getAddress());
            if (conn == null || !conn.isAlive()) {
                logger.warning("This node does not have a connection to " + member);
            }
        }
    }