Skip to content

Commit

Permalink
Merge pull request #4 from ModiaSim/dev
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
MartinOtter authored Jul 7, 2022
2 parents d4f7c6b + d77722a commit 791cc98
Show file tree
Hide file tree
Showing 16 changed files with 2,124 additions and 31 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run tests

env:
JULIA_NUM_THREADS: 4
on:
pull_request:
branches:
- main
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.7.3'
os:
- ubuntu-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SignalTables"
uuid = "3201582d-3078-4276-ba5d-0a1254d79d7c"
authors = ["[email protected] <[email protected]>"]
version = "0.3.4"
version = "0.3.5"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ are different to the Python 2.x version.

## Release Notes

### Version 0.3.5

- @usingPlotPackage(): If SilentNoPlot selected, use "using SignalTables.SilentNoPlot" instead of "import SignalTables.SilentNoPlot: plot ..:".
- writeSignalTable(..): Arrays get an additional key `layout = "column-major"` to clearly define that storage is in column-major order.
Furthermore, if a signal has an *alias* key, then the *values* or *value* array is not stored on file.

**Bug fixes**

- writeSignalTable(..): If arrays or numbers have Unitful units, these units are stripped off and provided via key `unit` as a string.

### Version 0.3.4

- Bug fix in usePreviousPlotPackage()
Expand Down
15 changes: 15 additions & 0 deletions examples/fileIO/CSV_ReadFromFile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module CSV_ReadFromFile

using SignalTables
import CSV

file = joinpath(SignalTables.path, "examples", "fileIO", "Rotational_First.csv")
println("\n... Read csv file \"$file\"")
sigTable = CSV.File(file)

println("\n... Show csv file as signal table")
showInfo(sigTable)

println("\ntime[1:10] = ", getSignal(sigTable, "time")[:values][1:10])

end
13 changes: 3 additions & 10 deletions examples/fileIO/JSON_WriteToFile.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
module JSON_WriteToFile

using SignalTables
import JSON
using SignalTables

sigTable = getSignalTableExample("VariousTypes")

open("VariousTypes_prettyPrint.json", "w") do io
JSON.print(io, sigTable, 2)
end

open("VariousTypes_compact.json", "w") do io
JSON.print(io, sigTable)
end
writeSignalTable("VariousTypes_prettyPrint.json", sigTable; indent=2, log=true)
writeSignalTable("VariousTypes_compact.json" , sigTable)

end
9 changes: 3 additions & 6 deletions examples/fileIO/JSON_WriteToString.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module JSON_WriteToString

using SignalTables
import JSON
using SignalTables

sigTable = getSignalTableExample("VariousTypes")
str = JSON.json(sigTable)

println("VariousType string = \n", str)
str = signalTableToJSON( getSignalTableExample("VariousTypes") )
println(str)

end
2,003 changes: 2,003 additions & 0 deletions examples/fileIO/Rotational_First.csv

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/fileIO/_include_all.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

include("JSON_WriteToFile.jl")
include("JSON_WriteToString.jl")

2 changes: 1 addition & 1 deletion src/ExampleSignalTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ elseif signalTableName == "VariousTypes"
"time" => Var(values= t, unit="s", independent=true),
"load.r" => Var(values= [sin.(t) cos.(t) sin.(t)], unit="m"),
"motor.angle" => Var(values= sin.(t), unit="rad", state=true, der="motor.w"),
"motor.w" => Var(values= cos.(t), unit="rad/s"),
"motor.w" => Var(values= cos.(t), unit="rad/s", state=true, start=1.0u"rad/s"),
"motor.w_ref" => Var(values= 0.9*[sin.(t) cos.(t)], unit = ["rad", "1/s"],
info="Reference angle and speed"),
"wm" => Var(alias = "motor.w"),
Expand Down
2 changes: 2 additions & 0 deletions src/NoPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module NoPlot

export plot, showFigure, saveFigure, closeFigure, closeAllFigures

include("AbstractPlotInterface.jl")

plot(signalTable, names::AbstractMatrix; heading::AbstractString="", grid::Bool=true, xAxis="time",
Expand Down
6 changes: 3 additions & 3 deletions src/PlotPackageDefinition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro usingPlotPackage()
elseif PlotPackage == "NoPlot"
@goto USE_NO_PLOT
elseif PlotPackage == "SilentNoPlot"
expr = :( import SignalTables.SilentNoPlot: plot, showFigure, saveFigure, closeFigure, closeAllFigures )
expr = :( using SignalTables.SilentNoPlot )
return esc( expr )
else
PlotPackage = Symbol("SignalTablesInterface_" * PlotPackage)
Expand All @@ -36,7 +36,7 @@ macro usingPlotPackage()
elseif PlotPackage == "NoPlot"
@goto USE_NO_PLOT
elseif PlotPackage == "SilentNoPlot"
expr = :( import SignalTables.SilentNoPlot: plot, showFigure, saveFigure, closeFigure, closeAllFigures )
expr = :( using SignalTables.SilentNoPlot )
return esc( expr )
else
PlotPackage = Symbol("SignalTablesInterface_" * PlotPackage)
Expand All @@ -51,7 +51,7 @@ macro usingPlotPackage()
end

@label USE_NO_PLOT
expr = :( using SignalTables.SilentNoPlot: plot, showFigure, saveFigure, closeFigure, closeAllFigures )
expr = :( using SignalTables.SilentNoPlot )
println("$expr")
return esc( expr )
end
Expand Down
42 changes: 34 additions & 8 deletions src/SignalTableFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ function encodeSignalTable(signalTable; signalNames=nothing)
end
for name in signalNames
signal = getSignal(signalTable, name)
if haskey(signal, :alias)
signal = copy(signal)
delete!(signal, :values)
delete!(signal, :value)
end
encodedSignal = encodeSignalTableElement(name, signal)
if !isnothing(encodedSignal)
jdict[name] = encodedSignal
Expand Down Expand Up @@ -726,22 +731,43 @@ function encodeSignalTableElement(path, element)
end

elseif typeof(element) <: AbstractArray && (elementBaseType(eltype(element)) <: Number || elementBaseType(eltype(element)) <: String)
if ndims(element) == 1 && string(elementBaseType(eltype(element))) in TypesWithoutEncoding
if ndims(element) == 1 && string(eltype(element)) in TypesWithoutEncoding
return element
end
jdict = OrderedDict{String,Any}("_class" => "Array",
"eltype" => string(eltype(element)),
"size" => Int[i for i in size(element)],
"values" => reshape(element, length(element)))
elunit = unitAsParseableString(element)
if elunit == ""
jdict = OrderedDict{String,Any}("_class" => "Array",
"eltype" => string(eltype(element)),
"size" => Int[i for i in size(element)],
"layout" => "column-major",
"values" => reshape(element, length(element)))
else
element = ustrip.(element)
jdict = OrderedDict{String,Any}("_class" => "Array",
"unit" => elunit,
"eltype" => string(eltype(element)),
"size" => Int[i for i in size(element)],
"layout" => "column-major",
"values" => reshape(element, length(element)))
end
return jdict

elseif string(typeof(element)) in TypesWithoutEncoding
return element

elseif typeof(element) <: Number
jdict = OrderedDict{String,Any}("_class" => "Number",
"type" => typeof(element),
"value" => element)
elunit = unitAsParseableString(element)
if elunit == ""
jdict = OrderedDict{String,Any}("_class" => "Number",
"type" => typeof(element),
"value" => element)
else
element = ustrip.(element)
jdict = OrderedDict{String,Any}("_class" => "Number",
"unit" => elunit,
"type" => typeof(element),
"value" => element)
end
return jdict

else
Expand Down
4 changes: 2 additions & 2 deletions src/SignalTables.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module SignalTables

const path = dirname(dirname(@__FILE__))
const version = "0.3.2"
const version_SignalTable_JSON = "0.3.1" # version tag to be stored in JSON files
const version = "0.3.5"
const version_SignalTable_JSON = "0.3.5" # version tag to be stored in JSON files

using OrderedCollections
using Unitful
Expand Down
2 changes: 2 additions & 0 deletions src/SilentNoPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module SilentNoPlot

export plot, showFigure, saveFigure, closeFigure, closeAllFigures

include("AbstractPlotInterface.jl")

plot(signalTable, names::AbstractMatrix; heading::AbstractString="", grid::Bool=true, xAxis="time",
Expand Down
1 change: 1 addition & 0 deletions test/include_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include("SignalTableFunctions/test_DataFrames.jl")
include("SignalTableFunctions/test_json.jl")

include("../examples/plots/_include_all.jl")
include("../examples/fileIO/_include_all.jl")

#=
include("LinePlots/test_06_OneScalarMeasurementSignal.jl")
Expand Down

0 comments on commit 791cc98

Please sign in to comment.