removed CSV export

development
Martin Scheidt 2022-05-12 16:50:27 +02:00
parent a5868af2c5
commit 840d1d0e46
10 changed files with 10 additions and 238 deletions

View File

@ -32,11 +32,13 @@ Categories: Added, Changed, Deprecated, Removed, Fixed, and Security.
* updated test files to railtoolkit/schema (2022.05)
### Removed
* dependency Plots
* dependency Plots and CSV
* AdditionalOutput.jl
* EnergySaving.jl
* test/testEnums.jl
* import.jl
* export.jl
* settings for CSV export
## Version [0.8] 2022-01-20

View File

@ -4,7 +4,6 @@ authors = ["Max Kannenberg", "Martin Scheidt", "contributors"]
version = "0.8.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
@ -13,7 +12,6 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
[compat]
CSV = "^0"
DataFrames = "^1"
JSONSchema = "^1"
YAML = "^0"

View File

@ -24,7 +24,6 @@ The required julia packages are
- YAML.jl
- JSONSchema.jl
- DataFrames.jl
- CSV.jl
------------

View File

@ -7,5 +7,4 @@ settings:
stepSize: 20 # step size, unit depends on stepVariable - distance in meter, time in seconds and velocity in meter/second.
approxLevel: 3 # value for approximation; used when rounding or interating
outputDetail: "running_time" # single value "running_time", array of "points_of_interest",complete array "driving_course", or dict() "everything"
outputFormat: "julia_dict" # output as "julia_dict" or as "csv"
outputDir: "." # used if other outputFormat than "julia dict"
outputFormat: "dataframe" # output as "dataframe" or as "dict"

View File

@ -11,11 +11,11 @@ module TrainRuns
## loading standard library packages
using UUIDs, Dates, Statistics
## loading external packages
using YAML, JSONSchema, CSV, DataFrames
using YAML, JSONSchema, DataFrames
export
## Interface
trainrun, Train, Path, Settings, exportToCsv
trainrun, Train, Path, Settings
## global variables
global g = 9.80665 # acceleration due to gravity (in m/s^2)
@ -30,7 +30,6 @@ include("calc.jl")
include("characteristics.jl")
include("behavior.jl")
include("output.jl")
include("export.jl")
## main function
"""

View File

@ -26,8 +26,7 @@ function Settings(file="DEFAULT")
stepSize = 20
approxLevel = 3
outputDetail = :running_time
outputFormat = :julia_dict
outputDir = "."
outputFormat = :dataframe
## load from file
if file != "DEFAULT"
@ -58,11 +57,7 @@ function Settings(file="DEFAULT")
"outputFormat": {
"description": "Output format",
"type": "string",
"enum": [ "julia_dict", "csv" ]
},
"outputDir": {
"description": "Path for the CSV export",
"type": "string"
"enum": [ "dataframe", "dict" ]
}
}
}""")
@ -84,10 +79,9 @@ function Settings(file="DEFAULT")
haskey(settings, "approxLevel") ? approxLevel = settings["approxLevel"] : nothing
haskey(settings, "outputDetail") ? outputDetail = Symbol(settings["outputDetail"]) : nothing
haskey(settings, "outputFormat") ? outputFormat = Symbol(settings["outputFormat"]) : nothing
haskey(settings, "outputDir") ? outputDir = settings["outputDir"] : nothing
end
Settings(massModel, stepVariable, stepSize, approxLevel, outputDetail, outputFormat, outputDir)
Settings(massModel, stepVariable, stepSize, approxLevel, outputDetail, outputFormat)
end #function Settings() # outer constructor

View File

@ -1,212 +0,0 @@
#!/usr/bin/env julia
# -*- coding: UTF-8 -*-
# __julia-version__ = 1.7.2
# __author__ = "Max Kannenberg"
# __copyright__ = "2020-2022"
# __license__ = "ISC"
function exportToCsv(runningTime::AbstractFloat, settings::Settings)
createCsvFile(runningTime, settings)
return true
end
function exportToCsv(dataPointsToExport::Vector{Dict}, settings::Settings)
createCsvFile(dataPointsToExport, settings)
return true
end
function exportToCsv(output::Dict)
if output[:settings][:outputFormat] == "CSV"
pathName = output[:path][:name]
trainName = output[:train][:name]
if output[:settings][:operationModeMinimumRunningTime] == true
operationMode = "minimum running time"
if output[:settings][:outputDetail] == "points of interest"
dataPointsToExport = output[:pointsOfInterestMinimumRunningTime]
else
dataPointsToExport = output[:drivingCourseMinimumRunningTime]
end
createCsvFile(dataPointsToExport, operationMode, pathName, trainName, output[:settings])
end
if output[:settings][:operationModeMinimumEnergyConsumption] == true
operationMode = "minimum energy consumption"
if output[:settings][:outputDetail] == "points of interest"
dataPointsToExport = output[:pointsOfInterestMinimumEnergyConsumption]
else
dataPointsToExport = output[:drivingCourseMinimumEnergyConsumption]
end
createCsvFile(dataPointsToExport, operationMode, pathName, trainName, output[:settings])
end
return true
end
return false
end #function exportToCsv
function createCsvFile(runningTime::AbstractFloat, settings::Settings)
# create DataFrame with running time information
df = DataFrame(column1=["t (in s)", runningTime])
# save DataFrame as a CSV-file at outputDir
date = Dates.now()
dateString = Dates.format(date, "yyyy-mm-dd_HH.MM.SS")
csvFilePath = settings[:outputDir]*"/"*dateString*"_RunningTime.csv"
CSV.write(csvFilePath, df, header=false)
println("The output CSV file has been created at ",csvFilePath)
return true
end #function createCsvFile
function createCsvFile(dataPointsToExport::Vector{Dict}, settings::Settings)
outputDetail = settings[:outputDetail]
header = ["i", "behavior", "Δ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)", "ΔW (in Ws)","W (in Ws)","ΔE (in Ws)","E (in Ws)","a (in m/s^2)"]
columnSymbols = [:i, :behavior, :Δs, :s, :Δt, :t, :Δv, :v, :F_T, :F_R, :R_path, :R_train, :R_traction, :R_wagons, :ΔW, :W, :ΔE, :E, :a]
allColumns = Array{Any,1}[]
for column in 1:length(header)
currentColumn = Any[]
push!(currentColumn, header[column])
for point in dataPointsToExport
push!(currentColumn, point[columnSymbols[column]])
end
push!(allColumns, currentColumn)
end # for
# combine the columns in a data frame and saving it as a CSV-file at outputDir
if outputDetail == "driving course" || outputDetail == "points of interest"
df = 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], c17=allColumns[17], c18=allColumns[18], c19=allColumns[19])
else
println("")
end
date = Dates.now()
dateString=Dates.format(date, "yyyy-mm-dd_HH.MM.SS")
csvFilePath=settings[:outputDir]*"/"*dateString*"_DataPoints.csv"
CSV.write(csvFilePath, df, header=false)
println("The output CSV file has been created at ",csvFilePath)
return true
end #function createCsvFile
function createCsvFile(dataPointsToExport::Vector{Dict}, operationMode::String, pathName::String, trainName::String, settings::Settings)
outputDetail = settings[:outputDetail]
massModel = settings.massModel
stepVariable = settings.stepVariable
stepSize = string(settings.stepSize)
# create accumulated data block
accumulatedData = Array{Any, 1}[]
push!(accumulatedData, ["i", "behavior", "Δ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)", "ΔW (in Ws)","W (in Ws)","ΔE (in Ws)","E (in Ws)","a (in m/s^2)"]) # push header to accumulatedData
for point in dataPointsToExport
row = [point[:i], point[:behavior], point[:Δs], point[:s], point[:Δt], point[:t], point[:Δv], point[:v], point[:F_T], point[:F_R], point[:R_path], point[:R_train], point[:R_traction], point[:R_wagons], point[:ΔW], point[:W], point[:ΔE], point[:E], point[:a]]
push!(accumulatedData, row) # push row to accumulatedData
end
#create information block
allColumns=Array{Any,1}[]
push!(allColumns, ["path name", "train name", "operation mode", "mass model", "step variable", "step size", ""])
push!(allColumns, [pathName, trainName, operationMode, massModel, stepVariable, stepSize, ""])
for column in 3:length(accumulatedData[1])
push!(allColumns, ["", "", "", "", "", "", ""])
end # for
# add driving data to the array
header = accumulatedData[1]
for column in 1:length(accumulatedData[1])
push!(allColumns[column], header[column])
for row in accumulatedData[2:end]
push!(allColumns[column], row[column])
end
end # for
# combine the columns in a data frame and saving it as a CSV-file at outputDir
df = 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], c17=allColumns[17], c18=allColumns[18], c19=allColumns[19])
date = Dates.now()
dateString=Dates.format(date, "yyyy-mm-dd_HH.MM.SS")
if operationMode == "minimum running time"
csvFilePath=settings[:outputDir]*"/"*dateString*"_MinimumRunningTime.csv"
elseif operationMode == "minimum energy consumption"
csvFilePath=settings[:outputDir]*"/"*dateString*"_MinimumEnergyConsumption.csv"
else
# should not be possible
end
CSV.write(csvFilePath, df, header=false)
println("The output CSV file has been created for ",operationMode," at ",csvFilePath)
return true
end #function createCsvFile
#=
function createCsvFile(movingSection::Dict, dataPointsToExport::Vector{Dict}, operationMode::String, pathName::String, trainName::String, settings::Settings)
outputDetail = settings[:outputDetail]
massModel = settings.massModel
stepVariable = settings.stepVariable
stepSize = string(settings.stepSize)
# create accumulated data block
accumulatedData = Array{Any, 1}[]
if outputDetail == "minimal"
push!(accumulatedData, ["s (in m)", "t (in s)","E (in Ws)"]) # push header to accumulatedData
row = [movingSection[:length], movingSection[:t], movingSection[:E]]
push!(accumulatedData, row) # push row to accumulatedData
elseif outputDetail == "driving course" || outputDetail == "points of interest"
push!(accumulatedData, ["i", "behavior", "Δ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)", "ΔW (in Ws)","W (in Ws)","ΔE (in Ws)","E (in Ws)","a (in m/s^2)"]) # push header to accumulatedData
for point in dataPointsToExport
row = [point[:i], point[:behavior], point[:Δs], point[:s], point[:Δt], point[:t], point[:Δv], point[:v], point[:F_T], point[:F_R], point[:R_path], point[:R_train], point[:R_traction], point[:R_wagons], point[:ΔW], point[:W], point[:ΔE], point[:E], point[:a]]
push!(accumulatedData, row) # push row to accumulatedData
end
end
#create information block
allColumns=Array{Any,1}[]
push!(allColumns, ["path name", "train name", "operation mode", "mass model", "step variable", "step size", ""])
push!(allColumns, [pathName, trainName, operationMode, massModel, stepVariable, stepSize, ""])
for column in 3:length(accumulatedData[1])
push!(allColumns, ["", "", "", "", "", "", ""])
end # for
# add driving data to the array
header = accumulatedData[1]
for column in 1:length(accumulatedData[1])
push!(allColumns[column], header[column])
for row in accumulatedData[2:end]
push!(allColumns[column], row[column])
end
end # for
# combine the columns in a data frame and saving it as a CSV-file at outputDir
if outputDetail == "minimal"
df = DataFrame(c1=allColumns[1], c2=allColumns[2],c3=allColumns[3])
elseif outputDetail=="driving course" || outputDetail == "points of interest"
df = 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], c17=allColumns[17], c18=allColumns[18], c19=allColumns[19])
end
date = Dates.now()
dateString=Dates.format(date, "yyyy-mm-dd_HH.MM.SS")
if operationMode == "minimum running time"
csvFilePath=settings[:outputDir]*"/"*dateString*"_MinimumRunningTime.csv"
elseif operationMode == "minimum energy consumption"
csvFilePath=settings[:outputDir]*"/"*dateString*"_MinimumEnergyConsumption.csv"
else
# should not be possible
end
CSV.write(csvFilePath, df, header=false)
println("The output CSV file has been created for ",operationMode," at ",csvFilePath)
return true
end #function createCsvFile
=#

View File

@ -13,8 +13,7 @@ struct Settings
approxLevel::Int # value for approximation; used when rounding or interating.
outputDetail::Symbol # single Float() ":running_time", Array() of ":points_of_interest",
# complete Array() ":driving_course", or Dict() ":everything".
outputFormat::Symbol # output as ":julia_dict" or as ":csv".
outputDir::String # if outputFormat is not ":julia_dict".
outputFormat::Symbol # output as ":dataframe" or as ":dict".
end #struct Settings

View File

@ -1,5 +0,0 @@
%YAML 1.2
---
settings:
outputFormat: "csv" # output as "julia_dict" or as "csv"
outputDir: "." # used if other outputFormat than "julia dict"

View File

@ -33,7 +33,6 @@ settings = Dict()
push!(settings, "time" => @time Settings("test/data/settings/time.yaml"))
push!(settings, "timestrip" => @time Settings("test/data/settings/time_strip.yaml"))
push!(settings, "velocity" => @time Settings("test/data/settings/velocity.yaml"))
push!(settings, "csvexport" => @time Settings("test/data/settings/csv_export.yaml"))
@test typeof(first(paths)[2]) == Path
@test typeof(first(settings)[2]) == Settings