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

Merge v24.1.14 into main #1040

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24.1.13
24.1.14
4 changes: 2 additions & 2 deletions python/lib/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def insert_parameter_file(self, file_id, parameter_name, value):

# convert list values into strings that could be inserted into parameter_file
if type(value) == list:
if type(value[0]) in [float, int]:
if value and type(value[0]) in [float, int]:
value = [str(f) for f in value]
value = f"[{', '.join(str(value))}]"
value = f"[{', '.join(value)}]"

# Gather column name & values to insert into parameter_file
param_type_id = self.get_parameter_type_id(parameter_name)
Expand Down
71 changes: 71 additions & 0 deletions tools/correct_lists_incorrectly_saved_in_parameter_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3

import os

from lib.database import Database
from lib.lorisgetopt import LorisGetOpt


__license__ = 'GPLv3'


def main():
usage = (
"\n"

"********************************************************************\n"
" CORRECT LISTS INCORRECTLY SAVED IN PARAMETER_FILE TABLE\n"
"********************************************************************\n"
"This script will query any value in parameter_file like '[[%%]]' which is unique and typical of"
" incorrectly saved lists in parameter_file. It will replace the extra characters in the parameter_file"
" table so that the list is properly saved. This follows the correction made in PR"
" https://github.com/aces/Loris-MRI/pull/1025\n\n"

"usage : correct_lists_incorrectly_saved_in_parameter_file.py -p <profile> ...\n\n"

"options: \n"
"\t-p, --profile : Name of the python database config file in dicom-archive/.loris_mri\n"
"\t-v, --verbose : If set, be verbose\n\n"

"required options are: \n"
"\t--profile\n"
)

options_dict = {
"profile": {
"value": None, "required": True, "expect_arg": True, "short_opt": "p", "is_path": False
},
"verbose": {
"value": False, "required": False, "expect_arg": False, "short_opt": "v", "is_path": False
},
"help": {
"value": False, "required": False, "expect_arg": False, "short_opt": "h", "is_path": False
},
}

# get the options provided by the user
loris_getopt_obj = LorisGetOpt(usage, options_dict, os.path.basename(__file__[:-3]))

# establish database connection
verbose = loris_getopt_obj.options_dict['verbose']['value']
db = Database(loris_getopt_obj.config_info.mysql, verbose)
db.connect()

# get the list of entries in parameter_file to correct and correct them
get_list_of_entries_in_parameter_file_to_correct(db)


def get_list_of_entries_in_parameter_file_to_correct(db):

results = db.pselect('SELECT * FROM parameter_file WHERE Value LIKE %s', ('[[%%]]',))

for row in results:
param_file_id = row['ParameterFileID']
value_str = row['Value']
new_value_str = value_str.replace("[[, ', ", "[").replace(", ', ]]", "]").replace(", ", "").replace("'", "")
new_value_str = new_value_str.replace(" ", '').replace(",", ", ").replace("[[", "[").replace("]]", "]")
db.update('UPDATE parameter_file SET Value=%s WHERE ParameterFileID=%s', (new_value_str, param_file_id))


if __name__ == "__main__":
main()
Loading