Esempio n. 1
0
 private function getDurationsByUser(WakaUser $user)
 {
     $settings = new Settings();
     $settings->username = $user->username;
     $settings->password = $user->password;
     $waka = new Client($settings);
     $now = $this->time->now();
     $weekAgo = $now - 7 * 86400;
     $lastFetch = $user->lastFetch;
     if (!$lastFetch) {
         $lastFetch = $weekAgo;
     }
     $today = date('Y-m-d', $now);
     $lastDate = date('Y-m-d', $lastFetch);
     if ($today > $lastDate) {
         $begin = new \DateTime($lastDate);
         $end = new \DateTime($today);
         $interval = \DateInterval::createFromDateString('1 day');
         $period = new \DatePeriod($begin, $interval, $end);
         /** @var \DateTime $dt */
         foreach ($period as $dt) {
             $date = $dt->format("Y-m-d");
             echo $date, PHP_EOL;
             $this->getDurationsByUserAndDate($user, $waka, $date);
             $user->lastFetch = strtotime($date);
             $user->save();
         }
     }
 }
Esempio n. 2
0
 public function get($key)
 {
     $value = parent::get($key);
     if (null !== $value) {
         $expire = $this->expire->get($key);
         if ($expire && $expire < $this->time->now()) {
             $this->delete($key);
             return null;
         }
         return $value;
     }
     return $value;
 }
Esempio n. 3
0
 public function keyExists($key)
 {
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $row = $this->db->select($this->table)->select('?', $this->expireField)->where('? = ?', $this->keyField, $key)->query()->fetchRow();
     if (!$row) {
         return false;
     } else {
         $expireUt = $row[$this->expireField->name];
         if ($expireUt && $this->time->now() > $expireUt) {
             $this->delete($key);
             return false;
         }
         return true;
     }
 }
Esempio n. 4
0
 /**
  * @param array|ProcessState[] $states
  */
 public function add(array $states)
 {
     $now = $this->time->now();
     $total = new State();
     /** @var State[] $groups */
     $groups = array();
     foreach ($states as $processState) {
         $total->memPercent += $processState->memPercent;
         $total->cpuPercent += $processState->cpuPercent;
         if ($processState->command === 'ps aux') {
             continue;
         }
         $group =& $groups[$processState->getProgramName()];
         if (null === $group) {
             $group = new State();
         }
         $group->memPercent += $processState->memPercent;
         $group->cpuPercent += $processState->cpuPercent;
         $group->rss += $processState->rss;
         if ($this->minCpuPercent && $processState->cpuPercent < $this->minCpuPercent) {
             //echo 'l';
             continue;
         }
         if ($this->minMemPercent && $processState->memPercent < $this->minMemPercent) {
             //echo 'l';
             continue;
         }
         if (isset($this->processes[$processState->pid])) {
             $process = $this->processes[$processState->pid];
         } else {
             $process = new Process();
             $process->user = $processState->user;
             $process->command = $processState->command;
             $process->pid = $processState->pid;
             $process->started = $processState->started;
             $this->processes[$processState->pid] = $process;
         }
         //echo 'o';
         $state = new State();
         $state->cpuPercent = $processState->cpuPercent;
         $state->memPercent = $processState->memPercent;
         $state->rss = $processState->rss;
         $state->stat = $processState->stat;
         $state->time = $processState->time;
         $state->tt = $processState->tt;
         $state->vsz = $processState->vsz;
         $this->states[$process->pid][$now] = $state;
     }
     foreach ($groups as $name => $state) {
         if ($this->minCpuPercent && $state->cpuPercent < $this->minCpuPercent) {
             //echo 'l';
             continue;
         }
         if ($this->minMemPercent && $state->memPercent < $this->minMemPercent) {
             //echo 'l';
             continue;
         }
         $this->groupStates[$name][$now] = $state;
     }
     $this->totals[$now] = $total;
 }