public function doAction()
 {
     if (empty($_SESSION['cid'])) {
         //user not logged
         throw new Exception("User Not Logged.");
     }
     if ($this->res_type == "prj") {
         $old_status = getProjectJobData($this->res_id);
         $strOld = '';
         foreach ($old_status as $item) {
             $strOld .= $item['id'] . ':' . $item['status_owner'] . ',';
         }
         $strOld = trim($strOld, ',');
         $this->result['old_status'] = $strOld;
         updateJobsStatus($this->res_type, $this->res_id, $this->new_status, $this->only_if, $this->undo);
         $start = ($this->page - 1) * $this->step + $this->step - 1;
         $projects = ManageUtils::queryProjects($start, 1, $this->search_in_pname, $this->search_source, $this->search_target, $this->search_status, $this->search_onlycompleted, $this->filter_enabled, null);
         $projnum = getProjectsNumber($start, $this->step, $this->search_in_pname, $this->search_source, $this->search_target, $this->search_status, $this->search_onlycompleted, $this->filter_enabled);
         $this->result['code'] = 1;
         $this->result['data'] = "OK";
         $this->result['status'] = $this->new_status;
         $this->result['newItem'] = $projects;
         $this->result['page'] = $this->page;
         $this->result['pnumber'] = $projnum[0]['c'];
     } else {
         updateJobsStatus($this->res_type, $this->res_id, $this->new_status, $this->only_if, $this->undo, $this->job_password);
         $this->result['code'] = 1;
         $this->result['data'] = "OK";
         $this->result['status'] = $this->new_status;
     }
 }
 public function doAction()
 {
     $this->project_data = getProjectJobData($this->project_id);
     try {
         if (empty($this->project_data)) {
             throw new Exception("No Project Found.", -1);
         }
         $pManager = new ProjectManager();
         $pStruct = $pManager->getProjectStructure();
         switch ($this->exec) {
             case 'merge':
                 $this->checkMergeAccess();
                 $pStruct['job_to_merge'] = $this->job_id;
                 $pManager->mergeALL($pStruct);
                 break;
             case 'check':
                 $this->checkSplitAccess();
                 $pStruct['job_to_split'] = $this->job_id;
                 $pStruct['job_to_split_pass'] = $this->job_pass;
                 $pManager->getSplitData($pStruct, $this->num_split, $this->split_values);
                 break;
             case 'apply':
                 $this->checkSplitAccess();
                 $pStruct['job_to_split'] = $this->job_id;
                 $pStruct['job_to_split_pass'] = $this->job_pass;
                 $pManager->getSplitData($pStruct, $this->num_split, $this->split_values);
                 $pManager->applySplit($pStruct);
                 break;
         }
         $this->result["data"] = $pStruct['split_result'];
     } catch (Exception $e) {
         $this->result['errors'][] = array("code" => $e->getCode(), "message" => $e->getMessage());
     }
 }
 public function doAction()
 {
     if (empty($this->id_project)) {
         $this->result['errors'] = array(-1, "No id project provided");
         return -1;
     }
     $_project_data = getProjectJobData($this->id_project);
     $passCheck = new AjaxPasswordCheck();
     $access = $passCheck->grantProjectAccess($_project_data, $this->ppassword) || $passCheck->grantProjectJobAccessOnJobPass($_project_data, null, $this->jpassword);
     if (!$access) {
         $this->result['errors'] = array(-10, "Wrong Password. Access denied");
         return -1;
     }
     $analysisStatus = new Analysis_WEBStatus($_project_data);
     $this->result = $analysisStatus->fetchData()->getResult();
 }
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @return mixed
  */
 function doAction()
 {
     $_project_data = getProjectJobData($this->id_project);
     $pCheck = new AjaxPasswordCheck();
     $access = $pCheck->grantProjectAccess($_project_data, $this->password);
     //check for Password correctness
     if (!$access) {
         $msg = "Error : wrong password provided for download \n\n " . var_export($_POST, true) . "\n";
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         return null;
     }
     $analysisStatus = new Analysis_XTRFStatus($_project_data);
     $outputContent = $analysisStatus->fetchData()->getResult();
     $this->content = $this->composeZip($_project_data[0]['pname'], $outputContent);
     $this->_filename = $_project_data[0]['pname'] . ".zip";
 }
Example #5
0
 public static function getTMProps($job_data)
 {
     try {
         $redisHandler = new Predis\Client(INIT::$REDIS_SERVERS);
         $redisHandler->get(1);
         //ping established connection
     } catch (Exception $e) {
         $redisHandler = null;
         Log::doLog($e->getMessage());
         Log::doLog("No Redis server(s) available.");
     }
     if (isset($redisHandler) && !empty($redisHandler)) {
         $_existingResult = $redisHandler->get("project_data_for_job_id:" . $job_data['id']);
         if (!empty($_existingResult)) {
             return unserialize($_existingResult);
         }
     }
     $projectData = getProjectJobData($job_data['id_project']);
     $result = array('project_id' => $projectData[0]['pid'], 'project_name' => $projectData[0]['pname'], 'job_id' => $job_data['id']);
     if (isset($redisHandler) && !empty($redisHandler)) {
         $redisHandler->setex("project_data_for_job_id:" . $job_data['id'], 60 * 60 * 24 * 15, serialize($result));
     }
     return $result;
 }
Example #6
0
 /**
  * Perform the computation
  *
  * @return $this
  */
 public function fetchData()
 {
     $this->_fetchProjectData();
     $this->result['data'] = $this->_data_struct;
     //array of totals per job-files
     $total_payable = array();
     $_total_segments_analyzed = 0;
     $_total_wc_fast_analysis = 0;
     $_total_wc_standard_fast_analysis = 0;
     $_total_raw_wc = 0;
     $_total_wc_tm_analysis = 0;
     $_total_wc_standard_analysis = 0;
     $_matecat_price_per_word = 0.03;
     //(dollari) se indipendente dalla combinazione metterlo nel config
     $_standard_price_per_word = 0.1;
     //(dollari) se indipendente dalla combinazione metterlo nel config
     //VERY Expensive cycle ± 0.7 s for 27650 segments ( 150k words )
     foreach ($this->_resultSet as $segInfo) {
         if ($segInfo['st_status_analysis'] == 'DONE') {
             $_total_segments_analyzed += 1;
         }
         if ($_total_wc_fast_analysis == 0 and $segInfo['fast_analysis_wc'] > 0) {
             $_total_wc_fast_analysis = $segInfo['fast_analysis_wc'];
         }
         if ($_total_wc_standard_fast_analysis == 0 and $segInfo['fast_analysis_wc'] > 0) {
             $_total_wc_standard_fast_analysis = $segInfo['fast_analysis_wc'];
         }
         $jid = $segInfo['jid'];
         $jpassword = $segInfo['jpassword'];
         $words = $segInfo['raw_word_count'];
         $eq_words = $segInfo['eq_word_count'];
         $st_word_count = $segInfo['standard_word_count'];
         $_total_raw_wc += $segInfo['raw_word_count'];
         $_total_wc_tm_analysis += $eq_words;
         $_total_wc_standard_analysis += $st_word_count;
         //init indexes to avoid notices
         if (!array_key_exists($jid, $this->result['data']['jobs'])) {
             $this->result['data']['jobs'][$jid] = array();
             $this->result['data']['jobs'][$jid]['chunks'] = array();
             $this->result['data']['jobs'][$jid]['totals'] = array();
             $total_payable[$jid] = array();
         }
         if (!array_key_exists($jpassword, $this->result['data']['jobs'][$jid]['chunks'])) {
             $this->result['data']['jobs'][$jid]['chunks'][$jpassword] = array();
             $total_payable[$jid][$jpassword] = array();
         }
         if (!array_key_exists($jpassword, $this->result['data']['jobs'][$jid]['totals'])) {
             $this->result['data']['jobs'][$jid]['totals'][$jpassword] = $this->_total_init_struct;
         }
         if (!isset($this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']])) {
             $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']] = $this->_total_init_struct;
         }
         //END init indexes
         if ($segInfo['match_type'] == "INTERNAL") {
             $keyValue = 'INTERNAL_MATCHES';
         } elseif ($segInfo['match_type'] == "MT") {
             $keyValue = 'MT';
         } elseif ($segInfo['match_type'] == "100%") {
             $keyValue = 'TM_100';
         } elseif ($segInfo['match_type'] == "100%_PUBLIC") {
             $keyValue = 'TM_100_PUBLIC';
         } elseif ($segInfo['match_type'] == "75%-99%") {
             $keyValue = 'TM_75_99';
         } elseif ($segInfo['match_type'] == "75%-84%") {
             $keyValue = 'TM_75_84';
         } elseif ($segInfo['match_type'] == "85%-94%") {
             $keyValue = 'TM_85_94';
         } elseif ($segInfo['match_type'] == "95%-99%") {
             $keyValue = 'TM_95_99';
         } elseif ($segInfo['match_type'] == "50%-74%") {
             $keyValue = 'TM_50_74';
         } elseif ($segInfo['match_type'] == "NO_MATCH" or $segInfo['match_type'] == "NEW") {
             $keyValue = 'NEW';
         } elseif ($segInfo['match_type'] == "ICE") {
             $keyValue = "ICE";
         } elseif ($segInfo['match_type'] == "REPETITIONS") {
             $keyValue = 'REPETITIONS';
         } else {
             $keyValue = 'NUMBERS_ONLY';
         }
         $w = $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']][$keyValue][0] + $words;
         $words_print = number_format($w, 0, ".", ",");
         $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']][$keyValue] = array($w, $words_print);
         $tmp_tot = $this->result['data']['jobs'][$jid]['totals'][$jpassword][$keyValue][0];
         $tmp_tot += $words;
         $words_print = number_format($tmp_tot, 0, ".", ",");
         $this->result['data']['jobs'][$jid]['totals'][$jpassword][$keyValue] = array($tmp_tot, $words_print);
         //SUM WITH PREVIOUS ( Accumulator )
         $eq_words = $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']]["TOTAL_PAYABLE"][0] + $eq_words;
         $eq_words_print = number_format($eq_words, 0, ".", ",");
         $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']]["TOTAL_PAYABLE"] = array($eq_words, $eq_words_print);
         //take note of payable words for job/file combination
         $total_payable[$jid][$jpassword][$segInfo['id_file']] = $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']]["TOTAL_PAYABLE"][0];
         $this->result['data']['jobs'][$jid]['chunks'][$jpassword][$segInfo['id_file']]['FILENAME'] = $segInfo['filename'];
     }
     $this->_resultSet = array();
     //free memory
     //sum all totals for each job
     //N^3 but there are a little number of rows max 30
     foreach ($total_payable as $jid => $chunks) {
         foreach ($chunks as $_jpassword => $files) {
             foreach ($files as $fid => $v) {
                 $this->result['data']['jobs'][$jid]['totals'][$_jpassword]["TOTAL_PAYABLE"][0] += $v;
                 //format numbers after sum
                 $this->result['data']['jobs'][$jid]['totals'][$_jpassword]["TOTAL_PAYABLE"][1] = number_format($this->result['data']['jobs'][$jid]['totals'][$_jpassword]["TOTAL_PAYABLE"][0] + 1.0E-8, 0, ".", ",");
             }
         }
     }
     if ($_total_wc_standard_analysis == 0 and $this->status_project == Constants_ProjectStatus::STATUS_FAST_OK) {
         $_total_wc_standard_analysis = $_total_wc_standard_fast_analysis;
     } elseif ($_total_segments_analyzed == 0 && $this->status_project == Constants_ProjectStatus::STATUS_NEW) {
         //Outsource Quote issue
         //fast analysis not done, return the number of raw word count
         //needed because the "getProjectStatsVolumeAnalysis" query based on segment_translations always returns null
         //( no segment_translations )
         $project_data_fallback = getProjectJobData($this->id_project);
         foreach ($project_data_fallback as $i => $_job_fallback) {
             $this->result['data']['jobs'][$_job_fallback['jid']]['totals'][$_job_fallback['jpassword']]["TOTAL_PAYABLE"][0] = $_job_fallback['standard_analysis_wc'];
             //format numbers after sum
             $this->result['data']['jobs'][$_job_fallback['jid']]['totals'][$_job_fallback['jpassword']]["TOTAL_PAYABLE"][1] = number_format($_job_fallback['standard_analysis_wc'], 0, ".", ",");
         }
         $_total_wc_standard_analysis = $_total_wc_tm_analysis = $_total_raw_wc = $project_data_fallback[0]['standard_analysis_wc'];
     }
     // if fast quote has been done and tm analysis has not produced any result yet
     if ($_total_wc_tm_analysis == 0 and $this->status_project == Constants_ProjectStatus::STATUS_FAST_OK and $_total_wc_fast_analysis > 0) {
         $_total_wc_tm_analysis = $_total_wc_fast_analysis;
     }
     if ($_total_wc_fast_analysis > 0) {
         $discount_wc = round(100 * $_total_wc_tm_analysis / $_total_wc_fast_analysis);
     }
     $discount_wc = 0;
     $standard_wc_time = $_total_wc_standard_analysis / INIT::$ANALYSIS_WORDS_PER_DAYS;
     $tm_wc_time = $_total_wc_tm_analysis / INIT::$ANALYSIS_WORDS_PER_DAYS;
     $fast_wc_time = $_total_wc_fast_analysis / INIT::$ANALYSIS_WORDS_PER_DAYS;
     $standard_wc_unit = 'day';
     $tm_wc_unit = 'day';
     $fast_wc_unit = 'day';
     if ($standard_wc_time > 0 and $standard_wc_time < 1) {
         $standard_wc_time *= 8;
         //convert to hours (1 work day = 8 hours)
         $standard_wc_unit = 'hour';
     }
     if ($standard_wc_time > 0 and $standard_wc_time < 1) {
         $standard_wc_time *= 60;
         //convert to minutes
         $standard_wc_unit = 'minute';
     }
     if ($tm_wc_time > 0 and $tm_wc_time < 1) {
         $tm_wc_time *= 8;
         //convert to hours (1 work day = 8 hours)
         $tm_wc_unit = 'hour';
     }
     if ($tm_wc_time > 0 and $tm_wc_time < 1) {
         $tm_wc_time *= 60;
         //convert to minutes
         $tm_wc_unit = 'minute';
     }
     if ($fast_wc_time > 0 and $fast_wc_time < 1) {
         $fast_wc_time *= 8;
         //convert to hours (1 work day = 8 hours)
         $fast_wc_unit = 'hour';
     }
     if ($fast_wc_time > 0 and $fast_wc_time < 1) {
         $fast_wc_time *= 60;
         //convert to minutes
         $fast_wc_unit = 'minute';
     }
     if ($standard_wc_time > 1) {
         $standard_wc_unit .= 's';
     }
     if ($fast_wc_time > 1) {
         $fast_wc_unit .= 's';
     }
     if ($tm_wc_time > 1) {
         $tm_wc_unit .= 's';
     }
     $matecat_fee = ($_total_wc_fast_analysis - $_total_wc_tm_analysis) * $_matecat_price_per_word;
     $standard_fee = ($_total_wc_standard_analysis - $_total_wc_tm_analysis) * $_standard_price_per_word;
     $discount = round($standard_fee - $matecat_fee);
     $this->result['data']['summary']['NAME'] = $this->_project_data[0]['pname'];
     $this->result['data']['summary']['IN_QUEUE_BEFORE'] = $this->_others_in_queue;
     $this->result['data']['summary']['STATUS'] = $this->status_project;
     $this->result['data']['summary']['TOTAL_SEGMENTS'] = $this->total_segments;
     $this->result['data']['summary']['SEGMENTS_ANALYZED'] = $_total_segments_analyzed;
     $this->result['data']['summary']['TOTAL_STANDARD_WC'] = $_total_wc_standard_analysis;
     $this->result['data']['summary']['TOTAL_FAST_WC'] = $_total_wc_fast_analysis;
     $this->result['data']['summary']['TOTAL_TM_WC'] = $_total_wc_tm_analysis;
     $this->result['data']['summary']['TOTAL_RAW_WC'] = $_total_raw_wc;
     $this->result['data']['summary']['TOTAL_PAYABLE'] = $_total_wc_tm_analysis;
     if ($this->status_project == 'FAST_OK' or $this->status_project == "DONE") {
         $this->result['data']['summary']['PAYABLE_WC_TIME'] = number_format($tm_wc_time, 0, ".", ",");
         $this->result['data']['summary']['PAYABLE_WC_UNIT'] = $tm_wc_unit;
     } else {
         $this->result['data']['summary']['PAYABLE_WC_TIME'] = number_format($fast_wc_time, 0, ".", ",");
         $this->result['data']['summary']['PAYABLE_WC_UNIT'] = $fast_wc_unit;
     }
     $this->result['data']['summary']['FAST_WC_TIME'] = number_format($fast_wc_time, 0, ".", ",");
     $this->result['data']['summary']['FAST_WC_UNIT'] = $fast_wc_unit;
     $this->result['data']['summary']['TM_WC_TIME'] = number_format($tm_wc_time, 0, ".", ",");
     $this->result['data']['summary']['TM_WC_UNIT'] = $tm_wc_unit;
     $this->result['data']['summary']['STANDARD_WC_TIME'] = number_format($standard_wc_time, 0, ".", ",");
     $this->result['data']['summary']['STANDARD_WC_UNIT'] = $standard_wc_unit;
     $this->result['data']['summary']['USAGE_FEE'] = number_format($matecat_fee, 2, ".", ",");
     $this->result['data']['summary']['PRICE_PER_WORD'] = number_format($_matecat_price_per_word, 3, ".", ",");
     $this->result['data']['summary']['DISCOUNT'] = number_format($discount, 0, ".", ",");
     $this->result['data']['summary']['DISCOUNT_WC'] = number_format($discount_wc, 0, ".", ",");
     $this->_globals = array('STATUS_PROJECT' => $this->status_project, 'IN_QUEUE_BEFORE' => $this->_others_in_queue, 'TOTAL_SEGMENTS' => $this->total_segments, 'SEGMENTS_ANALYZED' => $_total_segments_analyzed, 'TOTAL_STANDARD_WC' => $_total_wc_standard_analysis, 'TOTAL_FAST_WC' => $_total_wc_fast_analysis, 'TOTAL_TM_WC' => $_total_wc_tm_analysis + 1.0E-8, 'TOTAL_RAW_WC' => $_total_raw_wc, 'TOTAL_PAYABLE' => $_total_wc_tm_analysis + 1.0E-8);
     return $this;
 }