From 63e4fd3f1a4c242d60eb598bb69e4643c2e99fa6 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 18 Aug 2020 21:06:35 -0300 Subject: [PATCH 1/6] =?UTF-8?q?[#10]=20-=20Criando=20sistema=20de=20ordena?= =?UTF-8?q?=C3=A7=C3=A3o=20e=20aleatoriza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 1 + src/connector.jl | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 39244ce..0e01e7a 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.1.0" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [compat] diff --git a/src/connector.jl b/src/connector.jl index de62907..657eebb 100644 --- a/src/connector.jl +++ b/src/connector.jl @@ -1,4 +1,4 @@ -using Tables +using Tables, StatsBase abstract type AbstractConnector{T} end @@ -21,6 +21,14 @@ 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::DataFrames.DataFrame; + orderBy = nothing, + rev = false, + shuffle = false) + + shuffle == true ? df = df[StatsBase.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, DataFrames.order(orderBy, rev=rev)) + + return TablesConnector{DataFrame}(Tables.rows(df), 0) +end TablesConnector(filename::String) = TablesConnector{DataFrame}(CSV.read(filename; header = false)) \ No newline at end of file From 13e037cc71e0aa86d34708cf5a1b6a41c80948ca Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 18 Aug 2020 21:30:36 -0300 Subject: [PATCH 2/6] [#10] - Generalizando entrada do TablesConnector --- src/connector.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/connector.jl b/src/connector.jl index 657eebb..d28bca3 100644 --- a/src/connector.jl +++ b/src/connector.jl @@ -1,4 +1,4 @@ -using Tables, StatsBase +using Tables, Random abstract type AbstractConnector{T} end @@ -21,14 +21,14 @@ Base.length(conn::TablesConnector) = length(conn.rows) hasnext(conn::TablesConnector) = conn.state < length(conn) -function TablesConnector(df::DataFrames.DataFrame; +function TablesConnector(df::T; orderBy = nothing, rev = false, - shuffle = false) + shuffle = false) where {T} - shuffle == true ? df = df[StatsBase.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, DataFrames.order(orderBy, rev=rev)) + shuffle == true ? df = df[Random.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, orderBy, rev = rev) - return TablesConnector{DataFrame}(Tables.rows(df), 0) + return TablesConnector{T}(Tables.rows(df), 0) end TablesConnector(filename::String) = TablesConnector{DataFrame}(CSV.read(filename; header = false)) \ No newline at end of file From fd45487e0880f22c0cfac949fe53544042dd579f Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 19 Aug 2020 14:47:17 -0300 Subject: [PATCH 3/6] =?UTF-8?q?Adicionando=20tipagem=20nos=20argumentos=20?= =?UTF-8?q?e=20verifica=C3=A7=C3=A3o=20de=20coluna?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/connector.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/connector.jl b/src/connector.jl index d28bca3..cd7bc2e 100644 --- a/src/connector.jl +++ b/src/connector.jl @@ -1,4 +1,4 @@ -using Tables, Random +using Tables abstract type AbstractConnector{T} end @@ -22,11 +22,12 @@ Base.length(conn::TablesConnector) = length(conn.rows) hasnext(conn::TablesConnector) = conn.state < length(conn) function TablesConnector(df::T; - orderBy = nothing, - rev = false, - shuffle = false) where {T} + orderBy::Symbol = :default, + rev::Bool = false, + shuffle::Bool = false) where {T} - shuffle == true ? df = df[Random.shuffle(1:size(df,1)), :] : orderBy != nothing && sort!(df, orderBy, rev = rev) + 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 From e934618e039375e86a51ec8862985c095664778c Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 19 Aug 2020 14:47:28 -0300 Subject: [PATCH 4/6] Adicionando alguns testes --- test/runtests.jl | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2adc120..692c75b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) \ No newline at end of file +@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 \ No newline at end of file From be634f64895bfbf110072efde90c2ef97be5faec Mon Sep 17 00:00:00 2001 From: Filipe Braida Date: Wed, 19 Aug 2020 19:09:44 -0300 Subject: [PATCH 5/6] Removendo dep --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0e01e7a..39244ce 100644 --- a/Project.toml +++ b/Project.toml @@ -7,7 +7,6 @@ version = "0.1.0" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [compat] From 080aec583fe06d4ed3ad298868a8185cee08ce00 Mon Sep 17 00:00:00 2001 From: Filipe Braida Date: Wed, 19 Aug 2020 19:09:52 -0300 Subject: [PATCH 6/6] Adicionando newline --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 692c75b..74a38a7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,4 +18,4 @@ using Test for name in missing_names @test_logs (:warn,"A tabela não possui a coluna $name") EasyStream.TablesConnector(df, orderBy = name) end -end \ No newline at end of file +end