/** * Store to the database the given entities as entities decendent from the given * document. * * @param $document Parent document -- Must be a document entity on the database. * @param $entities List of entities to be created as decendents from the given document. * * @return multitype:string A status array containing the result status information. */ public function store($document, $entities) { $nEnts = count($entities); if ($nEnts <= 0 && $nEnts >= 10000) { // We will have problems processing empty files or more than 10,000 entities return ['error' => 'Unable to process files with more than 10,000 lines: ' . $nEnts . 'found']; } $activity = new Activity(); $activity->softwareAgent_id = $this->softwareComponent->_id; $activity->save(); $format = $document['format']; $domain = $document['domain']; $docType = $document['documentType'] . '-sentence'; $title = $document['title']; $parentId = $document['_id']; $project = $document['project']; $activityId = $activity->_id; if (Auth::check()) { $userId = Auth::user()->_id; } else { $userId = "crowdwatson"; } $idBase = 'entity/' . $format . '/' . $domain . '/' . $docType . '/'; $inc = $this->getLastDocumentInc($format, $domain, $docType); $fullEntities = []; foreach ($entities as $entitiy) { $fullEntity = ["_id" => $idBase . $inc, "documentType" => 'unit', "activity_id" => $activityId, "softwareAgent_id" => $this->softwareComponent->_id, "project" => $project, "user_id" => $userId, "type" => $docType, "unitParents" => [$parentId], "jobParents" => [], "children" => [], "judgements" => [], "metrics" => [], "source" => '', "format" => $format, "title" => strtolower($title), "domain" => $domain, "tags" => ['unit'], "content" => $entitiy, "hash" => md5(serialize($entitiy)), "updated_at" => new MongoDate(time()), "created_at" => new MongoDate(time())]; $inc++; array_push($fullEntities, $fullEntity); } \DB::collection('entities')->insert($fullEntities); \MongoDB\Temp::truncate(); return ['success' => 'Sentences created successfully']; }
public static function boot() { parent::boot(); static::creating(function ($jobconf) { // IFEXISTS CHECK IS NOT HERE. try { $c = $jobconf->content; if (isset($c['reward'])) { $c['reward'] = (double) $c['reward']; } if (isset($c['hitLifetimeInMinutes'])) { $c['hitLifetimeInMinutes'] = intval($c['hitLifetimeInMinutes']); } if (isset($c['autoApprovalDelayInMinutes'])) { $c['autoApprovalDelayInMinutes'] = intval($c['autoApprovalDelayInMinutes']); } if (isset($c['expirationInMinutes'])) { $c['expirationInMinutes'] = intval($c['expirationInMinutes']); } if (isset($c['workerunitsPerUnit'])) { $c['workerunitsPerUnit'] = intval($c['workerunitsPerUnit']); } if (isset($c['unitsPerTask'])) { $c['unitsPerTask'] = intval($c['unitsPerTask']); if ($c['unitsPerTask'] == 0) { $c['unitsPerTask'] = 1; } } $jobconf->content = $c; } catch (Exception $e) { if ($jobconf) { $jobconf->forceDelete(); } throw new Exception('Error saving JobConfiguration.'); } if (empty($jobconf->activity_id)) { try { $activity = new Activity(); $activity->label = "JobConfiguration is saved."; $activity->softwareAgent_id = 'jobcreator'; $activity->save(); $jobconf->activity_id = $activity->_id; Log::debug("Saved JobConfiguration with activity {$jobconf->activity_id}."); } catch (Exception $e) { if ($activity) { $activity->forceDelete(); } if ($jobconf) { $jobconf->forceDelete(); } throw new Exception('Error saving activity for JobConfiguration.'); } } }); }
public static function boot() { parent::boot(); static::saving(function ($job) { \Log::debug('Clearing jobCache and mainSearchFilters.'); \MongoDB\Temp::whereIn('_id', ['mainSearchFilters', 'jobCache', $job->_id])->forceDelete(); }); static::creating(function ($job) { try { if (!SoftwareAgent::find('jobcreator')) { $softwareAgent = new SoftwareAgent(); $softwareAgent->_id = 'jobcreator'; $softwareAgent->label = "Job creation"; } if (!isset($job->projectedCost) and !isset($job->iamemptyjob)) { $reward = $job->jobConfiguration->content['reward']; $workerunitsPerUnit = intval($job->jobConfiguration->content['workerunitsPerUnit']); $unitsPerTask = intval($job->jobConfiguration->content['unitsPerTask']); $unitsCount = count($job->batch->wasDerivedFrom); if (!$unitsPerTask) { $projectedCost = 0; } else { $projectedCost = round($reward / $unitsPerTask * ($unitsCount * $workerunitsPerUnit), 2); } $job->expectedWorkerunitsCount = $unitsCount * $job->jobConfiguration->content['workerunitsPerUnit']; $job->projectedCost = $projectedCost; } $job->unitsCount = count($job->batch->wasDerivedFrom); $job->latestMetrics = 0; $job->workerunitsCount = 0; $job->completion = 0.0; // 0.00-1.00 if (!isset($job->activity_id)) { $activity = new Activity(); $activity->label = "Job is uploaded to crowdsourcing platform."; $activity->softwareAgent_id = 'jobcreator'; // TODO: JOB softwareAgent_id = $platform. Does this need to be the same? $activity->save(); $job->activity_id = $activity->_id; } } catch (Exception $e) { // Something went wrong with creating the Entity $job->forceDelete(); throw $e; } Log::debug("Saved entity {$job->_id} with activity {$job->activity_id}."); }); }
/** * * @param array $input * @return result status structure containing * 'status' 'ok' or 'error' * 'message' 'A status message' * 'batch' the batch or null if error */ public function store(array $input) { try { $this->createBatchCreatorSoftwareAgent(); } catch (Exception $e) { return ['status' => 'error', 'message' => $e->getMessage(), 'batch' => null]; } try { $activity = new Activity(); $activity->softwareAgent_id = "batchcreator"; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $activity->forceDelete(); return ['status' => 'error', 'message' => $e->getMessage(), 'batch' => null]; } try { $entity = new Entity(); $entity->title = $input['batch_title']; $entity->format = $input['format']; $entity->domain = $input['domain']; $entity->documentType = 'batch'; $entity->softwareAgent_id = 'batchcreator'; $entity->parents = $input['units']; $entity->content = $input['batch_description']; $entity->hash = md5(serialize($entity->parents)); $entity->activity_id = $activity->_id; $entity->save(); Queue::push('Queues\\UpdateUnits', $input['units']); return ['status' => 'ok', 'message' => $input['batch_title'] . " batch was successfully created. (URI: {$entity->_id})", 'batch' => $entity]; } catch (Exception $e) { // Something went wrong with creating the Entity $activity->forceDelete(); $entity->forceDelete(); return ['status' => 'error', 'message' => $e->getMessage(), 'batch' => null]; } }
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 getConvertcsv() { if (($handle = fopen(storage_path() . '/jobs.csv', 'r')) === false) { die('Error opening file'); } /* foreach (\QuestionTemplate::get() as $q) $q->forceDelete(); foreach (\JobConfiguration::get() as $q) $q->forceDelete(); foreach (\Job::get() as $q) $q->forceDelete(); */ \MongoDB\Activity::truncate(); $activity = new \MongoDB\Activity(); $activity->label = "Imported jobs from CSV file."; //$activity->used = $job->_id; $activity->softwareAgent_id = 'importer'; $activity->save(); $headers = fgetcsv($handle, 1024, ','); $count = 0; $complete = array(); while ($row = fgetcsv($handle, 1024, ',')) { $c = array_combine($headers, $row); $c['platform'] = array($c['platform']); $j = new JobConfiguration(); //$j->_id = "entity/text/medical/jobconf/$count"; $j->type = isset($row['type']) ? $row['type'] : 'todo'; $j->content = $c; $j->hash = md5(serialize($j->content)); $j->activity_id = $activity->_id; $j->user_id = 'CrowdWatson'; $j->save(); $job = new Job(); $job->jobConf_id = $j->_id; $job->activity_id = $activity->_id; $job->batch_id = "entity/text/medical/batch/{$count}"; $job->type = isset($row['type']) ? $row['type'] : 'todo'; $job->user_id = 'CrowdWatson'; $job->status = 'finished'; $job->save(); $count++; } //new MongoDate(strtotime( fclose($handle); echo json_encode($complete, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); }
/** * Run the database counter seeds. * * @return void */ public function run() { Eloquent::unguard(); $this->command->info('Seeding all activities...'); $seeds = $this->getSeeds(Activity::distinct('_id')->get()); foreach ($seeds as $name => $seed) { $this->command->info('Seed: ' . $name . ' = ' . $seed); $counter = new Counter(); $counter['_id'] = $name; $counter['seq'] = $seed; $counter->save(); } $this->command->info('Seeding all entities...'); $seeds = $this->getSeeds(Entity::distinct('_id')->get()); foreach ($seeds as $name => $seed) { $this->command->info('Seed: ' . $name . ' = ' . $seed); $counter = new Counter(); $counter['_id'] = $name; $counter['seq'] = $seed; $counter->save(); } }
public function getProcesscrowdgames() { $gameJobs = Job::where('softwareAgent_id', 'DrDetectiveGamingPlatform')->get(); $activity = new Activity(); $activity->softwareAgent_id = 'DrDetectiveGamingPlatform'; $activity->save(); foreach ($gameJobs as $job) { // $annotations = Entity::where('jobParents', $job['_id'])->get(); // Create one annotation vector for each image on the game $images = Entity::where('jobParents', $job['_id'])->distinct('content.task_data')->get(); $annotationsSummary = []; foreach ($images as $image) { $imageName = $image[0]; // unpack data $annotations = Entity::where('jobParents', $job['_id'])->where('content.task_data', $imageName)->get(); $annotations = $annotations->toArray(); // Create an array with all coordinates given for target image. $coordinates = array_column(array_column(array_column($annotations, 'content'), 'response'), 'Coordinates'); $allCoordinates = []; foreach ($coordinates as $coords) { // Flatten to array of coords. foreach ($coords as $c) { $allCoordinates[] = $c; } } $aggCoords = static::aggregateCoordinates($allCoordinates); $annotationsSummary[] = ['image' => $imageName, 'aggregateCoordinates' => $aggCoords]; } // process annotations for this job into an annotation vector... $e = new Entity(); $e->jobParents = [$job['_id']]; $e->annotationVector = $annotationsSummary; $e->documentType = 'annotationVector'; $e->activity_id = $activity->_id; $e->softwareAgent_id = $job->softwareAgent_id; $e->project = $job->project; $e->user_id = $job->user_id; $e->save(); } return 'OK -- may need adjustments...'; }
private function createMetricActivity($jobid) { // Todo: create software agent $activity = new Activity(); $activity->label = "Metrics calculated on job."; $activity->used = $jobid; $activity->softwareAgent_id = 'metrics'; $activity->save(); }
public function store($format, $domain, $documentType, $parameters, $noOfVideos) { //fastcgi_finish_request(); $listOfVideoIdentifiers = array(); $this->listRecords($parameters, $noOfVideos, $listOfVideoIdentifiers); // 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 Entity(); $entity->_id = $entity->_id; $entity->title = strtolower($title); $entity->domain = $domain; $entity->format = $format; $entity->documentType = $documentType; $entity->source = "openimages"; $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; $entity->hash = md5(serialize([$entity->content])); $entity->activity_id = $activity->_id; $entity->save(); Queue::push('Queues\\UpdateUnits', [$entity->_id]); $status['success'][$title] = $title . " was successfully uploaded. (URI: {$entity->_id})"; if (isset($status['success'])) { $this->storeVideoDescription($entity); // dd($this->storeVideoDescription($entity)); } } 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; }
/** * Display current user activity */ public function getActivity(UserAgent $user) { $activities = Activity::getActivitiesForUser($user['_id']); return View::make('users.activity')->with('activities', $activities)->with('user', $user); }
public function storeNERDApi($parentEntity, $metadataDescriptionPreprocessing) { // $metadataDescriptionPreprocessing = unserialize(utf8_decode(utf8_encode(serialize($metadataDescriptionPreprocessing)))); $status = array(); try { $this->createNamedEntitiesExtractionNERDApiSoftwareAgent(); } catch (Exception $e) { $status['error']['nerd'] = $e->getMessage(); return $status; } try { $activity = new Activity(); $activity->softwareAgent_id = "nerdextractor"; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $activity->forceDelete(); $status['error'][$title] = $e->getMessage(); return $status; } $tempEntityID = null; $title = "nerdextractor-" . $parentEntity["title"]; //dd($title); try { $entity = new Entity(); $entity->_id = $tempEntityID; $entity->title = strtolower($title); $entity->domain = $parentEntity->domain; $entity->format = "text"; $entity->documentType = "nerdextractor"; $entity->parents = array($parentEntity->_id); $entity->source = $parentEntity->source; $content = array(); $content["description"] = $parentEntity->content; foreach ($metadataDescriptionPreprocessing as $key => $value) { $content["features"][$key] = $value; } $entity->content = $content; // //unset($twrexStructuredSentenceKeyVal['properties']); $entity->hash = md5(serialize($entity)); $entity->activity_id = $activity->_id; $entity->save(); $status['success'][$title] = $title . " was successfully processed into entities extraction. (URI: {$entity->_id})"; } catch (Exception $e) { // Something went wrong with creating the Entity $entity->forceDelete(); $status['error'][$title] = $e->getMessage(); } $tempEntityID = $entity->_id; return $status; }
public function anyTest() { try { if (!($data = Input::get('data'))) { if (!($data = \Request::getContent())) { return false; } } if (empty($data)) { return false; } $data = json_decode($data, true); $data['softwareAgent_id'] = strtolower($data['softwareAgent_id']); try { $this->createPostSoftwareAgent($data); } catch (Exception $e) { return serialize([$e->getMessage()]); } try { $activity = new Activity(); $activity->softwareAgent_id = $data['softwareAgent_id']; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $activity->forceDelete(); return serialize([$e->getMessage()]); } $entity = new Entity(); $entity->format = 'image'; $entity->domain = $data['domain']; $entity->tags = $data['tags']; $entity->documentType = $data['documentType']; $entity->softwareAgent_configuration = $data['softwareAgent_configuration']; if (isset($data['parents'])) { $entity->parents = $data['parents']; } $entity->content = $data['content']; if (isset($data['threshold'])) { $entity->threshold = $data['threshold']; } if (isset($data['relevantFeatures'])) { $entity->recognizedFeatures = $data['relevantFeatures']; } if (isset($data['hash'])) { $entity->hash = $data['hash']; } else { $entity->hash = md5(serialize($data['content'])); } $entity->activity_id = $activity->_id; if (Entity::where('hash', $entity->hash)->first()) { //dd('asdasd'); } else { $entity->save(); } return Response::json($entity); } catch (Exception $e) { dd($e->getMessage()); } }
/** * Store a new file to the database. Construct all entity information for such file. * * @param $fileFormat * @param $domain * @param $documentType * @param $project The name of the Project who owns the file data. * @param $domainCreate * @param $documentCreate * @param $files */ public function store($fileFormat, $domain, $documentType, $project, $domainCreate, $documentCreate, $files) { $format = $this->getType($fileFormat); $validatedFiles = $this->performValidation($files, $format); $newDomain = false; $newDocType = false; if ($domain == 'domain_type_other') { // Add new domain to DB $domain = $domainCreate; $domain = str_replace(' ', '', $domain); $domain = strtolower($domain); $domain = 'domain_type_' . $domain; $newDomain = true; } if ($documentType == 'document_type_other') { // Add new doc_type to DB $documentType = $documentCreate; $newDocType; } if ($newDomain || $newDocType) { if ($newDomain) { // newDomain and new DocType $domainName = $domainCreate; $upDomains = $this->softwareComponent->domains; $upDomains[$domain] = ["name" => $domainName, "file_formats" => [$fileFormat], "document_types" => [$documentType]]; $this->softwareComponent->domains = $upDomains; } else { if ($newDocType) { // Only docType is new -- domain already existed... $docTypes = $this->softwareComponent->domains[$domain]["document_types"]; array_push($docTypes, $documentType); $this->softwareComponent->domains[$domain]["document_types"] = $docTypes; } } $this->softwareComponent->save(); } $domain = str_replace("domain_type_", "", $domain); $documentType = str_replace("document_type_", "", $documentType); $status = []; try { $activity = new Activity(); $activity->softwareAgent_id = $this->softwareComponent->_id; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $activity->forceDelete(); $status['error'] = $e->getMessage(); return $status; } $files = $validatedFiles['passed']; foreach ($files as $file) { $title = $file->getClientOriginalName(); try { $entity = new Entity(); $entity->_id = $entity->_id; $entity->activity_id = $activity->_id; $entity->softwareAgent_id = $this->softwareComponent->_id; $entity->project = $project; $entity->title = strtolower($title); $entity->domain = $domain; $entity->format = "text"; $entity->documentType = $documentType; $entity->content = File::get($file->getRealPath()); $entity->hash = md5(serialize([$entity->content])); $entity->tags = ["unit"]; $entity->save(); $status['success'][$title] = $title . " was successfully uploaded. (URI: {$entity->_id})"; } catch (Exception $e) { // Something went wrong with creating the Entity $activity->forceDelete(); $entity->forceDelete(); $status['error'][$title] = $e->getMessage(); } } $files = $validatedFiles['failed']; foreach ($files as $file) { $title = $file->getClientOriginalName(); $status['error'][$title] = 'Validation failed'; } return $status; }
public function postSubmitFinal($ordersandbox = 'order') { $jc = unserialize(Session::get('jobconf')); $template = Session::get('template'); $batch = unserialize(Session::get('batch')); $questiontemplateid = Session::get('questiontemplateid'); $jobs = array(); if (!$jc->validate()) { $msg = ''; foreach ($jc->getErrors()->all() as $message) { $msg .= "<li>{$message}</li>"; } Session::flash('flashError', "<ul>{$msg}</ul>"); return Redirect::to("jobs/submit"); } try { // Save activity $activity = new MongoDB\Activity(); $activity->label = "Job is uploaded to crowdsourcing platform."; $activity->softwareAgent_id = 'jobcreator'; // JOB softwareAgent_id = $platform. Does this need to be the same? $activity->save(); // Save jobconf if necessary $hash = md5(serialize($jc->content)); if ($existingid = JobConfiguration::where('hash', $hash)->pluck('_id')) { $jcid = $existingid; } else { $jc->format = $batch->format; $jc->domain = $batch->domain; $jc->hash = $hash; $jc->activity_id = $activity->_id; $jc->save(); $jcid = $jc->_id; } // Publish jobs foreach ($jc->content['platform'] as $platformstring) { $j = new Job(); $j->format = $batch->format; $j->domain = $batch->domain; $j->type = explode('/', $template)[1]; $j->template = $template; // TODO: remove $j->batch_id = $batch->_id; $j->questionTemplate_id = $questiontemplateid; $j->jobConf_id = $jcid; $j->softwareAgent_id = $platformstring; $j->activity_id = $activity->_id; $j->publish($ordersandbox == 'sandbox' ? true : false); $jobs[] = $j; } // Success. //Session::flash('flashSuccess', "Created " . ($ordersandbox == 'sandbox' ? 'but didn\'t order' : 'and ordered') . " job(s) on " . // strtoupper(implode(', ', $jc->content['platform'])) . '.'); $successmessage = "Created job" . (count($jc->content['platform']) > 1 ? 's' : '') . " on " . strtoupper(implode(', ', $jc->content['platform'])) . '. Order it by pressing the button under \'Actions\'. Demo jobs are published on the sandbox or internal channels only.'; // TODO: this only takes the first job of potentially two if (!empty($jobs[0]->url)) { $successmessage .= ". After that, you can view it <a href='{$jobs[0]->url}' target='blank'>here</a>."; } Session::flash('flashSuccess', $successmessage); return Redirect::to("jobs/"); //(Auth::user()->role == 'demo' ? '. Because this is a demo account, you can not order it. Please take a look at our finished jobs!' : '. Click on \'actions\' on the job to order it.') } catch (Exception $e) { // Undo creation and delete jobs if (isset($jobs)) { foreach ($jobs as $j) { if (isset($j->platformJobId)) { $j->undoCreation($j->platformJobId); } $j->forceDelete(); } } //delete activity if ($activity) { $activity->forceDelete(); } throw $e; //for debugging Session::flash('flashError', $e->getMessage()); return Redirect::to("jobs/submit"); } }
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; }
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); }
public function OldcreateWorkerunitsAndCrowdAgents($mappedWorkerunitsWithUnits, $job_id, $taskType = "FactSpan") { $status = array(); $index = 0; try { $activity = new Activity(); $activity->softwareAgent_id = "cf"; $activity->save(); } catch (Exception $e) { $activity->forceDelete(); $status['error'][$index]['activity'] = $e->getMessage(); } foreach ($mappedWorkerunitsWithUnits as $mappedWorkerunitsWithUnit) { $index++; $crowdagent = CrowdAgent::where('platformAgentId', $mappedWorkerunitsWithUnit['_worker_id'])->where('softwareAgent_id', 'cf')->first(); if (!$crowdagent) { try { $crowdagent = new CrowdAgent(); $crowdagent->_id = "crowdagent/cf/" . $mappedWorkerunitsWithUnit['_worker_id']; $crowdagent->softwareAgent_id = 'cf'; $crowdagent->platformAgentId = (int) $mappedWorkerunitsWithUnit['_worker_id']; $crowdagent->country = $mappedWorkerunitsWithUnit['_country']; $crowdagent->region = $mappedWorkerunitsWithUnit['_region']; $crowdagent->city = $mappedWorkerunitsWithUnit['_city']; $crowdagent->cfWorkerTrust = (double) $mappedWorkerunitsWithUnit['_trust']; $crowdagent->save(); } catch (Exception $e) { $status['error'][$index]['crowdagent'] = $e->getMessage(); // continue; } } if (!Entity::where('softwareAgent_id', 'cf')->where('platformWorkerunitId', $mappedWorkerunitsWithUnit['_id'])->first()) { $entity = new Entity(); $entity->format = "text"; $entity->domain = "medical"; $entity->documentType = "workerunit"; $entity->job_id = $job_id; $entity->activity_id = $activity->_id; $entity->crowdAgent_id = $crowdagent->_id; $entity->softwareAgent_id = "cf"; $entity->unit_id = $mappedWorkerunitsWithUnit['unit']['_id']; $entity->platformWorkerunitId = (int) $mappedWorkerunitsWithUnit['_id']; $entity->cfChannel = $mappedWorkerunitsWithUnit['_channel']; $entity->acceptTime = new MongoDate(strtotime($mappedWorkerunitsWithUnit['_started_at'])); $entity->submitTime = new MongoDate(strtotime($mappedWorkerunitsWithUnit['_created_at'])); $entity->cfTrust = (double) $mappedWorkerunitsWithUnit['_trust']; if ($taskType == "FactSpan") { $entity->content = ["confirmfirstfactor" => $mappedWorkerunitsWithUnit['confirmfirstfactor'], "confirmsecondfactor" => $mappedWorkerunitsWithUnit['confirmsecondfactor'], "firstfactor" => $mappedWorkerunitsWithUnit['firstfactor'], "secondfactor" => $mappedWorkerunitsWithUnit['secondfactor'], "saveselectionids1" => $mappedWorkerunitsWithUnit['saveselectionids1'], "saveselectionids2" => $mappedWorkerunitsWithUnit['saveselectionids2'], "confirmids1" => $mappedWorkerunitsWithUnit['confirmids1'], "confirmids2" => $mappedWorkerunitsWithUnit['confirmids2'], "sentencefirstfactor" => $mappedWorkerunitsWithUnit['sentencefirstfactor'], "sentencesecondfactor" => $mappedWorkerunitsWithUnit['sentencesecondfactor']]; } elseif ($taskType == "RelEx") { $entity->content = ["step_1_select_the_valid_relations" => $mappedWorkerunitsWithUnit['step_1_select_the_valid_relations'], "step_2a_copy__paste_only_the_words_from_the_sentence_that_express_the_relation_you_selected_in_step1" => $mappedWorkerunitsWithUnit['step_2a_copy__paste_only_the_words_from_the_sentence_that_express_the_relation_you_selected_in_step1'], "step_2b_if_you_selected_none_in_step_1_explain_why" => $mappedWorkerunitsWithUnit['step_2b_if_you_selected_none_in_step_1_explain_why']]; } elseif ($taskType == "RelDir") { $entity->content = ["direction" => $mappedWorkerunitsWithUnit['direction']]; } try { $entity->save(); } catch (Exception $e) { $status['error'][$index]['entity'] = $e->getMessage(); } } } return $status; }
/** * Get activity for a user ordered by timestamp */ public static function getActivitiesForUser($userId) { return Activity::where('user_id', $userId)->orderBy('updated_at', 'desc')->get(); }