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 getUnit() { $result = array(); $aggregateOperators = $this->processAggregateInput(Input::all()); $unitID = Input::get('unit'); $resultT = \MongoDB\Temp::where('_id', $unitID)->get()->toArray(); if (sizeof($resultT) != 0) { $result['infoStat'] = \MongoDB\Temp::where('_id', $unitID)->get()->toArray()[0]; } else { $result['infoStat'] = \MongoDB\Entity::where('_id', $unitID)->get()->toArray()[0]; } $selection = \MongoDB\Entity::raw(function ($collection) use($aggregateOperators, $unitID) { $aggregateOperators['$match']['unit_id'] = $unitID; $aggregateOperators['$match']['documentType'] = 'workerunit'; $aggregateOperators['$project']['job_id'] = array('$ifNull' => array('$' . 'job_id', 0)); $aggregateOperators['$project']['crowdAgent_id'] = array('$ifNull' => array('$' . 'crowdAgent_id', 0)); $aggregateOperators['$project']['type'] = array('$ifNull' => array('$' . 'type', 0)); $aggregateOperators['$project']['workerunit'] = array('$ifNull' => array('$' . 'annotationVector', 0)); $aggregateOperators['$group']['_id'] = '$crowdAgent_id'; $aggregateOperators['$group']['count'] = array('$sum' => 1); $aggregateOperators['$group']['job_id'] = array('$push' => '$job_id'); $aggregateOperators['$group']['type'] = array('$push' => '$type'); $aggregateOperators['$group']['workerunit'] = array('$push' => '$workerunit'); return $collection->aggregate(array(array('$match' => $aggregateOperators['$match']), array('$project' => $aggregateOperators['$project']), array('$group' => $aggregateOperators['$group']))); }); $response = $selection['result']; $crowdAgentIDs = array(); $jobIDs = array(); $result['workerunitContent'] = array(); $result['jobContent'] = array(); $result['agentContent'] = array(); foreach ($response as $agent => $value) { $result['workerunitContent'][$value['_id']] = $value; array_push($crowdAgentIDs, $value['_id']); $workerunitType = array(); foreach ($value['job_id'] as $index => $type) { array_push($jobIDs, $value['job_id'][$index]); if (!array_key_exists($type, $workerunitType)) { $workerunitType[$type] = $value['workerunit'][$index]; } else { $annInfo = $value['workerunit'][$index]; foreach ($annInfo as $k => $v) { if (is_numeric($v)) { $workerunitType[$type][$k] += $v; } else { foreach ($v as $embeddedK => $embeddedV) { $workerunitType[$type][$k][$embeddedK] += $embeddedV; } } } } } $result['workerunitContent'][$value['_id']]['workerunitType'] = array(); foreach ($workerunitType as $job => $workerunit) { $workerunitInfo = array('job_id' => $job, 'workerunit' => $workerunit); $result['workerunitContent'][$value['_id']]['workerunitType'][$job] = $workerunitInfo; } } $crowdAgentIDs = array_unique($crowdAgentIDs); $agents = \MongoDB\CrowdAgent::whereIn('_id', $crowdAgentIDs)->get(array('cache', 'cfWorkerTrust', 'softwareAgent_id'))->toArray(); foreach ($agents as $index => $value) { $result['workerunitContent'][$value['_id']]["valuesWorker"] = $value; // $result['agentContent'][$value['_id']] = $value; } $jobIDs = array_unique($jobIDs); $jobs = \MongoDB\Entity::whereIn('_id', $jobIDs)->get(array('results.withoutSpam.' . $unitID, 'results.withSpam.' . $unitID, 'metrics.units.withoutSpam.' . $unitID, 'metrics.aggUnits', 'metrics.filteredunits', 'metrics.workers.withFilter', 'sofwareAgent_id', 'platformJobId'))->toArray(); foreach ($jobs as $index => $value) { $result['jobContent'][$value['_id']] = $value; $jobConfID = \MongoDB\Entity::where('_id', '=', $value['_id'])->lists('jobConf_id'); $jobTitle = \MongoDB\Entity::whereIn('_id', $jobConfID)->get(array('content.title'))->toArray(); $result['jobContent'][$value['_id']]['jobConf'] = $jobTitle[0]; } foreach ($result['workerunitContent'] as $id => $annInfo) { foreach ($result['workerunitContent'][$id]['workerunitType'] as $index => $value) { $job_id = $value['job_id']; $result['workerunitContent'][$id]['workerunitType'][$index]['job_info'] = $result['jobContent'][$job_id]; } } return $result; }
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))); }
/** * 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; }
public static function createMainSearchFiltersCache() { // $mainSearchFilters['media']['formats'] = $this->getDistinctFieldAndCount('format', ['unit']); // $mainSearchFilters['media']['domains'] = $this->getDistinctFieldAndCount('domain', ['unit']); $mainSearchFilters['media']['categories'] = static::getCategories(); $mainSearchFilters['media']['all'] = ["count" => \MongoDB\Entity::whereIn('tags', ['unit'])->count(), "label" => "All Media"]; //unset($mainSearchFilters['media']['documentTypes']['twrex']); $mainSearchFilters['job']['count'] = Entity::where('documentType', 'job')->count(); $mainSearchFilters['workers']['count'] = \MongoDB\CrowdAgent::all()->count(); ksort($mainSearchFilters['media']['categories']); $entity = new \MongoDB\Temp(); $entity->_id = "mainSearchFilters"; $entity->filters = $mainSearchFilters; $entity->save(); return $entity->toArray(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { // $documents = $this->repository->returnCollectionObjectFor($collection)->where('documentType', $documentType); // if(Input::has('id')){ // $documents = $this->repository->returnCollectionObjectFor("crowdagent")->with('hasDoneJobs')->with('hasGeneratedworkerunits'); // } else { //The following block returns one worker for the individual worker view if (Input::has('id')) { $id = Input::get('id'); $result = \MongoDB\CrowdAgent::with('hasGeneratedWorkerunits.hasJob')->with('hasGeneratedWorkerunits.hasUnit')->where('_id', $id)->get(); $result = $result->toArray(); $flattened = array(); foreach ($result as $resultValue) { if (count($resultValue['hasGeneratedWorkerunits']) > 0) { $resultValue['jobs'] = array(); foreach ($resultValue['hasGeneratedWorkerunits'] as $hasGeneratedWorkerunitKey => $hasGeneratedWorkerunitVal) { array_push($resultValue['jobs'], $hasGeneratedWorkerunitVal['hasJob']); unset($resultValue['hasGeneratedWorkerunits'][$hasGeneratedWorkerunitKey]['hasJob']); } $resultValue['jobs'] = array_unique($resultValue['jobs'], SORT_REGULAR); $resultValue['units'] = array(); foreach ($resultValue['hasGeneratedWorkerunits'] as $hasGeneratedWorkerunitKey => $hasGeneratedWorkerunitVal) { array_push($resultValue['units'], $hasGeneratedWorkerunitVal['hasUnit']); unset($resultValue['hasGeneratedWorkerunits'][$hasGeneratedWorkerunitKey]['hasUnit']); } $resultValue['units'] = array_unique($resultValue['units'], SORT_REGULAR); array_push($flattened, $resultValue); } } return $flattened; } $documents = $this->repository->returnCollectionObjectFor("crowdagent")->with('hasGeneratedWorkerunits'); if (Input::has('filter')) { foreach (Input::get('filter') as $filter => $value) { if (is_numeric($value)) { $documents = $documents->where($filter, (int) $value); continue; } if (is_array($value)) { foreach ($value as $operator => $subvalue) { if (in_array($operator, $this->operators)) { if (is_numeric($subvalue)) { $subvalue = (int) $subvalue; } if ($operator == 'like') { $subvalue = '%' . $subvalue . '%'; } $documents = $documents->where($filter, $operator, $subvalue); } } continue; } else { $value = array($value); } $documents = $documents->whereIn($filter, $value); } } // // Make sort possible on if (Input::has('sortBy')) { $sortBy = Input::get('sortBy'); if (Input::has('order')) { $order = Input::get('order'); } $documents = $documents->OrderBy($sortBy, $order); } // // If no sort is selected, newest jobs come on top if (!Input::has('sortBy')) { $documents = $documents->OrderBy('created_at', 'des'); } if (!($perPage = (int) Input::get('perPage'))) { $perPage = 10; } if (!($page = (int) Input::get('page'))) { $page = 1; $calcPage = 0; } else { $calcPage = $page - 1; } $total = $documents->count(); $skip = $calcPage * $perPage; $jobs = $documents->skip($skip)->take($perPage)->get(); // Paginate results, total amount of records, records per page and currentPage etc. //todo efficiency improvement to cache $jobs for pagination $paginator = array("total" => $total, "perPage" => $perPage, "currentPage" => $page, "data" => $jobs->toArray()); return Response::json($paginator); }