コード例 #1
0
 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;
 }