daff 1.1.9 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![NPM version](https://badge.fury.io/js/daff.svg)](http://badge.fury.io/js/daff)
3
3
  [![Gem Version](https://badge.fury.io/rb/daff.svg)](http://badge.fury.io/rb/daff)
4
4
  [![PyPI version](https://badge.fury.io/py/daff.svg)](http://badge.fury.io/py/daff)
5
+ [![PHP version](https://badge.fury.io/ph/paulfitz%2Fdaff-php.svg)](http://badge.fury.io/ph/paulfitz%2Fdaff-php)
5
6
 
6
7
  daff: data diff
7
8
  ===============
@@ -14,6 +14,7 @@ module Coopy
14
14
  @unchanged_column_context = 1
15
15
  @always_show_header = true
16
16
  @acts = nil
17
+ @ids = nil
17
18
  end
18
19
 
19
20
  attr_accessor :ordered
@@ -25,6 +26,7 @@ module Coopy
25
26
  attr_accessor :unchanged_column_context
26
27
  attr_accessor :always_show_header
27
28
  attr_accessor :acts
29
+ attr_accessor :ids
28
30
 
29
31
  def allow_update
30
32
  return true if @acts == nil
@@ -67,137 +67,182 @@ module Coopy
67
67
  ha = a.get_height
68
68
  hb = b.get_height
69
69
  av = a.get_cell_view
70
- n = 5
71
- columns = Array.new
72
- if common_units.length > n
73
- columns_eval = Array.new
70
+ ids = nil
71
+ ids = @comp.compare_flags.ids if @comp.compare_flags != nil
72
+ if ids != nil
73
+ index = ::Coopy::IndexPair.new
74
+ ids_as_map = {}
74
75
  begin
75
- _g11 = 0
76
- _g2 = common_units.length
77
- while(_g11 < _g2)
78
- i = _g11
79
- _g11+=1
80
- ct = 0
81
- mem = {}
82
- mem2 = {}
83
- ca = common_units[i].l
84
- cb = common_units[i].r
76
+ _g2 = 0
77
+ while(_g2 < ids.length)
78
+ id = ids[_g2]
79
+ _g2+=1
85
80
  begin
86
- _g21 = 0
87
- while(_g21 < ha)
88
- j = _g21
89
- _g21+=1
90
- key = av.to_s(a.get_cell(ca,j))
91
- if !mem.include?(key)
92
- mem[key] = 1
93
- ct+=1
94
- end
95
- end
96
- end
97
- begin
98
- _g22 = 0
99
- while(_g22 < hb)
100
- j1 = _g22
101
- _g22+=1
102
- key1 = av.to_s(b.get_cell(cb,j1))
103
- if !mem2.include?(key1)
104
- mem2[key1] = 1
105
- ct+=1
106
- end
107
- end
81
+ ids_as_map[id] = true
82
+ true
108
83
  end
109
- columns_eval.push([i,ct])
110
84
  end
111
85
  end
112
- sorter = lambda {|a1,b1|
113
- return 1 if a1[1] < b1[1]
114
- return -1 if a1[1] > b1[1]
115
- return 0
116
- }
117
- columns_eval.sort{|a,b| sorter.call(a,b)}
118
- columns = Lambda.array(Lambda.map(columns_eval,lambda {|v|
119
- return v[0]
120
- }))
121
- columns = columns.slice(0,n - 1)
122
- else
123
- _g12 = 0
124
- _g3 = common_units.length
125
- while(_g12 < _g3)
126
- i1 = _g12
127
- _g12+=1
128
- columns.push(i1)
129
- end
130
- end
131
- top = nil
132
- begin
133
- v1 = 2 ** columns.length
134
- top = v1.round
135
- end
136
- pending = {}
137
- begin
138
- _g4 = 0
139
- while(_g4 < ha)
140
- j2 = _g4
141
- _g4+=1
142
- pending[j2] = j2
143
- end
144
- end
145
- pending_ct = ha
146
- begin
147
- _g5 = 0
148
- while(_g5 < top)
149
- k = _g5
150
- _g5+=1
151
- next if k == 0
152
- break if pending_ct == 0
153
- active_columns = Array.new
154
- kk = k
155
- at = 0
156
- while(kk > 0)
157
- active_columns.push(columns[at]) if kk.remainder(2) == 1
158
- kk >>= 1
159
- at+=1
160
- end
161
- index = ::Coopy::IndexPair.new
162
- begin
163
- _g23 = 0
164
- _g13 = active_columns.length
165
- while(_g23 < _g13)
166
- k1 = _g23
167
- _g23+=1
168
- unit1 = common_units[active_columns[k1]]
86
+ begin
87
+ _g3 = 0
88
+ while(_g3 < common_units.length)
89
+ unit1 = common_units[_g3]
90
+ _g3+=1
91
+ na = av.to_s(a.get_cell(unit1.l,0))
92
+ nb = av.to_s(b.get_cell(unit1.r,0))
93
+ if ids_as_map.include?(na) || ids_as_map.include?(nb)
169
94
  index.add_columns(unit1.l,unit1.r)
170
95
  align.add_index_columns(unit1)
171
96
  end
172
97
  end
173
- index.index_tables(a,b)
174
- h = a.get_height
175
- h = b.get_height if b.get_height > h
176
- h = 1 if h < 1
177
- wide_top_freq = index.get_top_freq
178
- ratio = wide_top_freq
179
- ratio /= h + 20
180
- next if ratio >= 0.1
181
- @indexes.push(index) if @indexes != nil
182
- fixed = Array.new
183
- _it = ::Rb::RubyIterator.new(pending.keys)
184
- while(_it.has_next) do
185
- j3 = _it._next
186
- cross = index.query_local(j3)
98
+ end
99
+ index.index_tables(a,b)
100
+ @indexes.push(index) if @indexes != nil
101
+ begin
102
+ _g4 = 0
103
+ while(_g4 < ha)
104
+ j = _g4
105
+ _g4+=1
106
+ cross = index.query_local(j)
187
107
  spot_a = cross.spot_a
188
108
  spot_b = cross.spot_b
189
109
  next if spot_a != 1 || spot_b != 1
190
- fixed.push(j3)
191
- align.link(j3,cross.item_b.lst[0])
110
+ align.link(j,cross.item_b.lst[0])
192
111
  end
112
+ end
113
+ else
114
+ n = 5
115
+ columns = Array.new
116
+ if common_units.length > n
117
+ columns_eval = Array.new
193
118
  begin
194
- _g24 = 0
195
- _g14 = fixed.length
196
- while(_g24 < _g14)
197
- j4 = _g24
198
- _g24+=1
199
- pending.delete(fixed[j4])
200
- pending_ct-=1
119
+ _g11 = 0
120
+ _g5 = common_units.length
121
+ while(_g11 < _g5)
122
+ i = _g11
123
+ _g11+=1
124
+ ct = 0
125
+ mem = {}
126
+ mem2 = {}
127
+ ca = common_units[i].l
128
+ cb = common_units[i].r
129
+ begin
130
+ _g21 = 0
131
+ while(_g21 < ha)
132
+ j1 = _g21
133
+ _g21+=1
134
+ key = av.to_s(a.get_cell(ca,j1))
135
+ if !mem.include?(key)
136
+ mem[key] = 1
137
+ ct+=1
138
+ end
139
+ end
140
+ end
141
+ begin
142
+ _g22 = 0
143
+ while(_g22 < hb)
144
+ j2 = _g22
145
+ _g22+=1
146
+ key1 = av.to_s(b.get_cell(cb,j2))
147
+ if !mem2.include?(key1)
148
+ mem2[key1] = 1
149
+ ct+=1
150
+ end
151
+ end
152
+ end
153
+ columns_eval.push([i,ct])
154
+ end
155
+ end
156
+ sorter = lambda {|a1,b1|
157
+ return 1 if a1[1] < b1[1]
158
+ return -1 if a1[1] > b1[1]
159
+ return 0
160
+ }
161
+ columns_eval.sort{|a,b| sorter.call(a,b)}
162
+ columns = Lambda.array(Lambda.map(columns_eval,lambda {|v|
163
+ return v[0]
164
+ }))
165
+ columns = columns.slice(0,n - 1)
166
+ else
167
+ _g12 = 0
168
+ _g6 = common_units.length
169
+ while(_g12 < _g6)
170
+ i1 = _g12
171
+ _g12+=1
172
+ columns.push(i1)
173
+ end
174
+ end
175
+ top = nil
176
+ begin
177
+ v1 = 2 ** columns.length
178
+ top = v1.round
179
+ end
180
+ pending = {}
181
+ begin
182
+ _g7 = 0
183
+ while(_g7 < ha)
184
+ j3 = _g7
185
+ _g7+=1
186
+ pending[j3] = j3
187
+ end
188
+ end
189
+ pending_ct = ha
190
+ begin
191
+ _g8 = 0
192
+ while(_g8 < top)
193
+ k = _g8
194
+ _g8+=1
195
+ next if k == 0
196
+ break if pending_ct == 0
197
+ active_columns = Array.new
198
+ kk = k
199
+ at = 0
200
+ while(kk > 0)
201
+ active_columns.push(columns[at]) if kk.remainder(2) == 1
202
+ kk >>= 1
203
+ at+=1
204
+ end
205
+ index1 = ::Coopy::IndexPair.new
206
+ begin
207
+ _g23 = 0
208
+ _g13 = active_columns.length
209
+ while(_g23 < _g13)
210
+ k1 = _g23
211
+ _g23+=1
212
+ unit2 = common_units[active_columns[k1]]
213
+ index1.add_columns(unit2.l,unit2.r)
214
+ align.add_index_columns(unit2)
215
+ end
216
+ end
217
+ index1.index_tables(a,b)
218
+ h = a.get_height
219
+ h = b.get_height if b.get_height > h
220
+ h = 1 if h < 1
221
+ wide_top_freq = index1.get_top_freq
222
+ ratio = wide_top_freq
223
+ ratio /= h + 20
224
+ next if ratio >= 0.1
225
+ @indexes.push(index1) if @indexes != nil
226
+ fixed = Array.new
227
+ _it = ::Rb::RubyIterator.new(pending.keys)
228
+ while(_it.has_next) do
229
+ j4 = _it._next
230
+ cross1 = index1.query_local(j4)
231
+ spot_a1 = cross1.spot_a
232
+ spot_b1 = cross1.spot_b
233
+ next if spot_a1 != 1 || spot_b1 != 1
234
+ fixed.push(j4)
235
+ align.link(j4,cross1.item_b.lst[0])
236
+ end
237
+ begin
238
+ _g24 = 0
239
+ _g14 = fixed.length
240
+ while(_g24 < _g14)
241
+ j5 = _g24
242
+ _g24+=1
243
+ pending.delete(fixed[j5])
244
+ pending_ct-=1
245
+ end
201
246
  end
202
247
  end
203
248
  end
@@ -378,6 +378,12 @@ module Coopy
378
378
  @output_format = args[i + 1]
379
379
  args.slice!(i,2)
380
380
  break
381
+ elsif tag == "--id"
382
+ more = true
383
+ flags.ids = Array.new if flags.ids == nil
384
+ flags.ids.push(args[i + 1])
385
+ args.slice!(i,2)
386
+ break
381
387
  end
382
388
  end
383
389
  end
@@ -429,6 +435,7 @@ module Coopy
429
435
  io.write_stderr("\n")
430
436
  io.write_stderr("If you need more control, here is the full list of flags:\n")
431
437
  io.write_stderr(" daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv\n")
438
+ io.write_stderr(" --id: specify column to use as primary key (repeat for multi-column key)\n")
432
439
  io.write_stderr(" --color: highlight changes with terminal colors\n")
433
440
  io.write_stderr(" --context NUM: show NUM rows of context\n")
434
441
  io.write_stderr(" --all: do not prune unchanged rows\n")
@@ -499,7 +506,7 @@ module Coopy
499
506
  output = "-" if output == nil
500
507
  ok = true
501
508
  if cmd1 == "diff"
502
- ct1 = ::Coopy::Coopy.compare_tables3(parent,a,b)
509
+ ct1 = ::Coopy::Coopy.compare_tables3(parent,a,b,flags)
503
510
  align = ct1.align
504
511
  td = ::Coopy::TableDiff.new(align,flags)
505
512
  o = ::Coopy::SimpleTable.new(0,0)
@@ -543,23 +550,25 @@ module Coopy
543
550
  class << self
544
551
  attr_accessor :version
545
552
  end
546
- @version = "1.1.8"
553
+ @version = "1.1.11"
547
554
 
548
- def Coopy.compare_tables(local,remote)
555
+ def Coopy.compare_tables(local,remote,flags = nil)
549
556
  ct = ::Coopy::CompareTable.new
550
557
  comp = ::Coopy::TableComparisonState.new
551
558
  comp.a = local
552
559
  comp.b = remote
560
+ comp.compare_flags = flags
553
561
  ct.attach(comp)
554
562
  return ct
555
563
  end
556
564
 
557
- def Coopy.compare_tables3(parent,local,remote)
565
+ def Coopy.compare_tables3(parent,local,remote,flags = nil)
558
566
  ct = ::Coopy::CompareTable.new
559
567
  comp = ::Coopy::TableComparisonState.new
560
568
  comp.p = parent
561
569
  comp.a = local
562
570
  comp.b = remote
571
+ comp.compare_flags = flags
563
572
  ct.attach(comp)
564
573
  return ct
565
574
  end
@@ -569,35 +578,35 @@ module Coopy
569
578
  def Coopy.random_tests
570
579
  st = ::Coopy::SimpleTable.new(15,6)
571
580
  tab = st
572
- ::Haxe::Log._trace.call("table size is " + _hx_str(tab.get_width) + "x" + _hx_str(tab.get_height),{ file_name: "Coopy.hx", line_number: 51, class_name: "coopy.Coopy", method_name: "randomTests"})
581
+ ::Haxe::Log._trace.call("table size is " + _hx_str(tab.get_width) + "x" + _hx_str(tab.get_height),{ file_name: "Coopy.hx", line_number: 53, class_name: "coopy.Coopy", method_name: "randomTests"})
573
582
  tab.set_cell(3,4,::Coopy::SimpleCell.new(33))
574
583
  ::Haxe::Log._trace.call("element is " + _hx_str(lambda{ s = tab.get_cell(3,4)
575
- _r = s.to_s}.call()),{ file_name: "Coopy.hx", line_number: 53, class_name: "coopy.Coopy", method_name: "randomTests"})
584
+ _r = s.to_s}.call()),{ file_name: "Coopy.hx", line_number: 55, class_name: "coopy.Coopy", method_name: "randomTests"})
576
585
  compare = ::Coopy::Compare.new
577
586
  d1 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(10))
578
587
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(10))
579
588
  d3 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
580
589
  report = ::Coopy::Report.new
581
590
  compare.compare(d1,d2,d3,report)
582
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 61, class_name: "coopy.Coopy", method_name: "randomTests"})
591
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 63, class_name: "coopy.Coopy", method_name: "randomTests"})
583
592
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(50))
584
593
  report.clear
585
594
  compare.compare(d1,d2,d3,report)
586
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 65, class_name: "coopy.Coopy", method_name: "randomTests"})
595
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 67, class_name: "coopy.Coopy", method_name: "randomTests"})
587
596
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
588
597
  report.clear
589
598
  compare.compare(d1,d2,d3,report)
590
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 69, class_name: "coopy.Coopy", method_name: "randomTests"})
599
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 71, class_name: "coopy.Coopy", method_name: "randomTests"})
591
600
  d1 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
592
601
  report.clear
593
602
  compare.compare(d1,d2,d3,report)
594
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 73, class_name: "coopy.Coopy", method_name: "randomTests"})
603
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 75, class_name: "coopy.Coopy", method_name: "randomTests"})
595
604
  comp = ::Coopy::TableComparisonState.new
596
605
  ct = ::Coopy::CompareTable.new
597
606
  comp.a = st
598
607
  comp.b = st
599
608
  ct.attach(comp)
600
- ::Haxe::Log._trace.call("comparing tables",{ file_name: "Coopy.hx", line_number: 81, class_name: "coopy.Coopy", method_name: "randomTests"})
609
+ ::Haxe::Log._trace.call("comparing tables",{ file_name: "Coopy.hx", line_number: 83, class_name: "coopy.Coopy", method_name: "randomTests"})
601
610
  t1 = ::Coopy::SimpleTable.new(3,2)
602
611
  t2 = ::Coopy::SimpleTable.new(3,2)
603
612
  t3 = ::Coopy::SimpleTable.new(3,2)
@@ -605,13 +614,13 @@ module Coopy
605
614
  dt2 = ::Coopy::ViewedDatum.new(t2,::Coopy::SimpleView.new)
606
615
  dt3 = ::Coopy::ViewedDatum.new(t3,::Coopy::SimpleView.new)
607
616
  compare.compare(dt1,dt2,dt3,report)
608
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 89, class_name: "coopy.Coopy", method_name: "randomTests"})
617
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 91, class_name: "coopy.Coopy", method_name: "randomTests"})
609
618
  t3.set_cell(1,1,::Coopy::SimpleCell.new("hello"))
610
619
  compare.compare(dt1,dt2,dt3,report)
611
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 92, class_name: "coopy.Coopy", method_name: "randomTests"})
620
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 94, class_name: "coopy.Coopy", method_name: "randomTests"})
612
621
  t1.set_cell(1,1,::Coopy::SimpleCell.new("hello"))
613
622
  compare.compare(dt1,dt2,dt3,report)
614
- ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 95, class_name: "coopy.Coopy", method_name: "randomTests"})
623
+ ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 97, class_name: "coopy.Coopy", method_name: "randomTests"})
615
624
  v = ::Coopy::Viterbi.new
616
625
  td = ::Coopy::TableDiff.new(nil,nil)
617
626
  idx = ::Coopy::Index.new
@@ -717,7 +726,7 @@ module Coopy
717
726
  txt += "\n"
718
727
  end
719
728
  end
720
- ::Haxe::Log._trace.call(txt,{ file_name: "Coopy.hx", line_number: 694, class_name: "coopy.Coopy", method_name: "show"})
729
+ ::Haxe::Log._trace.call(txt,{ file_name: "Coopy.hx", line_number: 705, class_name: "coopy.Coopy", method_name: "show"})
721
730
  end
722
731
 
723
732
  def Coopy.jsonify(t)
@@ -31,19 +31,15 @@ module Coopy
31
31
 
32
32
  def index_table(t)
33
33
  @indexed_table = t
34
+ @keys[t.get_height - 1] = nil if @keys.length != t.get_height && t.get_height > 0
34
35
  begin
35
36
  _g1 = 0
36
37
  _g = t.get_height
37
38
  while(_g1 < _g)
38
39
  i = _g1
39
40
  _g1+=1
40
- key = nil
41
- if @keys.length > i
42
- key = @keys[i]
43
- else
44
- key = self.to_key(t,i)
45
- @keys.push(key)
46
- end
41
+ key = @keys[i]
42
+ @keys[i] = key = self.to_key(t,i) if key == nil
47
43
  item = @items[key]
48
44
  if item == nil
49
45
  item = ::Coopy::IndexItem.new
@@ -17,6 +17,7 @@ module Coopy
17
17
  attr_accessor :is_equal_known
18
18
  attr_accessor :has_same_columns
19
19
  attr_accessor :has_same_columns_known
20
+ attr_accessor :compare_flags
20
21
 
21
22
  def reset
22
23
  @completed = false
@@ -25,6 +26,7 @@ module Coopy
25
26
  @is_equal = false
26
27
  @has_same_columns = false
27
28
  @has_same_columns_known = false
29
+ @compare_flags = nil
28
30
  end
29
31
 
30
32
  end
@@ -293,7 +293,7 @@ module Coopy
293
293
  while(_g15 < _g6)
294
294
  i2 = _g15
295
295
  _g15+=1
296
- active[i2] = 0
296
+ active[units.length - 1 - i2] = 0
297
297
  end
298
298
  end
299
299
  allow_insert = @flags.allow_insert
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-29 00:00:00.000000000 Z
13
+ date: 2014-09-03 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Diff and patch tables
16
16
  email:
@@ -112,7 +112,8 @@ specification_version: 3
112
112
  summary: ! '[![Build Status](https://travis-ci.org/paulfitz/daff.svg?branch=master)](https://travis-ci.org/paulfitz/daff)
113
113
  [![NPM version](https://badge.fury.io/js/daff.svg)](http://badge.fury.io/js/daff)
114
114
  [![Gem Version](https://badge.fury.io/rb/daff.svg)](http://badge.fury.io/rb/daff)
115
- [![PyPI version](https://badge.fury.io/py/daff.svg)](http://badge.fury.io/py/daff) daff:
115
+ [![PyPI version](https://badge.fury.io/py/daff.svg)](http://badge.fury.io/py/daff)
116
+ [![PHP version](https://badge.fury.io/ph/paulfitz%2Fdaff-php.svg)](http://badge.fury.io/ph/paulfitz%2Fdaff-php) daff:
116
117
  data diff =============== This is a library for comparing tables, producing a summary
117
118
  of their differences, and using such a summary as a patch file. It is optimized
118
119
  for comparing tables that share a common origin, in other words multiple versions