Skip to content

This project uses Dark Sky API wrapped by python-forecastio as a tool to have a quick look on the historical weather data and derive some insights from it.

Notifications You must be signed in to change notification settings

chuhsuanlee/hot-summer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Document

This project uses Dark Sky API wrapped by python-forecastio as a tool to have a quick look on the historical weather data and derive some insights from it.

Requirements

  • Since this project is dockerized, Docker needs to be installed to run this project.

  • An API key must be claimed beforehand. Please go to this page and claim yours.

Quick start

After cloning this repository to your local machine, substitute the API_KEY in config.py with the key retrieved from above.

There are some commands you can use as indicated in Makefile, or simply type make help, it will show the Make commands that can be used.

More variables in config.py:

  • API_CALLS: How many API calls available

  • CITY_MAP: Dictionary that the city list is set as. Berlin is in default, and more cities can be added as an item with the format of incremental_int: (‘city_name’, (latitude, longitude)) as follows:

    CITY_MAP = {
        0: ('Berlin', (52.517, 13.3899)),
        1: ('Boston', (42.3601, -71.0589)),
    }
  • SQLALCHEMY_URI, SQLALCHEMY_ECHO: The configuration of database. It uses PyMySQL and SQLAlchemy packages as the communication tool between the program and database.

Functions

download_historical_data() fetches the historical daily data and saves a csv file in reports folder.

For historical data, only one day per API call can be fetched, and that’s the reason why the amount of API calls should be set beforehand in config.py. The process begins from yesterday, then one day before, and continues this way until it reaches the maximum of possible API calls.

The record model table schema is specified in model.py and database is configured in config.py. Related operations include update_record() and update_process().

Since there’s no real database server binded yet, this project uses the csv file as depicted above to retrieve the information.

daily_update() is the function excluded from execution but implemented as a procedure that keeps this database automatically updated for a set of cities. It assumes that after download_historical_data(), data before yesterday are all downloaded, so only data of yesterday (when the date moves to the next day, there’s no data for the ‘new’ yesterday yet) and forecasted data of the following 7 days need to be fetched or updated. Thus, it uses the Time Machine Request and Forecast Request separately.

required_computation() reads the csv file saved in download_historical_data(). It compares the maximum temperature of every single day in summer (June - August) between 2016-2018, and calculates the amount of hottest days in each year.

Sample output

Berlin historical record on 2018-10-21: 15/5.56
Berlin historical record on 2018-10-20: 12.44/2.56
Berlin historical record on 2018-10-19: 14.44/2.44
Berlin historical record on 2018-10-18: 15.75/7.44
Berlin historical record on 2018-10-17: 20.57/6

Successfully read 900 daily data.

The amount of hottest days in summer (June - August) between 2016 - 2018:
2016 has 21 hottest days.
2017 has 22 hottest days.
2018 has 49 hottest days.

Result report: The hottest year is 2018 with 49 hottest days in summer.

About

This project uses Dark Sky API wrapped by python-forecastio as a tool to have a quick look on the historical weather data and derive some insights from it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published