2022-04-28 17:29:24 +02:00
#!/usr/bin/env julia
# -*- coding: UTF-8 -*-
# __julia-version__ = 1.7.2
# __author__ = "Max Kannenberg"
# __copyright__ = "2020-2022"
# __license__ = "ISC"
2022-05-31 17:23:56 +02:00
using DataFrames
2022-05-12 16:32:15 +02:00
function createOutput ( train :: Train , settings :: Settings , path :: Path , movingSection :: Dict , drivingCourse :: Vector { Dict } )
2022-04-28 17:29:24 +02:00
if settings . outputDetail == :running_time
2022-05-31 17:23:56 +02:00
output = drivingCourse [ end ] [ :t ]
2022-04-28 17:29:24 +02:00
elseif settings . outputDetail == :points_of_interest
# add points of interest
2022-05-04 16:34:17 +02:00
if ! isempty ( path . poi )
2022-05-31 17:23:56 +02:00
# output = Dict[]
# POI = 1
# i = 1
# while POI <= length(path.poi) && i <= drivingCourse[end][:i]
# if path.poi[POI][:station] == drivingCourse[i][:s]
# push!(output, drivingCourse[i])
# POI = POI+1
# end
# i = i+1
# end
# get only the driving course's data points with POI labels
2022-05-04 16:34:17 +02:00
output = Dict [ ]
2022-05-31 17:23:56 +02:00
for point in 1 : length ( drivingCourse )
if point [ :label ] != " "
push! ( output , point )
2022-04-28 17:29:24 +02:00
end
end
end
elseif settings . outputDetail == :driving_course
output = drivingCourse
elseif settings . outputDetail == :everything
output = Dict { Symbol , Any } ( )
merge! ( output , Dict ( :train => train , :path => path , :settings => settings ) )
# add moving section and driving courses
2022-05-31 17:23:56 +02:00
merge! ( output , Dict ( :movingSection => movingSection ,
:drivingCourse => drivingCourse ) )
2022-04-28 17:29:24 +02:00
# add points of interest
2022-05-04 16:34:17 +02:00
if ! isempty ( path . poi )
2022-05-31 17:23:56 +02:00
pointsOfInterest = Dict [ ]
# get only the driving course's data points with POI labels
output = Dict [ ]
for point in 1 : length ( drivingCourse )
if point [ :label ] != " "
push! ( pointsOfInterest , point )
2022-04-28 17:29:24 +02:00
end
end
2022-05-31 17:23:56 +02:00
merge! ( output , Dict ( :pointsOfInterest => pointsOfInterest ) )
end
if settings . outputFormat == :dataframe
return createDataFrameForDataPoints ( output [ :drivingCourse ] )
else
return output
2022-04-28 17:29:24 +02:00
end
2022-05-31 17:23:56 +02:00
end
if settings . outputFormat == :dataframe
return createDataFrame ( output )
2022-04-28 17:29:24 +02:00
else
2022-05-31 17:23:56 +02:00
return output
2022-04-28 17:29:24 +02:00
end
end
2022-05-31 17:23:56 +02:00
function createDataFrame ( runningTime :: AbstractFloat )
# create DataFrame with running time information
dataFrame = DataFrame ( column1 = [ " t (in s) " , runningTime ] )
end
2022-04-28 17:29:24 +02:00
2022-05-31 17:23:56 +02:00
function createDataFrame ( dataPoints :: Vector { Dict } )
header = [ " i " , " behavior " , " station label " , " Δs (in m) " , " s (in m) " , " Δt (in s) " , " t (in s) " , " Δv (in m/s) " , " v (in m/s) " , " F_T (in N) " , " F_R (in N) " , " R_path (in N) " , " R_train (in N) " , " R_traction (in N) " , " R_wagons (in N) " , " a (in m/s^2) " ]
columnSymbols = [ :i , :behavior , :label , :Δs , :s , :Δt , :t , :Δv , :v , :F_T , :F_R , :R_path , :R_train , :R_traction , :R_wagons , :a ]
2022-04-28 17:29:24 +02:00
2022-05-31 17:23:56 +02:00
allColumns = Array { Any , 1 } [ ]
for column in 1 : length ( header )
currentColumn = Any [ ]
push! ( currentColumn , header [ column ] )
for point in dataPoints
push! ( currentColumn , point [ columnSymbols [ column ] ] )
2022-04-28 17:29:24 +02:00
end
2022-05-31 17:23:56 +02:00
push! ( allColumns , currentColumn )
end # for
2022-04-28 17:29:24 +02:00
2022-05-31 17:23:56 +02:00
# combine the columns in a data frame
dataFrame = DataFrame ( c1 = allColumns [ 1 ] , c2 = allColumns [ 2 ] , c3 = allColumns [ 3 ] , c4 = allColumns [ 4 ] , c5 = allColumns [ 5 ] , c6 = allColumns [ 6 ] , c7 = allColumns [ 7 ] , c8 = allColumns [ 8 ] , c9 = allColumns [ 9 ] , c10 = allColumns [ 10 ] , c11 = allColumns [ 11 ] , c12 = allColumns [ 12 ] , c13 = allColumns [ 13 ] , c14 = allColumns [ 14 ] , c15 = allColumns [ 15 ] , c16 = allColumns [ 16 ] )
2022-04-28 17:29:24 +02:00
2022-05-31 17:23:56 +02:00
return dataFrame
end #createDataFrameForDrivingCourse