Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

code-312/Code-for-Chicago-Data-Workgroup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rescue Chicago

PetFinder Dashboard for Rescue Dogs

By: Kayla Robinson, Chris Lynch, Evan Cooperman, Joseph Adorno, Cara Karter - Live site

Table of Contents

Main

In 2021 alone, Chicago Animal Care and Control, the city’s only publicly funded shelter, took in 4,122 stray, surrendered, or confiscated dogs. While some of the dogs who end up in the municipal shelter will be returned to their owner or adopted out directly, more than half of these animals are transferred to another animal rescue organization through the shelter’s Homeward Bound partnerships.

To learn more about the journeys of these rescued pups, we pulled data from the Petfinder API for dogs located within 100 miles of Chicago. Petfinder is the most widely used online database of adoptable pets. Many Chicago animal rescue organizations maintain their own organization pages and adoptable pet listings on the site. We are building an interactive data visualization dashboard to explore how different dog characteristics affect the average length of stay of these Chicagoland dogs in a shelter or foster placement prior to adoption.

  • We heard from Chicago animal rescue volunteers that if they knew why dogs weren't leaving the Chicago municipal shelter quickly then they could share that information with press/media to encourage volunteering and adopting.

  • To answer this question, and ultimately work toward getting more animals out of shelters into forever homes, we pulled data from the Petfinder API for dogs within 100 miles of Chicago.

  • We then created a first iteration of a publicly-available, interactive data dashboard that can be used to analyze how different dog characteristics may correlate with average length of stay in a shelter prior to adoption.

Key Features

  • Breed Trends by Length of Stay
  • Other Trends by Length of Stay
  • Breed Trends by Count
  • Other Trends by Count

Technology used

alt text alt text alt text alt text

Data Scraping and Cleaning

- Python (requests, pandas)

Database

- Python (sqlalchemy, pandas), SQL, PostgreSQL, Heroku

Visualization and App

- Python (streamlit, pandas, matplotlib), SQL, Heroku

How to use this application

  1. Clone the repository with Git:
https://github.com/Code-For-Chicago/Code-for-Chicago-Data-Workgroup.git
  1. Create a file called .env in the root directory. This file is ignored via the .gitignore file to avoid committing secrets.

  2. Open .env in a text editor and add this as the contents, replacing the second part with your personal API keys. There is also a .env.example to follow for more help.

  3. You can request a Petfinder API key and secret here.

PETFINDER_KEY=REPLACE_ME_WITH_PETFINDER_KEY
PETFINDER_SECRET=REPLACE_ME_WITH_PETFINDER_SECRET
DATABASE_URL=postgresql://username_goes_here:password_goes_here@localhost/app_name_here
PETFINDER_STREAMLIT_SHOW_QUERIES=False
PETFINDER_STREAMLIT_CHART_TYPE=advanced
HEROKU_POSTGRESQL_AMBER_URL=REPLACE_ME_WITH_HEROKU_URI
  • Set PETFINDER_STREAMLIT_SHOW_QUERIES to False or True if you want to see queries shown on the frontend. False is the default.
  • Set PETFINDER_STREAMLIT_CHART_TYPE to simple, advanced or all, depending which type of chart you would like to see. advanced is the default.
  • Scroll down to Option 1: Manual on how to setup HEROKU_POSTGRESQL_AMBER_URL
  • ** OPTIONAL ** - Scroll down to Local PostgreSQL Setup on how to setup a local psql database.

Now install required modules in requirements.txt:

pip install -r requirements.txt

To start Streamlit locally:

streamlit run projects/rescuechi/petfinder-streamlit/Home.py

Open the Network URL it gives you in your browser.

Data Getter

To pull down the first 100K results for dogs in and around Chicago, you can run:

python data_getter.py

This will create a file called chicago_animals.pkl in the rescuechi/petfinder/data folder.

Data Cleaner

This script reads and saves files locally, so no extra set-up beyond installing the python requirements is needed.

The script can be run by calling:

python data_cleaner.py

This will create a file called chicago_animals_clean.pkl in the rescuechi/petfinder/data folder.

Data Putter

This script syncs data to Heroku's PostgreSQL database. If you want the script to sync data locally, set the uri variable to DATABASE_URL.

python data_putter.py

Option 1: Manual

To copy the uri manually, you will first need to be part of the team's Heroku account. Then, navigate to https://data.heroku.com/ and select the datastore called postgresql-corrugated-21223. Click on settings, then View Credentials..., and look for a variable called URI.

Option 2: CLI

To use the Heroku CLI to get the database URI, first you will need to install the Heroku CLI by following the instructions here.

After this is installed and configured, you can run the following command:

export DATABASE_URL=$(heroku config:get HEROKU_POSTGRESQL_AMBER_URL --app  codeforchicago-rescuechi)

You can test that this worked by running

echo $DATABASE_URL

and checking that it prints back your uri.

Local PostgreSQL Setup

If you have PostgreSQL installed locally, in the terminal type psql and enter the commands:

CREATE USER username WITH PASSWORD 'password' CREATEDB;
CREATE DATABASE app_name WITH OWNER username;

Add your updated username, password and database name to your .env file. The DATABASE_URL line in your .env file should look like this with your details instead.

DATABASE_URL=postgresql://username:password@localhost/app_name

Once that's done you can follow the Data Getter & Setter guide up above. In the Data Putter, you will need to set the uri variable to DATABASE_URL instead of HEROKU_URL. I recommend using Postbird or a similar app to view the data.

* Note - While you can see the data locally with postbird, it doesn't work through Streamlit yet.

What's next

Expand dataset to other major metro areas in the US to look at differences. Add other fields from Petfinder to the dashboard including organizations and listing content. Expand to other pets.

Conclusion and Contributions

Project made during Women Who Code Hackathon for Social Good 2022.

Contributers -

Kayla Robinson, Chris Lynch, Evan Cooperman, Joseph Adorno, Cara Karter

About

Exploring datasets for potential Code for Chicago projects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •