Question: Hello need to modify this map-reduce program. It must demonstrate that each driver has covered average # of miles each week. The columns are :
Hello need to modify this map-reduce program. It must demonstrate that each driver has covered average # of miles each week.
The columns are : ID numbers of Drivers, the weeks they are driving, no of hours in each week they are driving and the miles they are covering each week.
Python Code
from mrjob.job import MRJob #importing the "MRjob" library
class MRTrucker(MRJob): #creates the class def mapper(self, _, line): #we are defining the mapper class instance (driversID, drivingWeeks, HoursPerWeek, MilesCovered) = line.split(',')#since we are using cvs #file it most be split with commas "," yield HoursPerWeek, float(MilesCovered) #the mapper ends and returning the HoursPerWeek, and the #MilesCovered and we are sending it as a float value
def reducer (self, HoursPerWeek, MilesCovered): #Defines the reducer function total = 0 #we are asigning the varible numElements = 0 #we are asigning another varible for x in MilesCovered: #The loop will search for x in this case "HoursPerWeek" in the list #Example: HoursPerWeek 40 [then it will find how many employees work 40 hours in the datafile total += x # EXAMPLE 325+2+221 and so on
numElements += 1
yield HoursPerWeek, total / numElements #These calculates the avarage total number #of drivers divided by the total number of people on the list
if __name__ == '__main__': #it runs the program MRTrucker.run()

AutoSave C H2 timesheet.co Search Carlos Fernandez Chinchilla C File Home Insert Draw Page Layout Formulas Data Review View Help Share Comments Calibri 11 ~A A == 82 Wrap Text ME X Out [Copy * Format Painter AutoSum rill General $ % , 90 49 Peste BIU H Insert Delete Tormat Sensitivity Merge & Center Conditional Format as Cell Formatting Table Styles Styles Clear Sort & Find & Filter Select Analyze Data Clipboard Font Alignment Cels Edting Analysis Serathir A1 > f 10 B E F H H P 0 R. s V w 1 70 10 10 10 2 3 4 70 60 10 10 D 3300 3300 2800 3100 3200 3300 3000 3300 5 6 10 7 8 1 2 3 4 5 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 10 10 10 10 10 9 10 11 70 70 70 70 70 70 50 70 70 70 70 3200 2500 3100 3300 3300 10 12 10 13 10 14 10 15 10 16 10 17 10 18 10 19 10 20 10 21 10 22 10 23 10 24 10 25 10 26 10 27 10 28 10 29 timesheet 70 70 70 70 70 30 50 3300 3400 3300 3300 3300 The list is way long This is just ( For Reference 22 70 70 70 70 24 25 26 27 28 29 1200 2500 3300 3300 3300 3300 2600 2700 1200 3300 66 33 70 + Reacy 1009 Type here to search 10:11 AM 2/12/2021 AutoSave C H2 timesheet.co Search Carlos Fernandez Chinchilla C File Home Insert Draw Page Layout Formulas Data Review View Help Share Comments Calibri 11 ~A A == 82 Wrap Text ME X Out [Copy * Format Painter AutoSum rill General $ % , 90 49 Peste BIU H Insert Delete Tormat Sensitivity Merge & Center Conditional Format as Cell Formatting Table Styles Styles Clear Sort & Find & Filter Select Analyze Data Clipboard Font Alignment Cels Edting Analysis Serathir A1 > f 10 B E F H H P 0 R. s V w 1 70 10 10 10 2 3 4 70 60 10 10 D 3300 3300 2800 3100 3200 3300 3000 3300 5 6 10 7 8 1 2 3 4 5 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 10 10 10 10 10 9 10 11 70 70 70 70 70 70 50 70 70 70 70 3200 2500 3100 3300 3300 10 12 10 13 10 14 10 15 10 16 10 17 10 18 10 19 10 20 10 21 10 22 10 23 10 24 10 25 10 26 10 27 10 28 10 29 timesheet 70 70 70 70 70 30 50 3300 3400 3300 3300 3300 The list is way long This is just ( For Reference 22 70 70 70 70 24 25 26 27 28 29 1200 2500 3300 3300 3300 3300 2600 2700 1200 3300 66 33 70 + Reacy 1009 Type here to search 10:11 AM 2/12/2021
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
