labimotion 2.0.0.rc2 → 2.0.0.rc4
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/labimotion/apis/standard_api.rb +1 -2
- data/lib/labimotion/apis/standard_layer_api.rb +4 -17
- data/lib/labimotion/apis/vocabulary_api.rb +6 -20
- data/lib/labimotion/constants.rb +21 -0
- data/lib/labimotion/entities/dataset_entity.rb +0 -1
- data/lib/labimotion/entities/element_entity.rb +1 -0
- data/lib/labimotion/entities/properties_entity.rb +101 -41
- data/lib/labimotion/entities/segment_entity.rb +0 -2
- data/lib/labimotion/entities/vocabulary_entity.rb +2 -13
- data/lib/labimotion/helpers/element_helpers.rb +2 -2
- data/lib/labimotion/helpers/generic_helpers.rb +6 -1
- data/lib/labimotion/helpers/param_helpers.rb +0 -16
- data/lib/labimotion/libs/converter.rb +0 -1
- data/lib/labimotion/libs/data/mapper/Chemwiki.json +236 -0
- data/lib/labimotion/libs/data/mapper/Source.json +78 -0
- data/lib/labimotion/libs/data/vocab/System.json +1 -1
- data/lib/labimotion/libs/dataset_builder.rb +70 -0
- data/lib/labimotion/libs/export_dataset.rb +165 -66
- data/lib/labimotion/libs/nmr_mapper.rb +204 -247
- data/lib/labimotion/utils/mapper_utils.rb +169 -0
- data/lib/labimotion/utils/utils.rb +22 -0
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +3 -3
- metadata +7 -2
@@ -0,0 +1,236 @@
|
|
1
|
+
{
|
2
|
+
"CHMO:0000025": {
|
3
|
+
"index": ["A", "B", "C", "Q1", "Q2", "Q3", "G", "H", "Q4", "Q5", "K", "L", "Q6", "N", "O", "P", "Q7", "R", "S", "T", "U", "V", "W", "X", "Q8", "Q9", "Q10"],
|
4
|
+
"mapper": {
|
5
|
+
"A": {
|
6
|
+
"sources": ["inchikey"]
|
7
|
+
},
|
8
|
+
"B": {
|
9
|
+
"sources": ["molfile"]
|
10
|
+
},
|
11
|
+
"C": {
|
12
|
+
"sources": ["concentration"]
|
13
|
+
},
|
14
|
+
"G": {
|
15
|
+
"sources": ["solvent_volume"]
|
16
|
+
},
|
17
|
+
"H": {
|
18
|
+
"sources": ["elect_inchikey"]
|
19
|
+
},
|
20
|
+
"K": {
|
21
|
+
"sources": ["elect_concentration"]
|
22
|
+
},
|
23
|
+
"L": {
|
24
|
+
"sources": ["reference_internal"]
|
25
|
+
},
|
26
|
+
"N": {
|
27
|
+
"sources": ["scan_rate"]
|
28
|
+
},
|
29
|
+
"O": {
|
30
|
+
"sources": ["scan_number"]
|
31
|
+
},
|
32
|
+
"P": {
|
33
|
+
"sources": ["voltage_limit_one", "voltage_limit_two"],
|
34
|
+
"separator": ","
|
35
|
+
},
|
36
|
+
"R": {
|
37
|
+
"sources": ["atmosphere"]
|
38
|
+
},
|
39
|
+
"S": {
|
40
|
+
"sources": ["temperature"]
|
41
|
+
},
|
42
|
+
"T": {
|
43
|
+
"sources": ["condition"]
|
44
|
+
},
|
45
|
+
"U": {
|
46
|
+
"sources": ["we"]
|
47
|
+
},
|
48
|
+
"V": {
|
49
|
+
"sources": ["we_area"]
|
50
|
+
},
|
51
|
+
"W": {
|
52
|
+
"sources": ["ce"]
|
53
|
+
},
|
54
|
+
"X": {
|
55
|
+
"sources": ["re"]
|
56
|
+
},
|
57
|
+
"Q1": {
|
58
|
+
"sources": ["redox"],
|
59
|
+
"separator": ","
|
60
|
+
},
|
61
|
+
"Q2": {
|
62
|
+
"sources": ["solvent"]
|
63
|
+
},
|
64
|
+
"Q3": {
|
65
|
+
"sources": ["solvent_molfile"]
|
66
|
+
},
|
67
|
+
"Q4": {
|
68
|
+
"sources": ["elect_molfile"]
|
69
|
+
},
|
70
|
+
"Q5": {
|
71
|
+
"sources": ["elect_purity"]
|
72
|
+
},
|
73
|
+
"Q6": {
|
74
|
+
"sources": ["reference_internal_compound_molfile"]
|
75
|
+
},
|
76
|
+
"Q7": {
|
77
|
+
"sources": ["scan_direction"],
|
78
|
+
"separator": ","
|
79
|
+
},
|
80
|
+
"Q8": {
|
81
|
+
"sources": ["details"],
|
82
|
+
"separator": ","
|
83
|
+
},
|
84
|
+
"Q9": {
|
85
|
+
"sources": ["includes"],
|
86
|
+
"separator": ","
|
87
|
+
},
|
88
|
+
"Q10": {
|
89
|
+
"sources": ["base_page"],
|
90
|
+
"separator": ","
|
91
|
+
}
|
92
|
+
},
|
93
|
+
"source": {
|
94
|
+
"concentration": {
|
95
|
+
"title": "Analyte concentration [mM]",
|
96
|
+
"param": "sample_preparation.concentration",
|
97
|
+
"type": "dataset"
|
98
|
+
},
|
99
|
+
"temperature": {
|
100
|
+
"title": "Temperature [°C]",
|
101
|
+
"param": "set.temperature",
|
102
|
+
"type": "dataset"
|
103
|
+
},
|
104
|
+
"condition": {
|
105
|
+
"title": "Condition",
|
106
|
+
"param": "set.conditions",
|
107
|
+
"type": "dataset"
|
108
|
+
},
|
109
|
+
"scan_rate": {
|
110
|
+
"title": "Scan rate [mV/s]",
|
111
|
+
"param": "meas.scan_rate",
|
112
|
+
"type": "dataset"
|
113
|
+
},
|
114
|
+
"atmosphere": {
|
115
|
+
"title": "Gas",
|
116
|
+
"param": "set.atmosphere",
|
117
|
+
"type": "dataset"
|
118
|
+
},
|
119
|
+
"scan_number": {
|
120
|
+
"title": "Scan number",
|
121
|
+
"param": "meas.cycles",
|
122
|
+
"type": "dataset"
|
123
|
+
},
|
124
|
+
"we": {
|
125
|
+
"title": "Working electrode",
|
126
|
+
"param": "electrodes.working",
|
127
|
+
"type": "dataset"
|
128
|
+
},
|
129
|
+
"we_area": {
|
130
|
+
"title": "Working electrode surface area",
|
131
|
+
"param": "electrodes.working_area",
|
132
|
+
"type": "dataset"
|
133
|
+
},
|
134
|
+
"ce": {
|
135
|
+
"title": "Counter electrode",
|
136
|
+
"param": "electrodes.counter",
|
137
|
+
"type": "dataset"
|
138
|
+
},
|
139
|
+
"re": {
|
140
|
+
"title": "Reference electrode",
|
141
|
+
"param": "electrodes.reference",
|
142
|
+
"type": "dataset"
|
143
|
+
},
|
144
|
+
"voltage_limit_one": {
|
145
|
+
"title": "Potential window",
|
146
|
+
"param": "meas.voltage_limit_one",
|
147
|
+
"type": "dataset"
|
148
|
+
},
|
149
|
+
"voltage_limit_two": {
|
150
|
+
"title": "Potential window",
|
151
|
+
"param": "meas.voltage_limit_two",
|
152
|
+
"type": "dataset"
|
153
|
+
},
|
154
|
+
"reference_internal": {
|
155
|
+
"title": "Internal reference compound_inchikey",
|
156
|
+
"param": "meas.reference_internal",
|
157
|
+
"type": "dataset"
|
158
|
+
},
|
159
|
+
"elect_inchikey": {
|
160
|
+
"title": "Electrolyte_inchikey",
|
161
|
+
"param": "sample_preparation.salt",
|
162
|
+
"type": "dataset"
|
163
|
+
},
|
164
|
+
"elect_concentration": {
|
165
|
+
"title": "Electrolyte concentration [M]",
|
166
|
+
"param": "sample_preparation.concentration_salt",
|
167
|
+
"type": "dataset"
|
168
|
+
},
|
169
|
+
"solvent": {
|
170
|
+
"title": "Solvent A_inchikey",
|
171
|
+
"param": "sample_preparation.solvent",
|
172
|
+
"type": "dataset"
|
173
|
+
},
|
174
|
+
"solvent_volume": {
|
175
|
+
"title": "Solvent volume [ml]",
|
176
|
+
"param": "sample_preparation.amount_sol",
|
177
|
+
"type": "dataset"
|
178
|
+
},
|
179
|
+
"solvent_molfile": {
|
180
|
+
"title": "Solvent A_molfile",
|
181
|
+
"param": "n/a",
|
182
|
+
"type": "string"
|
183
|
+
},
|
184
|
+
"scan_direction": {
|
185
|
+
"title": "Scan direction",
|
186
|
+
"param": "n/a",
|
187
|
+
"type": "string"
|
188
|
+
},
|
189
|
+
"reference_internal_compound_molfile": {
|
190
|
+
"title": "Internal reference compound_molfile",
|
191
|
+
"param": "n/a",
|
192
|
+
"type": "string"
|
193
|
+
},
|
194
|
+
"elect_purity": {
|
195
|
+
"title": "Electrolyte purity [%]",
|
196
|
+
"param": "n/a",
|
197
|
+
"type": "string"
|
198
|
+
},
|
199
|
+
"redox": {
|
200
|
+
"title": "Redox-Potential",
|
201
|
+
"param": "n/a",
|
202
|
+
"type": "string"
|
203
|
+
},
|
204
|
+
"elect_molfile": {
|
205
|
+
"title": "Electrolyte_inchikey",
|
206
|
+
"param": "n/a",
|
207
|
+
"type": "string"
|
208
|
+
},
|
209
|
+
"inchikey": {
|
210
|
+
"title": "Analyte_inchikey",
|
211
|
+
"param": "inchikey",
|
212
|
+
"type": "molecule"
|
213
|
+
},
|
214
|
+
"molfile": {
|
215
|
+
"title": "Analyte_molfile",
|
216
|
+
"param": "molfile",
|
217
|
+
"type": "sample"
|
218
|
+
},
|
219
|
+
"details": {
|
220
|
+
"title": "Details",
|
221
|
+
"param": "n/a",
|
222
|
+
"type": "string"
|
223
|
+
},
|
224
|
+
"includes": {
|
225
|
+
"title": "Included",
|
226
|
+
"param": "n/a",
|
227
|
+
"type": "string"
|
228
|
+
},
|
229
|
+
"base_page": {
|
230
|
+
"title": "BasePageName",
|
231
|
+
"param": "n/a",
|
232
|
+
"type": "string"
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
{
|
2
|
+
"sourceMap": {
|
3
|
+
"sourceSelector": [
|
4
|
+
"parm",
|
5
|
+
"acqus",
|
6
|
+
"procs"
|
7
|
+
],
|
8
|
+
"acqus": {
|
9
|
+
"file": "acqus",
|
10
|
+
"parameters": [
|
11
|
+
"DATE",
|
12
|
+
"D1",
|
13
|
+
"INSTRUM",
|
14
|
+
"NS",
|
15
|
+
"NUC1",
|
16
|
+
"NUC2",
|
17
|
+
"PROBHD",
|
18
|
+
"PULPROG",
|
19
|
+
"SFO1",
|
20
|
+
"SFO2",
|
21
|
+
"SOLVENT",
|
22
|
+
"SW",
|
23
|
+
"TD",
|
24
|
+
"TE",
|
25
|
+
"TITLE"
|
26
|
+
]
|
27
|
+
},
|
28
|
+
"procs": {
|
29
|
+
"file": "pdata/1/procs",
|
30
|
+
"parameters": [
|
31
|
+
"SI",
|
32
|
+
"SF",
|
33
|
+
"WDW",
|
34
|
+
"LB",
|
35
|
+
"GB"
|
36
|
+
]
|
37
|
+
},
|
38
|
+
"parm": {
|
39
|
+
"file": "pdata/1/parm.txt",
|
40
|
+
"parameters": [
|
41
|
+
"Date_",
|
42
|
+
"Time",
|
43
|
+
"INSTRUM",
|
44
|
+
"PROBHD",
|
45
|
+
"SOLVENT",
|
46
|
+
"TE",
|
47
|
+
"NS",
|
48
|
+
"PULPROG",
|
49
|
+
"TD",
|
50
|
+
"D1",
|
51
|
+
"SF",
|
52
|
+
"SFO1",
|
53
|
+
"SFO2",
|
54
|
+
"NUC1",
|
55
|
+
"NUC2"
|
56
|
+
]
|
57
|
+
},
|
58
|
+
"parameters": {
|
59
|
+
"DATE": "general.date",
|
60
|
+
"D1": "set.done",
|
61
|
+
"INSTRUM": "instrument.instrument",
|
62
|
+
"NS": "set.ns",
|
63
|
+
"NUC1": "set.nucone",
|
64
|
+
"NUC2": "set.nuctwo",
|
65
|
+
"SF": "set.sf",
|
66
|
+
"SFO1": "set.sfoone",
|
67
|
+
"SFO2": "set.sfotwo",
|
68
|
+
"PROBHD": "equipment.probehead",
|
69
|
+
"PULPROG": "set.PULPROG",
|
70
|
+
"SOLVENT": "sample_preparation.solvent",
|
71
|
+
"TD": "set.td",
|
72
|
+
"TE": "set.temperature",
|
73
|
+
"TITLE": "software.Name",
|
74
|
+
"Version": "software.Version",
|
75
|
+
"Time": "general.time"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'labimotion/utils/utils'
|
4
|
+
require 'labimotion/version'
|
5
|
+
|
6
|
+
module Labimotion
|
7
|
+
class DatasetBuilder
|
8
|
+
def self.build(container, content)
|
9
|
+
return unless valid_input?(container, content)
|
10
|
+
|
11
|
+
create_dataset_with_metadata(container, content)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.valid_input?(container, content)
|
17
|
+
container.present? &&
|
18
|
+
content.present? &&
|
19
|
+
content[:ols].present? &&
|
20
|
+
content[:metadata].present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create_dataset_with_metadata(container, content)
|
24
|
+
klass = find_dataset_klass(content[:ols])
|
25
|
+
return unless klass
|
26
|
+
|
27
|
+
dataset = create_dataset(container, klass)
|
28
|
+
build_result(dataset, content)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_dataset_klass(ols_term_id)
|
32
|
+
Labimotion::DatasetKlass.find_by(ols_term_id: ols_term_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.create_dataset(container, klass)
|
36
|
+
uuid = SecureRandom.uuid
|
37
|
+
props = prepare_properties(klass, uuid)
|
38
|
+
|
39
|
+
Labimotion::Dataset.create!(
|
40
|
+
uuid: uuid,
|
41
|
+
dataset_klass_id: klass.id,
|
42
|
+
element_type: 'Container',
|
43
|
+
element_id: container.id,
|
44
|
+
properties: props,
|
45
|
+
properties_release: klass.properties_release,
|
46
|
+
klass_uuid: klass.uuid
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.prepare_properties(klass, uuid)
|
51
|
+
props = klass.properties_release
|
52
|
+
props['uuid'] = uuid
|
53
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
54
|
+
props['klass'] = 'Dataset'
|
55
|
+
props
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.build_result(dataset, content)
|
59
|
+
{
|
60
|
+
dataset: dataset,
|
61
|
+
metadata: content[:metadata],
|
62
|
+
ols: content[:ols],
|
63
|
+
parameters: content[:parameters]
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
private_class_method :valid_input?, :create_dataset_with_metadata, :find_dataset_klass, :create_dataset,
|
68
|
+
:prepare_properties, :build_result
|
69
|
+
end
|
70
|
+
end
|
@@ -8,47 +8,190 @@ module Labimotion
|
|
8
8
|
DEFAULT_ROW_WIDTH = 100
|
9
9
|
DEFAULT_ROW_HEIGHT = 20
|
10
10
|
|
11
|
-
def initialize(
|
11
|
+
def initialize(id)
|
12
12
|
@xfile = Axlsx::Package.new
|
13
|
-
@file_extension = 'xlsx'
|
14
13
|
@xfile.workbook.styles.fonts.first.name = 'Calibri'
|
14
|
+
@file_extension = 'xlsx'
|
15
|
+
|
16
|
+
@id = id
|
17
|
+
@dataset = Labimotion::Dataset.find_by(element_id: @id, element_type: 'Container')
|
18
|
+
return if @dataset.nil?
|
19
|
+
|
20
|
+
@klass = @dataset.dataset_klass
|
21
|
+
@ols_term_id = @klass.ols_term_id
|
22
|
+
@label = @klass.label
|
23
|
+
@analysis = @dataset&.element&.parent
|
24
|
+
@element = @analysis&.root&.containable if @analysis.present?
|
25
|
+
@element_type = @element.class.name if @element.present?
|
26
|
+
end
|
27
|
+
|
28
|
+
def read
|
29
|
+
@xfile.to_stream.read
|
15
30
|
end
|
16
31
|
|
17
|
-
def res_name
|
18
|
-
element_name = Container.find(id)&.root_element&.short_label
|
19
|
-
ols = ols_name
|
32
|
+
def res_name
|
33
|
+
element_name = Container.find(@id)&.root_element&.short_label
|
34
|
+
ols = ols_name
|
20
35
|
"#{element_name}_#{ols.gsub(' ', '_')}.xlsx"
|
21
36
|
rescue StandardError => e
|
22
37
|
Labimotion.log_exception(e)
|
23
38
|
end
|
24
39
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
40
|
+
def spectra
|
41
|
+
name_mapping = []
|
42
|
+
## gds = Labimotion::Dataset.find_by(element_id: id, element_type: 'Container')
|
43
|
+
cds = Container.find(@id)
|
44
|
+
cds_csv = cds.attachments.where(aasm_state: 'csv').order(:filename)
|
45
|
+
csv_length = cds_csv.length
|
46
|
+
return if csv_length.zero?
|
47
|
+
|
48
|
+
cds_csv.each_with_index do |att, idx|
|
49
|
+
sheet_name = "Sheet#{idx+1}"
|
50
|
+
sheet = @xfile.workbook.add_worksheet(name: sheet_name)
|
51
|
+
name_mapping.push([sheet_name, att.filename])
|
52
|
+
File.open(att.attachment_url) do |fi|
|
53
|
+
fi.each_line do |line|
|
54
|
+
sheet.add_row(line.split(','))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return unless name_mapping.length > 1
|
59
|
+
|
60
|
+
first_sheet = @xfile.workbook.worksheets&.first
|
61
|
+
header_style = first_sheet&.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
|
62
|
+
first_sheet&.add_row(['Sheet name', 'File name'], style: header_style)
|
63
|
+
name_mapping&.each do |mapping|
|
64
|
+
next if mapping.length < 2
|
65
|
+
|
66
|
+
@xfile.workbook.worksheets&.first&.add_row([mapping[0].to_s, mapping[1].to_s])
|
67
|
+
end
|
68
|
+
rescue StandardError => e
|
69
|
+
Labimotion.log_exception(e)
|
70
|
+
end
|
71
|
+
|
72
|
+
def export
|
73
|
+
return if @dataset.nil? || @analysis.nil? || @element.nil?
|
74
|
+
|
75
|
+
description
|
76
|
+
dataset_info
|
77
|
+
# element_info
|
78
|
+
chemwiki_info
|
79
|
+
rescue StandardError => e
|
80
|
+
Labimotion.log_exception(e)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def chemwiki_info
|
86
|
+
config = Labimotion::MapperUtils.load_config(File.read(Constants::Mapper::WIKI_CONFIG))
|
87
|
+
return if config.nil? || config[@ols_term_id].nil?
|
28
88
|
|
29
|
-
|
89
|
+
sheet = @xfile.workbook.add_worksheet(name: 'ChemWiki')
|
90
|
+
map_index = config.dig(@ols_term_id, 'index')
|
91
|
+
map_mapper = config.dig(@ols_term_id, 'mapper')
|
92
|
+
map_source = config.dig(@ols_term_id, 'source')
|
30
93
|
|
31
|
-
|
32
|
-
name = match && match.length > 1 ? match[1] : name
|
94
|
+
return if map_index.nil? || map_mapper.nil? || map_source.nil?
|
33
95
|
|
34
|
-
|
35
|
-
|
96
|
+
return unless map_index.is_a?(Array) && map_mapper.is_a?(Hash) && map_source.is_a?(Hash)
|
97
|
+
|
98
|
+
# sheet.column_info.each { |col| col.width = map_width }
|
99
|
+
|
100
|
+
array_header = []
|
101
|
+
array_data = []
|
102
|
+
map_index.each do |key|
|
103
|
+
mapper = map_mapper.dig(key)
|
104
|
+
next if mapper.nil? || mapper['sources'].nil? || !mapper.is_a?(Hash)
|
105
|
+
|
106
|
+
col_header = ''
|
107
|
+
col_value = ''
|
108
|
+
mapper['sources'].each_with_index do |source_key, idx|
|
109
|
+
source = map_source&.dig(source_key)
|
110
|
+
next if source.nil? || source['title'].nil?
|
111
|
+
|
112
|
+
col_header = source['title']
|
113
|
+
|
114
|
+
if col_value.present?
|
115
|
+
col_value += (mapper['separator'] || '') + source_data(source)
|
116
|
+
else
|
117
|
+
col_value = source_data(source)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
array_header.push(col_header || '')
|
121
|
+
array_data.push(col_value || '')
|
122
|
+
end
|
123
|
+
sheet.add_row(array_header)
|
124
|
+
sheet.add_row(array_data)
|
125
|
+
rescue StandardError => e
|
126
|
+
Labimotion.log_exception(e)
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def conv_value(field, properties)
|
131
|
+
return '' if field.nil?
|
132
|
+
|
133
|
+
case field['type']
|
134
|
+
when 'select'
|
135
|
+
Labimotion::Utils.find_options_val(field, properties) || field['value']
|
136
|
+
else
|
137
|
+
field['value']
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def source_data(source)
|
142
|
+
param = source['param']
|
143
|
+
return '' if param.nil? || source['type'].nil?
|
144
|
+
|
145
|
+
val = case source['type']
|
146
|
+
when 'string'
|
147
|
+
param
|
148
|
+
when 'sample'
|
149
|
+
@element.send(param) if @element.respond_to?(param)
|
150
|
+
when 'molecule'
|
151
|
+
@element.molecule.send(param) if @element_type == 'Sample' && @element&.molecule&.respond_to?(param)
|
152
|
+
when 'dataset'
|
153
|
+
field = Labimotion::Utils.find_field(@dataset.properties, param)
|
154
|
+
# (field && field['value']) || ''
|
155
|
+
conv_value(field, @dataset.properties)
|
156
|
+
end
|
157
|
+
val || ''
|
158
|
+
rescue StandardError => e
|
159
|
+
Labimotion.log_exception(e)
|
160
|
+
end
|
161
|
+
|
162
|
+
def element_info
|
163
|
+
if @element.class.name == 'Sample'
|
164
|
+
sheet = @xfile.workbook.add_worksheet(name: 'Element')
|
165
|
+
sheet.add_row(['inchikey', @element.molecule_inchikey])
|
166
|
+
sheet.add_row(['molfile', @element.molfile])
|
167
|
+
end
|
168
|
+
rescue StandardError => e
|
169
|
+
Labimotion.log_exception(e)
|
170
|
+
end
|
171
|
+
|
172
|
+
def ols_name
|
173
|
+
#name = @dataset.dataset_klass.label
|
174
|
+
|
175
|
+
match = @label.match(/\((.*?)\)/)
|
176
|
+
name = match && match.length > 1 ? match[1] : @label
|
177
|
+
|
178
|
+
name = '1H NMR' if @ols_term_id == 'CHMO:0000593'
|
179
|
+
name = '13C NMR' if @ols_term_id == 'CHMO:0000595'
|
36
180
|
name.slice(0, 26)
|
37
181
|
rescue StandardError => e
|
38
182
|
Labimotion.log_exception(e)
|
39
183
|
'ols_name'
|
40
184
|
end
|
41
185
|
|
42
|
-
def description
|
43
|
-
wb = @xfile.workbook
|
186
|
+
def description
|
44
187
|
sheet = @xfile.workbook.add_worksheet(name: 'Description')
|
45
188
|
header_style = sheet.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
|
46
|
-
sheet.add_row(['File name', res_name
|
189
|
+
sheet.add_row(['File name', res_name])
|
47
190
|
sheet.add_row(['Time', Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")] )
|
48
191
|
sheet.add_row(['(This file is automatically generated by the system.)'])
|
49
192
|
sheet.add_row([''])
|
50
193
|
sheet.add_row([''])
|
51
|
-
sheet.add_row(['Fields description of sheet:' +
|
194
|
+
sheet.add_row(['Fields description of sheet:' + @dataset.dataset_klass.label])
|
52
195
|
sheet.add_row(['Fields', 'Field description'], style: header_style)
|
53
196
|
sheet.add_row(['Layer Label', 'The label of the layer'])
|
54
197
|
sheet.add_row(['Field Label', 'The label of the field'])
|
@@ -65,24 +208,18 @@ module Labimotion
|
|
65
208
|
Labimotion.log_exception(e)
|
66
209
|
end
|
67
210
|
|
68
|
-
def
|
69
|
-
|
70
|
-
return if ds.nil?
|
71
|
-
|
72
|
-
description(ds, id)
|
73
|
-
|
74
|
-
wb = @xfile.workbook
|
75
|
-
name = ols_name(id)
|
211
|
+
def dataset_info
|
212
|
+
name = ols_name
|
76
213
|
return if name.nil?
|
77
214
|
|
78
215
|
sheet = @xfile.workbook.add_worksheet(name: name)
|
79
|
-
sheet.add_row([
|
216
|
+
sheet.add_row([@dataset.dataset_klass.label])
|
80
217
|
header_style = sheet.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
|
81
218
|
layer_style = sheet.styles.add_style(b: true, bg_color: 'CEECF5')
|
82
219
|
sheet.add_row(header, style: header_style)
|
83
220
|
|
84
|
-
layers =
|
85
|
-
options =
|
221
|
+
layers = @dataset.properties[Labimotion::Prop::LAYERS] || {}
|
222
|
+
options = @dataset.properties[Labimotion::Prop::SEL_OPTIONS]
|
86
223
|
layer_keys = layers.keys.sort_by { |key| layers[key]['position'] }
|
87
224
|
layer_keys.each do |key|
|
88
225
|
layer = layers[key]
|
@@ -116,8 +253,6 @@ module Labimotion
|
|
116
253
|
end
|
117
254
|
sheet.rows.last.cells[2].value = show_value
|
118
255
|
sheet.rows.last.cells[8].value = field['system'] || field['device']
|
119
|
-
|
120
|
-
|
121
256
|
end
|
122
257
|
# sheet.column_widths nil, nil, nil, nil, 0, 0, 0, 0, 0
|
123
258
|
end
|
@@ -136,45 +271,9 @@ module Labimotion
|
|
136
271
|
field['value']
|
137
272
|
end
|
138
273
|
|
139
|
-
def spectra(id)
|
140
|
-
name_mapping = []
|
141
|
-
wb = @xfile.workbook
|
142
|
-
gds = Labimotion::Dataset.find_by(element_id: id, element_type: 'Container')
|
143
|
-
cds = Container.find(id)
|
144
|
-
cds_csv = cds.attachments.where(aasm_state: 'csv').order(:filename)
|
145
|
-
csv_length = cds_csv.length
|
146
|
-
return if csv_length.zero?
|
147
|
-
cds_csv.each_with_index do |att, idx|
|
148
|
-
sheet_name = "Sheet#{idx+1}"
|
149
|
-
sheet = @xfile.workbook.add_worksheet(name: sheet_name)
|
150
|
-
name_mapping.push([sheet_name, att.filename])
|
151
|
-
File.open(att.attachment_url) do |fi|
|
152
|
-
fi.each_line do |line|
|
153
|
-
sheet.add_row(line.split(','))
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
if name_mapping.length > 1
|
159
|
-
first_sheet = @xfile.workbook.worksheets&.first
|
160
|
-
header_style = first_sheet&.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
|
161
|
-
first_sheet&.add_row(['Sheet name', 'File name'], style: header_style)
|
162
|
-
name_mapping&.each do |mapping|
|
163
|
-
next if mapping.length < 2
|
164
|
-
|
165
|
-
@xfile.workbook.worksheets&.first&.add_row([mapping[0].to_s, mapping[1].to_s])
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
274
|
def header
|
172
275
|
['Layer Label', 'Field Label', 'Value', 'Unit', 'Name', 'Type', 'Source?', 'Source identifier', 'Source data', 'Ontology', 'Ontology Label', 'iri'].freeze
|
173
276
|
end
|
174
277
|
|
175
|
-
def read
|
176
|
-
@xfile.to_stream.read
|
177
|
-
end
|
178
|
-
|
179
278
|
end
|
180
279
|
end
|