Пример #1
0
 /**
  * @param WordCount_Struct $wordCount_Struct
  *
  * @return WordCount_Struct
  * @throws Exception
  */
 public function updateDB(WordCount_Struct $wordCount_Struct)
 {
     $res = updateWordCount($wordCount_Struct);
     if ($res < 0) {
         throw new Exception("Failed to update counter", $res);
     }
     $newWCount = new WordCount_Struct();
     $newWCount->setNewWords($this->oldWCount->getNewWords() + $wordCount_Struct->getNewWords());
     $newWCount->setTranslatedWords($this->oldWCount->getTranslatedWords() + $wordCount_Struct->getTranslatedWords());
     $newWCount->setApprovedWords($this->oldWCount->getApprovedWords() + $wordCount_Struct->getApprovedWords());
     $newWCount->setRejectedWords($this->oldWCount->getRejectedWords() + $wordCount_Struct->getRejectedWords());
     $newWCount->setDraftWords($this->oldWCount->getDraftWords() + $wordCount_Struct->getDraftWords());
     $newWCount->setIdSegment($this->oldWCount->getIdSegment());
     $newWCount->setOldStatus($this->oldStatus);
     $newWCount->setNewStatus($this->newStatus);
     $newWCount->setIdJob($this->oldWCount->getIdJob());
     $newWCount->setJobPassword($this->oldWCount->getJobPassword());
     return $newWCount;
 }
Пример #2
0
 /**
  * @param WordCount_Struct[] $wordCount_Struct
  *
  * @return WordCount_Struct
  */
 public function sumDifferentials($wordCount_Struct)
 {
     $newWCount = new WordCount_Struct();
     $newWCount->setIdSegment($this->oldWCount->getIdSegment());
     $newWCount->setOldStatus($this->oldStatus);
     $newWCount->setNewStatus($this->newStatus);
     $newWCount->setIdJob($this->oldWCount->getIdJob());
     $newWCount->setJobPassword($this->oldWCount->getJobPassword());
     /**
      * @var WordCount_Struct $count
      */
     foreach ($wordCount_Struct as $count) {
         $newWCount->setNewWords($newWCount->getNewWords() + $count->getNewWords());
         $newWCount->setTranslatedWords($newWCount->getTranslatedWords() + $count->getTranslatedWords());
         $newWCount->setApprovedWords($newWCount->getApprovedWords() + $count->getApprovedWords());
         $newWCount->setRejectedWords($newWCount->getRejectedWords() + $count->getRejectedWords());
         $newWCount->setDraftWords($newWCount->getDraftWords() + $count->getDraftWords());
     }
     return $newWCount;
 }
Пример #3
0
 /**
  * @param WordCount_Struct $wCount
  *
  * @return array
  */
 public static function getFastStatsForJob(WordCount_Struct $wCount)
 {
     $job_stats = array();
     $job_stats['id'] = $wCount->getIdJob();
     //        $job_stats[ 'NEW' ]        = $wCount->getNewWords();
     $job_stats['DRAFT'] = $wCount->getNewWords() + $wCount->getDraftWords();
     $job_stats['TRANSLATED'] = $wCount->getTranslatedWords();
     $job_stats['APPROVED'] = $wCount->getApprovedWords();
     $job_stats['REJECTED'] = $wCount->getRejectedWords();
     //sometimes new_words + draft_words < 0 (why?). If it happens, set draft words to 0
     if ($job_stats['DRAFT'] < 0) {
         $job_stats['DRAFT'] = 0;
     }
     //avoid division by zero warning
     $total = $wCount->getTotal();
     $job_stats['TOTAL'] = $total == 0 ? 1 : $total;
     $job_stats = self::_getStatsForJob($job_stats, true);
     //true set estimation check if present
     return self::_performanceEstimationTime($job_stats);
 }
Пример #4
0
/**
 * Update the word count for the job
 *
 * We perform an update in join with jobs table
 * because we want to update the word count only for the current chunk
 *
 * Update the status of segment_translation is needed to avoid duplicated calls
 * ( The second call fails for status condition )
 *
 * @param WordCount_Struct $wStruct
 *
 * @return int
 */
function updateWordCount(WordCount_Struct $wStruct)
{
    $db = Database::obtain();
    //Update in Transaction
    $query = "UPDATE jobs AS j SET\n                new_words = new_words + " . $wStruct->getNewWords() . ",\n                draft_words = draft_words + " . $wStruct->getDraftWords() . ",\n                translated_words = translated_words + " . $wStruct->getTranslatedWords() . ",\n                approved_words = approved_words + " . $wStruct->getApprovedWords() . ",\n                rejected_words = rejected_words + " . $wStruct->getRejectedWords() . "\n                  WHERE j.id = " . (int) $wStruct->getIdJob() . "\n                  AND j.password = '******'";
    $db->query($query);
    //	Log::doLog( $query . "\n" );
    $err = $db->get_error();
    $errno = $err['error_code'];
    if ($errno != 0) {
        Log::doLog($err);
        return $errno * -1;
    }
    Log::doLog("Affected: " . $db->affected_rows . "\n");
    return $db->affected_rows;
}
Пример #5
0
/**
 * Update the word count for the job
 *
 * We perform an update in join with jobs table
 * because we want to update the word count only for the current chunk
 *
 * Update the status of segment_translation is needed to avoid duplicated calls
 * ( The second call fails for status condition )
 *
 * @param WordCount_Struct $wStruct
 *
 * @return int
 */
function updateWordCount(WordCount_Struct $wStruct)
{
    $db = Database::obtain();
    //Update in Transaction
    $query = "UPDATE jobs AS j SET\n                new_words = new_words + " . $wStruct->getNewWords() . ",\n                draft_words = draft_words + " . $wStruct->getDraftWords() . ",\n                translated_words = translated_words + " . $wStruct->getTranslatedWords() . ",\n                approved_words = approved_words + " . $wStruct->getApprovedWords() . ",\n                rejected_words = rejected_words + " . $wStruct->getRejectedWords() . "\n                  WHERE j.id = " . (int) $wStruct->getIdJob() . "\n                  AND j.password = '******'";
    try {
        $db->query($query);
    } catch (PDOException $e) {
        Log::doLog($e->getMessage());
        return $e->getCode() * -1;
    }
    $affectedRows = $db->affected_rows;
    Log::doLog("Affected: " . $affectedRows . "\n");
    return $affectedRows;
}