mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 07:31:12 +08:00
Rename Preprocessing to DSVReader
* DSV stands for Delimiter-separated values. * Preprocessing is too vague.
This commit is contained in:
parent
ccf232a742
commit
1a3ad9553c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'unicode_plot'
|
require 'unicode_plot'
|
||||||
require 'youplot/version'
|
require 'youplot/version'
|
||||||
require 'youplot/preprocessing'
|
require 'youplot/dsv_reader'
|
||||||
require 'youplot/command'
|
require 'youplot/command'
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'preprocessing'
|
require_relative 'dsv_reader'
|
||||||
require_relative 'command/parser'
|
require_relative 'command/parser'
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
@ -55,9 +55,9 @@ module YouPlot
|
|||||||
|
|
||||||
@data = if @encoding
|
@data = if @encoding
|
||||||
input2 = input.dup.force_encoding(@encoding).encode('utf-8')
|
input2 = input.dup.force_encoding(@encoding).encode('utf-8')
|
||||||
Preprocessing.input(input2, delimiter, headers, transpose)
|
DSVReader.input(input2, delimiter, headers, transpose)
|
||||||
else
|
else
|
||||||
Preprocessing.input(input, delimiter, headers, transpose)
|
DSVReader.input(input, delimiter, headers, transpose)
|
||||||
end
|
end
|
||||||
|
|
||||||
pp @data if @debug
|
pp @data if @debug
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
require 'csv'
|
require 'csv'
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
module Preprocessing
|
# Read and interpret Delimiter-separated values format file or stream.
|
||||||
|
module DSVReader
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def input(input, delimiter, headers, transpose)
|
def input(input, delimiter, headers, transpose)
|
||||||
arr = parse_as_csv(input, delimiter)
|
arr = parse_as_csv(input, delimiter)
|
||||||
headers = get_headers(arr, headers, transpose)
|
headers = get_headers(arr, headers, transpose)
|
||||||
@ -68,19 +69,5 @@ module YouPlot
|
|||||||
transpose2(arr)
|
transpose2(arr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_values(arr)
|
|
||||||
# tally was added in Ruby 2.7
|
|
||||||
if Enumerable.method_defined? :tally
|
|
||||||
arr.tally
|
|
||||||
else
|
|
||||||
# https://github.com/marcandre/backports
|
|
||||||
arr.each_with_object(Hash.new(0)) { |item, res| res[item] += 1 }
|
|
||||||
.tap { |h| h.default = nil }
|
|
||||||
end
|
|
||||||
.sort { |a, b| a[1] <=> b[1] }
|
|
||||||
.reverse
|
|
||||||
.transpose
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
require_relative '../test_helper'
|
require_relative '../test_helper'
|
||||||
|
|
||||||
class YouPlotPreprocessingTest < Test::Unit::TestCase
|
class YouPlotDSVReaderTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@m = YouPlot::Preprocessing
|
@m = YouPlot::DSVReader
|
||||||
end
|
end
|
||||||
|
|
||||||
test :transpose2 do
|
test :transpose2 do
|
||||||
@ -124,9 +124,4 @@ class YouPlotPreprocessingTest < Test::Unit::TestCase
|
|||||||
[2, 4],
|
[2, 4],
|
||||||
[3, 5, 6]], false, false))
|
[3, 5, 6]], false, false))
|
||||||
end
|
end
|
||||||
|
|
||||||
test :count_values do
|
|
||||||
assert_equal([%i[a b c], [3, 2, 1]], @m.count_values(%i[a a a b b c]))
|
|
||||||
assert_equal([%i[c b a], [3, 2, 1]], @m.count_values(%i[a b b c c c]))
|
|
||||||
end
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user