Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatter #89

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "yas"
37 changes: 37 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: format-check
on:
push:
branches:
- 'main'
- /^release-.*$/
tags: ['*']
ericphanson marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
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:
format-check:
name: Format check (Julia ${{ matrix.julia-version }} - ${{ github.event_name }})
# Run on push's or non-draft PRs
if: (github.event_name == 'push') || (github.event.pull_request.draft == false)
runs-on: ubuntu-latest
strategy:
matrix:
julia-version: [1.9.3]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
- uses: actions/checkout@v1
- name: Instantiate `format` environment and format
run: |
julia --project=format -e 'using Pkg; Pkg.instantiate()'
julia --project=format 'format/run.jl'
- uses: reviewdog/action-suggester@v1
if: github.event_name == 'pull_request'
with:
tool_name: JuliaFormatter
fail_on_error: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docs/build/
docs/site/
.DS_Store
tmpdir/*
!format/Manifest.toml
27 changes: 17 additions & 10 deletions OndaEDFSchemas.jl/src/OndaEDFSchemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export PlanV1, PlanV2, FilePlanV1, FilePlanV2, EDFAnnotationV1
kind::Union{Missing,AbstractString} = lift(String, kind)
channel::Union{Missing,AbstractString} = lift(String, channel)
sample_unit::Union{Missing,AbstractString} = lift(String, sample_unit)
sample_resolution_in_unit::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type, sample_resolution_in_unit)
sample_offset_in_unit::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type, sample_offset_in_unit)
sample_type::Union{Missing,AbstractString} = lift(onda_sample_type_from_julia_type, sample_type)
sample_rate::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type, sample_rate)
sample_resolution_in_unit::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type,
sample_resolution_in_unit)
sample_offset_in_unit::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type,
sample_offset_in_unit)
sample_type::Union{Missing,AbstractString} = lift(onda_sample_type_from_julia_type,
sample_type)
sample_rate::Union{Missing,LPCM_SAMPLE_TYPE_UNION} = lift(convert_number_to_lpcm_sample_type,
sample_rate)
# errors, use `nothing` to indicate no error
error::Union{Nothing,String} = coalesce(error, nothing)
end
Expand All @@ -52,21 +56,21 @@ end
seconds_per_record::Float64
# Onda.SignalV2 fields (channels -> channel), may be missing
recording::Union{UUID,Missing} = lift(UUID, recording)
sensor_type::Union{Missing,AbstractString} = lift(_validate_signal_sensor_type, sensor_type)
sensor_type::Union{Missing,AbstractString} = lift(_validate_signal_sensor_type,
sensor_type)
sensor_label::Union{Missing,AbstractString} = lift(_validate_signal_sensor_label,
coalesce(sensor_label, sensor_type))
channel::Union{Missing,AbstractString} = lift(_validate_signal_channel, channel)
sample_unit::Union{Missing,AbstractString} = lift(String, sample_unit)
sample_resolution_in_unit::Union{Missing,Float64}
sample_offset_in_unit::Union{Missing,Float64}
sample_type::Union{Missing,AbstractString} = lift(onda_sample_type_from_julia_type, sample_type)
sample_type::Union{Missing,AbstractString} = lift(onda_sample_type_from_julia_type,
sample_type)
sample_rate::Union{Missing,Float64}
# errors, use `nothing` to indicate no error
error::Union{Nothing,String} = coalesce(error, nothing)
end



const PLAN_DOC_TEMPLATE = """
@version PlanV{{ VERSION }} begin
# EDF.SignalHeader fields
Expand Down Expand Up @@ -159,11 +163,14 @@ end
@doc _file_plan_doc(1) FilePlanV1
@doc _file_plan_doc(2) FilePlanV2

const OndaEDFSchemaVersions = Union{PlanV1SchemaVersion,PlanV2SchemaVersion,FilePlanV1SchemaVersion,FilePlanV2SchemaVersion}
const OndaEDFSchemaVersions = Union{PlanV1SchemaVersion,PlanV2SchemaVersion,
FilePlanV1SchemaVersion,FilePlanV2SchemaVersion}
Legolas.accepted_field_type(::OndaEDFSchemaVersions, ::Type{String}) = AbstractString
# we need this because Arrow write can introduce a Missing for the error column
# (I think because of how missing/nothing sentinels are handled?)
Legolas.accepted_field_type(::OndaEDFSchemaVersions, ::Type{Union{Nothing,String}}) = Union{Nothing,Missing,AbstractString}
function Legolas.accepted_field_type(::OndaEDFSchemaVersions, ::Type{Union{Nothing,String}})
return Union{Nothing,Missing,AbstractString}
end

@schema "edf.annotation" EDFAnnotation

Expand Down
19 changes: 10 additions & 9 deletions OndaEDFSchemas.jl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ function mock_plan(; v, rng=GLOBAL_RNG)
physical_dimension="uV",
physical_minimum=0.0,
physical_maximum=2.0,
digital_minimum=-1f4,
digital_maximum=1f4,
digital_minimum=-1.0f4,
digital_maximum=1.0f4,
prefilter="HP 0.1Hz; LP 80Hz; N 60Hz",
samples_per_record=128,
seconds_per_record=1.0,
channel=ingested ? "cz-m1" : missing,
sample_unit=ingested ? "microvolt" : missing,
sample_resolution_in_unit=ingested ? 1f-4 : missing,
sample_resolution_in_unit=ingested ? 1.0f-4 : missing,
sample_offset_in_unit=ingested ? 1.0 : missing,
sample_type=ingested ? "float32" : missing,
sample_rate=ingested ? 1/128 : missing,
sample_rate=ingested ? 1 / 128 : missing,
error=errored ? "Error blah blah" : nothing,
recording= (ingested && rand(rng, Bool)) ? uuid4() : missing,
recording=(ingested && rand(rng, Bool)) ? uuid4() : missing,
specific_kwargs...)
end

Expand All @@ -63,7 +63,7 @@ end

@testset "Schema version $v" for v in (1, 2)
SamplesInfo = v == 1 ? Onda.SamplesInfoV1 : SamplesInfoV2

@testset "ondaedf.plan@$v" begin
rng = StableRNG(10)
plans = mock_plan(30; v, rng)
Expand All @@ -75,21 +75,22 @@ end
# conversion to samples info with channel -> channels
@test all(x -> isa(x, SamplesInfo),
SamplesInfo(Tables.rowmerge(p; channels=[p.channel]))
for p in plans if !ismissing(p.channel))
for p in plans if !ismissing(p.channel))
kleinschmidt marked this conversation as resolved.
Show resolved Hide resolved
end

@testset "ondaedf.file-plan@$v" begin
rng = StableRNG(11)
file_plans = mock_file_plan(50; v, rng)
schema = Tables.schema(file_plans)
@test nothing === Legolas.validate(schema, Legolas.SchemaVersion("ondaedf.file-plan", v))
@test nothing ===
Legolas.validate(schema, Legolas.SchemaVersion("ondaedf.file-plan", v))
tbl = Arrow.Table(Arrow.tobuffer(file_plans; maxdepth=9))
@test isequal(Tables.columntable(tbl), Tables.columntable(file_plans))

# conversion to samples info with channel -> channels
@test all(x -> isa(x, SamplesInfo),
SamplesInfo(Tables.rowmerge(p; channels=[p.channel]))
for p in file_plans if !ismissing(p.channel))
for p in file_plans if !ismissing(p.channel))
kleinschmidt marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using OndaEDF
using Documenter

makedocs(modules=[OndaEDF, OndaEDF.OndaEDFSchemas],
makedocs(; modules=[OndaEDF, OndaEDF.OndaEDFSchemas],
sitename="OndaEDF",
authors="Beacon Biosignals and other contributors",
pages=["OndaEDF" => "index.md",
"Converting from EDF" => "convert-to-onda.md",
"API Documentation" => "api.md"])

deploydocs(repo="github.com/beacon-biosignals/OndaEDF.jl.git",
deploydocs(; repo="github.com/beacon-biosignals/OndaEDF.jl.git",
push_preview=true)
Loading