Building statistics on the full job retention period may not be what's needed. Also, the longer the period analyzed the longer it takes to generate this page. So let the user specify which period to analyze and default to 7 days, a reasonable period to get values that are not unduly influenced by short-term patch storms, but also short enough to reflect current trends.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Stats.pl | 80 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)
diff --git a/testbot/web/Stats.pl b/testbot/web/Stats.pl index 4c213ab45..43f14948b 100644 --- a/testbot/web/Stats.pl +++ b/testbot/web/Stats.pl @@ -21,9 +21,10 @@ use strict;
package StatsPage;
-use ObjectModel::CGI::Page; -our @ISA = qw(ObjectModel::CGI::Page); +use ObjectModel::CGI::FreeFormPage; +our @ISA = qw(ObjectModel::CGI::FreeFormPage);
+use ObjectModel::BasicPropertyDescriptor; use ObjectModel::Collection; use WineTestBot::Config; use WineTestBot::Activity; @@ -36,10 +37,33 @@ sub _initialize($$$) { my ($self, $Request, $RequiredRole) = @_;
+ $self->{Days} = $self->GetParam("Days"); + $self->Validate(); + $self->{start} = Time(); $self->SUPER::_initialize($Request, $RequiredRole); }
+sub Validate($) +{ + my ($self) = @_; + + if (!defined $self->{Days}) + { + $self->{Days} = 7; + $self->{NoStats} = 1; + } + elsif ($self->{Days} !~ /^[0-9]{1,2}$/) + { + $self->{ErrField} = "Days"; + $self->{ErrMessage} = "The number of days must be between 1 and 99"; + $self->{NoStats} = 1; + $self->{Days} = 7; + return undef; + } + return $self->SUPER::Validate(); +} + sub GetPageTitle($$) { my ($self, $Page) = @_; @@ -168,7 +192,15 @@ sub GenerateBody($) { my ($self) = @_;
+ return $self->SUPER::GenerateBody() if ($self->{NoStats}); + print "<h1>${ProjectName} Test Bot activity statistics</h1>\n"; + $self->GenerateFormStart(); + $self->GenerateFields(); + $self->GenerateRequiredLegend(); + $self->GenerateActions(); + $self->GenerateFormEnd(); + print "<div class='Content'>\n";
### Get the sorted VMs list @@ -176,7 +208,7 @@ sub GenerateBody($) my $VMs = CreateVMs(); $VMs->FilterEnabledRole(); my @SortedVMs = sort _CompareVMs @{$VMs->GetItems()}; - my $Stats = GetStatistics($VMs); + my $Stats = GetStatistics($VMs, $self->{Days} * 24 * 60 * 60);
### Show global statistics
@@ -342,9 +374,51 @@ sub GenerateBody($) print "</tbody></table></div>\n"; }
+sub GetPropertyDescriptors($) +{ + my ($self) = @_; + + $self->{PropertyDescriptors} ||= [ + CreateBasicPropertyDescriptor("Days", "Days to analyze", !1, !1, "N", 2), + ]; + + return $self->SUPER::GetPropertyDescriptors(); +} + +sub GetDisplayValue($$) +{ + my ($self, $PropertyDescriptor) = @_; + + return $self->{$PropertyDescriptor->GetName()}; +} + +sub GetActions($) +{ + my ($self) = @_; + + my $Actions = $self->SUPER::GetActions(); + push @$Actions, "Update"; + return $Actions; +} + +sub OnAction($$) +{ + my ($self, $Action) = @_; + + if ($Action eq "Update") + { + return $self->Validate() ? 1 : undef; + } + + return $self->SUPER::OnAction($Action); +} + sub GenerateFooter($) { my ($self) = @_; + + return $self->SUPER::GenerateFooter() if ($self->{NoStats}); + print "<p></p><div class='CollectionBlock'><table>\n"; print "<thead><tr><th class='Record'>Legend</th></tr></thead>\n"; print "<tbody><tr><td class='Record'>\n";