Skip to content

molleighH/SQLAlchemy-Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 

Repository files navigation

# SQLAlchemy-Challenge
Module 10 Homework Challenge

Congratulations! You've decided to treat yourself to a long holiday vacation in Honolulu, Hawaii. To help with your trip planning, you decide to do a climate analysis about the area. The following sections outline the steps that you need to take to accomplish this task.



PART 1: ANALYZE & EXPLORE THE CLIMATE DATA</font size>

In this section, you’ll use Python and SQLAlchemy to do a basic climate analysis and data exploration of your climate database. Specifically, you’ll use SQLAlchemy ORM queries, Pandas, and Matplotlib.


To do so, complete the following steps:

  1. Note that you’ll use the provided files (climate_starter.ipynb) and (hawaii.sqlite) to complete your climate analysis and data exploration.
  2. Use the SQLAlchemy create_engine() function to connect to your SQLite database
  3. Use the SQLAlchemy automap_base() function to reflect your tables into classes, and then save references to the classes named (station) and (measurement).
  4. Link Python to the database by creating a SQLAlchemy session.

    IMPORTANT: Remember to close your session at the end of your notebook
  5. Perform a precipitation analysis and then a station analysis by completing the steps in the following two subsections.

PERCIPITATION ANALYSIS

  1. Find the most recent date in the dataset.
  2. Using that date, get the previous 12 months of precipitation data by querying the previous 12 months of data.
    HINT: Don't pass the date as a variable to your query
  3. Select only the "date" and "prcp" values.
  4. Load the query results into a Pandas DataFrame. Explicitly set the column names.
  5. Sort the DataFrame values by "date".
  6. Plot the results by using the DataFrame [plot] method, as the following image shows:
    alt text
  7. Use Pandas to print the summary statistics for the precipitation data.

STATION ANALYSIS

  1. Design a query to calculate the total number of stations in the dataset.

  2. Design a query to find the most-active stations (that is, the stations that have the most rows).
    To do so, complete the following steps:
    2a. List the stations and observation counts in descending order.
    HINT: You’ll need to use the [func.count] function in your query
    2b. Answer the following question: which station id has the greatest number of observations?

  3. Design a query that calculates the lowest, highest, and average temperatures that filters on the most-active station id found in the previous query.
    HINT: You’ll need to use functions such as [func.min], [func.max], and [func.avg] in your query.

  4. Design a query to get the previous 12 months of temperature observation (TOBS) data.
    To do so, complete the following steps:
    4a. Filter by the station that has the greatest number of observations.
    4b. Query the previous 12 months of TOBS data for that station.
    4c. Plot the results as a histogram with [bins=12], as the following image shows:
    alt text

  5. Close your session.


Part 2: Design Your Climate App
Now that you’ve completed your initial analysis, you’ll design a Flask API based on the queries that you just developed.
To do so, use Flask to create your routes as follows:

  1. [ / ]
    1a. Start at the homepage.
    1b. List all the available routes.

  2. [ /api/v1.0/precipitation ]
    2a. Convert the query results from your precipitation analysis (i.e. retrieve only the last 12 months of data) to a dictionary using [date] as the key and [prcp] as the value.
    2b. Return the JSON representation of your dictionary.

  3. [ /api/v1.0/stations ]
    3a. Return a JSON list of stations from the dataset.

  4. [ /api/v1.0/tobs ]
    4a. Query the dates and temperature observations of the most-active station for the previous year of data.
    4b. Return a JSON list of temperature observations for the previous year.

  5. [ /api/v1.0/ ] and [ /api/v1.0// ]
    5a. Return a JSON list of the minimum temperature, the average temperature, and the maximum temperature for a specified start or start-end range.
    5b. For a specified start, calculate [TMIN], [TAVG], and [TMAX] for all the dates greater than or equal to the start date.
    5c. For a specified start date and end date, calculate [TMIN], [TAVG], and [TMAX] for the dates from the start date to the end date, inclusive.
    HINTS:Join the station and measurement tables for some of the queries.
    HINTS:Use the Flask [jsonify] function to convert your API data to a valid JSON response object.



Requirements
Jupyter Notebook Database Connection (10 points)

To receive all points, you must:

1. Use the SQLAlchemy [create_engine()] function to connect to your SQLite database (1 point)

2. Use the SQLAlchemy [automap_base()] function to reflect your tables into classes (3 points)

3. Save references to the classes named [station] and [measurement] (4 points)

4. Link Python to the database by creating a SQLAlchemy session (1 point)

5. Close your session at the end of your notebook (1 point)



Precipitation Analysis (16 points)

To receive all points, you must:

A. Create a query that finds the most recent date in the dataset (8/23/2017) (2 points)

B. Create a query that collects only the [date] and [precipitation] for the last year of data without passing the date as a variable (4 points)

C. Save the query results to a Pandas DataFrame to create [date] and [precipitation] columns (2 points)

D. Sort the DataFrame by [date] (2 points)

E. Plot the results by using the DataFrame [plot] method with [date] as the x and [precipitation] as the y variables (4 points)

F. Use Pandas to print the summary statistics for the precipitation data (2 points)



Station Analysis (16 points)
To receive all points, you must:

A. Design a query that correctly finds the number of stations in the dataset (9) (2 points)

B. Design a query that correctly lists the stations and observation counts in descending order and finds the most active station (USC00519281) (2 points)

C. Design a query that correctly finds the min, max, and average temperatures for the most active station (USC00519281) (3 points)

D. Design a query to get the previous 12 months of temperature observation (TOBS) data that filters by the station that has the greatest number of observations (3 points)

E. Save the query results to a Pandas DataFrame (2 points)

F. Correctly plot a histogram with bins=12 for the last year of data using tobs as the column to count. (4 points)



API SQLite Connection & Landing Page (10 points)

To receive all points, your Flask application must:

A. Correctly generate the engine to the correct sqlite file (2 points)

B. Use [automap_base()] and reflect the database schema (2 points)

C. Correctly save references to the tables in the sqlite file ([measurement] and [station]) (2 points)

D. Correctly create and binds the session between the python app and database (2 points)

E. Display the available routes on the landing page (2 points)

API Static Routes (15 points)

To receive all points, your Flask application must include:

-A precipitation route that:
A) Returns json with the date as the key and the value as the precipitation (3 points)
B) Only returns the jsonified precipitation data for the last year in the database (3 points)

-A stations route that:
A) Returns jsonified data of all of the stations in the database (3 points)

-A tobs route that:
A) Returns jsonified data for the most active station (USC00519281) (3 points)
B) Only returns the jsonified data for the last year of data (3 points)

API Dynamic Route (15 points)

To receive all points, your Flask application must include:

-A start route that:
A) Accepts the start date as a parameter from the URL (2 points)
B) Returns the min, max, and average temperatures calculated from the given start date to the end of the dataset (4 points)

-A start/end route that:
A) Accepts the start and end dates as parameters from the URL (3 points)
B) Returns the min, max, and average temperatures calculated from the given start date to the given end date (6 points)

Coding Conventions and Formatting (8 points)

To receive all points, your code must:

-Place imports at the top of the file, just after any module comments and docstrings, and before module globals and constants. (2 points)

-Name functions and variables with lowercase characters, with words separated by underscores. (2 points)

-Follow DRY (Don't Repeat Yourself) principles, creating maintainable and reusable code. (2 points)

-Use concise logic and creative engineering where possible. (2 points)

Deployment and Submission (6 points)
To receive all points, you must:

-Submit a link to a GitHub repository that’s cloned to your local machine and contains your files. (2 points)

-Use the command line to add your files to the repository. (2 points)

-Include appropriate commit messages in your files. (2 points)

Comments (4 points)

To receive all points, your code must:

-Be well commented with concise, relevant notes that other developers can understand. (4 points)

About

Module 10 Homework Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published