forked from Ada-C10/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
janes_worksheet.rb
125 lines (119 loc) · 2.65 KB
/
janes_worksheet.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
drivers = {
"DR0001" => [
ride_one: {
DATE: "3rd Feb 2016",
COST: 10,
RIDER_ID: "RD0003",
RATING: 3
},
ride_two: {
DATE: "3rd Feb 2016",
COST: 30,
RIDER_ID: "RD0015",
RATING: 4
},
ride_three: {
DATE: "5th Feb 2016",
COST: 45,
RIDER_ID: "RD0003",
RATING: 2
}
],
"DR0002" => [
ride_one: {
DATE: "3rd Feb 2016",
COST: 25,
RIDER_ID: "RD0073",
RATING: 5
},
ride_two: {
DATE: "4rd Feb 2016",
COST: 15,
RIDER_ID: "RD0013",
RATING: 1
},
ride_three: {
DATE: "5th Feb 2016",
COST: 35,
RIDER_ID: "RD0066",
RATING: 3
}
],
"DR0003" => [
ride_one: {
DATE: "4rd Feb 2016",
COST: 5,
RIDER_ID: "RD0066",
RATING: 5
},
ride_two: {
DATE: "5rd Feb 2016",
COST: 50,
RIDER_ID: "RD0003",
RATING: 2
}
],
"DR0004" => [
ride_one: {
DATE: "3rd Feb 2016",
COST: 5,
RIDER_ID: "RD0022",
RATING: 5
},
ride_two: {
DATE: "4rd Feb 2016",
COST: 10,
RIDER_ID: "RD0022",
RATING: 4
},
ride_three: {
DATE: "5th Feb 2016",
COST: 20,
RIDER_ID: "RD0073",
RATING: 5
}
]
}
# - The number of rides each driver has given X
# - The total amount of money each driver has made X
# - The average rating for each driver X
# - Which driver made the most money? X
# - Which driver has the highest average rating? X
# - For each driver, on which day did they make the most money? X
total_money_made = {}
ratings_average = {}
drivers.each do |driver_id, driver_info|
sum = 0
rating_sum = 0
most_money = 0
best_day = ""
driver_info.each do |rides|
puts "#{driver_id} had #{rides.length} rides."
rides.each do |ride_number, ride_info|
sum += rides[ride_number][:COST]
rating_sum += rides[ride_number][:RATING]
if most_money < rides[ride_number][:COST]
most_money = rides[ride_number][:COST]
best_day = rides[ride_number][:DATE]
end
end
puts "#{driver_id} made $#{sum} total."
puts "#{driver_id} has a #{rating_sum / rides.length} star average rating."
total_money_made[driver_id] = sum
ratings_average[driver_id] = rating_sum / rides.length
end
puts "#{driver_id} made the most money on #{best_day}.\n \n"
end
def highest(drivers)
most = 0
most_driver = ""
drivers.map do |key, value|
if value > most
most = value
most_driver = key
end
end
return most_driver
end
puts "#{highest(total_money_made)} made the most money."
puts "#{highest(ratings_average)} had the highest average rating."