2022-04-28 17:29:24 +02:00
|
|
|
|
#!/usr/bin/env julia
|
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
# __author__ = "Max Kannenberg"
|
|
|
|
|
# __copyright__ = "2020-2022"
|
|
|
|
|
# __license__ = "ISC"
|
|
|
|
|
|
2022-09-09 18:50:22 +02:00
|
|
|
|
"""
|
|
|
|
|
createOutput(settings, drivingCourse, pointsOfInterest)
|
|
|
|
|
|
|
|
|
|
Create output information depending on `settings`, `drivingCourse` and `pointsOfInterest`.
|
|
|
|
|
|
|
|
|
|
See also [`createOutput`](@ref).
|
|
|
|
|
|
|
|
|
|
# Arguments
|
|
|
|
|
- `settings::Settings`: the Settings object containing settings for output format and detail.
|
|
|
|
|
- `drivingCourse::Vector{Dict}`: the Vector containing dictionaries for all support points.
|
|
|
|
|
- `pointsOfInterest::Vector{NamedTuple}`: the Vector containing tuples for the paths' points of interest.
|
|
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
```julia-repl
|
|
|
|
|
julia> createOutput(settings_poi, drivingCourse_longdistance, pointsOfInterest_pathWithSlope)
|
|
|
|
|
5×11 DataFrame
|
|
|
|
|
Row │ label driving_mode s v t a F_T F_R R_path R_traction R_wagons
|
|
|
|
|
│ String String Real Real Real Real Real Real Real Real Real
|
|
|
|
|
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
1 │ view_point_1 accelerating 850.0 28.707 54.049 0.331 1.93049e5 36602.1 0.0 9088.56 27513.6
|
|
|
|
|
2 │ distant_signal_1 accelerating 1000.0 30.325 59.129 0.294 1.82746e5 43604.7 4344.35 9795.13 29465.2
|
|
|
|
|
3 │ main_signal_1 accelerating 2000.0 37.356 88.468 0.185 1.48352e5 60899.4 8688.69 13259.1 38951.5
|
|
|
|
|
4 │ main_signal_3 braking 9000.0 27.386 258.578 -0.375 0.0 34522.1 0.0 8537.05 25985.0
|
|
|
|
|
5 │ clearing_point_1 braking 9203.37 24.443 266.426 -0.375 0.0 30176.2 0.0 7389.44 22786.8
|
|
|
|
|
```
|
|
|
|
|
"""
|
2022-08-19 19:51:02 +02:00
|
|
|
|
function createOutput(settings::Settings, drivingCourse::Vector{Dict}, pointsOfInterest::Vector{NamedTuple})
|
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-08-08 16:10:38 +02:00
|
|
|
|
elseif settings.outputDetail == :points_of_interest
|
2022-06-22 11:11:44 +02:00
|
|
|
|
# get only the driving course's support points with POI labels
|
2022-08-08 16:10:38 +02:00
|
|
|
|
# if there is no point with POI label return the information of departure and arrival (first and last points)
|
2022-06-02 12:32:00 +02:00
|
|
|
|
output = Dict[]
|
2022-08-08 16:10:38 +02:00
|
|
|
|
if isempty(pointsOfInterest)
|
|
|
|
|
push!(output, drivingCourse[1])
|
|
|
|
|
push!(output, drivingCourse[end])
|
|
|
|
|
else
|
|
|
|
|
supportPoint = 1
|
|
|
|
|
for POI in 1:length(pointsOfInterest)
|
|
|
|
|
while supportPoint <= length(drivingCourse)
|
2022-08-22 19:07:49 +02:00
|
|
|
|
if pointsOfInterest[POI][:s] == drivingCourse[supportPoint][:s]
|
2022-08-08 16:10:38 +02:00
|
|
|
|
push!(output, drivingCourse[supportPoint])
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
supportPoint += 1
|
2022-06-03 18:11:28 +02:00
|
|
|
|
end
|
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-08-08 16:10:38 +02:00
|
|
|
|
elseif settings.outputDetail == :driving_course
|
2022-06-03 18:11:28 +02:00
|
|
|
|
output = drivingCourse
|
2022-05-31 17:23:56 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if settings.outputFormat == :dataframe
|
2022-08-08 16:12:08 +02:00
|
|
|
|
return createDataFrame(output, settings.outputDetail, settings.approxLevel)
|
2022-06-02 12:32:00 +02:00
|
|
|
|
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-09-09 18:50:22 +02:00
|
|
|
|
"""
|
|
|
|
|
createDataFrame(output_vector, outputDetail, approxLevel)
|
|
|
|
|
|
|
|
|
|
Create a DataFrame from `output_vector` with `outputDetail` and `approxLevel`.
|
|
|
|
|
|
|
|
|
|
See also [`createOutput`](@ref).
|
|
|
|
|
|
|
|
|
|
# Arguments
|
|
|
|
|
|
|
|
|
|
- `output_vector::Vector{Dict}`: the Vector containing all data to be outputted.
|
|
|
|
|
- `outputDetail::Symbol`: the detail level the DataFrame is created for.
|
|
|
|
|
- `approxLevel::Int`: the number of digits for rounding each Number in the DataFrame.
|
|
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
```julia-repl
|
|
|
|
|
julia> createDataFrame(vector_pointsOfInterest, detail_data_points, approxLevel_default)
|
|
|
|
|
5×11 DataFrame
|
|
|
|
|
Row │ label driving_mode s v t a F_T F_R R_path R_traction R_wagons
|
|
|
|
|
│ String String Real Real Real Real Real Real Real Real Real
|
|
|
|
|
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
1 │ view_point_1 accelerating 850.0 28.707 54.049 0.331 1.93049e5 36602.1 0.0 9088.56 27513.6
|
|
|
|
|
2 │ distant_signal_1 accelerating 1000.0 30.325 59.129 0.294 1.82746e5 43604.7 4344.35 9795.13 29465.2
|
|
|
|
|
3 │ main_signal_1 accelerating 2000.0 37.356 88.468 0.185 1.48352e5 60899.4 8688.69 13259.1 38951.5
|
|
|
|
|
4 │ main_signal_3 braking 9000.0 27.386 258.578 -0.375 0.0 34522.1 0.0 8537.05 25985.0
|
|
|
|
|
5 │ clearing_point_1 braking 9203.37 24.443 266.426 -0.375 0.0 30176.2 0.0 7389.44 22786.8
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
function createDataFrame(output_vector::Vector{Dict}, outputDetail::Symbol, approxLevel::Int)
|
2022-06-02 12:32:00 +02:00
|
|
|
|
if outputDetail == :running_time
|
2022-06-03 12:26:58 +02:00
|
|
|
|
# create a DataFrame with running time information
|
2022-08-08 16:12:08 +02:00
|
|
|
|
dataFrame = DataFrame(t=[round(output_vector[end][:t], digits=approxLevel)])
|
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
|
2022-08-08 16:12:08 +02:00
|
|
|
|
currentRealColumn = round.(currentRealColumn, digits=approxLevel)
|
2022-06-03 12:26:58 +02:00
|
|
|
|
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
|