Esempio n. 1
0
def run(input_file_name, output_file_name):
    # Load data set
    input_file = parsing.CSV().from_file(input_file_name)
    header = input_file.read_line(sep=" ")
    for i in range(len(header)):
        header[i] = int(header[i])

    rides = input_file.read_n_line(int(header[3]), " ")
    for i in range(len(rides)):
        rides[i].append(i)
    for i in range(len(rides)):
        for j in range(len(rides[0])):
            rides[i][j] = int(rides[i][j])
    rides = sort.by_time_lastest(rides, header[3])

    # Create fleet
    cars_1 = fleet.create(header[2])
    cars_2 = fleet.create(header[2])

    rides_2 = rides
    nb_ride_failed_1 = my_try_run(rides, cars_1)
    rides_2.reverse()
    nb_ride_failed_2 = my_try_run(rides_2, cars_2)

    # Export
    output_file = exporting.CSV().from_file(output_file_name)
    if nb_ride_failed_1 < nb_ride_failed_2:
        for car in cars_1:
            output_file.write_line(car.export(), sep=" ")
    else:
        for car in cars_2:
            output_file.write_line(car.export(), sep=" ")

    print("End of", input_file_name)
Esempio n. 2
0
 def test_get(self):
     file = exporting.CSV()
     file_name, stream = file.get()
     if file_name != "" or stream is not None:
         self.fail()
     file.from_file("sample.csv")
     file_name, stream = file.get()
     if file_name != "sample.csv" or stream is None:
         self.fail()
     file.close()
Esempio n. 3
0
 def test_write_line(self):
     file = exporting.CSV().from_file("sample.csv")
     file.write_line(['M', 'T', 'M'])
     file.close()
     file = parsing.CSV().from_file("sample.csv")
     line = file.read_line()
     if len(line) != 3:
         self.fail()
     if line[0] != 'M' or line[1] != 'T' or line[2] != 'M':
         self.fail()
     file.close()
Esempio n. 4
0
 def test_write_n_line(self):
     file = exporting.CSV().from_file("sample.csv")
     file.write_n_line([['M', 'T', 'M'], ['T', 'M', 'T'], ['M', 'T', 'M']],
                       2)
     file.close()
     file = parsing.CSV().from_file("sample.csv")
     lines = file.read_n_line(n=2)
     if len(lines) != 2:
         self.fail()
     if lines[0][0] != 'M' or lines[0][1] != 'T' or lines[0][2] != 'M':
         self.fail()
     if lines[1][0] != 'T' or lines[1][1] != 'M' or lines[1][2] != 'T':
         self.fail()
     file.close()