From d52383206e9be6310965cc2d59fd6abd8dc880e0 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Sat, 22 Sep 2018 14:12:08 +0100 Subject: [PATCH] Generate a summary rather than recent decisions on the homepage --- bin/build | 27 +++++++++++++++++++++++++-- views/index.haml | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/bin/build b/bin/build index fe92065..c1e3fce 100755 --- a/bin/build +++ b/bin/build @@ -49,8 +49,31 @@ def create_output_dir end def gen_homepage - decisions = ScraperWiki.select("* from `applications` order by date_decision desc limit 20") - write_page('.', 'index', { decisions: decisions }) + summary = ScraperWiki.select(" + authority_name, status, decision, appeal_status, appeal_decision, count(*) as applications + from applications + group by authority_name, status, decision, appeal_status, appeal_decision + ") + write_page('.', 'index', { summary: summary }) + + # Summary CSV file + csv_string = CSV.generate do |csv| + csv << summary.first.keys # header row + summary.each { |row| csv << row.values } + end + + write_csv('.', 'inlink-summary', csv_string) + + # Full CSV file + apps = ScraperWiki.select("* from applications") + + csv_string = CSV.generate do |csv| + csv << apps.first.keys # header row + apps.each { |app| csv << app.values } + end + + write_csv('.', 'inlink-full', csv_string) +end def gen_new apps = ScraperWiki.select("* from `applications` order by date_received desc limit 30") diff --git a/views/index.haml b/views/index.haml index 8fa6786..cacc7db 100644 --- a/views/index.haml +++ b/views/index.haml @@ -1,22 +1,33 @@ -%h2 Latest decisions +%h1 Summary + +%p.warning There are typically two applications per kiosk: one for full planning permission or telecoms prior approval, and one for advertisement consent. So the number of kiosks applied for is half the number of applications. + +%p + - csv_fn = 'inlink-summary.csv' + %a.button{ :href => csv_fn, :download => csv_fn } + Download summary CSV data +   + - csv_fn = 'inlink-full.csv' + %a.button{ :href => csv_fn, :download => csv_fn } + Download full CSV data + %table %thead %tr %th Authority - %th Reference - %th Date - %th Address + %th Status %th Decision + %th   + %th   + %th Applications %tbody - - decisions.each do |app| - %tr - %td - %a{ :href => "/authorities/#{ slug(app['authority_name'])}" } - = app['authority_name'] - %td - %a{ href: app['info_url']} - = app['council_reference'] - %td= short_date(app['date_decision']) - %td= app['address'] - %td= app['decision'] - \ No newline at end of file + - summary.each do |row| + %tr + %td + %a{ href: authority_url(row['authority_name']) } + = row['authority_name'] + %td= row['status'] + %td= row['decision'] + %td= cleanup(row['appeal_status']) + %td= cleanup(row['appeal_decision']) + %td.right= row['applications']