mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-05 22:31:11 +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 'youplot/version'
|
||||
require 'youplot/preprocessing'
|
||||
require 'youplot/dsv_reader'
|
||||
require 'youplot/command'
|
||||
|
||||
module YouPlot
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'preprocessing'
|
||||
require_relative 'dsv_reader'
|
||||
require_relative 'command/parser'
|
||||
|
||||
# FIXME
|
||||
@ -55,9 +55,9 @@ module YouPlot
|
||||
|
||||
@data = if @encoding
|
||||
input2 = input.dup.force_encoding(@encoding).encode('utf-8')
|
||||
Preprocessing.input(input2, delimiter, headers, transpose)
|
||||
DSVReader.input(input2, delimiter, headers, transpose)
|
||||
else
|
||||
Preprocessing.input(input, delimiter, headers, transpose)
|
||||
DSVReader.input(input, delimiter, headers, transpose)
|
||||
end
|
||||
|
||||
pp @data if @debug
|
||||
|
@ -3,9 +3,10 @@
|
||||
require 'csv'
|
||||
|
||||
module YouPlot
|
||||
module Preprocessing
|
||||
# Read and interpret Delimiter-separated values format file or stream.
|
||||
module DSVReader
|
||||
module_function
|
||||
|
||||
|
||||
def input(input, delimiter, headers, transpose)
|
||||
arr = parse_as_csv(input, delimiter)
|
||||
headers = get_headers(arr, headers, transpose)
|
||||
@ -68,19 +69,5 @@ module YouPlot
|
||||
transpose2(arr)
|
||||
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
|
@ -2,9 +2,9 @@
|
||||
|
||||
require_relative '../test_helper'
|
||||
|
||||
class YouPlotPreprocessingTest < Test::Unit::TestCase
|
||||
class YouPlotDSVReaderTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@m = YouPlot::Preprocessing
|
||||
@m = YouPlot::DSVReader
|
||||
end
|
||||
|
||||
test :transpose2 do
|
||||
@ -124,9 +124,4 @@ class YouPlotPreprocessingTest < Test::Unit::TestCase
|
||||
[2, 4],
|
||||
[3, 5, 6]], false, false))
|
||||
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
|
Loading…
Reference in New Issue
Block a user