-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmm_fulcrum_cmp
92 lines (77 loc) · 2.36 KB
/
tmm_fulcrum_cmp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script compares 2 TMM to Fulcrum CSV files
require 'optparse'
require 'ostruct'
require 'os'
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
root_dir = File.dirname(script_dir)
require_relative File.join(root_dir, "lib", "logger")
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
# Process the script parameters.
options = OpenStruct.new
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} csv1_file csv2_file"
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(opts)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 2
script_logger.info(option_parser.help)
return
end
# Process the command line parameters.
csv1_file = File.expand_path(ARGV[0])
csv2_file = File.expand_path(ARGV[1])
unless File.file?(csv1_file) and File.file?(csv2_file)
script_logger.error("invalid path #{csv1_file},#{csv2_file}")
exit 1
end
require 'csv'
script_logger.info("comparing #{File.basename(csv1_file)} to #{File.basename(csv2_file)}")
csv1 = CSV.parse(
File.read(csv1_file),
headers: true,
return_headers: false
)
csv2 = CSV.parse(
File.read(csv2_file, encoding: 'bom|utf-8'),
headers: true,
return_headers: false
)
puts "csv_count:#{csv1.count},#{csv2.count}"
puts "csv_header_count:#{csv1.headers.count},#{csv2.headers.count}"
diff1_rows = []
diff2_rows = []
diff_row = []
for i in 0..csv1.count-1 do
unless csv1[i].to_s == csv2[i].to_s
diff1_rows << csv1[i]
diff2_rows << csv2[i]
diff_row << (i+2)
end
end
puts "diff_cnt:#{diff1_rows.count},#{diff2_rows.count}"
for i in 0..diff1_rows.count-1 do
row1 = diff1_rows[i]
row2 = diff2_rows[i]
title1 = row1[csv1.headers[0]]
title2 = row2[csv2.headers[0]]
for j in 0..csv1.headers.count-1 do
#next unless j == 0
val1 = row1[csv1.headers[j]]
val2 = row2[csv2.headers[j]]
unless val1 == val2
#puts "#{i},#{diff_row[i]},#{csv1.headers[j]}:len:#{val1.length},#{val2.length},#{title1}$$$#{title2}"
puts "#{i},#{diff_row[i]},#{csv1.headers[j]}:len:#{val1.length},#{val2.length},#{title1}"
#puts "#{i},#{diff_row[i]},#{key}:equal #{val1==val2[0..val1.length-1]}"
#puts "#{i},#{diff_row[i]},#{key}"
#puts val1
#puts val2
#exit 0
end
end
end