labimotion 1.0.19 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81bff41ed125305e39e96062f4789d51afca7736e5a1f3d20b1168ed018dac49
4
- data.tar.gz: e755bb4cb53c46e133d4c4f6a79400ec9bf5abbefb6db708027d4d6f8a36232a
3
+ metadata.gz: 0c374697be6dd59785865b85ea34a92de6d9e87d8d0fe9d5416b5b58c5f18f11
4
+ data.tar.gz: 11b8842141477f92d08e50c0fc55c29f82c7a098dc8c08ed9be610b9d037c0ae
5
5
  SHA512:
6
- metadata.gz: fa3fbcc006bd09ac31ed3086929fe16778aaf580ad855696bca1c4a42c21b97a53d2ee4c267fbb088dad89f70063d306c526789b31f5aaa79dd777296766d623
7
- data.tar.gz: baf3d2120168d03d921a4caeeb95ea8214fd7184c50736158176666564cf223b91b7dae5df4f1168c4f93d68dcc604bd0caf70a33d4303fd3233e65a2152281e
6
+ metadata.gz: 0ebbb6edd334c5f13bbf3196cc7f5b56510019925f516abb35404b0943c9546e21fd16227ffebe5365955d9202b7201b795fac019c72050d0a59f902d4aa70ca
7
+ data.tar.gz: eded51a9e589660b0a6dcf20187eb715e946448fa9a047263176212c0136d0a648c9015d50a3de0ae06ea39ba6942fcfc23e00b085aecaa583e8faa57e67f1ee
@@ -19,7 +19,7 @@ module Labimotion
19
19
  get do
20
20
  list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
21
21
  list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
22
- entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props])
22
+ entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props], root: 'list')
23
23
  rescue StandardError => e
24
24
  Labimotion.log_exception(e, current_user)
25
25
  []
@@ -20,7 +20,10 @@ module Labimotion
20
20
 
21
21
  def self.process_ds(id, current_user = {})
22
22
  att = Attachment.find_by(id: id, con_state: Labimotion::ConState::CONVERTED)
23
- return if att.nil? || att.attachable_id.nil? || att.attachable_type != 'Container'
23
+ return if att.nil? || att.attachable_id.nil? || att.attachable_type != 'Container' || att.filename.split('.')&.last != 'zip'
24
+
25
+ eln_ds = Container.find_by(id: att.attachable_id, container_type: 'dataset')
26
+ return if eln_ds.nil? || eln_ds.parent.nil? || eln_ds.parent&.container_type != 'analysis'
24
27
 
25
28
  dsr = []
26
29
  ols = nil
@@ -40,6 +40,8 @@ module Labimotion
40
40
  header_style = sheet.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
41
41
  sheet.add_row(['File name', res_name(id)])
42
42
  sheet.add_row(['Time', Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")] )
43
+ sheet.add_row(['(This file is automatically generated by the system.)'])
44
+ sheet.add_row([''])
43
45
  sheet.add_row([''])
44
46
  sheet.add_row(['Fields description of sheet:' + ds.dataset_klass.label])
45
47
  sheet.add_row(['Fields', 'Field description'], style: header_style)
@@ -49,13 +51,11 @@ module Labimotion
49
51
  sheet.add_row(['Unit', 'The unit of the field'])
50
52
  sheet.add_row(['Name', 'The key of the field, can be used to identify the field'])
51
53
  sheet.add_row(['Type', 'The type of the field'])
52
- sheet.add_row(['From device?', '[Yes] if the field is from the device, [No] if the field is manually entered by the user, [SYS] if the field is automatically generated by the system'])
53
- sheet.add_row(['Device source', 'The source tag of the device file, available only if the ontology term is 1H NMR or 13C NMR'])
54
- sheet.add_row(['Device data', 'The original device data, can not be changed after data uploaded'])
55
- sheet.add_row([''])
54
+ sheet.add_row(['Source?', '[Device] from device, [Chemotion] from Chemotion'])
55
+ sheet.add_row(['Source identifier', 'The source identifier'])
56
+ sheet.add_row(['Source data', 'The data from Device or Chemotion, cannot be modified once a generic dataset is created'])
56
57
  sheet.add_row([''])
57
58
  sheet.add_row([''])
58
- sheet.add_row(['', '(This file is automatically generated by the system.)'])
59
59
  end
60
60
 
61
61
  def export(id)
@@ -84,29 +84,41 @@ module Labimotion
84
84
  next if field['type'] == 'dummy'
85
85
 
86
86
  type = field['type']
87
- from_device = field['device'].present? ? 'Yes' : 'No'
88
- from_device = field['system'].present? ? 'SYS' : from_device
87
+ from_device = field['device'].present? ? 'Device' : ''
88
+ from_device = field['system'].present? ? 'Chemotion' : from_device
89
89
  type = "#{field['type']}-#{field['option_layers']}" if field['type'] == 'select' || field['type'] == 'system-defined'
90
90
 
91
91
  show_value = field['value'] =~ /\A\d+,\d+\z/ ? field['value']&.gsub(',', '.') : field['value']
92
- sheet.add_row([' ', field['label'], show_value, field['value_system'], field['field'], type, from_device, field['dkey'], field['system'] || field['device']].freeze)
92
+ sheet.add_row([' ', field['label'], nil, field['value_system'], field['field'], type, from_device, field['dkey'], nil].freeze)
93
+
94
+ if %w[system-defined integer].include? field['type']
95
+ sheet.rows.last.cells[2].type = :integer
96
+ sheet.rows.last.cells[8].type = :integer
97
+ else
98
+ sheet.rows.last.cells[2].type = :string
99
+ sheet.rows.last.cells[8].type = :string
100
+ end
101
+ sheet.rows.last.cells[2].value = show_value
102
+ sheet.rows.last.cells[8].value = field['system'] || field['device']
103
+
104
+
93
105
  end
94
106
  # sheet.column_widths nil, nil, nil, nil, 0, 0, 0, 0, 0
95
107
  end
96
108
  end
97
109
 
98
110
  def spectra(id)
111
+ name_mapping = []
99
112
  wb = @xfile.workbook
100
113
  gds = Labimotion::Dataset.find_by(element_id: id, element_type: 'Container')
101
114
  cds = Container.find(id)
102
- cds_csv = cds.attachments.where(aasm_state: 'csv')
115
+ cds_csv = cds.attachments.where(aasm_state: 'csv').order(:filename)
103
116
  csv_length = cds_csv.length
104
117
  return if csv_length.zero?
105
118
  cds_csv.each_with_index do |att, idx|
106
- name = File.basename(att.filename, '.csv')
107
- name = name.slice(0, (25 - csv_length.to_s.length - 1))
108
- sheet_name = "#{name}_#{idx}"
119
+ sheet_name = "Sheet#{idx+1}"
109
120
  sheet = @xfile.workbook.add_worksheet(name: sheet_name)
121
+ name_mapping.push([sheet_name, att.filename])
110
122
 
111
123
  if Labimotion::IS_RAILS5 == true
112
124
  File.open(att.store.path) do |fi|
@@ -122,10 +134,22 @@ module Labimotion
122
134
  end
123
135
  end
124
136
  end
137
+
138
+ if name_mapping.length > 1
139
+ first_sheet = @xfile.workbook.worksheets&.first
140
+ header_style = first_sheet&.styles.add_style(sz: 12, fg_color: 'FFFFFF', bg_color: '00008B', border: { style: :thick, color: 'FF777777', edges: [:bottom] })
141
+ first_sheet&.add_row(['Sheet name', 'File name'], style: header_style)
142
+ name_mapping&.each do |mapping|
143
+ next if mapping.length < 2
144
+
145
+ @xfile.workbook.worksheets&.first&.add_row([mapping[0].to_s, mapping[1].to_s])
146
+ end
147
+ end
148
+
125
149
  end
126
150
 
127
151
  def header
128
- ['Layer Label', 'Field Label', 'Value', 'Unit', 'Name', 'Type', 'from device?', 'Device source', 'Device data'].freeze
152
+ ['Layer Label', 'Field Label', 'Value', 'Unit', 'Name', 'Type', 'Source?', 'Source identifier', 'Source data'].freeze
129
153
  end
130
154
 
131
155
  def read
@@ -10,8 +10,12 @@ module Labimotion
10
10
  att = Attachment.find_by(id: id, con_state: Labimotion::ConState::NMR)
11
11
  return if att.nil?
12
12
 
13
- content = is_brucker_binary(id)
14
- if content.nil?
13
+ result = is_brucker_binary(id)
14
+ if result[:is_bagit] == true
15
+ att.update_column(:con_state, Labimotion::ConState::CONVERTED)
16
+ Labimotion::Converter.metadata(id)
17
+ Labimotion::ConState::COMPLETED
18
+ elsif result[:metadata] == nil
15
19
  Labimotion::ConState::NONE
16
20
  else
17
21
  data = process(att, id, content)
@@ -29,7 +33,9 @@ module Labimotion
29
33
  zip_file.each do |entry|
30
34
  if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
31
35
  metadata = entry.get_input_stream.read.force_encoding('UTF-8')
32
- return metadata
36
+ return { is_bagit: false, metadata: metadata }
37
+ elsif entry.name.include?('metadata/') && entry.name.include?('converter.json')
38
+ return { is_bagit: true, metadata: nil }
33
39
  end
34
40
  end
35
41
  end
@@ -39,13 +45,15 @@ module Labimotion
39
45
  zip_file.each do |entry|
40
46
  if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
41
47
  metadata = entry.get_input_stream.read.force_encoding('UTF-8')
42
- return metadata
48
+ return { is_bagit: false, metadata: metadata }
49
+ elsif entry.name.include?('metadata/') && entry.name.include?('converter.json')
50
+ return { is_bagit: true, metadata: nil }
43
51
  end
44
52
  end
45
53
  end
46
54
  end
47
55
  end
48
- nil
56
+ { is_bagit: false, metadata: nil }
49
57
  end
50
58
 
51
59
  def self.process(att, id, content)
@@ -3,9 +3,5 @@
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
5
  IS_RAILS5 = false
6
- VERSION_ELN = '1.0.19'
7
- VERSION_REPO = '0.3.1'
8
-
9
- VERSION = Labimotion::VERSION_REPO if Labimotion::IS_RAILS5 == true
10
- VERSION = Labimotion::VERSION_ELN if Labimotion::IS_RAILS5 == false
6
+ VERSION = '1.1.0'
11
7
  end
data/lib/labimotion.rb CHANGED
@@ -8,7 +8,7 @@ module Labimotion
8
8
  end
9
9
 
10
10
  def self.log_exception(exception, current_user = nil)
11
- Labimotion.logger.error("version: #{Labimotion::VERSION}; #{Labimotion::IS_RAILS5}, (#{current_user&.id}) \n Exception: #{exception.message}")
11
+ Labimotion.logger.error("version: #{Labimotion::VERSION}; (#{current_user&.id}) \n Exception: #{exception.message}")
12
12
  Labimotion.logger.error(exception.backtrace.join("\n"))
13
13
  end
14
14
 
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: 1.0.19
4
+ version: 1.1.0
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: 2023-11-14 00:00:00.000000000 Z
12
+ date: 2024-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.4.18
119
+ rubygems_version: 3.1.6
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Chemotion LabIMotion