smartchicago / chicagoworksforyou

A citywide dashboard with ward-by-ward views of service delivery in Chicago. Includes complete API. Built using Chicago Open311 data.
http://www.chicagoworksforyou.com
MIT License
17 stars 6 forks source link

Daily closed counts #234

Closed cgansen closed 11 years ago

cgansen commented 11 years ago

Closes #205

This updates the ward/[id]/counts.json endpoint to return the number of SR opened and closed in a given ward over a range of days.

$ curl "http://localhost:5000/wards/10/counts.json?count=7&end_date=2013-08-30"
{
  "2013-08-24": {
    "Opened": 0,
    "Closed": 0
  },
  "2013-08-25": {
    "Opened": 0,
    "Closed": 0
  },
  "2013-08-26": {
    "Opened": 7,
    "Closed": 4
  },
  "2013-08-27": {
    "Opened": 20,
    "Closed": 37
  },
  "2013-08-28": {
    "Opened": 18,
    "Closed": 34
  },
  "2013-08-29": {
    "Opened": 7,
    "Closed": 6
  },
  "2013-08-30": {
    "Opened": 0,
    "Closed": 0
  }
}
cgansen commented 11 years ago

Quick data sanity checks:

cwfy=# SELECT COUNT(*) FROM service_requests WHERE DATE(closed_datetime) = '2013-08-20' AND ward = 32 AND service_code = '4fd3b167e750846744000005' AND duplicate IS NULL;
 count
-------
    12
(1 row)

cwfy=# select * from daily_closed_counts WHERE requested_date = '2013-08-20' AND ward = 32 AND service_code = '4fd3b167e750846744000005';
 requested_date |       service_code       | total | ward
----------------+--------------------------+-------+------
 2013-08-20     | 4fd3b167e750846744000005 |    12 |   32
(1 row)

cwfy=# select * from daily_closed_counts WHERE requested_date = '2013-08-20' AND ward = 1 AND service_code = '4fd3b167e750846744000005';
 requested_date |       service_code       | total | ward
----------------+--------------------------+-------+------
 2013-08-20     | 4fd3b167e750846744000005 |     7 |    1
(1 row)

cwfy=# SELECT COUNT(*) FROM service_requests WHERE DATE(closed_datetime) = '2013-08-20' AND ward = 1 AND service_code = '4fd3b167e750846744000005' AND duplicate IS NULL;
 count
-------
     7
(1 row)

cwfy=# select sum(total) from daily_closed_counts WHERE requested_date = '2013-08-20'  AND service_code = '4fd3b167e750846744000005';
 sum
-----
 500
(1 row)

cwfy=# SELECT COUNT(*) FROM service_requests WHERE DATE(closed_datetime) = '2013-08-20' AND service_code = '4fd3b167e750846744000005' AND duplicate IS NULL;
 count
-------
   500
(1 row)
cgansen commented 11 years ago

@santheo this is now on staging. Data will be sparse until we reload everything.