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; }
public function getA() { //Queue::push('Queues\UpdateUnits', array("entity/text/medical/relex-structured-sentence/1078")); $ca = \MongoDB\CrowdAgent::where("_id", "crowdagent/cf/14781069")->first(); Queue::push('Queues\\UpdateCrowdAgent', array('crowdagent' => serialize($ca))); }
public function getJob() { $result = array(); // $aggregateOperators = $this->processAggregateInput(Input::all()); $jobID = Input::get('job'); $result['infoStat'] = \MongoDB\Entity::where('_id', $jobID)->get()->toArray()[0]; $jobConfID = \MongoDB\Entity::where('_id', $jobID)->lists('jobConf_id'); $jobConf = \MongoDB\Entity::whereIn('_id', $jobConfID)->get()->toArray(); $result['infoStat']['jobConf'] = $jobConf[0]; if (isset($result['infoStat']['metrics'])) { foreach ($result['infoStat']['metrics']['workers']['withoutFilter'] as $workerId => $value) { $result['infoStat']['workers'][$workerId] = \MongoDB\CrowdAgent::where('_id', $workerId)->get()->toArray()[0]; } foreach ($result['infoStat']['results']['withSpam'] as $unitId => $value) { $result['infoStat']['units'][$unitId] = \MongoDB\Entity::where('_id', $unitId)->get()->toArray()[0]; } } return $result; }
/** * needs workerId in postdata. */ public function postUnflag() { try { $return = array('status' => 'ok'); $this->authenticateUser(); $workerid = Input::get('workerid'); $crowdagent = CrowdAgent::where('_id', $workerid)->first(); $crowdagent->unflag(); $return['message'] = "Unflagged worker {$workerid} successfully."; } catch (Exception $e) { $return['message'] = $e->getMessage(); $return['status'] = 'bad'; } return $return; }