# Little script to change the working directory if the module is executed from this file.

if __name__ == "__main__" :
    from os.path import abspath as get_abspath
    from os.path import dirname as get_dirname
    from os import chdir as change_wdir
    from os import getcwd as get_wdir
    from sys import path
    change_wdir(get_dirname(get_abspath(__file__)))
    change_wdir( ".." )
    path.append(get_wdir())

# This script is used to generate the benchmark for the route function. You can replace the strings 
# and change the function if you need to benchmark something else.

from LazyFrame import LazyFrame
from functions import route
from pathlib import Path
from time import time

directory = "/home/mkel/Documents/FAC/M1/TPE/ais-operations/ressources/BD-AIS/FichiersCSV-Exemples/"
results = dict()
benchmark = open("/home/mkel/Documents/FAC/M1/TPE/ais-operations/resources/data/benchmark.dat", "w")

# For each file.
for file in Path(directory).iterdir():
    totalTime = 0

    # Do it 10 times to have an average.
    for i in range(10):
        lazyFrame = LazyFrame(str(file))
        startTime = time()
        lazyFrame = route(lazyFrame)
        lazyFrame.save()
        endTime = time()
        totalTime += endTime - startTime
    results[file.stat().st_size] = totalTime / 10

# Sort the results by size of the file.
for key, value in sorted(results.items()):
    benchmark.write(str(key) + " " + str(value) + "\n")
benchmark.close()