Skip to content

Commit

Permalink
Merge pull request #13 from ATISLabs/features/table_orderer
Browse files Browse the repository at this point in the history
[#10] - Criando sistema de ordenação e aleatorização
  • Loading branch information
filipebraida authored Aug 19, 2020
2 parents 5f7d59e + 080aec5 commit a0286ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
11 changes: 10 additions & 1 deletion src/connector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ Base.length(conn::TablesConnector) = length(conn.rows)

hasnext(conn::TablesConnector) = conn.state < length(conn)

TablesConnector(df::DataFrames.DataFrame) = TablesConnector{DataFrame}(Tables.rows(df), 0)
function TablesConnector(df::T;
orderBy::Symbol = :default,
rev::Bool = false,
shuffle::Bool = false) where {T}

shuffle == true ? df = df[Random.shuffle(1:size(df,1)), :] : nothing
orderBy != :default && orderBy in propertynames(df) ? df = sort(df, orderBy, rev = rev) : @warn "A tabela não possui a coluna $orderBy"

return TablesConnector{T}(Tables.rows(df), 0)
end

TablesConnector(filename::String) = TablesConnector{DataFrame}(CSV.read(filename; header = false))
48 changes: 18 additions & 30 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
using EasyStream
using Test

stream = EasyStream.Dataset1CDT(5)

filter = EasyStream.FilterModifier([:Column1, :Column1])

EasyStream.push!(stream, filter)

EasyStream.listen(stream)




using DataFrames

x = stream.connector.rows[1]



values1 = DataFrame[]

push!(values1, DataFrame(x))

DataFrame(values1)

w = vcat(values1...)


w


select!(w, :Column1)
@testset "sort and shuffle functionalities" begin
df = EasyStream.DataFrame(x = [1, 2, 3, 4, 5, 6], y = [6, 5, 4, 3, 2, 1])

cnn = EasyStream.TablesConnector(df, orderBy = :y)
for x in df[:,1]
@test EasyStream.next(cnn)[2][1] == x
end

cnn = EasyStream.TablesConnector(df, orderBy = :x, rev = true)
for y in df[:,2]
@test EasyStream.next(cnn)[1][1] == y
end

missing_names = [:c, :d, :e]
for name in missing_names
@test_logs (:warn,"A tabela não possui a coluna $name") EasyStream.TablesConnector(df, orderBy = name)
end
end

0 comments on commit a0286ef

Please sign in to comment.