Skip to content

Commit

Permalink
Add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
abcsds committed Dec 30, 2024
1 parent 18e055e commit ded7e79
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options
style = "blue"
41 changes: 41 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
push:
branches:
- main
tags: ['*']
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
fail-fast: false
matrix:
version:
- '1.11'
- '1.6'
- 'pre'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Manifest.toml
Dockerfile
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.0-DEV] - Unreleased
- Add CI workflow for versions 1.11, 1.6 (LTS), and "pre".
- Format [blue](https://github.com/JuliaDiff/BlueStyle)

## [0.2.0] - 2022-02-23
- Add support for string markers and string streams ([#2](https://github.com/cbrnr/XDF.jl/pull/2) by [Alberto Barradas](https://github.com/abcsds) and [Clemens Brunner](https://github.com/cbrnr))
- Make header and footer XML available in "xml" key ([#4](https://github.com/cbrnr/XDF.jl/pull/4) by [Alberto Barradas](https://github.com/abcsds))
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "XDF"
uuid = "31bc19ec-0089-417f-990e-a2b5e7515868"
authors = ["Clemens Brunner <[email protected]>"]
version = "0.2.0"
version = "1.0.0-DEV"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
49 changes: 26 additions & 23 deletions src/XDF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ export read_xdf

using Logging: @info, @debug


CHUNK_TYPE = Dict(1=>"FileHeader",
2=>"StreamHeader",
3=>"Samples",
4=>"ClockOffset",
5=>"Boundary",
6=>"StreamFooter")

DATA_TYPE = Dict("int8"=>Int8,
"int16"=>Int16,
"int32"=>Int32,
"int64"=>Int64,
"float32"=>Float32,
"double64"=>Float64,
"string"=>String)

CHUNK_TYPE = Dict(
1 => "FileHeader",
2 => "StreamHeader",
3 => "Samples",
4 => "ClockOffset",
5 => "Boundary",
6 => "StreamFooter",
)

DATA_TYPE = Dict(
"int8" => Int8,
"int16" => Int16,
"int32" => Int32,
"int64" => Int64,
"float32" => Float32,
"double64" => Float64,
"string" => String,
)

"""
read_xdf(filename::AbstractString, sync::Bool=true)
Read XDF file and optionally sync streams (default true).
"""
function read_xdf(filename::AbstractString, sync::Bool=true)
streams = Dict{Int, Any}()
streams = Dict{Int,Any}()
counter = Dict(zip(keys(CHUNK_TYPE), zeros(Int, length(CHUNK_TYPE)))) # count chunks

open(filename) do io
Expand Down Expand Up @@ -123,9 +125,13 @@ function read_xdf(filename::AbstractString, sync::Bool=true)
streams[id]["time"][index[id]] = previous + delta
end
if streams[id]["dtype"] === String
streams[id]["data"][index[id], :] .= String(read(io, read_varlen_int(io)))
streams[id]["data"][index[id], :] .= String(
read(io, read_varlen_int(io))
)
else
streams[id]["data"][index[id], :] = reinterpret(dtype, read(io, sizeof(dtype) * nchannels))
streams[id]["data"][index[id], :] = reinterpret(
dtype, read(io, sizeof(dtype) * nchannels)
)
end
index[id] += 1
end
Expand All @@ -152,7 +158,6 @@ function read_xdf(filename::AbstractString, sync::Bool=true)
return streams
end


"Read variable-length integer."
function read_varlen_int(io::IO)
nbytes = read(io, Int8)
Expand All @@ -165,15 +170,13 @@ function read_varlen_int(io::IO)
end
end


"Find XML tag and return its content (optionally converted to specified type)."
function findtag(xml::AbstractString, tag::AbstractString, type=String::DataType)
m = match(Regex("<$tag>(.*)</$tag>"), xml)
content = isnothing(m) ? nothing : m[1]
return isnothing(content) || type == String ? content : parse(type, content)
end


"Synchronize clock values by their given offsets."
function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2})
x = hcat(ones(size(offsets, 1), 1), offsets[:, 1])
Expand All @@ -182,4 +185,4 @@ function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2})
return time .+ (coefs[1] .+ coefs[2] .* time)
end

end
end
24 changes: 13 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ using XDF, Downloads, Test
@test endswith(streams[0]["header"], "</uid></info>")
@test startswith(streams[0]["footer"], "<?xml version=\"1.0\"?>")
@test endswith(streams[0]["footer"], "</clock_offsets></info>")
@test streams[0]["data"] == [192 255 238
12 22 32
13 23 33
14 24 34
15 25 35
12 22 32
13 23 33
14 24 34
15 25 35]
@test streams[0]["data"] == [
192 255 238
12 22 32
13 23 33
14 24 34
15 25 35
12 22 32
13 23 33
14 24 34
15 25 35
]

@test 46202862 in keys(streams)
@test streams[46202862]["name"] == "SendDataString"
Expand All @@ -37,8 +39,8 @@ using XDF, Downloads, Test
@test size(streams[46202862]["data"]) == (9, 1)
@test startswith(streams[46202862]["data"][1, 1], "<?xml version")
@test endswith(streams[46202862]["data"][1, 1], "</info>")
@test streams[46202862]["data"][2:end, 1] == ["Hello", "World", "from", "LSL", "Hello",
"World", "from", "LSL"]
@test streams[46202862]["data"][2:end, 1] ==
["Hello", "World", "from", "LSL", "Hello", "World", "from", "LSL"]
end

@testset "XDF file with clock resets" begin
Expand Down

0 comments on commit ded7e79

Please sign in to comment.