/** * @param $data = array(unitids) */ public function fire($job, $data) { foreach ($data as $id) { set_time_limit(600); $unit = Entity::id($id)->first(); $batches = count(Batch::whereIn('parents', [$unit->_id])->get()->toArray()); $workerunit = array('count' => 0, 'spam' => 0, 'nonSpam' => 0); $workerlist = $workersspam = $workersnonspam = $joblist = array(); foreach (Workerunit::where('unit_id', $unit->_id)->get() as $a) { $joblist[] = $a->job_id; $workerlist[] = $a->crowdAgent_id; if ($a->spam) { $workerunit['spam']++; $workersspam[] = $a->crowdAgent_id; } else { $workerunit['nonSpam']++; $workersnonspam[] = $a->crowdAgent_id; } } $workerunit['count'] = $workerunit['spam'] + $workerunit['nonSpam']; $workers['count'] = count(array_unique($workerlist)); $workers['spam'] = count(array_unique($workersspam)); $workers['nonSpam'] = count(array_unique($workersnonspam)); $workers['potentialSpam'] = count(array_intersect($workersspam, $workersnonspam)); $platformField = array(); $platformField['cf'] = count(Entity::where('unit_id', $unit->_id)->where('softwareAgent_id', 'cf')->get()->toArray()); $platformField['amt'] = count(Entity::where('unit_id', $unit->_id)->where('softwareAgent_id', 'amt')->get()->toArray()); //filtered $filteredField = array(); $filteredField['job_ids'] = array_flatten(Job::where('metrics.filteredUnits.list', 'all', array($unit['_id']))->get(['_id'])->toArray()); $filteredField['count'] = count($filteredField['job_ids']); $derivatives = Entity::whereIn('parents', array($unit->_id))->lists('_id'); $children["count"] = count($derivatives); $children["list"] = $derivatives; $unit->cache = ["jobs" => 1, "workers" => $workers, "softwareAgent" => $platformField, "workerunits" => $workerunit, "filtered" => $filteredField, "batches" => $batches, "children" => $children]; $avg_clarity = Entity::where('metrics.units.withoutSpam.' . $unit->_id, 'exists', 'true')->avg('metrics.units.withoutSpam.' . $unit->id . '.avg.max_relation_Cos'); if (!isset($avg_clarity)) { $avg_clarity = 0; } $unit->avg_clarity = $avg_clarity; $unit->update(); \Log::debug("Updated unit {$unit->_id}."); } $job->delete(); // the Queue job... }
/** * Create worker unit */ public function createWorkerUnit($activityId, $unitId, $acceptTime, $channel, $trust, $content, $agentId, $jobId, $annId, $submitTime, $settings) { $workerunit = Workerunit::where('platformWorkerUnitId', $annId)->first(); if ($workerunit) { // do not delete this on rollback if (!array_key_exists($workerunit->_id, $this->workerUnits)) { $this->duplicateWorkerUnits++; $workerunit->_existing = true; $this->workerUnits[$workerunit->_id] = $workerunit; } } else { $workerunit = new Workerunit(); $workerunit->activity_id = $activityId; $workerunit->unit_id = $unitId; $workerunit->acceptTime = $acceptTime; $workerunit->cfChannel = $channel; $workerunit->cfTrust = $trust; $workerunit->content = $content; $workerunit->crowdAgent_id = $agentId; $workerunit->job_id = $jobId; $workerunit->platformWorkerunitId = $annId; $workerunit->submitTime = $submitTime; $workerunit->documentType = $settings['documentType']; $workerunit->project = $settings['project']; $workerunit->softwareAgent_id = $settings['platform']; $workerunit->softwareAgent_id = 'cf2'; $workerunit->contradiction = $settings['contradiction']; \Queue::push('Queues\\SaveWorkerunit', array('workerunit' => serialize($workerunit))); $this->workerUnits[$workerunit->_id] = $workerunit; } return $workerunit; }