Code Monkey home page Code Monkey logo

dsc-mod-2-lab-online-ds-ft-090919's Introduction

Module 2 Summative Lab

Introduction

For today's section, we're going to work on a single big lab to apply everything we've learned in Module 2!

About This Lab

A quick note before getting started--this lab isn't like other labs you seen so far. This lab is meant to take ~8 hours to complete, so it's much longer and more challenging than the average labs you've seen so far. If you feel like this lab is challenging or that you might be struggling a bit, don't fret--that's by design! With everything we've learned about Web Scraping, APIs, and Databases, the best way to test our knowledge of it is to build something substantial!

The Project

In this lab, we're going to make use of everything we've learned about APIs, databases, and Object-Oriented Programming to Extract, Transform, and Load (or ETL, for short) some data from a SQL database into a MongoDB Database.

You'll find a database containing information about soccer teams and the matches they've played in the file database.sqlite. For this project, our goal is to get the data we think is important from this SQL database, do some calculations and data transformation, and then store everything in a MongoDB database.

Let's get into the specifics of this project.

The Goal

Start by examining the data dictionary for the SQL database we'll be working with, which comes from this kaggle page. Familiarize yourself with the tables it contains, and what each column means. We'll be using this database to get data on each soccer team, calculate some summary statistics, and then store each in a MongoDB database.

Upon completion of this lab, each unique team in this dataset should have a record in the MongoDB instance containing the following information:

  • The name of the team
  • The total number of goals scored by the team during the 2011 season
  • The total number of wins the team earned during the 2011 season
  • A histogram visualization of the team's wins and losses for the 2011 season (store the visualization directly by assigning it to a variable)
  • The team's win percentage on days where it was raining during games in the 2011 season.

Getting the Weather Data

Note that for this last calculation, you'll need to figure out if it was raining or not during the game. The database itself does not contain this information, but it does contain the date on which the game was played. For this, you'll need to use the DarkSky API to get the historical weather data for that day. Note that each game is played in a different location, and this information is not contained in our SQL database. However, the teams in this database are largely german, so go ahead and just use the weather in Berlin, Germany as a proxy for this information. If it was raining in Berlin on the day the game was played, count that as rain game--you do not need to try and figure out the actual weather at each game's location, because we don't have that information!

NOTE: The DarkSky API is limited to 1000 free API calls a day, so be sure to test your model on very small samples. Otherwise, you'll hit the rate limit!

Project Architecture

Unlike previous labs, this lab is more open-ended, and will require you to make design decisions and plan out your strategy for building a system with this many working parts. However, using Object-Oriented Programming is a requirement for this project--you must create at least 2 separate, well-structured classes in your solution! Although it may seem easier to "just start coding", this is a classic beginner's mistake. Instead, think about separating out the different functionalities you'll need to reach your goal, and then build classes to handle each. For instance, at a minimum, you'll need to:

  • Query the SQL database
  • Calculate summary statistics
  • Get the weather data from the DarkSky API
  • Load the data into MongoDB

We strongly recommend you consider creating separate classes for handling at least some of these tasks. Be sure to plan the inputs, outputs, and methods for each class before you begin coding!

NOTE: We have provided some empty classes below. You are welcome to delete them and use a different architecture for this project if you so choose. You do not have to use each of them, they are just there to give you an idea of what sorts of classes you may want to consider using.

Rapid Prototyping and Refactoring

It's totally okay to try to get a task working without using OOP. For instance, when experimenting with the DarkSky API for getting historical weather data, it makes sense to just write the code in the cells and rapidly iterate until you get it all working. However, once you get it working, you're not done--you should then Refactor your code into functions or classes to make your code more modular, reusable, understandable, and maintainable!

In short--do what you need to do to get each separate piece of functionality working, and then refactor it into a class after you've figured it out!

Some Final Advice

You haven't built anything this big or complex thus far, so you may not yet fully realize how much trial and error goes into it. If your code keeps breaking, resist the urge to get frustrated, and just keep working. Software development is an iterative process! No one writes perfect code that works the first time for something this involved. You're going to run into a lot of small errors in this project, right up until the point where it just works, and then you're done! However, you can reduce these errors by planning out your code, and thinking about how all of the pieces fit together before you begin coding. Once you have some basic understanding of how it all will work, then you'll know what you need to build, and then all that is left is to build it!

In short:

  • Plan ahead--you'll thank yourself later!
  • Errors and broken code aren't bad, they're normal.
  • Keep working, and stay confident--you can do this!

Good luck--we look forward to seeing your completed project!

# You don't have to use these classes, but we recommend them as a good place to start!
class WeatherGetter():
    pass
class MongoHandler():
    pass

Summary

In this lab, we dug deep and used everything we've learned so far about python programming, databases, HTTP requests and API calls to ETL data from a SQL database into a MongoDB instance!

dsc-mod-2-lab-online-ds-ft-090919's People

Contributors

mike-kane avatar mas16 avatar menach123 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.