Ejemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     Log::$fileName = "languageStats.log";
     self::$sleepTime = 10;
     //60 * 60 * 24 * 30 * 1;
 }
Ejemplo n.º 2
0
 function main($args)
 {
     $db = Database::obtain();
     do {
         //TODO: create DAO for this
         $today = date("Y-m-d");
         $queryJobs = "SELECT\n                        source,\n                        target,\n                        sum( total_time_to_edit ) as total_time_to_edit,\n                        sum(translated_words) + sum(approved_words) + sum(rejected_words) as total_words,\n                        sum( COALESCE (avg_post_editing_effort, 0) ) as total_post_editing_effort,\n                        count(*) as job_count\n                      FROM\n                        jobs j\n                      WHERE\n                        completed = 1\n                        AND source = '%s'\n                      GROUP BY target";
         $queryInsert = "INSERT into language_stats\n                        (date, source, target, total_word_count, total_post_editing_effort, total_time_to_edit, job_count)\n                        VALUES %s\n                        ON DUPLICATE KEY UPDATE\n                          total_post_editing_effort = values( total_post_editing_effort ),\n                          total_time_to_edit = values( total_time_to_edit ),\n                          job_count = values( job_count )";
         $updateTuplesTemplate = "( '%s', '%s', '%s', %f, %f, %f, %u )";
         $langsObj = Langs_Languages::getInstance();
         //getlanguage list
         $languages = $langsObj->getEnabledLanguages();
         $languages = Utils::array_column($languages, 'code');
         foreach ($languages as $source_language) {
             Log::doLog("Current source_language: {$source_language}");
             echo "Current source_language: {$source_language}\n";
             $languageStats = $db->fetch_array(sprintf($queryJobs, $source_language));
             $languageTuples = array();
             foreach ($languageStats as $languageCoupleStat) {
                 Log::doLog("Current language couple: " . $source_language . "-" . $languageCoupleStat['target']);
                 echo "Current language couple: " . $source_language . "-" . $languageCoupleStat['target'] . "\n";
                 $languageTuples[] = sprintf($updateTuplesTemplate, $today, $languageCoupleStat['source'], $languageCoupleStat['target'], round($languageCoupleStat['total_words'], 4), round($languageCoupleStat['total_post_editing_effort'], 4), round($languageCoupleStat['total_time_to_edit'], 4), $languageCoupleStat['job_count']);
             }
             if (count($languageTuples) > 0) {
                 Log::doLog("Found some stats. Saving in DB..");
                 echo "Found some stats. Saving in DB..\n";
                 $db->query(sprintf($queryInsert, implode(", ", $languageTuples)));
             }
             usleep(100);
         }
         //for the moment, this daemon is single-loop-execution
         self::$RUNNING = false;
         if (self::$RUNNING) {
             sleep(self::$sleeptime);
         }
     } while (self::$RUNNING);
 }