Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default profile added so developers can ensure a rudimentary workflow… #139

Open
wants to merge 113 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
3cdeef0
Added HPLC Reader (as tar archive)
StarmanMartin May 27, 2024
e6cf7fd
requirement fix
StarmanMartin May 27, 2024
5600744
requirement ci fix
StarmanMartin May 27, 2024
e026781
requirement ci fix
StarmanMartin May 27, 2024
4ba5e73
requirement ci fix
StarmanMartin May 27, 2024
c54a3c1
requirement ci fix
StarmanMartin May 27, 2024
154d581
requirement ci fix
StarmanMartin May 27, 2024
5692ecd
requirement ci fix
StarmanMartin May 27, 2024
e3bedcb
test ci fix
StarmanMartin May 27, 2024
b813658
add pybind11 to requirements
StarmanMartin May 29, 2024
ef551aa
removed pybind11 to requirements
StarmanMartin May 29, 2024
b44c8c2
Fixed Wave as single table
StarmanMartin May 29, 2024
bccf784
Fixed metadata
StarmanMartin Jun 4, 2024
ae72f0d
Added XML Reader
StarmanMartin Jul 5, 2024
050e6e1
Fixed Tests
StarmanMartin Jul 5, 2024
ee74cd6
Fixed Tests
StarmanMartin Jul 5, 2024
3a37f93
Fixed Tests
StarmanMartin Jul 8, 2024
3d583bd
Merge remote-tracking branch 'origin/101-new-hplc-reader' into 111-tr…
StarmanMartin Jul 9, 2024
6b16d84
added tar xz
StarmanMartin Jul 9, 2024
fed9327
Fixing Tests
StarmanMartin Jul 9, 2024
fb0cf5d
Revert "Merge remote-tracking branch 'origin/101-new-hplc-reader' int…
StarmanMartin Jul 9, 2024
73c154d
Fixed profile selection BUG
StarmanMartin Jul 9, 2024
74f8a2e
Update test date
StarmanMartin Jul 9, 2024
5c41d62
Update ci
StarmanMartin Jul 9, 2024
fc63793
Added UXD reader for file version 2 & 3
StarmanMartin Jul 9, 2024
26b562e
Merge branch '111-transmission-error-of-certain-data-types-from-chemo…
StarmanMartin Jul 9, 2024
1a2c100
Test data
StarmanMartin Jul 9, 2024
89003a9
Added Step size
StarmanMartin Jul 10, 2024
61ae2ed
Numbering Fixes
StarmanMartin Jul 15, 2024
2b9a4fe
Test data
StarmanMartin Jul 15, 2024
8a3dd71
Added new data type
Sep 20, 2024
23de42a
feat: Added AFM Reader
headri Sep 30, 2024
a1f5f4a
feat: Added CSM Reader
headri Oct 1, 2024
215a24c
feat: Added VSI Reader
headri Oct 2, 2024
7ba890f
Update XML Reader
Oct 7, 2024
65bcadc
Update XML Reader
Oct 7, 2024
0bf5099
Update Test files with new Reader
Oct 7, 2024
ebf5b88
Update Test files with new Reader
Oct 7, 2024
02d0ff6
Test Fix
Oct 7, 2024
04c1f8e
Update afm.py
headri Oct 7, 2024
2ab58dd
Added XML Reader
StarmanMartin Jul 5, 2024
4ced38a
Fixed Tests
StarmanMartin Jul 8, 2024
4be5d64
Added UXD reader for file version 2 & 3
StarmanMartin Jul 9, 2024
89cf77f
Added HPLC Reader (as tar archive)
StarmanMartin May 27, 2024
03cf7ac
requirement fix
StarmanMartin May 27, 2024
7e36fa9
requirement ci fix
StarmanMartin May 27, 2024
743edee
requirement ci fix
StarmanMartin May 27, 2024
1e6ed3b
requirement ci fix
StarmanMartin May 27, 2024
450368f
requirement ci fix
StarmanMartin May 27, 2024
2ab43ca
requirement ci fix
StarmanMartin May 27, 2024
1cdaf1e
test ci fix
StarmanMartin May 27, 2024
cd7aa00
add pybind11 to requirements
StarmanMartin May 29, 2024
a9ebe27
removed pybind11 to requirements
StarmanMartin May 29, 2024
0872e5a
Fixed Wave as single table
StarmanMartin May 29, 2024
342d19a
Fixed metadata
StarmanMartin Jun 4, 2024
f671549
added tar xz
StarmanMartin Jul 9, 2024
051df8b
Fixing Tests
StarmanMartin Jul 9, 2024
66e0590
Revert "Merge remote-tracking branch 'origin/101-new-hplc-reader' int…
StarmanMartin Jul 9, 2024
9d09e19
Fixed profile selection BUG
StarmanMartin Jul 9, 2024
8313bc2
Update ci
StarmanMartin Jul 9, 2024
2b4fe39
Added Step size
StarmanMartin Jul 10, 2024
2aede91
Numbering Fixes
StarmanMartin Jul 15, 2024
5c679f4
Update XML Reader
Oct 7, 2024
c5233f2
Update XML Reader
Oct 7, 2024
d04fa8b
Fixed for float_pattern regex:
Oct 9, 2024
e9a1f0d
Merge remote-tracking branch 'origin/100-new-powerxrd-reader' into 10…
Oct 9, 2024
6fdd2ba
Merge with remote
Oct 9, 2024
fb89c3c
Fixed for float_pattern regex:
Oct 9, 2024
47b05e8
Updated XML reader: extracting more data tables
Oct 9, 2024
2ea1da5
fix
Oct 9, 2024
45a615f
bug fix
Oct 11, 2024
6a2d6ba
bug fix
Oct 12, 2024
b0f514d
test result fix
Oct 12, 2024
af1effd
Added UVVIS Reader
headri Oct 18, 2024
4f241af
fix: added out of bounds check
headri Oct 21, 2024
ab6daf7
Fixed PR comments
Nov 11, 2024
5fa0bb4
Fixed PR comments
Nov 11, 2024
ae89722
Fixed tests
Nov 12, 2024
088fea6
Comment fix
Nov 12, 2024
b9a9318
Merge pull request #121 from ComPlat/100-new-powerxrd-reader
StarmanMartin Nov 12, 2024
bb81fdb
Added tar archive extraction
Nov 13, 2024
8c8501a
feat: Added metadata to excel reader
headri Nov 13, 2024
f080afa
refactor: linting nested blocks
headri Nov 14, 2024
f637f65
Merge branch 'master' into 117-converter-reader-für-afm-csm-vis
headri Nov 14, 2024
25c6a5a
added log files to ignore
Nov 14, 2024
b703274
Changed VIS reader
headri Nov 15, 2024
e930729
Added col meta key extraction
Nov 15, 2024
6950a9e
Merge pull request #125 from ComPlat/arbin-excel-reader
StarmanMartin Nov 19, 2024
a5a4988
Added new check for VIS (.xml) files
Nov 19, 2024
24c2209
Changed Identifier for csm
Nov 19, 2024
52fee2f
Merge pull request #118 from ComPlat/117-converter-reader-für-afm-csm…
StarmanMartin Nov 19, 2024
f830f8a
Merge pull request #122 from ComPlat/120-UVVIS-ezspec-reader
StarmanMartin Nov 19, 2024
4083efd
Merge branch 'master' into 116-add-linear-sweep-voltammetry-to-data-t…
StarmanMartin Nov 19, 2024
916177c
Fixed tests
Nov 19, 2024
7fe10d2
Fixed typo
Nov 20, 2024
0d7e689
Merge pull request #126 from ComPlat/116-add-linear-sweep-voltammetry…
StarmanMartin Nov 20, 2024
a0917aa
Added new error messages
Dec 5, 2024
61c52db
Update README.md
herrdivad Jul 25, 2024
7f2a8bb
Merge pull request #114 from ComPlat/herrdivad-patch-1
StarmanMartin Dec 5, 2024
8ec09e5
Merge pull request #128 from ComPlat/96-differentation-for-error-mess…
StarmanMartin Dec 6, 2024
0d18ad4
Added json links
StarmanMartin Jun 4, 2024
7da1552
added import
Dec 11, 2024
82b9828
Resolve test result inconsistencies across different machines.
Oct 7, 2024
96f864b
fixed merge error
Dec 11, 2024
3896397
Fixed file_path property of models.File Object
Dec 17, 2024
a9ad4e7
Merge pull request #132 from ComPlat/124-handle-tar-files-as-a-list-o…
StarmanMartin Dec 17, 2024
1aaa110
enabled gcd to read tar balls
Dec 17, 2024
83a6a6c
Merge pull request #133 from ComPlat/131-gcbid-tar-files
StarmanMartin Dec 20, 2024
e1abc4f
Merge pull request #130 from ComPlat/98-json-reader
StarmanMartin Jan 9, 2025
98936c3
Merge pull request #129 from ComPlat/Test-case-generator-fixes
StarmanMartin Jan 9, 2025
f33bfd4
Default profile added so developers can ensure a rudimentary workflow…
Jan 21, 2025
b21ce1a
Fix id issues
Jan 21, 2025
e4a2392
added bool flag to profiles if they are a default profile
Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools pip pybind11 --upgrade
pip install -r ./requirements/dev.txt
pip install pylint
- name: Analysing the code with pylint
Expand Down
33 changes: 16 additions & 17 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ jobs:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./requirements/dev.txt
pip install pytest
- name: Build tests
run: |
python test_manager/__init__.py -t -g -tp
- name: Test the code with pytest
run: |
pytest ./test_manager/test_profiles.py
pytest ./test_manager/test_readers.py
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install wheel setuptools pip pybind11 --upgrade
pip install -r ./requirements/dev.txt
pip install pytest
- name: Build tests
run: |
python test_manager/__init__.py -t -g -tp
- name: Test the code with pytest
run: |
pytest .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ __pycache__/
test_manager/test_readers.py
/test_manager/test_profiles.py
/test_files/
/.venv/
logs/

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ The Flask development server can be started now:
flask run
```

Troubleshooting (when unsing Windows, updated 25.07.2024)
---------------
1. Please make sure that you are using a fresh Python3.10 virtual environment (without any packages installed, 3.12 and 3.9 are not supported)
2. Before installing the requirements ```pip install wheel setuptools pip pybind11 # always using pip of your virtual environment ```
3. After installing all requirements via ```pip install -e .``` and ```pip install -r requirements/dev.txt``` check if you have ```python-magic-bin``` and / or ```python-magic``` installed. If not ```pip install python-magic-bin```
4. Now try starting it with the following env variables ```PYTHONUNBUFFERED=1;FLASK_APP=converter_app/app.py;FLASK_ENV=development;FLASK_DEBUG=1```
5. If you are still getting ERRORS containing "libmagic" try uninstalling ```python-magic``` but keeping ```python-magic-bin```


Production setup
----------------

Expand Down
136 changes: 79 additions & 57 deletions converter_app/converters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import datetime
import logging
import os
import re
Expand Down Expand Up @@ -209,29 +210,9 @@ def process(self):
:return:
"""
for output_table_index, output_table in enumerate(self.output_tables):
header = {}
for key, value in output_table.get('header', {}).items():
if isinstance(value, dict):
# this is a table identifier, e.g. FIRSTX
match = self.match_identifier(value)
if match:
header[key] = match['value']
else:
header[key] = value

# merge the metadata from the profile (header) with the metadata
# extracted using the identifiers (see self.match)
for match in self.matches:
match_result = match.get('result')
if match_result:
match_output_key = match.get('identifier', {}).get('outputKey')
match_output_table_index = match.get('identifier', {}).get('outputTableIndex')
match_value = match_result.get('value')
if match_output_key and (
output_table_index == match_output_table_index or
match_output_table_index is None
):
header[match_output_key] = match_value
header = self._process_prepare_header(output_table)

self._process_prepare_metadata(header, output_table_index)

x_column = output_table.get('table', {}).get('xColumn')
y_column = output_table.get('table', {}).get('yColumn')
Expand All @@ -248,30 +229,7 @@ def process(self):
if operation.get('type') == 'column':
operation['rows'] = []

for table_index, table in enumerate(self.input_tables):
for _, row in enumerate(table['rows']):
for column_index, _ in enumerate(table['columns']):
if x_column and \
table_index == x_column.get('tableIndex') and \
column_index == x_column.get('columnIndex'):
x_rows.append(self.get_value(row, column_index))

if y_column and \
table_index == y_column.get('tableIndex') and \
column_index == y_column.get('columnIndex'):
y_rows.append(self.get_value(row, column_index))

for operation in x_operations:
if operation.get('type') == 'column' and \
table_index == operation.get('column', {}).get('tableIndex') and \
column_index == operation.get('column', {}).get('columnIndex'):
operation['rows'].append(self.get_value(row, column_index))

for operation in y_operations:
if operation.get('type') == 'column' and \
table_index == operation.get('column', {}).get('tableIndex') and \
column_index == operation.get('column', {}).get('columnIndex'):
operation['rows'].append(self.get_value(row, column_index))
self._process_prepare_data(x_column, x_operations, x_rows, y_column, y_operations, y_rows)

for operation in x_operations:
x_rows = self._run_operation(x_rows, operation)
Expand All @@ -284,6 +242,59 @@ def process(self):
'y': y_rows
})

def _process_prepare_data(self, x_column, x_operations, x_rows, y_column, y_operations, y_rows):
for table_index, table in enumerate(self.input_tables):
for _, row in enumerate(table['rows']):
for column_index, _ in enumerate(table['columns']):
if x_column and \
table_index == x_column.get('tableIndex') and \
column_index == x_column.get('columnIndex'):
x_rows.append(self.get_value(row, column_index))

if y_column and \
table_index == y_column.get('tableIndex') and \
column_index == y_column.get('columnIndex'):
y_rows.append(self.get_value(row, column_index))

for operation in x_operations:
if operation.get('type') == 'column' and \
table_index == operation.get('column', {}).get('tableIndex') and \
column_index == operation.get('column', {}).get('columnIndex'):
operation['rows'].append(self.get_value(row, column_index))

for operation in y_operations:
if operation.get('type') == 'column' and \
table_index == operation.get('column', {}).get('tableIndex') and \
column_index == operation.get('column', {}).get('columnIndex'):
operation['rows'].append(self.get_value(row, column_index))

def _process_prepare_metadata(self, header, output_table_index):
# merge the metadata from the profile (header) with the metadata
# extracted using the identifiers (see self.match)
for match in self.matches:
match_result = match.get('result')
if match_result:
match_output_key = match.get('identifier', {}).get('outputKey')
match_output_table_index = match.get('identifier', {}).get('outputTableIndex')
match_value = match_result.get('value')
if match_output_key and (
output_table_index == match_output_table_index or
match_output_table_index is None
):
header[match_output_key] = match_value

def _process_prepare_header(self, output_table):
header = {}
for key, value in output_table.get('header', {}).items():
if isinstance(value, dict):
# this is a table identifier, e.g. FIRSTX
match = self.match_identifier(value)
if match:
header[key] = match['value']
else:
header[key] = value
return header

def _run_operation(self, rows, operation):
for i, row in enumerate(rows):
op_value = None
Expand All @@ -304,10 +315,16 @@ def _run_identifier_operation(self, value, operation):
op_value = operation.get('value')
if op_value:
return self.apply_operation(value, op_value, operation.get('operator'))
else:
return value
return value

def apply_operation(self, value, op_value, op_operator):
"""
Apply mathematical operator
:param value: numeric value left
:param op_value: numeric value right
:param op_operator: mathematical operator
:return:
"""
try:
float_value = float(self._fix_float(value))

Expand All @@ -328,8 +345,7 @@ def get_input_table(self, index, input_tables):
try:
if int(index) >= len(input_tables):
return None
else:
return input_tables[int(index)]
return input_tables[int(index)]
except KeyError:
return None

Expand Down Expand Up @@ -364,15 +380,21 @@ def match_profile(cls, client_id, file_data):
"""
converter = None
matches = 0

for profile in Profile.list(client_id):
latest_profile_uploaded = 0
for profile in Profile.list_including_default(client_id):
current_converter = cls(profile, file_data)
current_matches = current_converter.match()

try:
profile_uploaded = datetime.datetime.fromisoformat(
profile.as_dict['data']['metadata'].get('uploaded')).timestamp()
except (ValueError, TypeError):
profile_uploaded = 1
logger.info('profile=%s matches=%s', profile.id, current_matches)

if current_matches is not False and current_matches > matches:
if (current_matches is not False and
(current_matches > matches or current_matches == matches and
profile_uploaded > latest_profile_uploaded)):
matches = max(matches, current_matches)
latest_profile_uploaded = profile_uploaded
converter = current_converter
matches = current_matches

return converter
Loading
Loading