ea 0.6.147 → 0.6.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ea/qea/factory/enum_transformer.rb +9 -2
- data/lib/ea/svg/parity/corpus_report.rb +42 -4
- data/lib/ea/svg/parity/differ.rb +169 -3
- data/lib/ea/svg/parity/suite.rb +59 -15
- data/lib/ea/version.rb +1 -1
- data/lib/ea/xmi/parser.rb +2 -0
- data/lib/tasks/svg_bench.rake +93 -73
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d143a80d034a606fa2dedae83b531d86efdb32c2787fdf23c2cf964c8a234329
|
|
4
|
+
data.tar.gz: d385a7270b77210a912b6a176d3d2dfc0a8c28b0cc109b09b1f9516bd95746c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84270956322f9417de60234cb5ab7b0f3150c98452c2398eb50f5d08788030f4a05ec01ea2811afac143ba2d7ae71fe5814e731fa0d2d7ee58b385bfa753090f
|
|
7
|
+
data.tar.gz: 5acca009a511334a1a2b9cd027877bf59e3dfc3715b61b5f5079e2800126c16c02bc961567ba6ef304f91b4a8fd8720c083d55f6e1ca4feeee695a753e1cc4ce
|
|
@@ -62,12 +62,19 @@ module Ea
|
|
|
62
62
|
def build_enum_value(ea_attr)
|
|
63
63
|
Lutaml::Uml::Value.new.tap do |value|
|
|
64
64
|
value.name = ea_attr.name
|
|
65
|
+
value.initial = present_text(ea_attr.default)
|
|
65
66
|
value.id = normalize_guid_to_xmi_format(ea_attr.ea_guid, "EAID")
|
|
66
|
-
value.definition = ea_attr.notes
|
|
67
|
-
ea_attr.notes.nil? || ea_attr.notes.empty?
|
|
67
|
+
value.definition = present_text(ea_attr.notes)
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# @return [String, nil] the text when non-blank, otherwise nil
|
|
72
|
+
def present_text(text)
|
|
73
|
+
return nil if text.nil? || text.empty?
|
|
74
|
+
|
|
75
|
+
text
|
|
76
|
+
end
|
|
77
|
+
|
|
71
78
|
end
|
|
72
79
|
end
|
|
73
80
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
+
require "yaml"
|
|
4
5
|
|
|
5
6
|
module Ea
|
|
6
7
|
module Svg
|
|
@@ -35,8 +36,41 @@ module Ea
|
|
|
35
36
|
result
|
|
36
37
|
end
|
|
37
38
|
|
|
39
|
+
# YAML uses plain string keys so gate consumers can safe-load it.
|
|
40
|
+
# Include clean diagrams with zero counts; omit unreferenced diagrams
|
|
41
|
+
# exactly as Suite does. Counts use Suite's default tolerances.
|
|
42
|
+
def run_baseline(output_path:, io: $stdout)
|
|
43
|
+
suite = Suite.new(document, ref_dir).measure
|
|
44
|
+
rows = baseline_rows(suite)
|
|
45
|
+
result = { "totals" => baseline_totals(rows), "diagrams" => rows }
|
|
46
|
+
File.write(output_path, YAML.dump(result))
|
|
47
|
+
print_baseline(suite, rows, io)
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
|
|
38
51
|
private
|
|
39
52
|
|
|
53
|
+
def baseline_rows(suite)
|
|
54
|
+
suite.per_diagram.map do |diagram|
|
|
55
|
+
{ "id" => diagram.id, "name" => diagram.name,
|
|
56
|
+
"deltas" => diagram.delta_summary.transform_keys(&:to_s) }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def baseline_totals(rows)
|
|
61
|
+
rows.each_with_object(Hash.new(0)) do |row, sum|
|
|
62
|
+
row.fetch("deltas").each { |key, count| sum[key] += count }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def print_baseline(suite, rows, io)
|
|
67
|
+
io.puts "Diagrams: #{suite.total} (failures: #{suite.failures.size})"
|
|
68
|
+
rows.each do |row|
|
|
69
|
+
deltas = row.fetch("deltas").map { |key, count| "#{key}=#{count}" }.join(" ")
|
|
70
|
+
io.puts " #{row.fetch("id")} (#{row.fetch("name")}): #{deltas}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
40
74
|
def diagrams_with_references
|
|
41
75
|
document.diagrams.select { |d| reference_path_for(d) }
|
|
42
76
|
end
|
|
@@ -45,7 +79,7 @@ module Ea
|
|
|
45
79
|
# fall back to the raw diagram id for non-QEA sources.
|
|
46
80
|
def reference_path_for(diagram)
|
|
47
81
|
[
|
|
48
|
-
File.join(ref_dir, "EAID_#{diagram.id.tr(
|
|
82
|
+
File.join(ref_dir, "EAID_#{diagram.id.tr("-", "_")}.svg"),
|
|
49
83
|
File.join(ref_dir, "#{Ea::Sources::Qea::IdNormalizer.to_eaid(diagram.id)}.svg"),
|
|
50
84
|
File.join(ref_dir, "#{diagram.id}.svg")
|
|
51
85
|
].find { |p| File.exist?(p) }
|
|
@@ -55,9 +89,7 @@ module Ea
|
|
|
55
89
|
ref_path = reference_path_for(diagram)
|
|
56
90
|
return nil unless ref_path
|
|
57
91
|
|
|
58
|
-
ours =
|
|
59
|
-
diagram, model_index: index, document: document
|
|
60
|
-
).render
|
|
92
|
+
ours = render_diagram(diagram, index)
|
|
61
93
|
differ = Differ.new(ours: ours, reference: File.read(ref_path))
|
|
62
94
|
deltas = differ.text_deltas
|
|
63
95
|
|
|
@@ -68,6 +100,12 @@ module Ea
|
|
|
68
100
|
}
|
|
69
101
|
end
|
|
70
102
|
|
|
103
|
+
def render_diagram(diagram, index)
|
|
104
|
+
Ea::Svg::EaEmitter::Document.new(
|
|
105
|
+
diagram, model_index: index, document: document
|
|
106
|
+
).render
|
|
107
|
+
end
|
|
108
|
+
|
|
71
109
|
def totals(rows)
|
|
72
110
|
sum = DELTA_KEYS.to_h { |k| [k, 0] }
|
|
73
111
|
shapes = { matched: 0, missing: 0, extra: 0 }
|
data/lib/ea/svg/parity/differ.rb
CHANGED
|
@@ -96,7 +96,7 @@ module Ea
|
|
|
96
96
|
.map { |(x, y)| [x.to_f, y.to_f] }
|
|
97
97
|
{
|
|
98
98
|
kind: :path, points: points,
|
|
99
|
-
centroid: centroid(points), closed: node["d"].to_s.
|
|
99
|
+
centroid: centroid(points), closed: node["d"].to_s.match?(/[zZ]/),
|
|
100
100
|
stroke: g_style[/stroke:([^;]+)/, 1]
|
|
101
101
|
}
|
|
102
102
|
end
|
|
@@ -223,6 +223,171 @@ module Ea
|
|
|
223
223
|
private_constant :TextComparison
|
|
224
224
|
include TextComparison
|
|
225
225
|
|
|
226
|
+
# Endpoint distances are Euclidean distances after canvas alignment.
|
|
227
|
+
# Arrowhead tips correspond by geometry. An unpaired arrowhead
|
|
228
|
+
# has infinite drift; correctly placed endpoints and tips have zero.
|
|
229
|
+
module ConnectorComparison
|
|
230
|
+
def connector_deltas
|
|
231
|
+
heads = shape_pairs(arrowheads(@reference), arrowheads(@ours))
|
|
232
|
+
connector_pairs.map do |ours, ref|
|
|
233
|
+
connector_delta(ours, ref).merge(arrowhead_deltas: arrowhead_deltas(ours, ref, heads))
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def connector_delta(ours, ref)
|
|
238
|
+
{
|
|
239
|
+
kind: ours[:kind], ours: ours, reference: ref,
|
|
240
|
+
source_delta: endpoint_distance(ours[:points].first, ref[:points].first),
|
|
241
|
+
target_delta: endpoint_distance(ours[:points].last, ref[:points].last)
|
|
242
|
+
}
|
|
243
|
+
end
|
|
244
|
+
private :connector_delta
|
|
245
|
+
|
|
246
|
+
def connectors(primitives)
|
|
247
|
+
primitives.select do |primitive|
|
|
248
|
+
%i[path line].include?(primitive[:kind]) && !primitive[:closed] &&
|
|
249
|
+
primitive[:points].size >= 2 && !open_arrowhead?(primitive)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
private :connectors
|
|
253
|
+
|
|
254
|
+
# Preserve local matches even when both docks move: the allowance
|
|
255
|
+
# for total endpoint drift scales with connector length. Choose the
|
|
256
|
+
# smallest total endpoint drift first, so a shared target cannot
|
|
257
|
+
# steal another connector's exact match.
|
|
258
|
+
def connector_pairs
|
|
259
|
+
candidates = connectors(@ours).product(connectors(@reference))
|
|
260
|
+
candidates.sort_by! { |ours, ref| connector_distance(ours, ref) }
|
|
261
|
+
used = {}.compare_by_identity
|
|
262
|
+
candidates.select do |ours, ref|
|
|
263
|
+
next false if used[ours] || used[ref] || !connector_distance(ours, ref).finite?
|
|
264
|
+
|
|
265
|
+
used[ours] = used[ref] = true
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
private :connector_pairs
|
|
269
|
+
|
|
270
|
+
def connector_distance(ours, ref)
|
|
271
|
+
return Float::INFINITY unless ours[:kind] == ref[:kind]
|
|
272
|
+
|
|
273
|
+
drifts = connector_delta(ours, ref).values_at(:source_delta, :target_delta)
|
|
274
|
+
return drifts.sum if drifts.min <= MATCH_DISTANCE
|
|
275
|
+
return drifts.sum if shape_distance(shift_primitive(ours), ref) <= MATCH_DISTANCE
|
|
276
|
+
return drifts.sum if drifts.sum <= [connector_length(ours), connector_length(ref)].max
|
|
277
|
+
|
|
278
|
+
Float::INFINITY
|
|
279
|
+
end
|
|
280
|
+
private :connector_distance
|
|
281
|
+
|
|
282
|
+
def connector_length(primitive)
|
|
283
|
+
primitive[:points].each_cons(2).sum { |first, last| point_distance(first, last) }
|
|
284
|
+
end
|
|
285
|
+
private :connector_length
|
|
286
|
+
|
|
287
|
+
def endpoint_distance(ours, ref)
|
|
288
|
+
return Float::INFINITY unless ours && ref
|
|
289
|
+
|
|
290
|
+
Math.hypot(ours[0] + @shift[0] - ref[0], ours[1] + @shift[1] - ref[1])
|
|
291
|
+
end
|
|
292
|
+
private :endpoint_distance
|
|
293
|
+
end
|
|
294
|
+
private_constant :ConnectorComparison
|
|
295
|
+
include ConnectorComparison
|
|
296
|
+
|
|
297
|
+
# EA emits triangle/diamond polygons and symmetric open V paths. The
|
|
298
|
+
# latter have their tip at the middle vertex, rather than at an end.
|
|
299
|
+
module ArrowheadComparison
|
|
300
|
+
def arrowheads(primitives)
|
|
301
|
+
primitives.select { |primitive| primitive[:kind] == :polygon || open_arrowhead?(primitive) }
|
|
302
|
+
end
|
|
303
|
+
private :arrowheads
|
|
304
|
+
|
|
305
|
+
def open_arrowhead?(primitive)
|
|
306
|
+
return false unless primitive[:kind] == :path && !primitive[:closed] && primitive[:points].size == 3
|
|
307
|
+
|
|
308
|
+
symmetric_wings?(*primitive[:points])
|
|
309
|
+
end
|
|
310
|
+
private :open_arrowhead?
|
|
311
|
+
|
|
312
|
+
def symmetric_wings?(first, tip, last)
|
|
313
|
+
left = point_distance(first, tip)
|
|
314
|
+
right = point_distance(last, tip)
|
|
315
|
+
base = point_distance(first, last)
|
|
316
|
+
# EA rounds each vertex to whole pixels, allowing up to sqrt(2)
|
|
317
|
+
# error per wing. Ordinary right-angle bends are not arrowheads.
|
|
318
|
+
(left - right).abs <= 2 * Math.sqrt(2) && base.positive? && base < [left, right].min
|
|
319
|
+
end
|
|
320
|
+
private :symmetric_wings?
|
|
321
|
+
|
|
322
|
+
def point_distance(first, last)
|
|
323
|
+
Math.hypot(first[0] - last[0], first[1] - last[1])
|
|
324
|
+
end
|
|
325
|
+
private :point_distance
|
|
326
|
+
|
|
327
|
+
def arrowhead_deltas(ours, ref, heads)
|
|
328
|
+
{ source: 0, target: -1 }.filter_map do |name, index|
|
|
329
|
+
pair = arrowhead_pair(ours[:points][index], ref[:points][index], heads)
|
|
330
|
+
next unless pair
|
|
331
|
+
|
|
332
|
+
our_head, ref_head, anchor, tip = pair
|
|
333
|
+
{ end: name, ours: our_head, reference: ref_head,
|
|
334
|
+
tip_delta: endpoint_distance(corresponding_tip(our_head, anchor, tip),
|
|
335
|
+
corresponding_tip(ref_head, anchor, tip)) }
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
private :arrowhead_deltas
|
|
339
|
+
|
|
340
|
+
def arrowhead_pair(our_point, ref_point, heads)
|
|
341
|
+
if (attachment = touching_arrowhead(@reference, ref_point))
|
|
342
|
+
ref, tip = attachment
|
|
343
|
+
ours = heads.find { |_, candidate| candidate.equal?(ref) }&.first
|
|
344
|
+
elsif (attachment = touching_arrowhead(@ours, our_point))
|
|
345
|
+
ours, tip = attachment
|
|
346
|
+
ref = heads.find { |candidate, _| candidate.equal?(ours) }&.last
|
|
347
|
+
else
|
|
348
|
+
return
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
[ours, ref, attachment.first, tip]
|
|
352
|
+
end
|
|
353
|
+
private :arrowhead_pair
|
|
354
|
+
|
|
355
|
+
# Removing each head's translation lets the reference tip identify
|
|
356
|
+
# its counterpart even when polygon vertices start at another corner
|
|
357
|
+
# or run in the opposite direction.
|
|
358
|
+
def corresponding_tip(head, anchor, index)
|
|
359
|
+
return unless head
|
|
360
|
+
return head[:points][1] if head[:kind] == :path
|
|
361
|
+
|
|
362
|
+
offset = centered_point(anchor[:points][index], anchor)
|
|
363
|
+
head[:points].min_by { |point| point_distance(centered_point(point, head), offset) }
|
|
364
|
+
end
|
|
365
|
+
private :corresponding_tip
|
|
366
|
+
|
|
367
|
+
def centered_point(point, primitive)
|
|
368
|
+
[point[0] - primitive[:centroid][0], point[1] - primitive[:centroid][1]]
|
|
369
|
+
end
|
|
370
|
+
private :centered_point
|
|
371
|
+
|
|
372
|
+
def touching_arrowhead(primitives, endpoint)
|
|
373
|
+
vertices = arrowheads(primitives).flat_map do |head|
|
|
374
|
+
indices = head[:kind] == :path ? [1] : head[:points].each_index
|
|
375
|
+
indices.map { |index| [head, index] }
|
|
376
|
+
end
|
|
377
|
+
nearest = vertices.min_by { |polygon, index| vertex_distance(polygon, index, endpoint) }
|
|
378
|
+
nearest if nearest && vertex_distance(*nearest, endpoint) <= EPSILON
|
|
379
|
+
end
|
|
380
|
+
private :touching_arrowhead
|
|
381
|
+
|
|
382
|
+
def vertex_distance(polygon, index, endpoint)
|
|
383
|
+
point = polygon[:points][index]
|
|
384
|
+
Math.hypot(point[0] - endpoint[0], point[1] - endpoint[1])
|
|
385
|
+
end
|
|
386
|
+
private :vertex_distance
|
|
387
|
+
end
|
|
388
|
+
private_constant :ArrowheadComparison
|
|
389
|
+
include ArrowheadComparison
|
|
390
|
+
|
|
226
391
|
def parse(svg)
|
|
227
392
|
PrimitiveParser.new.parse(svg)
|
|
228
393
|
end
|
|
@@ -271,8 +436,9 @@ module Ea
|
|
|
271
436
|
end
|
|
272
437
|
private :dimension_delta
|
|
273
438
|
|
|
274
|
-
def shape_pairs(ref_shapes = @reference.reject { |p| p[:kind] == :text }
|
|
275
|
-
|
|
439
|
+
def shape_pairs(ref_shapes = @reference.reject { |p| p[:kind] == :text },
|
|
440
|
+
our_shapes = @ours.reject { |p| p[:kind] == :text })
|
|
441
|
+
our_shapes.filter_map do |ours|
|
|
276
442
|
shifted = shift_primitive(ours)
|
|
277
443
|
ref = ref_shapes.min_by { |c| shape_distance(shifted, c) }
|
|
278
444
|
next unless ref && shape_distance(shifted, ref) <= MATCH_DISTANCE
|
data/lib/ea/svg/parity/suite.rb
CHANGED
|
@@ -5,12 +5,14 @@ require "nokogiri"
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Svg
|
|
7
7
|
module Parity
|
|
8
|
-
# Drives
|
|
8
|
+
# Drives Checker and Differ across every diagram in a Document
|
|
9
9
|
# that has a matching reference SVG. Drives from any source
|
|
10
10
|
# the Document supports (qea or xmi) since the Document is
|
|
11
11
|
# format-agnostic.
|
|
12
12
|
class Suite
|
|
13
13
|
ELEMENT_TYPES = %i[rect polygon path text].freeze
|
|
14
|
+
TEXT_DELTAS = %i[moved_text missing_text extra_text wrong_font wrong_size wrong_weight].freeze
|
|
15
|
+
GEOMETRY_DELTAS = %i[dx dy dwidth dheight max_point_delta].freeze
|
|
14
16
|
|
|
15
17
|
attr_reader :document, :ref_dir
|
|
16
18
|
|
|
@@ -47,10 +49,54 @@ module Ea
|
|
|
47
49
|
document: document).render
|
|
48
50
|
reference = File.read(ref_path)
|
|
49
51
|
checker = Checker.new(ours: ours, reference: reference)
|
|
50
|
-
DiagramReport.new(diagram: diagram, report: checker.report
|
|
52
|
+
DiagramReport.new(diagram: diagram, report: checker.report,
|
|
53
|
+
differ: Differ.new(ours: ours, reference: reference))
|
|
51
54
|
end
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
# Epsilon applies to measured geometry; text/font mismatches retain
|
|
57
|
+
# Differ's classification (including its text movement threshold).
|
|
58
|
+
Tolerances = Data.define(:epsilon) do
|
|
59
|
+
def initialize(epsilon: Differ::EPSILON)
|
|
60
|
+
raise ArgumentError, "epsilon must be finite and non-negative" unless epsilon.finite? && epsilon >= 0
|
|
61
|
+
|
|
62
|
+
super
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
DiagramReport = Struct.new(:diagram, :report, :differ, keyword_init: true) do
|
|
67
|
+
def delta_summary(tolerances = Tolerances.new)
|
|
68
|
+
texts = differ.text_deltas
|
|
69
|
+
TEXT_DELTAS.to_h { |key| [key, texts[key].size] }.merge(
|
|
70
|
+
missing_shapes: differ.shape_summary[:missing],
|
|
71
|
+
extra_shapes: differ.shape_summary[:extra],
|
|
72
|
+
shape_geometry: geometry_count(tolerances),
|
|
73
|
+
**connector_summary(tolerances)
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def clean?(tolerances = Tolerances.new)
|
|
78
|
+
delta_summary(tolerances).values.all?(&:zero?)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def geometry_count(tolerances)
|
|
82
|
+
differ.shape_deltas.count do |delta|
|
|
83
|
+
delta.slice(*GEOMETRY_DELTAS).values.any? { |value| value.abs > tolerances.epsilon }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
private :geometry_count
|
|
87
|
+
|
|
88
|
+
def connector_summary(tolerances)
|
|
89
|
+
deltas = differ.connector_deltas
|
|
90
|
+
{
|
|
91
|
+
source_endpoints: deltas.count { |delta| delta[:source_delta] > tolerances.epsilon },
|
|
92
|
+
target_endpoints: deltas.count { |delta| delta[:target_delta] > tolerances.epsilon },
|
|
93
|
+
arrowhead_tips: deltas.sum do |delta|
|
|
94
|
+
delta[:arrowhead_deltas].count { |head| head[:tip_delta] > tolerances.epsilon }
|
|
95
|
+
end
|
|
96
|
+
}
|
|
97
|
+
end
|
|
98
|
+
private :connector_summary
|
|
99
|
+
|
|
54
100
|
def id
|
|
55
101
|
diagram.id
|
|
56
102
|
end
|
|
@@ -64,6 +110,7 @@ module Ea
|
|
|
64
110
|
end
|
|
65
111
|
end
|
|
66
112
|
|
|
113
|
+
# Collects diagram results and aggregates counts across the suite.
|
|
67
114
|
class Report
|
|
68
115
|
attr_reader :per_diagram
|
|
69
116
|
|
|
@@ -71,6 +118,10 @@ module Ea
|
|
|
71
118
|
@per_diagram = per_diagram
|
|
72
119
|
end
|
|
73
120
|
|
|
121
|
+
def failures(tolerances = Tolerances.new)
|
|
122
|
+
per_diagram.reject { |diagram| diagram.clean?(tolerances) }
|
|
123
|
+
end
|
|
124
|
+
|
|
74
125
|
def total
|
|
75
126
|
per_diagram.size
|
|
76
127
|
end
|
|
@@ -80,19 +131,12 @@ module Ea
|
|
|
80
131
|
end
|
|
81
132
|
|
|
82
133
|
def aggregate_shape_counts
|
|
83
|
-
ours
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
ours[:path] += dr.report.path.ours
|
|
89
|
-
ours[:text] += dr.report.text.ours
|
|
90
|
-
ref[:rect] += dr.report.rect.reference
|
|
91
|
-
ref[:polygon] += dr.report.polygon.reference
|
|
92
|
-
ref[:path] += dr.report.path.reference
|
|
93
|
-
ref[:text] += dr.report.text.reference
|
|
134
|
+
%i[ours reference].to_h do |side|
|
|
135
|
+
counts = ELEMENT_TYPES.to_h do |type|
|
|
136
|
+
[type, per_diagram.sum { |dr| dr.report.public_send(type).public_send(side) }]
|
|
137
|
+
end
|
|
138
|
+
[side, counts]
|
|
94
139
|
end
|
|
95
|
-
{ ours: ours, reference: ref }
|
|
96
140
|
end
|
|
97
141
|
|
|
98
142
|
def text_overlap_avg
|
data/lib/ea/version.rb
CHANGED
data/lib/ea/xmi/parser.rb
CHANGED
|
@@ -601,6 +601,8 @@ module Ea
|
|
|
601
601
|
|
|
602
602
|
::Lutaml::Uml::Value.new.tap do |value|
|
|
603
603
|
value.name = owned_literal.name
|
|
604
|
+
ext_attr = fetch_attribute_node(owned_literal.id)
|
|
605
|
+
value.initial = ext_attr.initial if ext_attr&.initial
|
|
604
606
|
value.type = lookup_entity_name(uml_type_id) || uml_type_id
|
|
605
607
|
value.definition = lookup_attribute_documentation(owned_literal.id)
|
|
606
608
|
end
|
data/lib/tasks/svg_bench.rake
CHANGED
|
@@ -3,85 +3,105 @@
|
|
|
3
3
|
require "ea"
|
|
4
4
|
require "ea/svg/parity"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
agg = suite.aggregate_shape_counts
|
|
6
|
+
module Ea
|
|
7
|
+
module Svg
|
|
8
|
+
module Parity
|
|
9
|
+
# Formatting shared by the benchmark tasks; parity baselines use CorpusReport.
|
|
10
|
+
module BenchOutput
|
|
11
|
+
def self.shape_counts(counts, width:)
|
|
12
|
+
%i[rect path polygon text].each do |key|
|
|
13
|
+
ours = counts[:ours][key]
|
|
14
|
+
reference = counts[:reference][key]
|
|
15
|
+
delta = ours - reference
|
|
16
|
+
puts " #{key.to_s.ljust(7)} ours=#{ours.to_s.rjust(width)} ref=#{reference.to_s.rjust(width)} " \
|
|
17
|
+
"delta=#{delta.to_s.rjust(5)} (#{percentage(delta, reference)}%)"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
outliers = suite.outliers(shape_tolerance: tolerance)
|
|
35
|
-
unless outliers.empty?
|
|
36
|
-
puts "\nOutliers (#{outliers.size}):"
|
|
37
|
-
outliers.first(20).each do |dr|
|
|
38
|
-
r = dr.report
|
|
39
|
-
puts " #{dr.id} (#{dr.name}): shape_delta=#{r.shape_delta_total} text=#{r.text_delta}"
|
|
21
|
+
def self.percentage(delta, reference)
|
|
22
|
+
reference.zero? ? 0.0 : (delta.to_f / reference * 100).round(1)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.reference_dir(exports_dir, name)
|
|
26
|
+
# EA export folders may omit a QEA version suffix such as ".1".
|
|
27
|
+
names = [name, name.sub(/\.\d+$/, "")]
|
|
28
|
+
paths = names.product(%w[images Images]).map do |base, images|
|
|
29
|
+
File.join(exports_dir, base, images)
|
|
30
|
+
end
|
|
31
|
+
paths.find { |path| Dir.exist?(path) }
|
|
32
|
+
end
|
|
40
33
|
end
|
|
41
34
|
end
|
|
42
35
|
end
|
|
36
|
+
end
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Dir.glob("#{qea_dir}/*.qea").sort.each do |qea_path|
|
|
53
|
-
name = File.basename(qea_path, ".qea")
|
|
54
|
-
# Strip version suffixes like ".1" from names like
|
|
55
|
-
# "20251010_current_plateau_v5.1" to match the exports
|
|
56
|
-
# directory "20251010_current_plateau_v5".
|
|
57
|
-
stripped_name = name.sub(/\.\d+$/, "")
|
|
58
|
-
# Reference images live in examples/exports/<name>/images or Images
|
|
59
|
-
candidates = [
|
|
60
|
-
File.join(exports_dir, name, "images"),
|
|
61
|
-
File.join(exports_dir, name, "Images"),
|
|
62
|
-
File.join(exports_dir, stripped_name, "images"),
|
|
63
|
-
File.join(exports_dir, stripped_name, "Images")
|
|
64
|
-
]
|
|
65
|
-
ref_dir = candidates.find { |p| Dir.exist?(p) }
|
|
66
|
-
if ref_dir.nil?
|
|
67
|
-
puts "#{name}: SKIP (no exports/images directory)"
|
|
68
|
-
next
|
|
69
|
-
end
|
|
38
|
+
desc "Report Suite deltas and write a YAML baseline (SOURCE, REF_DIR, OUTPUT_PATH=parity-baseline.yml)"
|
|
39
|
+
task "svg:parity_report", %i[source ref_dir output_path] do |_t, args|
|
|
40
|
+
source = args[:source]
|
|
41
|
+
ref_dir = args[:ref_dir]
|
|
42
|
+
abort "usage: rake svg:parity_report[source,ref_dir,output_path]" unless source && ref_dir
|
|
43
|
+
abort "source not found: #{source}" unless File.exist?(source)
|
|
44
|
+
abort "ref_dir not found: #{ref_dir}" unless Dir.exist?(ref_dir)
|
|
70
45
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
46
|
+
doc = Ea::Svg::Parity::Source.new(source).load
|
|
47
|
+
Ea::Svg::Parity::CorpusReport.new(document: doc, ref_dir: ref_dir)
|
|
48
|
+
.run_baseline(output_path: args[:output_path] || "parity-baseline.yml")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc "Score rendered SVG against EA reference SVGs (SOURCE.xmi or .qea + REF_DIR)"
|
|
52
|
+
task "svg:bench", %i[source ref_dir tolerance] do |_t, args|
|
|
53
|
+
source = args[:source] || ENV["EA_BENCH_SOURCE"] ||
|
|
54
|
+
File.expand_path("~/src/mn/mn-samples-plateau/sources/xmi/plateau_all_packages_export.xmi")
|
|
55
|
+
ref_dir = args[:ref_dir] || ENV["EA_BENCH_REF_DIR"] ||
|
|
56
|
+
File.expand_path("~/src/mn/mn-samples-plateau/sources/001-mds/xmi-images")
|
|
57
|
+
tolerance = (args[:tolerance] || ENV["EA_BENCH_TOLERANCE"] || "5").to_i
|
|
58
|
+
|
|
59
|
+
abort "source not found: #{source}" unless File.exist?(source)
|
|
60
|
+
abort "ref_dir not found: #{ref_dir}" unless Dir.exist?(ref_dir)
|
|
61
|
+
|
|
62
|
+
doc = Ea::Svg::Parity::Source.new(source).load
|
|
63
|
+
suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
|
|
64
|
+
agg = suite.aggregate_shape_counts
|
|
65
|
+
|
|
66
|
+
puts "Source: #{source}"
|
|
67
|
+
puts "Refs: #{ref_dir}"
|
|
68
|
+
puts "Diagrams: #{suite.total} (matched: #{suite.matched(shape_tolerance: tolerance)})"
|
|
69
|
+
Ea::Svg::Parity::BenchOutput.shape_counts(agg, width: 6)
|
|
70
|
+
puts "Text overlap avg: #{(suite.text_overlap_avg * 100).round(1)}%"
|
|
71
|
+
|
|
72
|
+
outliers = suite.outliers(shape_tolerance: tolerance)
|
|
73
|
+
unless outliers.empty?
|
|
74
|
+
puts "\nOutliers (#{outliers.size}):"
|
|
75
|
+
outliers.first(20).each do |dr|
|
|
76
|
+
r = dr.report
|
|
77
|
+
puts " #{dr.id} (#{dr.name}): shape_delta=#{r.shape_delta_total} text=#{r.text_delta}"
|
|
85
78
|
end
|
|
86
79
|
end
|
|
87
80
|
end
|
|
81
|
+
|
|
82
|
+
desc "Bench every example QEA in examples/qea against its exports/Images"
|
|
83
|
+
task "svg:examples" do
|
|
84
|
+
project_root = File.expand_path("../..", __dir__)
|
|
85
|
+
qea_dir = File.join(project_root, "examples", "qea")
|
|
86
|
+
exports_dir = File.join(project_root, "examples", "exports")
|
|
87
|
+
|
|
88
|
+
abort "examples/qea not found at #{qea_dir}" unless Dir.exist?(qea_dir)
|
|
89
|
+
|
|
90
|
+
Dir.glob("#{qea_dir}/*.qea").sort.each do |qea_path|
|
|
91
|
+
name = File.basename(qea_path, ".qea")
|
|
92
|
+
ref_dir = Ea::Svg::Parity::BenchOutput.reference_dir(exports_dir, name)
|
|
93
|
+
if ref_dir.nil?
|
|
94
|
+
puts "#{name}: SKIP (no exports/images directory)"
|
|
95
|
+
next
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
doc = Ea::Sources::Qea::Adapter.from_path(qea_path)
|
|
99
|
+
suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
|
|
100
|
+
agg = suite.aggregate_shape_counts
|
|
101
|
+
|
|
102
|
+
matched = suite.matched(shape_tolerance: 5)
|
|
103
|
+
puts "#{name.ljust(40)} #{matched}/#{suite.total} matched"
|
|
104
|
+
Ea::Svg::Parity::BenchOutput.shape_counts(agg, width: 5)
|
|
105
|
+
puts ""
|
|
106
|
+
end
|
|
107
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ea
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.149
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|