public function getUnit() { $result = array(); $aggregateOperators = $this->processAggregateInput(Input::all()); $unitID = Input::get('unit'); $resultT = Temp::where('_id', $unitID)->get()->toArray(); if (sizeof($resultT) != 0) { $result['infoStat'] = Temp::where('_id', $unitID)->get()->toArray()[0]; } else { $result['infoStat'] = Entity::where('_id', $unitID)->get()->toArray()[0]; } $selection = Entity::raw(function ($collection) use($aggregateOperators, $unitID) { $aggregateOperators['$match']['unit_id'] = $unitID; $aggregateOperators['$match']['type'] = '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 = 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 = 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 = Entity::where('_id', '=', $value['_id'])->lists('jobConf_id'); $jobTitle = 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 static function createJobCache() { \Session::flash('rawArray', 1); $db = \DB::getMongoDB(); $db = $db->temp; $result = Entity::where('type', 'job')->with('hasConfiguration')->get()->toArray(); if (count($result) > 0) { try { Temp::where('type', 'job')->forceDelete(); $db->batchInsert($result, array('continueOnError' => true)); } catch (Exception $e) { // ContinueOnError will still throw an exception on duplication, even though it continues, so we just move on. } } \Session::forget('rawArray'); }