Permalink
Browse files

fixed problem with job clock entry and stats display.

  • Loading branch information...
1 parent d40fef3 commit f0e5f10b0bb706a6e1d679ab0f42768264fa98f4 Zach Hoeken committed Apr 25, 2013
Showing with 32 additions and 4 deletions.
  1. +2 −2 controllers/main.php
  2. +23 −1 models/bot.php
  3. +1 −1 models/queue.php
  4. +6 −0 scripts/populate-job-clock-table.php
@@ -164,7 +164,7 @@ public function stats()
$this->set('total_completed_jobs', db()->getValue($sql));
//total printing hours
- $sql = "SELECT CEIL(SUM(unix_timestamp(end_date) - unix_timestamp(start_date)) / 3600) AS total FROM job_clock";
+ $sql = "SELECT CEIL(SUM(unix_timestamp(end_date) - unix_timestamp(start_date)) / 3600) AS total FROM job_clock WHERE status != 'working'";
$this->set('total_printing_time', db()->getValue($sql));
//user leaderboard
@@ -190,7 +190,7 @@ public function stats()
$this->set('my_total_completed_jobs', db()->getValue($sql));
//total printing hours
- $sql = "SELECT CEIL(SUM(unix_timestamp(end_date) - unix_timestamp(start_date)) / 3600) AS total FROM job_clock WHERE user_id = " . (int)User::$me->id;
+ $sql = "SELECT CEIL(SUM(unix_timestamp(end_date) - unix_timestamp(start_date)) / 3600) AS total FROM job_clock WHERE status != 'working' AND user_id = " . (int)User::$me->id;
$this->set('my_total_printing_time', db()->getValue($sql));
}
}
View
@@ -204,6 +204,15 @@ public function grabJob($job, $can_slice = true)
$job->save();
}
}
+
+ $log = new JobClockEntry();
+ $log->set('job_id', $job->id);
+ $log->set('user_id', User::$me->id);
+ $log->set('bot_id', $this->id);
+ $log->set('queue_id', $job->get('queue_id'));
+ $log->set('start_date', date("Y-m-d H:i:s"));
+ $log->set('status', 'working');
+ $log->save();
$this->set('job_id', $job->id);
$this->set('status', 'working');
@@ -243,6 +252,11 @@ public function dropJob($job)
$job->set('progress', 0);
$job->set('temperature_data', '');
$job->save();
+
+ $log = $job->getLatestTimeLog();
+ $log->set('end_date', date("Y-m-d H:i:s"));
+ $log->set('status', 'dropped');
+ $log->save();
$this->set('job_id', 0);
$this->set('status', 'idle');
@@ -281,6 +295,11 @@ public function completeJob($job)
$job->set('finished_time', date('Y-m-d H:i:s'));
$job->save();
+ $log = $job->getLatestTimeLog();
+ $log->set('end_date', date("Y-m-d H:i:s"));
+ $log->set('status', 'complete');
+ $log->save();
+
$this->set('status', 'waiting');
$this->set('last_seen', date("Y-m-d H:i:s"));
$this->save();
@@ -326,9 +345,12 @@ public function getStats()
$stats = db()->getArray($sql);
$data['total_waittime'] = (int)$stats[0]['wait'];
- $data['total_runtime'] = (int)$stats[0]['runtime'];
$data['total_time'] = (int)$stats[0]['total'];
+ //pull in our runtime stats
+ $sql = "SELECT sum(unix_timestamp(end_date) - unix_timestamp(start_date)) FROM job_clock WHERE status != 'working' AND bot_id = " . db()->escape($this->id);
+ $data['total_runtime'] = (int)db()->getValue($sql);
+
if ($data['total'])
{
$data['avg_waittime'] = $stats[0]['wait'] / $data['total'];
View
@@ -209,7 +209,7 @@ public function getStats()
$data['total_time'] = (int)$stats[0]['total'];
//pull in our runtime stats
- $sql = "SELECT sum(unix_timestamp(end_date) - unix_timestamp(start_date)) FROM job_clock WHERE queue_id = " . db()->escape($this->id);
+ $sql = "SELECT sum(unix_timestamp(end_date) - unix_timestamp(start_date)) FROM job_clock WHERE status != 'working' AND queue_id = " . db()->escape($this->id);
$data['total_runtime'] = (int)db()->getValue($sql);
if ($data['total'] > 0)
@@ -21,6 +21,12 @@
$log->set('status', 'complete');
$log->save();
}
+ else if ($row['status'] == 'taken' || $row['status'] == 'slicing')
+ {
+ $log->set('start_date', $row['taken_time']);
+ $log->set('status', 'working');
+ $log->save();
+ }
}
//finished!!!!

0 comments on commit f0e5f10

Please sign in to comment.