Question: why i ' m not getting any output from this path: my _ results, A 0 1 _ Part 1 : result.txt . Technology: Python

why i'm not getting any output from this path: my_results, A01_Part1: result.txt.
Technology:
Python (without using the MapReduce simulator).
Your task is to:
Compute the top_n_bikes with highest total duration time for their trips.
Complete the function my_main of the Python program.
o Do not modify the name of the function nor the parameters it receives.
o In particular, the function must read the dataset provided in input_folder and must open
and write the results to output_file. The number of bikes to output is specified by the
parameter top_n_bikes. For example, if top_n_bikes =10, then you must output the 10
bikes with highest total duration time for their trips.
o You can use the auxiliary function process_line which, given one line from a dataset
file, returns a tuple with its content.
o You can also program any other auxiliary functions you might need.
Results:
Output one text line per bike_id. Lines must follow decreasing order in highest total duration
time for their trips. Each line must have the following format:
bike_id \t (total_duration_time_for_their_trips, total_number_of_trips)
def my_main(input_folder, output_file, top_n_bikes):
bikeIdList =[]
bikeIdListUnique = set()
combined_data =[]
for filepath in glob.iglob(input_folder +'*.csv'):
with open(filepath,'r') as file:
for row in file:
combined_data.append(process_line(row))
for cd in combined_data:
bikeIdList.append(cd[11])
for x in bikeIdList:
bikeIdListUnique.add(x)
bike_tuple_list =[]
for x in bikeIdListUnique:
totalTripDuration =0
totalTripNumber =0
for d in combined_data:
if d[11]== x:
totalTripDuration += d[2]
totalTripNumber +=1
bike_tuple_list.append((x, totalTripDuration, totalTripNumber))
bike_tuple_list = sorted(bike_tuple_list, key=lambda t: t[1], reverse=True)[:top_n_bikes]
# Open file for writing to
with open(output_file, 'w') as file:
# Loop over the list of tuples and write each to the file as a line of text
for x in bike_tuple_list:
file.write(str(x[0])+"\t("+ str(x[1])+","+ str(x[2])+")
")
# PYTHON EXECUTION
if __name__=='__main__':
input_folder ="../../my_dataset/"
output_file ="../../my_results/A01_Part2/result.txt"
top_n_bikes =5
if len(sys.argv)>1:
input_folder = sys.argv[1]
output_file = sys.argv[2]
my_main(input_folder, output_file, top_n_bikes)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!