Ejemplo n.º 1
0
 /**
  * Called for each interaction consumed.
  *
  * @param DataSift_StreamConsumer $consumer    The consumer sending the
  *                                             event.
  * @param array                   $interaction The interaction data.
  * @param string                  $hash        The hash of the stream that
  *                                             matched this interaction.
  *
  * @return void
  */
 public function onInteraction($consumer, $interaction, $hash)
 {
     // Disable Facebook interactions from DataSift, since they
     // don't have enough information attached
     if ($interaction['interaction']['type'] == 'facebook') {
         return;
     }
     Log::info('Type: ' . $interaction['interaction']['type']);
     // Convert all created_at columns to the MongoDate type
     $this->convertDates($interaction);
     $interaction['internal'] = array('filter_id' => $this->filter->id);
     // Twitter specific operations
     if ($interaction['interaction']['type'] == 'twitter') {
         // If we have a tweet location
         if (array_key_exists('geo', $interaction['twitter'])) {
             Log::info('Got location via tweet location');
             $location = $this->reverseGeocode($interaction['twitter']['geo']['latitude'], $interaction['twitter']['geo']['longitude']);
             $interaction['internal']['location'] = array('source' => 'tweet', 'coords' => array($interaction['twitter']['geo']['longitude'], $interaction['twitter']['geo']['latitude']), 'state' => $location['state'], 'county' => $location['county'], 'country' => $location['country']);
             // Else get lat/lon from users bio location if available
         } elseif (array_key_exists('user', $interaction['twitter']) && array_key_exists('location', $interaction['twitter']['user'])) {
             Log::info('Got location via user');
             $location = $this->geocode($interaction['twitter']['user']['location']);
             if (!is_null($location)) {
                 $interaction['internal']['location'] = array('source' => 'bio', 'coords' => array((double) $location['lon'], (double) $location['lat']), 'state' => $location['state'], 'county' => $location['county'], 'country' => $location['country']);
             }
         }
     }
     // Insert interaction into the collection
     Interaction::insert($interaction);
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ini_set('max_execution_time', 0);
     $data = DB::select('select * from interaction');
     $insert = [];
     foreach ($data as $d) {
         $ans = DB::select("select * from option_ans where attribute_id = '{$d->attribute_id}'");
         $ans1 = DB::select("select * from option_ans where attribute_id = '{$d->attribute_id1}'");
         if (isset($ans[0]) && isset($ans1[0])) {
             $insert[] = ['id_answer_from' => $ans[0]->id, 'id_answer_to' => $ans1[0]->id, 'point' => $d->point];
         }
     }
     Interaction::insert($insert);
 }