forked from Ada-C10/ride-share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathride_share_sabine.rb
281 lines (208 loc) · 5.97 KB
/
ride_share_sabine.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
########################################################
# Step 1: Establish the layers
# Write a list of the layers here
# ride_share = {driver1: => {data}}
# data { date => trips}
# trips [ {riderID:, cost: rating:}]
########################################################
# Step 2: Assign a data structure to each layer
# Copy your list from above, and write what data structure each layer should have
#### ride_share = {driver1: => {date}}
# ride_share is an array with key (driver), value (data) pair
#### data {date => trips}
# data is a set of ashes that will contain drivers'data organized by
# date ashes
#### trips [ {riderID:, cost: rating:}]
# trips is an arary containing many ashes of key value data sets
# capturing the values associated with each trip on that date
########################################################
# Step 3: Make the data structure!
# Setup the data structure and manually write in data presented in rides.csv
ride_share = {
DR0001: {
Feb3_2016: {
trips: [
{
riderid: "RD0003",
cost:10,
rating:3
},
{
riderid: "RD0015",
cost:30,
rating:4
},
]
},
Feb5_2016: {
trips: [
{
riderid: "RD0003",
cost:45,
rating:2
}
]
}
},
DR0002: {
Feb3_2016: {
trips: [
{
riderid:"RD0073",
cost:25,
rating:5
}
]
},
Feb4_2016: {
trips: [
{
riderid: "RD0013",
cost:15,
rating:1
}
]
},
Feb5_2016: {
trips: [
{
riderid: "RD0066",
cost:35,
rating:3
}
]
}
},
DR0003: {
Feb4_2016: {
trips: [
{
riderid: "RD0066",
cost:5,
rating:5
}
]
},
Feb5_2016: {
trips: [
{
riderid: "RD0003",
cost:50,
rating:2
}
]
}
},
DR0004: {
Feb3_2016: {
trips: [
{
riderid:"RD0022",
cost:5,
rating:5
}
]
},
Feb4_2016: {
trips: [
{
riderid: "RD0022",
cost:10,
rating:4
}
]
},
Feb5_2016: {
trips: [
{
riderid: "RD0003",
cost:20,
rating:5
}
]
}
}
}
# puts ride_share[:DR0001]
# puts
# puts ride_share[:DR0002]
# puts
# puts ride_share[:DR0003]
# puts
# puts ride_share[:DR0004]
#######################################################
# Step 4: Total Driver's Earnings and Number of Rides
# Use an iteration block to print driver's total rides and money made
############### this code below works with RUBY
def ride_numbers (number)
total_rides = []
ride_tally.each do |driver|
# need to let RUBY know what value to search for
total_rides << driver_1
end
ride_share[:DR0001][:Feb3_2016][:trips].length
ride_share[:DR0001][:Feb5_2016][:trips].length
driver_1 = ride_share[:DR0001][:Feb3_2016][:trips].length + ride_share[:DR0001][:Feb5_2016][:trips].length
puts "Total of rides for driver 1 is #{driver_1}"
d2_day_1 = ride_share[:DR0002][:Feb3_2016][:trips].length
d2_day_2 = ride_share[:DR0002][:Feb4_2016][:trips].length
d2_day_3 = ride_share[:DR0002][:Feb5_2016][:trips].length
driver_2 = d2_day_1 + d2_day_2 + d2_day_3
puts "Total of rides for driver 2 is #{driver_2}"
d3_day_1 = ride_share[:DR0003][:Feb4_2016][:trips].length
d3_day_2 = ride_share[:DR0003][:Feb5_2016][:trips].length
driver_3 = d3_day_1 + d3_day_2
puts "Total of rides for driver 3 is #{driver_3}"
d4_day_1 = ride_share[:DR0004][:Feb3_2016][:trips].length
d4_day_2 = ride_share[:DR0004][:Feb4_2016][:trips].length
d4_day_3 = ride_share[:DR0004][:Feb5_2016][:trips].length
driver_4 = d4_day_1 + d4_day_2 + d4_day_3
puts "Total of rides for driver 4 is #{driver_4}"
###############################
# def ride_cost (cost)
# total_cost = []
# cost_tally.each do |driver|
# # I need to let RUBY know what value I am searching
# total_cost <<
# end
driver_1_total_cost = []
cost1_1 = ride_share[:DR0001][:Feb3_2016][:trips][0][:cost]
cost1_2 = ride_share[:DR0001][:Feb3_2016][:trips][1][:cost]
cost1_3 = ride_share[:DR0001][:Feb5_2016][:trips][0][:cost]
//
driver_1_total_cost << cost1_1
driver_1_total_cost << cost1_2
driver_1_total_cost << cost1_3
# driver_one_cost << cost1_3.to_i
# puts driver_1_total_cost
driver1_final_cost = driver_1_total_cost[0] + driver_1_total_cost[1] + driver_1_total_cost[2]
#
puts "This is how much driver one made in total for day 1 $#{driver1_final_cost}"
#################################
driver_2_total_cost = []
cost2_1 = ride_share[:DR0002][:Feb3_2016][:trips][0][:cost]
cost2_2 = ride_share[:DR0002][:Feb4_2016][:trips][0][:cost]
cost2_3 = ride_share[:DR0002][:Feb5_2016][:trips][0][:cost]
//
driver_2_total_cost << cost2_1
driver_2_total_cost << cost2_2
driver_2_total_cost << cost2_3
# driver_one_cost << cost1_3.to_i
# puts driver_2_total_cost
driver2_final_cost = driver_2_total_cost[0] + driver_2_total_cost[1] + driver_2_total_cost[2]
#
puts "This is how much driver two made in total for day 1 $#{driver2_final_cost}"
# Need to create a case statement here to identity driver who made the most $
if
driver1_final_cost > driver2_final_cost
puts "The driver that made the most money is Driver 1"
elsif
driver2_final_cost > driver3_final_cost && driver2_final_cost > driver1_final_cost
puts "The driver that made the most money is Driver 2"
elsif
driver3_final_cost > driver4_final_cost && driver3_final_cost > driver2_final_cost && driver3_final_cost > driver1_final_cost
puts "The driver that mads the most money is Driver 3"
elsif
driver4_final_cost > driver1final_cost && driver4_final_cost > driver2_final_cost && driver4_final_cost > driver3_final_cost
puts "The driver that made the most money is Driver 4"
end