-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.rb
executable file
·64 lines (50 loc) · 1.72 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
#### TraitDB YML/CSV File validator ####
APP_ROOT = File.dirname(__FILE__) # a constant, based on the directory containing this file
$:.unshift APP_ROOT # puts the directory into the search path
require 'import_template'
require 'validator' # loads once the validator.rb file
require 'downloader'
require 'pp'
# Instantiate a template validator with the first argument
# which should be a YML file
if ARGV.length == 0
puts "Usage: #{__FILE__} <config.yml> [<dataset.csv>]"
exit -1
end
import_template = TraitDB::ImportTemplate.new(ARGV[0])
#
#puts "Import Config Continuous Trait Names".center(80,'=')
#PP.pp(import_template.continuous_trait_column_names)
#puts "Import Config Categorical Trait Names".center(80,'=')
#PP.pp(import_template.categorical_trait_column_names)
exit -1 if ARGV.length < 2
# Validator takes a template and a path to a CSV file
validator = TraitDB::Validator.new(import_template, ARGV[1])
begin
validation_results = validator.validate
rescue Exception => e
if e.message == 'invalid byte sequence in UTF-8' && validator.encoding.nil?
validator.encoding = 'ISO-8859-1'
validation_results = validator.validate
else
puts "ERROR: #{ARGV[1]} is not valid a CSV file".center(80, '=')
puts e.message
exit -1
end
end
extra_columns = validator.extra_columns
puts "Extra columns: #{extra_columns.count} ".ljust(100,'=')
PP.pp(extra_columns)
puts "Validation Results ".ljust(100,'=')
puts ""
PP.pp(validation_results)
parse_results = validator.parse
puts "Parse Issues: #{parse_results[:issues].count} ".ljust(100,'=')
parse_results[:issues].each do |issue|
pp(issue)
end
datasets = validator.datasets
puts "Datasets: #{datasets.count} ".ljust(100,'=')
puts ""
# PP.pp(datasets)