using Pkg
Pkg.activate(".")

#Pkg.add(url="https://gitlab.gwdg.de/smuehle1/RidePooling/", rev="planned_pickup")
#Pkg.instantiate()   #there may be an error here concerning PyCall. The dependencies assume Python to be installed on your system, with package 'matplotlib' installed.
                    #Either just run 'conda install -c conda-forge matplotlib' in your system shell, or follow instructions below (after running this cell and getting an error) to solve everything from within Julia.
import RidePooling

#include("../RidePooling/src/RidePooling.jl")
RP = RidePooling
using DataFrames
using CSV
include("./sim_functions.jl")




index=1
save_path = pwd()*"/example/ruben/"
N=10
request_type = :now
# Get Parameters from commandline
println(ARGS)


try
    global N = eval(Meta.parse(ARGS[1]))
    global save_path = ARGS[2]
    global index = eval(Meta.parse(ARGS[3]))
    global request_type = Symbol(Meta.parse(ARGS[4]))
    println("Using Command line parameters \n\tN = $N\n\tsave_path = $save_path\n\tindex = $index\n\trequest_type=$request_type")
catch e
    println(e)
try
    global N = eval(Meta.parse(ARGS[1]))
    global save_path = ARGS[2]
    global index = eval(Meta.parse(ARGS[3]))
    println("Using Command line parameters \n\tN = $N\n\tsave_path = $save_path\n\tindex = $index\n\trequest_type=$request_type")
catch e
    println(e)
try
    global N=10
    global save_path = Meta.parse(ARGS[1])
    global index = eval(Meta.parse(ARGS[2]))
    println("No N found. Falling back to standart value:\n\tN=$N\n\trequest_type=$request_type")
catch e
    println(e)
try
    global save_path = pwd()*"/results/"
    global N=10
    global index=eval(Meta.parse(ARGS[1]))
    println("No Savepath or N found. Falling back to standart values:\n\tN=$N\n\tfilepath=$save_path\n\trequest_type=$request_type")
catch e
    println(e)
    global index=1
    global save_path = pwd()*"/results/"
    global N=10
    println("No Filepath and no Index found. Falling back to standart values:\n\tindex = $index\n\tSave Path = $save_path\n\trequest_type=$request_type")
end
end
end
end


# Set the Filepaths
paths = Dict(:data => "data/",
            :model => "model/",
            :map => "example_map/map/",
            :dispatcher => "example_map/delays_wt1reldelta1/")


for (name, path) in paths
    paths[name] = save_path * path
end

#TODO Gucke ob die Ordner existieren
if !isdir(paths[:data])
    print("Please create data folder at $(paths[:data])")
end
if !isdir(paths[:model])
    print("Please create model folder at $(paths[:model])")
end

map_folder = paths[:map]
requested = 2000 * N
served = 2000 * N

include(paths[:map]*"map.jl") #
include(paths[:dispatcher]*"dispatcher.jl")



x, y = getValue(index-1, 4, 60, 40, 0.1, 1.5, 40)

println("$index\t$x\t$y")
max_detour = 1.0
max_wait = t0
random_gens = Dict(request_type => [:notRandom, y*t0])
specs=(;
        map=mymap,
        route_matrix=RM,
        subspaces=:all_edges,
        routing=:lookup,
        speed_dict = speed_dict,
        seed = 1,
        request_type = request_type,
        random_gens = random_gens,
        t_max_wait = t0 )

specs = merge(specs, dispatcher)

@time data = simulate_rp(paths,N, x, y, t0, specs, request_type, served=served, requested=requested)