2022-04-28 17:29:24 +02:00
|
|
|
#!/usr/bin/env julia
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
# __author__ = "Max Kannenberg"
|
|
|
|
# __copyright__ = "2020-2022"
|
|
|
|
# __license__ = "ISC"
|
|
|
|
|
2022-06-03 18:11:28 +02:00
|
|
|
function createOutput(settings::Settings, drivingCourse::Vector{Dict}, pointsOfInterest::Vector{Tuple})
|
2022-04-28 17:29:24 +02:00
|
|
|
if settings.outputDetail == :running_time
|
2022-06-02 12:32:00 +02:00
|
|
|
output::Vector{Dict} = [Dict(:t => drivingCourse[end][:t])]
|
2022-04-28 17:29:24 +02:00
|
|
|
|
2022-06-03 18:11:28 +02:00
|
|
|
elseif settings.outputDetail == :points_of_interest && !isempty(pointsOfInterest)
|
2022-06-22 11:11:44 +02:00
|
|
|
# get only the driving course's support points with POI labels
|
2022-06-02 12:32:00 +02:00
|
|
|
output = Dict[]
|
2022-06-22 11:11:44 +02:00
|
|
|
supportPoint = 1
|
2022-06-03 18:11:28 +02:00
|
|
|
for POI in 1:length(pointsOfInterest)
|
2022-06-22 11:11:44 +02:00
|
|
|
while supportPoint <= length(drivingCourse)
|
|
|
|
if pointsOfInterest[POI][1] == drivingCourse[supportPoint][:s]
|
|
|
|
push!(output, drivingCourse[supportPoint])
|
2022-06-03 18:11:28 +02:00
|
|
|
break
|
|
|
|
end
|
2022-06-22 11:11:44 +02:00
|
|
|
supportPoint += 1
|
2022-04-28 17:29:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-22 13:04:54 +02:00
|
|
|
elseif settings.outputDetail == :data_points
|
|
|
|
# get the driving course's support points where a new behavior section starts and the driving mode changes
|
|
|
|
output = Dict[]
|
|
|
|
# the first support point is the first data point
|
|
|
|
push!(output, drivingCourse[1])
|
|
|
|
|
|
|
|
for supportPoint in 2:length(drivingCourse)
|
|
|
|
if drivingCourse[supportPoint-1][:behavior] != drivingCourse[supportPoint][:behavior]
|
|
|
|
push!(output, drivingCourse[supportPoint])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-02 12:32:00 +02:00
|
|
|
else #if settings.outputDetail == :driving_course || (settings.outputDetail == :points_of_interest && !isempty(path.poi))
|
2022-06-03 18:11:28 +02:00
|
|
|
output = drivingCourse
|
2022-05-31 17:23:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if settings.outputFormat == :dataframe
|
2022-06-02 12:32:00 +02:00
|
|
|
return createDataFrame(output, settings.outputDetail)
|
|
|
|
elseif settings.outputFormat == :vector
|
2022-05-31 17:23:56 +02:00
|
|
|
return output
|
2022-04-28 17:29:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-06-02 12:32:00 +02:00
|
|
|
function createDataFrame(output_vector::Vector{Dict}, outputDetail)
|
|
|
|
if outputDetail == :running_time
|
2022-06-03 12:26:58 +02:00
|
|
|
# create a DataFrame with running time information
|
|
|
|
dataFrame = DataFrame(t=[output_vector[end][:t]])
|
2022-06-22 13:04:54 +02:00
|
|
|
else # :points_of_interest, :data_points or :driving_course
|
2022-06-02 12:32:00 +02:00
|
|
|
columnSymbols = [:label, :behavior, :s, :v, :t, :a, :F_T, :F_R, :R_path, :R_traction, :R_wagons]
|
|
|
|
|
2022-06-03 12:26:58 +02:00
|
|
|
allColumns = []
|
|
|
|
for column in 1:length(columnSymbols)
|
|
|
|
if typeof(output_vector[1][columnSymbols[column]]) == String
|
|
|
|
currentStringColumn::Vector{String} = []
|
|
|
|
for point in output_vector
|
|
|
|
push!(currentStringColumn, point[columnSymbols[column]])
|
|
|
|
end
|
|
|
|
push!(allColumns, currentStringColumn)
|
|
|
|
elseif typeof(output_vector[1][columnSymbols[column]]) <: Real
|
|
|
|
currentRealColumn::Vector{Real} = []
|
|
|
|
for point in output_vector
|
|
|
|
push!(currentRealColumn, point[columnSymbols[column]])
|
|
|
|
end
|
|
|
|
push!(allColumns, currentRealColumn)
|
2022-06-02 12:32:00 +02:00
|
|
|
end
|
|
|
|
end # for
|
2022-04-28 17:29:24 +02:00
|
|
|
|
2022-06-02 12:32:00 +02:00
|
|
|
# combine the columns in a data frame
|
2022-06-03 12:26:58 +02:00
|
|
|
dataFrame = DataFrame(label=allColumns[1], driving_mode=allColumns[2], s=allColumns[3], v=allColumns[4], t=allColumns[5], a=allColumns[6], F_T=allColumns[7], F_R=allColumns[8], R_path=allColumns[9], R_traction=allColumns[10], R_wagons=allColumns[11])
|
2022-06-02 12:32:00 +02:00
|
|
|
end
|
2022-04-28 17:29:24 +02:00
|
|
|
|
2022-05-31 17:23:56 +02:00
|
|
|
return dataFrame
|
2022-06-22 11:11:44 +02:00
|
|
|
end #createDataFrame
|