forked from Ada-C8/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrideshare.rb
56 lines (50 loc) · 2.2 KB
/
rideshare.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
########################################################
# Step 1: Establish the layers
# Write a list of the layers here
# 1. Information for each driver
# 2. List of each driver's rides
# 3. Iinformation about each ride: date, rider ID, cost, and rating
########################################################
# Step 2: Assign a data structure to each layer
# Copy your list from above, and write what data structure each layer should have
# HASH >> 1. Information for each driver
# ARRAY >> 2. List of each driver's rides
# HASH >> 3. Iinformation about each ride: date, rider ID, cost, and rating
########################################################
# Step 3: Make the data structure!
# Setup the data strcture and manually write in data presented in rides.csv
drivers = {
"DR0001" => [
{date: "3rd Feb 2016", cost: 10, rider: "RD0003", rating: 3},
{date: "3rd Feb 2016", cost: 30, rider: "RD0015", rating: 4},
{date: "5th Feb 2016", cost: 45, rider: "RD0003", rating: 2}
],
"DR0002" => [
{date: "3rd Feb 2016", cost: 25, rider: "RD0073", rating: 5},
{date: "4th Feb 2016", cost: 15, rider: "RD0013", rating: 1},
{date: "5th Feb 2016", cost: 35, rider: "RD0066", rating: 3}
],
"DR0003" => [
{date: "4th Feb 2016", cost: 5, rider: "RD0066", rating: 5},
{date: "5th Feb 2016", cost: 50, rider: "RD0003", rating: 2}
],
"DR0004" => [
{date: "3rd Feb 2016", cost: 5, rider: "RD0022", rating: 5},
{date: "4th Feb 2016", cost: 10, rider: "RD0022", rating: 4},
{date: "5th Feb 2016", cost: 20, rider: "RD0073", rating: 5}
]
}
########################################################
# Step 4: Total Divers Earnings and Number of Rides
# Use an iteration block to print driver's total rides and money made
# Total Rides, Money Made, and Average Rating
drivers.each do | driver, rides |
total = 0
average = 0
rides.each do | ride |
total += ride[:cost]
average += ride[:rating]
end
average /= rides.length.to_f
puts "Driver ##{driver} gave #{rides.length} rides, made $#{total}, and averaged a #{sprintf("%.1f",(average))} rating."
end