示例#1
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($workerunit) {
         //    dd($workerunit);
         // Inherit type, domain and format
         if (empty($workerunit->type) or empty($workerunit->domain) or empty($workerunit->format)) {
             $j = Job::where('_id', $workerunit->job_id)->first();
             $workerunit->type = $j->type;
             $workerunit->domain = $j->domain;
             $workerunit->format = $j->format;
         }
         $workerunit->annotationVector = $workerunit->createAnnotationVector();
         // Activity if not exists
         if (empty($workerunit->activity_id)) {
             try {
                 $activity = new Activity();
                 $activity->label = "Workerunit is saved.";
                 $activity->softwareAgent_id = $workerunit->softwareAgent_id;
                 $activity->save();
                 $workerunit->activity_id = $activity->_id;
                 Log::debug("Saving workerunit {$workerunit->_id} with activity {$workerunit->activity_id}.");
             } catch (Exception $e) {
                 if ($activity) {
                     $activity->forceDelete();
                 }
                 //if($workerunit) $workerunit->forceDelete();
                 throw new Exception('Error saving activity for workerunit.');
             }
         }
     });
 }
 public static function boot()
 {
     parent::boot();
     static::saving(function ($questiontemplate) {
         if (empty($questiontemplate->activity_id)) {
             try {
                 $activity = new Activity();
                 $activity->label = "Questiontemplate is saved.";
                 $activity->softwareAgent_id = 'templatebuilder';
                 $activity->save();
                 $questiontemplate->activity_id = $activity->_id;
                 Log::debug("Saving QuestionTemplate {$questiontemplate->_id} with activity {$questiontemplate->activity_id}.");
             } catch (Exception $e) {
                 if ($activity) {
                     $activity->forceDelete();
                 }
                 if ($questiontemplate) {
                     $questiontemplate->forceDelete();
                 }
                 throw new Exception('Error saving activity for QuestionTemplate.');
             }
         }
     });
 }
 public function storeVideoSegments($parentEntity, $videoSegmenting)
 {
     $tempEntityID = null;
     $status = array();
     try {
         $this->createVideoSegmentingSoftwareAgent();
     } catch (Exception $e) {
         $status['error']['videosegmenting'] = $e->getMessage();
         return $status;
     }
     try {
         $activity = new Activity();
         $activity->softwareAgent_id = "videosegmenting";
         $activity->save();
     } catch (Exception $e) {
         // Something went wrong with creating the Activity
         $activity->forceDelete();
         $status['error'][$title] = $e->getMessage();
         return $status;
     }
     for ($i = 0; $i < sizeof($videoSegmenting); $i++) {
         $videoSegmentName = explode("/", $videoSegmenting[$i]["storage_url"]);
         $title = $videoSegmentName[sizeof($videoSegmentName) - 1];
         try {
             $entity = new Entity();
             $entity->_id = $tempEntityID;
             $entity->title = strtolower($title);
             $entity->domain = $parentEntity->domain;
             $entity->format = "video";
             $entity->documentType = "videosegment";
             $entity->parents = array($parentEntity->_id);
             $entity->source = $parentEntity->source;
             $entity->content = $videoSegmenting[$i];
             //unset($relexStructuredSentenceKeyVal['properties']);
             $entity->hash = md5(serialize($videoSegmenting[$i]));
             $entity->activity_id = $activity->_id;
             $entity->save();
             $status['success'][$title] = $title . " was successfully processed into a video segment. (URI: {$entity->_id})";
         } catch (Exception $e) {
             // Something went wrong with creating the Entity
             $entity->forceDelete();
             $status['error'][$title] = $e->getMessage();
         }
         $tempEntityID = $entity->_id;
     }
     $status['success']['noEntitiesCreated'] = sizeof($videoSegmenting);
     //dd($status);
     return $status;
 }
示例#4
0
 public function store($documentType, $parameters, $noOfVideos)
 {
     //fastcgi_finish_request();
     $listOfVideoIdentifiers = array();
     $this->listRecords($parameters, $noOfVideos, $listOfVideoIdentifiers);
     // get list of existing projects
     $projects = ProjectHandler::listProjects();
     //	dd("done");
     $status = array();
     try {
         $this->createOpenimagesVideoGetterSoftwareAgent();
     } catch (Exception $e) {
         $status['error']['OnlineData'] = $e->getMessage();
         return $status;
     }
     try {
         $activity = new Activity();
         $activity->softwareAgent_id = "openimagesgetter";
         $activity->save();
     } catch (Exception $e) {
         // Something went wrong with creating the Activity
         $status['error']['OnlineData'] = $e->getMessage();
         $activity->forceDelete();
         return $status;
     }
     $count["count"] = 0;
     foreach ($listOfVideoIdentifiers as $video) {
         $title = $video;
         try {
             $entity = new Unit();
             $entity->_id = $entity->_id;
             $entity->title = strtolower($title);
             $entity->documentType = $documentType;
             $entity->source = "openimages";
             $entity->project = "soundandvision";
             $entity->type = "unit";
             $videoMetadata = $this->getRecord($video, $parameters["metadataPrefix"]);
             $entity->content = $videoMetadata["content"];
             $parents = array();
             $entity->parents = $parents;
             $entity->tags = array("unit");
             $entity->segments = $count;
             $entity->keyframes = $count;
             $hashing = array();
             $hashing["content"] = $entity->content;
             $hashing["project"] = $entity->project;
             $entity->hash = md5(serialize($hashing));
             $entity->activity_id = $activity->_id;
             $entity->save();
             $status['success'][$title] = $title . " was successfully uploaded. (URI: {$entity->_id})";
             // add the project if it doesnt exist yet
             if (!in_array($entity->project, $projects)) {
                 ProjectHandler::createGroup($entity->project);
                 // add the project to the temporary list
                 array_push($projects, $entity->project);
             }
             // add the user to the project if it has no access yet
             if (!ProjectHandler::inGroup($entity->user_id, $entity->project)) {
                 $user = UserAgent::find($entity->user_id);
                 ProjectHandler::grantUser($user, $entity->project, Roles::PROJECT_MEMBER);
             }
         } catch (Exception $e) {
             // Something went wrong with creating the Entity
             $activity->forceDelete();
             $entity->forceDelete();
             $status['error'][$title] = $e->getMessage();
         }
     }
     $status["recno"] = count($listOfVideoIdentifiers);
     return $status;
 }
示例#5
0
 public function postFeatures()
 {
     $return = array('status' => 'ok');
     $input = Input::get();
     $domain = $input[1];
     $type = $input[2];
     // CREATE ACTIVITY FOR BATCH
     $activity = new Activity();
     $activity->label = "Images posted for processing.";
     $activity->softwareAgent_id = 'imagegetter';
     $activity->save();
     // LOOP THROUGH IMAGES CREATE ENTITIES WITH ACTIVITY-ID FOR NEW IMAGES
     $url_ids = "";
     foreach ($input[0] as $img) {
         \Log::debug(json_encode($img));
         try {
             $parse = parse_url($img['url']);
             //$source = $parse['host'];
             // Save images as parent
             $image = new Entity();
             $image->domain = $domain;
             $image->format = "image";
             $content = $image->content;
             $content['url'] = $img['url'];
             $content['title'] = $img['title'];
             $content['height'] = $img['height'];
             $content['width'] = $img['width'];
             $content['description'] = $img['description'];
             $content['author'] = $img['author'];
             $image->content = $content;
             $image->documentType = $type;
             $image->source = "Rijksmuseum";
             $image->tags = ['unit'];
             $image->activity_id = $activity->_id;
             $image->softwareAgent_id = "imagegetter";
             // Take last part of URL as image title
             $temp = explode('/', $img['url']);
             //$image->title = end($temp);
             // CHECK WHETHER URL EXISTS ALREADY
             $hash = md5(serialize($image->content));
             if ($existingid = Entity::where('hash', $hash)->pluck('_id')) {
                 $imageid = $existingid;
             } else {
                 $image->hash = $hash;
                 $image->activity_id = $activity->_id;
                 \Log::debug(json_encode($image->toArray()));
                 $image->save();
                 $existingid = $image->_id;
             }
             $url_ids .= "{$img['url']} {$existingid} ";
         } catch (Exception $e) {
             //delete image
             if (isset($image)) {
                 $image->forceDelete();
             }
             //delete activity
             if (isset($activity)) {
                 $activity->forceDelete();
             }
             //Session::flash('flashError', $e->getMessage());
             $return['error'] = $e->getMessage();
             $return['status'] = 'bad';
             \Log::debug($e->getMessage());
             return $return;
         }
         // RUN PYTHON SCRIPT THAT CALLS APIs TO ADD FEATURES TO IMAGE
     }
     //return $url_ids;
     try {
         //$command = "/usr/bin/python2.7 /var/www/crowd-watson/app/lib/getAPIS/getRijks.py " . $domain . " " . $type . " " . 4 . " " . "vogel";
         $command = "/usr/bin/python2.7 " . base_path() . "/app/lib/getAPIS/getMany.py " . $domain . " " . $type . " " . Auth::user()->email . " " . $url_ids;
         //$command = "/usr/bin/python2.7 /var/www/crowd-watson/app/lib/getAPIS/getMany.py art painting http://lh3.ggpht.com/Q1GZTdmwa8iTLgdbu5uAgzovmLbb7lsYhG-QgVcoN8A-WJtIsNUo4-VyTMd9iKHLp-XNm812WyUaSgQdHdjQjDioJQI=s0 999";
         //return $command;
         \Log::debug("Running {$command}");
         exec($command, $output, $error);
         $return['oo'] = $output;
         $return['ee'] = $error;
         //$return['a'] = $a;
         //throw $e; // for debugging.
         //return $error;
     } catch (Exception $e) {
         //throw $e; // for debugging.
         \Log::debug("ERROR: " . $e->getMessage());
         $return['error'] = $e->getMessage();
         $return['status'] = 'bad';
     }
     return $this->returnJson($return);
 }