Segment explorer

@link    https://strava.github.io/api/v3/segments/#explore
@param   string $bounds
@param   string $activity_type
@param   int $min_cat
@param   int $max_cat
@return  array
@throws  Exception
540955
public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null)
    {
        try {
            return $this->service->getSegmentExplorer($bounds, $activity_type, $min_cat, $max_cat);
        } catch (ServiceException $e) {
            throw new ClientException('[SERVICE] ' . $e->getMessage());
        }
    }
1100207
public void getTransformedBounds(RectF outBounds) {
    getParentTransform(sTempTransform);
    // IMPORTANT: {@code getBounds} should be called after {@code getParentTransform},
    // because the parent may have to change our bounds.
    outBounds.set(getBounds());
    sTempTransform.mapRect(outBounds);
  }
433202
public function getByFlagRange(int $min, int $max = Settings::FLAG_MAX, int $trackableType = Tracker::TRACKER_ANY, int $perPage = 15) : LengthAwarePaginator
    {
        $query = $this->getModel()->newQuery();

        if ($max === Settings::FLAG_MAX) {
            $query->where('level', '>=', $min);
        } else {
            $query->whereBetween('level', [$min, $max]);
        }

        $query->where($this->typeClosure($trackableType));

        return $query->paginate($perPage);
    }
89240
@Override
    public Collection<SegmentMetadata> getEvictionCandidates(long sequenceNumberCutoff, int maxCount) {
        long adjustedCutoff = Math.min(sequenceNumberCutoff, this.lastTruncatedSequenceNumber.get());
        List<SegmentMetadata> candidates;
        synchronized (this.lock) {
            candidates = this.metadataById
                    .values().stream()
                    .filter(m -> isEligibleForEviction(m, adjustedCutoff))
                    .collect(Collectors.toList());
        }

        // If we have more candidates than were requested to return, then return only the ones that were not recently used.
        if (candidates.size() > maxCount) {
            candidates.sort(Comparator.comparingLong(SegmentMetadata::getLastUsed));
            candidates = candidates.subList(0, maxCount);
        }

        return candidates;
    }
250202
def get_activities(self, activity_ids=None, max_records=50):
        
        return self.connection.get_all_activities(self, activity_ids,
                                                  max_records)
452510
public int getMaxSlots(TaskTrackerStatus status, TaskType type) {
    return (type == TaskType.MAP) ? status.getMaxMapSlots() :
        status.getMaxReduceSlots();
  }
929153
public final Parser<Void> skipTimes(int min, int max) {
    Checks.checkMinMax(min, max);
    return new SkipTimesParser(this, min, max);
  }
1130560
public void setBounds(int minOccurs, int maxOccurs) {
    if (minOccurs < 0 || maxOccurs < -1)
      throw new IllegalArgumentException("Bounds cannot be negative");
    else if (maxOccurs > 0 && minOccurs > maxOccurs)
      throw new IllegalArgumentException("Minimum bounds less than maximum bounds");
    limits = new int[] { minOccurs, maxOccurs };
  }
488091
public static function fromExecutionTracker(ExecutionTracker $execution_tracker, int $max_cycles): self
    {
        $cycle_crumbs = $execution_tracker->detectExecutionLoop();
        $message = sprintf("Trying to execute more than the allowed number of %d workflow steps.\n", $max_cycles);
        if (count($cycle_crumbs) === count($execution_tracker->getBreadcrumbs())) {
            $message .= "It is likely that an intentional cycle inside the workflow isn't properly exiting.\n".
                "The executed states where:\n";
        } else {
            $message .= "Looks like there is a loop between: ";
        }
        $message .= implode(' -> ', $cycle_crumbs->toArray());
        return new self($message);
    }
1072381
private function quickSort($min, $max) {

        $i = $min;
        $j = $max;

        $pivot = $this->values[$min + ($max - $min) / 2];

        while ($i <= $j) {

            while (true === $this->functor->compare($this->values[$i], $pivot)) {
                ++$i;
            }

            while (true === $this->functor->compare($pivot, $this->values[$j])) {
                --$j;
            }

            if ($i <= $j) {
                $this->swap($i, $j);
                ++$i;
                --$j;
            }
        }

        if ($min < $j) {
            $this->quickSort($min, $j);
        }
        if ($i < $max) {
            $this->quickSort($i, $max);
        }
    }
1367337
def getBestMatchingCell(self, c, activeState):
    
    # Collect all cells in column c that have at least minThreshold in the most
    # activated segment
    bestActivityInCol = self.minThreshold
    bestSegIdxInCol = -1
    bestCellInCol = -1

    for i in xrange(self.cellsPerColumn):

      maxSegActivity = 0
      maxSegIdx = 0

      for j,s in enumerate(self.cells[c][i]):

        activity = self.getSegmentActivityLevel(s, activeState, connectedSynapsesOnly =False)

        if self.verbosity >= 6:
          print " Segment Activity for column ", c, " cell ", i, " segment ", " j is ", activity

        if activity > maxSegActivity:
          maxSegActivity = activity
          maxSegIdx = j

      if maxSegActivity >= bestActivityInCol:
        bestActivityInCol = maxSegActivity
        bestSegIdxInCol = maxSegIdx
        bestCellInCol = i

    if self.verbosity >= 6:
      print "Best Matching Cell In Col: ", bestCellInCol
    if bestCellInCol == -1:
      return (None, None)
    else:
      return bestCellInCol, self.cells[c][bestCellInCol][bestSegIdxInCol]
522189
public function whereNotBetween($expr, $min, $max)
    {
        if ($min === null || $min === '') {
            return $max === null || $max === '' ? $this : $this->whereCmp($expr, '>', $max);
        } elseif ($max === null || $max === '') {
            return $min === null || $min === '' ? $this : $this->whereCmp($expr, '<', $min);
        }

        $minKey = '_min_' . $this->_hiddenParamNumber;
        $maxKey = '_max_' . $this->_hiddenParamNumber;

        $this->_hiddenParamNumber++;

        if (strpos($expr, '[') === false && strpos($expr, '(') === false) {
            if (strpos($expr, '.') !== false) {
                $expr = '[' . str_replace('.', '].[', $expr) . ']';
            } else {
                $expr = '[' . $expr . ']';
            }
        }

        $this->_conditions[] = "$expr NOT BETWEEN :$minKey AND :$maxKey";

        $this->_bind[$minKey] = $min;
        $this->_bind[$maxKey] = $max;

        return $this;
    }
1361994
public Map<PvmActivity, PvmExecutionImpl> instantiateScopes(List<PvmActivity> activityStack,
                                                              boolean skipCustomListeners,
                                                              boolean skipIoMappings) {

    if (activityStack.isEmpty()) {
      return Collections.emptyMap();
    }

    this.skipCustomListeners = skipCustomListeners;
    this.skipIoMapping = skipIoMappings;

    ExecutionStartContext executionStartContext = new ExecutionStartContext(false);

    InstantiationStack instantiationStack = new InstantiationStack(new LinkedList<>(activityStack));
    executionStartContext.setInstantiationStack(instantiationStack);
    setStartContext(executionStartContext);

    performOperation(PvmAtomicOperation.ACTIVITY_INIT_STACK_AND_RETURN);

    Map<PvmActivity, PvmExecutionImpl> createdExecutions = new HashMap<>();

    PvmExecutionImpl currentExecution = this;
    for (PvmActivity instantiatedActivity : activityStack) {
      // there must exactly one child execution
      currentExecution = currentExecution.getNonEventScopeExecutions().get(0);
      if (currentExecution.isConcurrent()) {
        // there may be a non-scope execution that we have to skip (e.g. multi-instance)
        currentExecution = currentExecution.getNonEventScopeExecutions().get(0);
      }

      createdExecutions.put(instantiatedActivity, currentExecution);
    }

    return createdExecutions;
  }
297970
public function minMax($min, $max=PHP_INT_MAX){
        return $this->markErrorIf($this->value < $min || $this->value > $max);
    }
1088200
function fetchExpandedTypes(sBaseMetaPath, mQueryOptions) {
			if (mQueryOptions && mQueryOptions.$expand) {
				Object.keys(mQueryOptions.$expand).forEach(function (sNavigationPath) {
					var sMetaPath = sBaseMetaPath;

					sNavigationPath.split("/").forEach(function (sSegment) {
						sMetaPath += "/" + sSegment;
						fetchType(sMetaPath);
					});
					fetchExpandedTypes(sMetaPath, mQueryOptions.$expand[sNavigationPath]);
				});
			}
		}
833166
final public function fetch(\DateTime $maxAge = null)
    {
        $destination = $this->getDestination();

        // check if we need to download feed
        $event = new TransportEvent($this);
        if (!$this->isFresh($destination, $maxAge)) {
            // make sure directory exists
            $dir = dirname($destination);
            if (!is_dir($dir)) {
                if (true !== @mkdir($dir, 0777, true)) {
                    throw new TransportException(sprintf('Could not create feed dir "%s"', $dir));
                }
            }

            // perform an atomic write operation: first write to a tmp destination, then rename it.
            $tmpDestination = $this->getTempDestination($destination);

            $this->eventDispatcher->dispatch(FeedEvents::PRE_FETCH, $event);

            $this->doFetch($tmpDestination);
            if (false === rename($tmpDestination, $destination)) {
                unlink($tmpDestination);

                throw new TransportException(sprintf('Could not rename "%s" to "%s"', $tmpDestination, $destination));
            }

            $this->eventDispatcher->dispatch(FeedEvents::POST_FETCH, $event);
        } else {
            $this->eventDispatcher->dispatch(FeedEvents::FETCH_CACHED, $event);
        }

        return $destination;
    }
1060978
public static function getBoundsOfBounds($boundaries, $margin = 0.0)
    {
        $minLat = 1000;
        $maxLat = -1000;
        $minLng = 1000;
        $maxLng = -1000;
        foreach ($boundaries as $bounds) {
            if (!($bounds instanceof LatLngBounds)) {
                throw new InvalidParamException('"$boundaries" must be an array of "' . self::className() . '" objects');
            }
            $minLat = min($minLat, $bounds->getSouthWest()->getLat());
            $minLng = min($minLng, $bounds->getSouthWest()->getLng());
            $maxLat = max($maxLat, $bounds->getNorthEast()->getLat());
            $maxLng = max($maxLng, $bounds->getNorthEast()->getLng());
        }

        if ($margin > 0) {
            $minLat = $minLat - $margin * ($maxLat - $minLat);
            $minLng = $minLng - $margin * ($maxLng - $minLng);
            $maxLat = $maxLat + $margin * ($maxLat - $minLat);
            $maxLng = $maxLng + $margin * ($maxLng - $minLng);
        }

        return new self(
            [
                'southWest' => new LatLng(['lat' => $minLat, 'lng' => $minLng]),
                'northEast' => new LatLng(['lat' => $maxLat, 'lng' => $maxLng])]
        );
    }