Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed May 22, 2021
1 parent 6c89f0c commit 06637b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MetidaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module MetidaBase

using StatsModels, Tables
import Tables: istable, columnaccess, columns, getcolumn, columnnames
import Base: getindex, length
import Base: getindex, length, ht_keyindex

include("abstracttype.jl")
include("types.jl")
Expand Down
29 changes: 27 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Tables.getcolumn(t, nm::Symbol) = t.table[nm]

Tables.columnnames(t::MetidaTable) = collect(keys(t.table))


# MetidaFreq.jl
# All

struct DataSet{T <: AbstractData}
data::Vector{T}
Expand All @@ -32,6 +31,32 @@ function Base.length(ds::DataSet)
length(ds.data)
end

function getindormiss(d, i)
ind = ht_keyindex(d, i)
if ind > 0 return d.vals[ind] else return missing end
end
function islessdict(a::Dict{A1,A2}, b::Dict{B1,B2}, k::Union{AbstractVector, Set}) where A1 where A2 where B1 where B2
l = length(k)
av = Vector{Union{Missing, A2}}(undef, l)
bv = Vector{Union{Missing, B2}}(undef, l)
@inbounds for i = 1:l
av[i] = getindormiss(a, k[i])
bv[i] = getindormiss(b, k[i])
end
isless(av, bv)
end
function islessdict(a::Dict, b::Dict, k)
isless(getindormiss(a, k), getindormiss(b, k))
end
function Base.sort!(a::DataSet{T}, k; alg::Base.Algorithm = QuickSort, lt=nothing, by=nothing, rev::Bool=false, order::Base.Ordering = Base.Forward) where T <: AbstractIdData
if isnothing(by) by = x -> x.id end
if isnothing(lt) lt = (x, y) -> islessdict(x, y, k) end
sort!(a.data; alg = alg, lt = lt, by = by, rev = rev, order = order)
a
end

# MetidaFreq.jl

struct Proportion <: AbstractData
x::Int
n::Int
Expand Down

0 comments on commit 06637b1

Please sign in to comment.