Exemple #1
0
 /**
  * Checks if the given JSON file can be loaded into memory
  *
  * The method tries to free enough memory if needed
  *
  * @param $filePath
  * @return bool
  */
 public function checkMemoryForJsonFile($filePath)
 {
     $guessedMemory = $this->guessMemoryForJsonFile($filePath);
     $availableMemory = $this->getAvailableMemory();
     //		DebugUtility::pl('Available memory: %s', GeneralUtility::formatBytes($availableMemory));
     //		DebugUtility::pl('We will need about %s', GeneralUtility::formatBytes($guessedMemory));
     if ($guessedMemory > $availableMemory) {
         //			DebugUtility::pl('Please free %s bytes', GeneralUtility::formatBytes($guessedMemory - $availableMemory));
         if (!$this->freeMemory($guessedMemory - $availableMemory)) {
             DebugUtility::pl('Required estimated memory amount of %s not available', GeneralUtility::formatBytes($guessedMemory - $availableMemory));
             //				throw new MemoryException(sprintf(
             //					'Required memory amount of %s not available',
             //					GeneralUtility::formatBytes($guessedMemory - $availableMemory))
             //				);
         }
     }
 }
Exemple #2
0
 /**
  * Filter the given Database by the given comparisons
  *
  * @param Database                              $dataCollection       Database instance to filter
  * @param array|SplFixedArray|\SplObjectStorage $comparisonCollection Filter conditions
  * @param bool                                  $pushMatchesToResult  If set to TRUE the matching objects will be added to the result through calling parent::push()
  * @return SplFixedArray
  */
 protected function _filterCollectionWithComparisons($dataCollection, $comparisonCollection, $pushMatchesToResult = FALSE)
 {
     if (is_array($comparisonCollection)) {
         $comparisonCollection = SplFixedArray::fromArray($comparisonCollection);
     } else {
         $comparisonCollection->rewind();
         $comparisonCollection = SplFixedArray::fromArray(iterator_to_array($comparisonCollection));
     }
     $comparisonCollectionCount = $comparisonCollection->getSize();
     if ($comparisonCollectionCount == 0) {
         return $dataCollection;
     }
     $dataCollectionRaw = $dataCollection->getRawData();
     $dataCollectionCount = $dataCollectionRaw->getSize();
     $resultArray = new SplFixedArray($dataCollectionCount);
     $i = 0;
     $matchesIndex = 0;
     while ($i < $dataCollectionCount) {
         $j = 0;
         $item = $dataCollectionRaw[$i];
         $comparisonResult = TRUE;
         while ($j < $comparisonCollectionCount) {
             $comparison = $comparisonCollection[$j];
             if (!$comparison->perform($item)) {
                 $comparisonResult = FALSE;
             }
             $j++;
         }
         if ($comparisonResult) {
             $matchingItem = $dataCollection->getObjectDataForIndexOrTransformIfNotExists($i);
             if ($matchingItem === NULL) {
                 DebugUtility::var_dump($item);
                 DebugUtility::pl('Object for index %d is NULL', $i);
             }
             $resultArray[$matchesIndex] = $matchingItem;
             if ($pushMatchesToResult) {
                 parent::offsetSet($matchesIndex, $matchingItem);
             }
             $matchesIndex++;
         }
         $i++;
     }
     $resultArray->setSize($matchesIndex);
     return SplFixedArray::fromArray($resultArray->toArray());
 }
Exemple #3
0
 /**
  * Converts the raw data at the given index to a Document instance
  *
  * @param integer $index
  * @return DocumentInterface
  */
 protected function _convertDataAtIndexToObject($index)
 {
     if (isset($this->rawData[$index]) && $this->rawData[$index] === null) {
         return null;
     }
     if (!isset($this->rawData[$index])) {
         DebugUtility::var_dump(__METHOD__ . ' valid', $this->index < $this->count() || isset($this->rawData[$this->index]), $this->index < $this->count(), isset($this->rawData[$this->index]));
         DebugUtility::var_dump($index, $index < $this->count() || isset($this->rawData[$index]), $index < $this->count(), isset($this->rawData[$index]));
         DebugUtility::var_dump($this->rawData);
         throw new IndexOutOfRangeException('Invalid index ' . $index, 1411316363);
     }
     //		if (!isset($this->rawData[$index])) throw new IndexOutOfRangeException('Invalid index ' . $index);
     $rawData = $this->rawData[$index];
     $rawData = DocumentUtility::assertDocumentIdentifierOfData($rawData);
     $dataObject = new Document($rawData, $this->identifier);
     //		if (isset($rawMetaData['creation_time'])) {
     //			$dataObject->setCreationTime($rawMetaData['creation_time']);
     //		}
     //		if (isset($rawMetaData['modification_time'])) {
     //			$dataObject->setModificationTime($rawMetaData['modification_time']);
     //		}
     return $dataObject;
 }
Exemple #4
0
 /**
  * @test
  */
 public function sortPersonsByLatitudeAfterAddingAPersonTest()
 {
     $this->checkPersonFile();
     /** @var Reader $databaseReader */
     $databaseReader = $this->getDiContainer()->get('\\Cundd\\PersistentObjectStore\\DataAccess\\Reader');
     $newlyLoadedDatabase = $databaseReader->loadDatabase('people');
     $dataInstance = new Document();
     $dataInstance->setData(array('_id' => '541f004ef8f4d2df32ca60c2', 'index' => 5000, 'isActive' => FALSE, 'balance' => '$2,925.56', 'picture' => 'http://placehold.it/32x32', 'age' => 31, 'eyeColor' => 'brown', 'name' => 'Daniel Corn', 'gender' => 'male', 'company' => 'FARMEX', 'email' => '*****@*****.**', 'phone' => '+1 (973) 480-3194', 'address' => '125 Stone Avenue, Worton, Alabama, 6669', 'about' => 'Dolore in excepteur nisi dolor laboris ipsum proident cupidatat proident. Aliquip commodo culpa adipisicing ullamco ad. Ut ex duis tempor do id enim. Proident exercitation officia veniam magna mollit nostrud duis do qui reprehenderit. Ea culpa anim ullamco aliqua culpa nulla ex nisi irure qui incididunt reprehenderit. Labore do velit amet duis aute occaecat. Et sunt ex Lorem qui do deserunt ullamco labore.\\r\\n', 'registered' => '2014-06-29T15:29:47 -02:00', 'latitude' => 52.37284, 'longitude' => -70.88927, 'tags' => ['id', 'consequat', 'aute', 'deserunt', 'in', 'enim', 'veniam'], 'friends' => [array('id' => 0, 'name' => 'Bray Ruiz'), array('id' => 1, 'name' => 'Carr Kerr'), array('id' => 2, 'name' => 'Carter Dejesus')], 'greeting' => 'Hello, Conway Burch! You have 3 unread messages.', 'favoriteFruit' => 'apple'));
     $newlyLoadedDatabase->add($dataInstance);
     /** @var Database $database */
     $database = $this->coordinator->getDatabase('people');
     //		$start = microtime(TRUE);
     $sortedDatabase = $this->fixture->sortCollectionByPropertyKeyPath($newlyLoadedDatabase, 'latitude');
     //		$end = microtime(TRUE);
     //		printf("Sort %0.8f\n", $end - $start);
     $maxIterations = 100;
     $maxIterations = $database->count();
     // TODO: Make this work
     // $this->assertEquals($database->count(), $sortedDatabase->count());
     // $this->assertNotEquals($database->count(), $newlyLoadedDatabase->count());
     //		var_dump($sortedDatabase[$sortedDatabase->count() - 1]);
     $lastLatitude = -PHP_INT_MAX;
     for ($i = 0; $i < $maxIterations; $i++) {
         /** @var DocumentInterface $item */
         $item = $sortedDatabase[$i];
         $this->assertNotNull($item);
         //			printf('%d: Last latitude %0.9f to current %0.9f' . PHP_EOL, $i, $lastLatitude, $item->valueForKey('latitude'));
         if ($lastLatitude === $item->valueForKey('latitude')) {
             DebugUtility::var_dump($i, $item, $sortedDatabase[$i - 1]);
         }
         $this->assertGreaterThan($lastLatitude, $item->valueForKey('latitude'), 'Current latitude is not bigger than last for loop number ' . $i);
         $lastLatitude = $item->valueForKey('latitude');
     }
     //		$sortedDatabase = $this->fixture->sortCollectionByPropertyKeyPath($database, 'latitude', TRUE);
     //
     //		$this->assertEquals($database->count(), $sortedDatabase->count());
     //
     //		$lastLatitude = PHP_INT_MAX;
     //		for ($i = 0; $i < $maxIterations; $i++) {
     //			/** @var DocumentInterface $item */
     //			$item = $sortedDatabase[$i];
     //			$this->assertNotNull($item);
     //
     //			$this->assertLessThan($lastLatitude, $item->valueForKey('latitude'));
     //			$lastLatitude = $item->valueForKey('latitude');
     //		}
 }