/**
  * upload all data to recommeder
  * 
  */
 public function upload(DataApi\Client $client)
 {
     if (!is_null($this->filePath)) {
         $batchSize = 25000;
         $csvFile = new CsvFile($this->filePath);
         $csvFile->rewind();
         if (!$csvFile->valid()) {
             break;
         }
         $header = $csvFile->current();
         $csvFile->next();
         $interactionsBatch = new DataApi\Batch\InteractionsBatch();
         $batchRowsCount = 0;
         while ($csvFile->valid()) {
             $attributes = array_combine($header, $csvFile->current());
             $csvFile->next();
             // process row
             try {
                 if (is_numeric($attributes['timestamp'])) {
                     $date = new DateTime('@' . $attributes['timestamp']);
                 } else {
                     $date = new DateTime($attributes['timestamp']);
                 }
             } catch (Exception $e) {
                 throw new Exception('Invalid date format in "' . $this->getName() . '" table');
             }
             $interactionsBatch->addInteraction($attributes['user_id'], $attributes['item_id'], $attributes['interaction_id'], $date);
             $batchRowsCount += 1;
             if ($batchRowsCount == $batchSize || !$csvFile->valid()) {
                 $client->insertInteractions($interactionsBatch);
                 $interactionsBatch = new DataApi\Batch\InteractionsBatch();
                 $batchRowsCount = 0;
             }
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 private function seedInteractions()
 {
     $interactionTime = new DateTime();
     $this->client->insertInteractions((new InteractionsBatch())->addInteraction(self::USER_JOHN, self::ITEM_FOO, self::INTERACTION_LIKE, $interactionTime)->addInteraction(self::USER_JOHN, self::ITEM_BAR, self::INTERACTION_DISLIKE, $interactionTime)->addInteraction(self::USER_PAUL, self::ITEM_FOO, self::INTERACTION_LIKE, $interactionTime)->addInteraction(self::USER_PAUL, self::ITEM_FOO, self::INTERACTION_PURCHASE, $interactionTime)->addInteraction(self::USER_SUZIE, self::ITEM_BAZ, self::INTERACTION_DISLIKE, $interactionTime));
 }