dcm 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli.rb +20 -6
- data/lib/codinginfo.rb +29 -19
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24fe5532820ef2590dd51fcb42433a4a3972b716ce5f77269653a58d33f93435
|
4
|
+
data.tar.gz: 96b84123a8fe6b36916aa1648729373f896712a0a2e6a8b5301854896091c409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6725d774fdaa8b235463a141a3b3d504d4fbc5b52e77f8dc1f0fd0b5d56388b4381f4dd718f43b7a0c588ae4aeb1d64e816bb4f1c849709274facff262872657
|
7
|
+
data.tar.gz: ca12146d598edd1b8264eb19c766416c945e99df79d0ed1c020b68ef64fba92ce738416e9f4e0e05b1ceb6471b27e6e43a1a7244b394b7af6192358a0cbb9e7f
|
data/lib/cli.rb
CHANGED
@@ -18,6 +18,8 @@ module Dcm
|
|
18
18
|
|
19
19
|
class CLI < Thor
|
20
20
|
|
21
|
+
ALLOWED_FILTERKEYS = [:swfk_id, :typekey, :devkey]
|
22
|
+
|
21
23
|
desc "show FILE", "Show all labels in FILE"
|
22
24
|
option :oneline, type: :boolean, aliases: ["-l"]
|
23
25
|
def show(file=nil)
|
@@ -40,20 +42,20 @@ module Dcm
|
|
40
42
|
loop { LabelSelector.choose_from(list) }
|
41
43
|
end
|
42
44
|
|
43
|
-
desc "creta2begu
|
44
|
-
def creta2begu(
|
45
|
+
desc "creta2begu FILTER CODING FILE", "Convert a hierarchical DCM to a flat DCM"
|
46
|
+
def creta2begu(expr, codingpath, file)
|
45
47
|
list = parse_file(file)
|
46
48
|
|
47
|
-
puts Codinginfo.new(
|
49
|
+
puts Codinginfo.new(codingpath, parse_filter(expr))
|
48
50
|
.flatten_list(list)
|
49
51
|
.to_dcm
|
50
52
|
end
|
51
53
|
|
52
|
-
desc "begu2creta
|
53
|
-
def begu2creta(
|
54
|
+
desc "begu2creta FILTER CODING FILE", "Convert a flat DCM to a hierarchical DCM"
|
55
|
+
def begu2creta(expr, codingpath, file)
|
54
56
|
list = parse_file(file)
|
55
57
|
|
56
|
-
puts Codinginfo.new(
|
58
|
+
puts Codinginfo.new(codingpath, parse_filter(expr))
|
57
59
|
.unflatten_list(list)
|
58
60
|
.to_dcm
|
59
61
|
end
|
@@ -254,6 +256,18 @@ module Dcm
|
|
254
256
|
Ecu::LabelList.new([label])
|
255
257
|
end
|
256
258
|
|
259
|
+
def check_filter(expr)
|
260
|
+
return if ALLOWED_FILTERKEYS.include?(expr.split(":").first)
|
261
|
+
|
262
|
+
fail "Unknown filter expression #{expr}. Possible keys are #{ALLOWED_FILTERKEYS.join(", ")}. Use key:value1,value2 syntax."
|
263
|
+
end
|
264
|
+
|
265
|
+
def parse_filter(expr)
|
266
|
+
expr
|
267
|
+
.split(":")
|
268
|
+
.then { { _1.to_sym => _2.split(",") } }
|
269
|
+
end
|
270
|
+
|
257
271
|
def display_list(list:, detail:, format: :tty)
|
258
272
|
case format
|
259
273
|
when :tty
|
data/lib/codinginfo.rb
CHANGED
@@ -25,8 +25,8 @@ class Codinginfo
|
|
25
25
|
def to_s = "#{name}=#{value}"
|
26
26
|
def ==(other) = name == other.name
|
27
27
|
|
28
|
-
def
|
29
|
-
fail "Cannot
|
28
|
+
def combine(other)
|
29
|
+
fail "Cannot combine #{name} with #{other.name}" unless self == other
|
30
30
|
|
31
31
|
self.class.new \
|
32
32
|
name: name,
|
@@ -47,7 +47,7 @@ class Codinginfo
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def initialize(
|
50
|
+
def initialize(filepath, filter)
|
51
51
|
@doc = SimpleXlsxReader.open(filepath)
|
52
52
|
@headers = []
|
53
53
|
@variants = []
|
@@ -56,11 +56,8 @@ class Codinginfo
|
|
56
56
|
overview_sheet
|
57
57
|
.rows
|
58
58
|
.each do |row|
|
59
|
-
|
60
|
-
next
|
61
|
-
next if row[1].nil? || row[3].nil?
|
62
|
-
next unless ids.any? { row[1].match?(/#{_1}/i) }
|
63
|
-
next unless row[3].match?(/CVAR/)
|
59
|
+
next unless headers_parsed?(row)
|
60
|
+
next unless matches_filter?(row, *filter.to_a.first)
|
64
61
|
|
65
62
|
@variants << Variant.new(@headers, row)
|
66
63
|
end
|
@@ -88,6 +85,14 @@ class Codinginfo
|
|
88
85
|
.tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? }
|
89
86
|
end
|
90
87
|
|
88
|
+
def matches_filter?(row, key, values)
|
89
|
+
return false unless row[3]
|
90
|
+
return false unless row[3].match?(/CVAR/)
|
91
|
+
return false unless @headers.include?(key)
|
92
|
+
|
93
|
+
values.any? { row[@headers.index(key)].match?(/#{_1}/i) }
|
94
|
+
end
|
95
|
+
|
91
96
|
def variant
|
92
97
|
fail "No variant matching #{id} found!" if @variants.empty?
|
93
98
|
fail "More than one variant matching #{id} found!" if @variants.size > 1
|
@@ -99,11 +104,11 @@ class Codinginfo
|
|
99
104
|
Ecu::LabelList.new \
|
100
105
|
list.flat_map { |label|
|
101
106
|
if has_cvar_assignment?(label)
|
102
|
-
@variants.map { label.with(name: add_cvar_prefix(label, _1)) }
|
107
|
+
@variants.map { label.with(name: add_cvar_prefix(label.name, _1)) }
|
103
108
|
else
|
104
109
|
label
|
105
110
|
end
|
106
|
-
}
|
111
|
+
}.uniq
|
107
112
|
end
|
108
113
|
|
109
114
|
def flatten_list(list)
|
@@ -124,28 +129,33 @@ class Codinginfo
|
|
124
129
|
variant.cvars.any? { label.name.match?(_1.label_prefix) }
|
125
130
|
end
|
126
131
|
|
127
|
-
def add_cvar_prefix(
|
132
|
+
def add_cvar_prefix(name, variant)
|
128
133
|
variant
|
129
134
|
.cvars
|
130
|
-
.find { _1 == @assignments[
|
131
|
-
.then { _1.
|
132
|
-
.then { _1.label_prefix +
|
135
|
+
.find { _1 == @assignments[name] }
|
136
|
+
.then { _1.combine(@assignments[name]) }
|
137
|
+
.then { _1.label_prefix + name }
|
133
138
|
end
|
134
139
|
|
135
140
|
def remove_cvar_prefix(name)
|
136
141
|
name.sub(CVAR_PREFIX_REGEXP, "")
|
137
142
|
end
|
138
143
|
|
139
|
-
def
|
140
|
-
return
|
141
|
-
|
142
|
-
return unless row[
|
144
|
+
def headers_parsed?(row)
|
145
|
+
return true if @headers.any?
|
146
|
+
|
147
|
+
return false unless row[1]&.match?(/SWFK-ID/)
|
148
|
+
return false unless row[1]&.match?(/CVAR_BeguData/)
|
149
|
+
return false unless row[2]&.match?(/Kommentar/)
|
143
150
|
|
144
151
|
@headers = row
|
145
152
|
.map(&:chomp)
|
146
153
|
.map(&:lstrip)
|
147
154
|
.map(&:strip)
|
148
155
|
.map { _1.sub(/\n.*/, "") }
|
149
|
-
.tap { _1[0] =
|
156
|
+
.tap { _1[0] = :typestr }
|
157
|
+
.tap { _1[1] = :swfk_id }
|
158
|
+
.tap { _1[4] = :typekey }
|
159
|
+
.tap { _1[6] = :devkey }
|
150
160
|
end
|
151
161
|
end
|
data/lib/version.rb
CHANGED