aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-06-16 20:36:52 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-06-18 11:45:15 +0100
commit04d217ae31c156c17d95e757842693caa31c06ed (patch)
treeb04490721764ff4da978f9b3d1bd16500256a353
parent32ad0501c46816b3e6b28b53c0df5bccc5fa057a (diff)
[Hounslow] Closed as well as fixed on front page.
-rw-r--r--perllib/FixMyStreet/Cobrand/Hounslow.pm25
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm17
-rw-r--r--t/cobrand/hounslow.t9
-rw-r--r--templates/web/hounslow/front/stats.html40
4 files changed, 89 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());
diff --git a/t/cobrand/hounslow.t b/t/cobrand/hounslow.t
index 91c1cb455..e58309925 100644
--- a/t/cobrand/hounslow.t
+++ b/t/cobrand/hounslow.t
@@ -38,6 +38,15 @@ my ($report) = $mech->create_problems_for_body(1, $hounslow_id, 'A brand new pro
cobrand => 'fixmystreet'
});
+subtest "showing the front page" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'hounslow',
+ }, sub {
+ $mech->get_ok('/');
+ $mech->content_contains('completed in past month');
+ };
+};
+
subtest "it still shows old reports on fixmystreet.com" => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
diff --git a/templates/web/hounslow/front/stats.html b/templates/web/hounslow/front/stats.html
new file mode 100644
index 000000000..23d035551
--- /dev/null
+++ b/templates/web/hounslow/front/stats.html
@@ -0,0 +1,40 @@
+[% USE Number.Format %]
+
+[%
+ stats = c.cobrand.front_stats_data();
+
+ new_text =
+ stats.recency == '1 week'
+ ? nget(
+ "<big>%s</big> report in past week",
+ "<big>%s</big> reports in past week",
+ stats.new
+ )
+ : nget(
+ "<big>%s</big> report recently",
+ "<big>%s</big> reports recently",
+ stats.new
+ );
+
+ completed_text = nget(
+ "<big>%s</big> completed in past month",
+ "<big>%s</big> completed in past month",
+ stats.completed
+ );
+
+ updates_text = nget(
+ "<big>%s</big> update on reports",
+ "<big>%s</big> updates on reports",
+ stats.updates
+ );
+
+ new_n = stats.new | format_number;
+ completed_n = stats.completed | format_number;
+ updates_n = stats.updates | format_number;
+%]
+
+<div id="front_stats">
+ <div>[% tprintf( new_text, decode(new_n) ) %]</div>
+ <div>[% tprintf( completed_text, decode(completed_n) ) %]</div>
+ <div>[% tprintf( updates_text, decode(updates_n) ) %]</div>
+</div>