Code Monkey home page Code Monkey logo

ride-share's Introduction

Ride Sharing Data with Arrays and Hashes

Learning Goals

  • Logically order data into a nested data structure
  • Understand benefits of organizing data in a nested structure
  • Iterate through a nested data structure to return specific information

Objective

We will review drivers of a ride sharing service and their ride history. We want to be able to see how many rides each driver has given and how much money a driver has made.

Currently, the data is stored in a CSV. We will take that data and thoughtfully organize it into a nested data structure using both arrays and hashes.

But why?

Sometimes applications rely on using data from another source, like Google Maps or Twitter. That data needs to be sent in a way that other applications can read and interact with, regardless of what programming language is being used.

The most common way you'll see that data represented is in JSON. We'll learn more about JSON more in depth later, but what you need to know now is that data is often represented with several layers of nested data structures. Ultimately making up one big data structure.

Have a look at this example of JSON from Google Maps and answer the following questions.

  • How many different layers of data structures are there?
  • What data structures were used?
  • Why were those data structures used for those layers?

Let's do this!

Use the file, worksheet.rb, to complete this activity.

Step 1: Establish the layers

Based on the data provided in the rides.csv, make a list of the different layers our data structure will need. These layers will each represent a new data structure that will nested within another.

Step 2: Assign a data structure to each layer

Now that you know what layers you have, decide what data structure would be most appropriate to use for each layer.

Step 3: Make the data structure!

Create the data structure by starting with the outline, then manually input all the data from rides.csv into it.

Remember: Be mindful of indentation, it will make it substantially easier to read data as it become more nested.

Step 4: Total Divers Earnings and Number of Rides

Iterate through the data structure to display, by printing in terminal, how many rides each driver has given and how much money they have made.

If you have time, also display what the drivers average rating is.

Wrap up

By having this data structure, we can now more easily target specific parts of our data to see how many rides a driver has given.

What are other useful ways we could use this data structure?

ride-share's People

Contributors

pilgrimmemoirs avatar kariabancroft avatar

Watchers

James Cloos avatar Isaac Del Rosario 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.