Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time - Angela #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Time - Angela #44

wants to merge 1 commit into from

Conversation

angethuy
Copy link

Assignment Submission: Ride Share

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question Answer
What did your data structure look like at first? Did this structure evolve over time? Why? My data structure used to have an array to track rides for each driver. Each ride hash contained the date, rider_id, cost, and rating. Eventually, I decided to pull date out of each ride hash and turn date into a hash key, with an array of rides now represented by just their date/rider_id/cost. I did this because I wanted to be able to look at all rides given by a driver for a particular date, which felt like a reasonable enough lookup that might be done repeatedly thus it justified structuring the data to account for "rides given on date" lookup. Dates are unique so they are also good candidates for hash keys.
What was your strategy for going through the data structure and gathering information? I used a loop to look at each driver, and then enumerators to count and sum cost/ratings.
What was an example of something that was necessary to store in a variable? Why was it necessary, useful, or helpful? At first I thought I'd be able to find the highest earner/highest rated drivers by using enumerators, mostly as a challenge to myself to see if I could manipulate my data structure in slick ways. However for the sake of time/my sanity, I finally decided to track highest earner/rated in their own hashes that updated as I looped through the drivers. It was helpful to do so because I was able to track the highest rankings as I processed the drivers individually, instead of having to go back and use more enumerator methods to find the highest.
What kinds of iteration did you use? Did you use .map? If so, when? If not, why, or when would be a good opportunity to use it? I did not use map. I relied on count and sum to return totals for each driver. A good opportunity to use it would be to answer the optional question of "which day did each driver earn the most" because I could create a map that stores the most lucrative workday for each driver.
Were some calculations easier than others? Why? After I figured out the first calculation (number of rides given per driver), the rest was a lot easier because I had solved the first hurdle of figuring out how the enumeration methods match up to my data nesting scheme. It then became a matter of tweaking my "daisy chain" of methods.

@kaidamasaki
Copy link

Ride Share

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Correctly creates, reads, and modifies variables ✔️
Correctly creates and accesses arrays ✔️
Correctly creates and accesses hashes ✔️
Reasonably organizes large amounts of related data into nested arrays and hashes ✔️
Correctly iterates through a nested data structure using loops and/or Enumerable methods ✔️
Reasonably organizes small pieces of code into methods, and calls/invokes those methods Didn't make any new methods.

Functional Requirements

Functional Requirement yes/no
To the terminal, the program outputs the correct number of rides each driver has given ✔️
... outputs the total amount of money each driver has made ✔️
... outputs the average rating for each driver ✔️
... outputs which driver made the most money ✔️
... outputs which driver has the highest average rating ✔️

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 4+ in Code Review && 3+ in Functional Requirements ✔️
Yellow (Approaches Standards) 2-3 in Code Review && 2+ in Functional Requirements
Red (Not at Standard) 0,1 in Code Review or 0,1 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging

Your code was generally quite clean and concise however you didn't wind up organizing things into methods which would have made the code a little bit clearer. This was a pretty small program but in the future trying to do things without methods will be challenging.

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever
Descriptive/Readable
Concise
Logical/Organized Using methods would really help with making your program more organized.

drivers = {
DR0001: [
{
"3rd Feb 2016": [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note about a confusing point of Ruby. Even if you use quotes if you use the "key": value syntax instead of the "key" => value the key will wind up a symbol.

Note the : before the quotes in the output.

irb(main):001:0> {"3rd Feb 2016": []}
=> {:"3rd Feb 2016"=>[]}

(Yes, symbols can have spaces, you just need to use quotes after the :.)

puts "#{driver} stats:"

# The number of rides each driver has given
ride_count = workdays.sum { |dates, rides| dates.sum { | date, rides | rides.count } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of a block with .sum! This lets you skip using a .map.

This is equivalent to doing:

   ride_count = workdays.map { |dates, rides| dates.sum { | date, rides | rides.count } }.sum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants