labimotion 2.0.0 → 2.0.1

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labimotion/apis/labimotion_api.rb +3 -1
  3. data/lib/labimotion/apis/labimotion_hub_api.rb +83 -10
  4. data/lib/labimotion/apis/standard_api.rb +2 -1
  5. data/lib/labimotion/apis/standard_layer_api.rb +17 -4
  6. data/lib/labimotion/apis/vocabulary_api.rb +20 -6
  7. data/lib/labimotion/constants.rb +7 -0
  8. data/lib/labimotion/entities/dataset_entity.rb +1 -0
  9. data/lib/labimotion/entities/element_entity.rb +0 -1
  10. data/lib/labimotion/entities/klass_revision_entity.rb +5 -9
  11. data/lib/labimotion/entities/properties_entity.rb +41 -102
  12. data/lib/labimotion/entities/segment_entity.rb +2 -0
  13. data/lib/labimotion/entities/vocabulary_entity.rb +12 -3
  14. data/lib/labimotion/helpers/element_helpers.rb +1 -2
  15. data/lib/labimotion/helpers/generic_helpers.rb +1 -6
  16. data/lib/labimotion/helpers/param_helpers.rb +16 -0
  17. data/lib/labimotion/libs/converter.rb +1 -0
  18. data/lib/labimotion/libs/data/layer/StdDataset.json +212 -0
  19. data/lib/labimotion/libs/data/vocab/System.json +1 -1
  20. data/lib/labimotion/libs/export_dataset.rb +98 -343
  21. data/lib/labimotion/libs/nmr_mapper.rb +247 -204
  22. data/lib/labimotion/libs/template_hub.rb +28 -10
  23. data/lib/labimotion/models/concerns/generic_klass_revisions.rb +0 -1
  24. data/lib/labimotion/models/concerns/generic_revisions.rb +0 -3
  25. data/lib/labimotion/models/concerns/klass_revision.rb +23 -0
  26. data/lib/labimotion/models/dataset_klasses_revision.rb +4 -1
  27. data/lib/labimotion/models/element.rb +0 -3
  28. data/lib/labimotion/models/element_klasses_revision.rb +3 -2
  29. data/lib/labimotion/models/segment_klasses_revision.rb +4 -1
  30. data/lib/labimotion/models/template_submission.rb +52 -0
  31. data/lib/labimotion/utils/utils.rb +0 -21
  32. data/lib/labimotion/version.rb +1 -1
  33. data/lib/labimotion.rb +3 -3
  34. metadata +5 -6
  35. data/lib/labimotion/libs/data/mapper/Chemwiki.json +0 -236
  36. data/lib/labimotion/libs/data/mapper/Source.json +0 -78
  37. data/lib/labimotion/libs/dataset_builder.rb +0 -70
  38. data/lib/labimotion/utils/mapper_utils.rb +0 -169
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labimotion/models/concerns/klass_revision'
4
+
3
5
  module Labimotion
4
6
  class SegmentKlassesRevision < ApplicationRecord
5
7
  acts_as_paranoid
6
8
  self.table_name = :segment_klasses_revisions
7
- has_one :segment_klass, class_name: 'Labimotion::SegmentKlass'
9
+ include KlassRevision
10
+ belongs_to :segment_klass, class_name: 'Labimotion::SegmentKlass'
8
11
  end
9
12
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # == Schema Information
4
+ #
5
+ # Table name: template_submissions
6
+ #
7
+ # id :bigint not null, primary key
8
+ # template_klass :string not null
9
+ # template :jsonb not null, default: {}
10
+ # metadata :jsonb not null, default: {}
11
+ # origin :string not null
12
+ # state :integer not null, default: 0
13
+ # created_at :datetime not null
14
+ # updated_at :datetime
15
+ # deleted_at :datetime
16
+ #
17
+ # Indexes
18
+ #
19
+ # idx_template_submissions_template (template) USING gin
20
+ # idx_template_submissions_metadata (metadata) USING gin
21
+ #
22
+
23
+ module Labimotion
24
+ class TemplateSubmission < ApplicationRecord
25
+ acts_as_paranoid
26
+
27
+ # State enum
28
+ enum state: {
29
+ pending: 0,
30
+ approved: 1,
31
+ rejected: 2,
32
+ released: 3
33
+ }
34
+
35
+ # Validations
36
+ validates :template_klass, presence: true
37
+ validates :template, presence: true
38
+ validates :metadata, presence: true
39
+ validates :origin, presence: true
40
+
41
+ # Scopes
42
+ scope :by_template_klass, ->(klass) { where(template_klass: klass) }
43
+ scope :by_state, ->(state) { where(state: state) }
44
+ scope :by_origin, ->(origin) { where(origin: origin) }
45
+ scope :by_email, ->(email) { where("metadata->'submission'->>'email' = ?", email) }
46
+ scope :by_contact_email, ->(email) { where("metadata->'submission'->>'contact_email' = ?", email) }
47
+ scope :by_any_email, lambda { |email|
48
+ where("metadata->'submission'->>'email' = ? OR metadata->'submission'->>'contact_email' = ?", email, email)
49
+ }
50
+ scope :recent, -> { order(created_at: :desc) }
51
+ end
52
+ end
@@ -80,27 +80,6 @@ module Labimotion
80
80
  current_version
81
81
  end
82
82
 
83
- def self.find_field(properties, field_path, separator = '.')
84
- return if properties.nil? || field_path.nil?
85
-
86
- layer_name, field_name = field_path.split(separator)
87
- fields = properties.dig(Labimotion::Prop::LAYERS, layer_name, Labimotion::Prop::FIELDS)
88
- return unless fields
89
-
90
- fields.find { |f| f['field'] == field_name }
91
- end
92
-
93
- def self.find_options_val(field, properties)
94
- return if field.nil? || properties.nil? || field['option_layers'].nil? || field['value'].nil?
95
-
96
- option_layers = properties.dig(Labimotion::Prop::SEL_OPTIONS, field['option_layers'])
97
- options = option_layers && option_layers['options']
98
- return if options.nil?
99
-
100
- sel_option = options.find { |o| o['key'] == field['value'] }
101
- sel_option && sel_option['label']
102
- end
103
-
104
83
  def self.pkg(pkg)
105
84
  pkg = {} if pkg.nil?
106
85
  pkg['eln'] = Chemotion::Application.config.version
@@ -2,5 +2,5 @@
2
2
 
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
- VERSION = '2.0.0'
5
+ VERSION = '2.0.1'
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # In your_gem_name.rb or main Ruby file
2
2
  module Labimotion
3
+
3
4
  autoload :CONF, 'labimotion/conf'
4
5
  autoload :VERSION, 'labimotion/version'
5
- autoload :Constants, 'labimotion/constants'
6
6
 
7
7
  def self.logger
8
8
  @@labimotion_logger ||= Logger.new(Rails.root.join('log/labimotion.log')) # rubocop:disable Style/ClassVars
@@ -13,7 +13,6 @@ module Labimotion
13
13
  Labimotion.logger.error(exception.backtrace.join("\n"))
14
14
  end
15
15
 
16
- autoload :MapperUtils, 'labimotion/utils/mapper_utils'
17
16
  autoload :Utils, 'labimotion/utils/utils'
18
17
 
19
18
  ######## APIs
@@ -63,7 +62,6 @@ module Labimotion
63
62
 
64
63
  ######## Libs
65
64
  autoload :Converter, 'labimotion/libs/converter'
66
- autoload :DatasetBuilder, 'labimotion/libs/dataset_builder'
67
65
  autoload :NmrMapper, 'labimotion/libs/nmr_mapper'
68
66
  autoload :NmrMapperRepo, 'labimotion/libs/nmr_mapper_repo' ## for Chemotion Repository
69
67
  autoload :TemplateHub, 'labimotion/libs/template_hub'
@@ -116,4 +114,6 @@ module Labimotion
116
114
  autoload :Datasetable, 'labimotion/models/concerns/datasetable'
117
115
  autoload :AttachmentConverter, 'labimotion/models/concerns/attachment_converter.rb'
118
116
  autoload :LinkedProperties, 'labimotion/models/concerns/linked_properties'
117
+
118
+
119
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labimotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chia-Lin Lin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-03-25 00:00:00.000000000 Z
12
+ date: 2025-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -76,11 +76,9 @@ files:
76
76
  - lib/labimotion/helpers/vocabulary_helpers.rb
77
77
  - lib/labimotion/libs/attachment_handler.rb
78
78
  - lib/labimotion/libs/converter.rb
79
- - lib/labimotion/libs/data/mapper/Chemwiki.json
80
- - lib/labimotion/libs/data/mapper/Source.json
79
+ - lib/labimotion/libs/data/layer/StdDataset.json
81
80
  - lib/labimotion/libs/data/vocab/Standard.json
82
81
  - lib/labimotion/libs/data/vocab/System.json
83
- - lib/labimotion/libs/dataset_builder.rb
84
82
  - lib/labimotion/libs/export_dataset.rb
85
83
  - lib/labimotion/libs/export_element.rb
86
84
  - lib/labimotion/libs/nmr_mapper.rb
@@ -93,6 +91,7 @@ files:
93
91
  - lib/labimotion/models/concerns/datasetable.rb
94
92
  - lib/labimotion/models/concerns/generic_klass_revisions.rb
95
93
  - lib/labimotion/models/concerns/generic_revisions.rb
94
+ - lib/labimotion/models/concerns/klass_revision.rb
96
95
  - lib/labimotion/models/concerns/linked_properties.rb
97
96
  - lib/labimotion/models/concerns/segmentable.rb
98
97
  - lib/labimotion/models/concerns/workflow.rb
@@ -113,12 +112,12 @@ files:
113
112
  - lib/labimotion/models/segments_revision.rb
114
113
  - lib/labimotion/models/std_layer.rb
115
114
  - lib/labimotion/models/std_layers_revision.rb
115
+ - lib/labimotion/models/template_submission.rb
116
116
  - lib/labimotion/models/vocabulary.rb
117
117
  - lib/labimotion/utils/con_state.rb
118
118
  - lib/labimotion/utils/export_utils.rb
119
119
  - lib/labimotion/utils/field_type.rb
120
120
  - lib/labimotion/utils/import_utils.rb
121
- - lib/labimotion/utils/mapper_utils.rb
122
121
  - lib/labimotion/utils/prop.rb
123
122
  - lib/labimotion/utils/search.rb
124
123
  - lib/labimotion/utils/serializer.rb
@@ -1,236 +0,0 @@
1
- {
2
- "CHMO:0000025": {
3
- "index": ["A", "B", "C", "D", "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
- "D": {
15
- "sources": ["redox"],
16
- "separator": ","
17
- },
18
- "G": {
19
- "sources": ["solvent_volume"]
20
- },
21
- "H": {
22
- "sources": ["elect_inchikey"]
23
- },
24
- "K": {
25
- "sources": ["elect_concentration"]
26
- },
27
- "L": {
28
- "sources": ["reference_internal"]
29
- },
30
- "N": {
31
- "sources": ["scan_rate"]
32
- },
33
- "O": {
34
- "sources": ["scan_number"]
35
- },
36
- "P": {
37
- "sources": ["voltage_limit_one", "voltage_limit_two"],
38
- "separator": ","
39
- },
40
- "R": {
41
- "sources": ["atmosphere"]
42
- },
43
- "S": {
44
- "sources": ["temperature"]
45
- },
46
- "T": {
47
- "sources": ["condition"]
48
- },
49
- "U": {
50
- "sources": ["we"]
51
- },
52
- "V": {
53
- "sources": ["we_area"]
54
- },
55
- "W": {
56
- "sources": ["ce"]
57
- },
58
- "X": {
59
- "sources": ["re"]
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": 6,
202
- "type": "spc"
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
- }
@@ -1,78 +0,0 @@
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
- }
@@ -1,70 +0,0 @@
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