Skip to content

Commit

Permalink
Merge pull request #34 from ukigumo/feature/elapsed_time
Browse files Browse the repository at this point in the history
Store and show elapsed time
  • Loading branch information
moznion committed Apr 3, 2014
2 parents 8a68cf9 + 5e0eed7 commit 104c0f9
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/Ukigumo/Server/API/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ post '/api/v1/report/add' => [
body => { isa => 'Str', optional => 1 },
revision => { isa => 'Str' },
repo => { isa => 'Str' },
compare_url => { isa => 'Str', optional => 1 }
compare_url => { isa => 'Str', optional => 1 },
elapsed_time_sec => { isa => 'Int', optional => 1 },
] => sub {
my ($c, $args) = @_;

Expand Down
32 changes: 31 additions & 1 deletion lib/Ukigumo/Server/Command/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ sub list {
0;
}
};

map {$_->{elapsed_time} = $class->_convert_sec_to_formatted_time($_->{elapsed_time_sec})} @$reports;

my $pager = Data::Page::NoTotalEntries->new(
has_next => $has_next,
entries_per_page => $args->{limit},
Expand Down Expand Up @@ -172,6 +175,7 @@ sub insert {
body => { isa => 'Str', optional => 1 },
vc_log => { isa => 'Str', optional => 1 },
compare_url => { isa => 'Str', optional => 1 },
elapsed_time_sec => { isa => 'Int', optional => 1 },
);
my $args = $rule->validate(@_);

Expand Down Expand Up @@ -241,10 +245,17 @@ sub find {
my $args = $rule->validate(@_);

local c->db->{suppress_row_objects} = 1;
return $class->_uncompress_text_data(c->db->single_by_sql(
my $report = $class->_uncompress_text_data(c->db->single_by_sql(
q{SELECT branch.project, branch.branch, report.* FROM report INNER JOIN branch ON (report.branch_id=branch.branch_id) WHERE report_id=?},
[$args->{report_id}]
));

if (my $elapsed_time = $class->_convert_sec_to_formatted_time($report->{elapsed_time_sec})) {
$report->{elapsed_time} = $elapsed_time;
}

return unless %$report;
return $report;
}

sub _compress_text_data {
Expand Down Expand Up @@ -292,4 +303,23 @@ sub __uncompress {
$_[0];
}

sub _convert_sec_to_formatted_time {
my ($class, $sec) = @_;

return unless defined $sec;

my $hour = int($sec / 3600);
$sec -= $hour * 3600;
my $min = int($sec / 60);
$sec -= $min * 60;

my $formatted_time = '';
if ($hour) {
$formatted_time = "$hour hour ";
}
$formatted_time .= "$min min $sec sec";

return $formatted_time;
}

1;
1 change: 1 addition & 0 deletions lib/Ukigumo/Server/DB/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ table {
{ name => 'body', type => SQL_LONGVARCHAR }, # TEXT
{ name => 'ctime', type => SQL_INTEGER }, # INTEGER
{ name => 'compare_url', type => SQL_VARCHAR }, # VARCHAR
{ name => 'elapsed_time_sec', type => SQL_INTEGER }, # INTEGER
;
};

Expand Down
1 change: 1 addition & 0 deletions lib/Ukigumo/Server/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ create_table report => columns {
text 'body', null;
integer 'ctime';
varchar 'compare_url', null;
integer 'elapsed_time_sec', null;

add_index report_branch_idx => [qw/branch_id/];
};
Expand Down
1 change: 1 addition & 0 deletions lib/Ukigumo/Server/Web/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ get '/project/{project}/{branch:[A-Za-z0-9/_\-\.]+}' => sub {
page => $page,
limit => $limit,
);

return $c->render(
'report_list.tx' => {
project => $project,
Expand Down
1 change: 1 addition & 0 deletions share/sql/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS `report` (
`body` text NULL,
`ctime` INTEGER NOT NULL,
`compare_url` VARCHAR(255) NULL DEFAULT NULL,
`elapsed_time_sec` INTEGER NULL DEFAULT NULL,
INDEX `report_branch_idx` (`branch_id`),
PRIMARY KEY (`report_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
Expand Down
3 changes: 2 additions & 1 deletion share/sql/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ CREATE TABLE IF NOT EXISTS report (
vc_log TEXT,
body TEXT,
ctime INTEGER NOT NULL,
compare_url VARCHAR(255) DEFAULT NULL
compare_url VARCHAR(255) DEFAULT NULL,
elapsed_time_sec INTEGER DEFAULT NULL
);

CREATE INDEX IF NOT EXISTS report_branch_idx ON report (branch_id);
Expand Down
2 changes: 2 additions & 0 deletions share/tmpl/report_list.tx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
<th><: l('Revision') :></th>
<th><: l('Status') :></th>
<th><: l('Date') :></th>
<th><: l('Elapsed Time') :></th>
</tr>
: for $reports -> $v {
<tr>
<td><: $v.revision || '-' :></td>
<td style="color: <: $v.status | status_color :>"><: $v.status | status_str :> </td>
<td><a href="<: uri_for('/report/' ~ $v.report_id) :>"><: ago($now-$v.ctime, 1) :></a></td>
<td><: $v.elapsed_time || '-' :></td>
</tr>
: }
</table>
Expand Down
9 changes: 6 additions & 3 deletions share/tmpl/show_report.tx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
<h1><a href="<: uri_for('/', {project => $report.project}) :>"><: $report.project :></a> [<a href="<: uri_for('/project/' ~ uri($report.project) ~ '/' ~ uri($report.branch)) :>"><: $report.branch :></a>](<: $report.revision :>)
<span style="font-weight:bold; font-size: 130%; color: <: $report.status | status_color :>"><: $report.status | status_str | l :></span>
</h1>
<p>
: if $report.compare_url {
<p>
Compare: <a href="<: $report.compare_url :>" target="_blank"><: $report.compare_url :></a>
</p>
Compare: <a href="<: $report.compare_url :>" target="_blank"><: $report.compare_url :></a>
: }
: if $report.elapsed_time {
Elapsed Time: <: $report.elapsed_time :>
: }
</p>
: if $report.vc_log {
<ul>
: for $report.vc_log.split("\n") -> $log {
Expand Down

0 comments on commit 104c0f9

Please sign in to comment.