<commit_before><?php namespace URFBattleground\Managers\LolApi;

class LimitManager {

	/** @var Limit[] array */
	private $limits = [];
	/** @var Limit[] array */
	private $skippedLimits = [];

	public function __construct(array $limits = [])
	{
		$this->addLimits($limits);
	}

	/**
	 * @param array $limits
	 * @return $this
	 */
	public function addLimits(array $limits)
	{
		foreach ($limits as $limit) {
			$this->addLimit($limit[0], $limit[1]);
		}

		return $this;
	}

	/**
	 * @param $beats
	 * @param $seconds
	 */
	public function addLimit($beats, $seconds)
	{
		$beats = (int) $beats;
		$seconds = (int) $seconds;
		if (isset($this->limits[$seconds])) {
			$currentLimit = $this->limits[$seconds];
			/** @var Limit $currentLimit */
			if ($currentLimit->getBeats() > $beats) {
				$this->limits[$seconds] = new Limit($beats, $seconds);
			} else {
				// skipped limits
				$this->skippedLimits[] = new Limit($beats, $seconds);
			}
		} else {
			$this->limits[$seconds] = new Limit($beats, $seconds);
		}
		ksort($this->limits);
		$this->markIrrelevantLimits();
	}

	/**
	 * @return Limit[]
	 */
	public function getSkippedLimits()
	{
		return $this->skippedLimits;
	}

	/**
	 * @void
	 */
	private function markIrrelevantLimits()
	{
		if (!empty($this->limits)) {
			// the first limit will always be actual
			/** @var Limit $firstLimit */
			$firstLimit = current($this->limits)->setActual(true);
			$tmpBeats = $firstLimit->getBeats();

			/** @var Limit $next */
			while ($next = next($this->limits)) {
				if ($next->getBeats() < $tmpBeats) {
					$next->setActual(false);
				} else {
					$next->setActual(true);
					$tmpBeats = $next->getBeats();
				}
			}
		}
	}

}<commit_msg>add some basics for limit manipulation<commit_after><?php namespace URFBattleground\Managers\LolApi;

class LimitManager {

	/** @var Limit[] array */
	private $limits = [];
	/** @var Limit[] array */
	private $skippedLimits = [];

	public function __construct(array $limits = [])
	{
		$this->addLimits($limits);
	}

	/**
	 * @param array $limits
	 * @return $this
	 */
	public function addLimits(array $limits)
	{
		foreach ($limits as $limit) {
			$this->addLimit($limit[0], $limit[1]);
		}

		return $this;
	}

	/**
	 * @param $beats
	 * @param $seconds
	 */
	public function addLimit($beats, $seconds)
	{
		$beats = (int) $beats;
		$seconds = (int) $seconds;
		if (isset($this->limits[$seconds])) {
			$currentLimit = $this->limits[$seconds];
			/** @var Limit $currentLimit */
			if ($currentLimit->getBeats() > $beats) {
				$this->limits[$seconds] = new Limit($beats, $seconds);
			} else {
				// skipped limits
				$this->skippedLimits[] = new Limit($beats, $seconds);
			}
		} else {
			$this->limits[$seconds] = new Limit($beats, $seconds);
		}
		ksort($this->limits);
		$this->markIrrelevantLimits();
	}

	/**
	 * @return Limit[]
	 */
	public function getSkippedLimits()
	{
		return $this->skippedLimits;
	}

	/**
	 * @void
	 */
	private function markIrrelevantLimits()
	{
		if (!empty($this->limits)) {
			// the first limit will always be actual
			/** @var Limit $firstLimit */
			$firstLimit = current($this->limits)->setActual(true);
			$tmpBeats = $firstLimit->getBeats();

			/** @var Limit $next */
			while ($next = next($this->limits)) {
				if ($next->getBeats() < $tmpBeats) {
					$next->setActual(false);
				} else {
					$next->setActual(true);
					$tmpBeats = $next->getBeats();
				}
			}
		}
	}

	public function isLimitExceed()
	{
		// TODO
		return false;
	}

	public function tick()
	{
		if ($this->isLimitExceed()) {
			throw new \Exception('Limit exceed');
		}
		// TODO
	}

	public function getActualLimits()
	{
		$limits = [];
		foreach ($this->limits as $limit) {
			/** @var Limit $limit */
			if ($limit->isActual()) {
				$limits[] = $limit;
			}
		}

		return $limits;
	}

}
{'fraction_non_alphanumeric': 0.1912611198325484, 'fraction_numerical': 0.0010465724751439038, 'mean_word_length': 3.1872946330777654, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3729361', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1342, 'n_words': 278}