-
Notifications
You must be signed in to change notification settings - Fork 54
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
marj-ride-share-project #36
base: master
Are you sure you want to change the base?
Conversation
…3 method, started step 4
…ver summary variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, a few comments to review, but this is quite well done.
1. What _things_ (objects, nouns) are represented or described in this file? We can think of at least six different things. | ||
A. Driver, Date, Cost, Rider, Rating, One Ride, | ||
|
||
2. From the things you listed in the previous question, all of those things have relationships to each other. (an ID belongs to a person, for instance. As an abstract, unrelated example a VIN belongs to a vehicle, and a vehicle has a VIN.) Consider the relationships between the pieces of data. | ||
A. All of the information combines to form the data for one ride. You can find the amount of times or average times the driver or rider has a ride. You can find the average rating a rider gives or the average rating a driver gets. You can see this not just for one driver or rider, but for all as a grouped average. You can count how many rides on a given day, month, or year. You may be able to determine the possible cause for a high or low cost - distance, traffic / time of day, (split cost for ride share if an option)... but that would need more data like a time stamp. You could see if there is a link between cost and ratings. You can find rider trends in travel cost - are there more low cost shorter trips or higher cost long trips (although this may also need more data like start and stop locations). | ||
|
||
3. Lastly, in this assignment, we will rearrange all of the data into one data structure (with a lot of nested layers), that can be held in one variable. List some ideas: considering all of the relationships listed in the last question, what piece of data can contain the others at the top-most level? (Compared to the json example before, think about what the top-most layer of the hash and what that represented.) There is more than one correct answer, so just list out the options at this moment. | ||
A. An array can hold the other data at the top-most level, with each hash representing a ride. Since each row represents a ride, I think it best to maintain that structure as much as possible. If I think about the things that I want to get from the data, or what this data may be used to analyse, I still think using the table/column headings as keys in each ride hash is wise. If more columns are added in the future to collect more data, it will be easier to add the column to the ride hashes and the data of that column by following the same pattern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
rides_data = [ | ||
['DRIVER_ID','DATE','COST','RIDER_ID','RATING'], | ||
['DR0004','3rd Feb 2016','5','RD0022','5'], | ||
['DR0001','3rd Feb 2016','10','RD0003','3'], | ||
['DR0002','3rd Feb 2016','25','RD0073','5'], | ||
['DR0001','3rd Feb 2016','30','RD0015','4'], | ||
['DR0003','4th Feb 2016','5','RD0066','5'], | ||
['DR0004','4th Feb 2016','10','RD0022','4'], | ||
['DR0002','4th Feb 2016','15','RD0013','1'], | ||
['DR0003','5th Feb 2016','50','RD0003','2'], | ||
['DR0002','5th Feb 2016','35','RD0066','3'], | ||
['DR0004','5th Feb 2016','20','RD0073','5'], | ||
['DR0001','5th Feb 2016','45','RD0003','2'] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a 2D array here, also called an array of arrays. This works, but you have to use the 1st row for the titles of each field in the subsequent sub-arrays.
You could instead have an array of hashes.
rides_data = [
{
driver_id: "DR0004",
date: "3rd Feb 2016",
cost: 5,
rider_id: "RD0022",
rating: 5,
},
...
]
ride = Hash[headings[0], row[0], headings[1], parse_date(row[1]), headings[2], row[2].to_i, headings[3], row[3], headings[4], row[4].to_i] | ||
top_array << ride | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really cool that you were able to write the code here to structure the data this way. That said, why not structure the data this way to start with since you were entering it manually in the beginning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very true. It would have saved me time and energy! I think in my mind, it was an exercise in what I think getting data from an csv file might be like.
ride_share_data = structure_ride_share(rides_data) | ||
line_break | ||
puts 'Ride Share Data:' | ||
line_break | ||
pp ride_share_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for readability it's best to put your methods at the top of the file and the main program code all together at the bottom.
In reading this I was seeing
[method definitions]
some lines in the program here
[more method definitions]
more lines in the main program
So the methods here break up the flow of the regular program and make it harder to trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback on this! I will re-arrange!
######################################################## | ||
# Step 4: Total Driver's Earnings and Number of Rides | ||
|
||
# Use an iteration blocks to print the following answers: | ||
def find_unique_values(value_type, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
total_rides = count_total_rides(id, data) | ||
total_ratings = 0.to_f | ||
|
||
data.each{ |ride_hash| total_ratings += ride_hash[:rating] if ride_hash.value?(id) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use reduce
or sum_by
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look into those methods to do refactoring with. Thank you for bringing my attention to those methods :)
} | ||
end | ||
#test | ||
pp driver_summaries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works to summarize the driver data, but it looks like an array of hashes instead of neat output appealing to an end-user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:D Yes! During round tables today, another classmate had printed out great summaries for an end user, and I kept thinking, I need to do that for my code too! Thanks~!
Assignment Submission: Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
.map
? If so, when? If not, why, or when would be a good opportunity to use it?