Skip to content

Commit

Permalink
images
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed May 5, 2015
1 parent c433f2a commit 4d2f205
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
Binary file added buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 28 additions & 31 deletions chi_foia.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ foia_logs <- c(
oemc='8pxc-mzcv',
health='4h87-zdcp',
compliance='pv55-neb6',
#finance='7avf-ek45',
#finance='7avf-ek45', # Something's wrong with the SODA API
procurement='bcyv-67qk',
mayor='srzw-dcvg',
water='cxfr-dd4a',
streets='zpd8-zq4w',
admin.hearing='t58s-ja5s',
admin.hearing='t58s-ja5s',
human.resources='7zkx-3pp7',
budget='c323-fb2i',
doit='4nng-j9hd',
Expand Down Expand Up @@ -76,45 +76,42 @@ for (i in 1:length(foia_logs)) {
}


log_url <- paste(
'https://data.cityofchicago.org/resource/',
'ten5-q8vs',
'.csv?$select=date_trunc_ym(',
request_date,
')%20as%20year_month,COUNT(*)&$group=year_month&$order=year_month',
sep='')
log.csv <- RCurl::getURLContent(log_url)
log <- read.csv(textConnection(log.csv))
names(log) <- c("year_month", log_name)
full_log <- merge(full_log, log, by="year_month", all=TRUE)


full_log$year_month <- as.Date(full_log$year_month, '%m/%d/%Y %I:%M:%S %p')

write.csv(full_log, file="foia_logs.csv", row.names=FALSE)

good_log <- full_log[full_log$year_month >= "2010-05-01" & full_log$year_month < "2015-05-01" & !is.na(full_log$year),]
write.csv(full_log[order(full_log$year_month),],
file="foia_logs.csv", row.names=FALSE)

good_log <- good_log[, -10]
# Quarter 1 of 2011 was the first Quarter where we had data for
# all the FOIA logs
good_log <- full_log[(full_log$year_month >= "2011-01-01"
& full_log$year_month < "2015-01-01"
& !is.na(full_log$year)),]
good_log <- good_log[, colSums(is.na(good_log)) != nrow(good_log)]

log_xts <- xts::xts(good_log[,-1],
good_log$year_month)
funky_datasets <- c("police", "admin.hearing", "health")
good_log$total <- rowSums(good_log[, !(names(good_log)
%in%
c("year_month",
funky_datasets))],
na.rm=TRUE)

ordered_depts <- names(sort(colSums(good_log[, -1],
na.rm=TRUE)))
log_xts <- xts::xts(good_log[, -1],
good_log$year_month)


par(mfrow=c(5,3))
i <- 0
for (dept in ordered_depts) {
plot(log_xts[, dept], main=dept)
i <- i + 1
if (i %% 15 == 0) {
Sys.sleep(5)
}
Sys.sleep(2)
}
par(mfrow=c(1,1))
plot(c())

png("total.png", width=480, height=240)
plot(xts::apply.quarterly(log_xts$total, sum), main="Total")
dev.off()

png("buildings.png", width=480, height=240)
plot(xts::apply.quarterly(log_xts$total, sum), main="Buildings")
dev.off()



plot(log_xts$zoning)
Binary file added total.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4d2f205

Please sign in to comment.