diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Hounslow.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 17 |
2 files changed, 40 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm index bc1c80571..f37fec6a7 100644 --- a/perllib/FixMyStreet/Cobrand/Hounslow.pm +++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm @@ -171,4 +171,29 @@ sub lookup_site_code_config { { # their cobrand at all. sub cut_off_date { '2019-05-06' } +sub front_stats_data { + my ( $self ) = @_; + + my $recency = '1 week'; + my $shorter_recency = '3 days'; + + my $completed = $self->problems->recent_completed(); + my $updates = $self->problems->number_comments(); + my $new = $self->problems->recent_new( $recency ); + + if ( $new > $completed ) { + $recency = $shorter_recency; + $new = $self->problems->recent_new( $recency ); + } + + my $stats = { + completed => $completed, + updates => $updates, + new => $new, + recency => $recency, + }; + + return $stats; +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 2ce4c04be..9f7c035ed 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -72,13 +72,26 @@ sub _cache_timeout { FixMyStreet->config('CACHE_TIMEOUT') // 3600; } +sub recent_completed { + my $rs = shift; + $rs->_recent_in_states('completed', [ + FixMyStreet::DB::Result::Problem->fixed_states(), + FixMyStreet::DB::Result::Problem->closed_states() + ]); +} + sub recent_fixed { my $rs = shift; - my $key = "recent_fixed:$site_key"; + $rs->_recent_in_states('fixed', [ FixMyStreet::DB::Result::Problem->fixed_states() ]); +} + +sub _recent_in_states { + my ($rs, $state_key, $states) = @_; + my $key = "recent_$state_key:$site_key"; my $result = Memcached::get($key); unless ($result) { $result = $rs->search( { - state => [ FixMyStreet::DB::Result::Problem->fixed_states() ], + state => $states, lastupdate => { '>', \"current_timestamp-'1 month'::interval" }, } )->count; Memcached::set($key, $result, _cache_timeout()); |