Added fix for sorting Ratio

This commit is contained in:
lkrsnik 2024-08-30 12:32:25 +02:00
parent 0b9f6cb216
commit fff44a99bd

11
app.py
View File

@ -158,13 +158,6 @@ def create_app():
} }
if 'Absolute frequency in second treebank' in head: if 'Absolute frequency in second treebank' in head:
table_columns2displayed_table_columns['Absolute frequency'] = gettext('Frequency in A') table_columns2displayed_table_columns['Absolute frequency'] = gettext('Frequency in A')
# table_columns2displayed_table_columns['Absolute frequency in second treebank'] = gettext('Frequency in B')
# if 'MI' in table_columns2displayed_table_columns:
# del table_columns2displayed_table_columns['MI']
# if 'logDice' in table_columns2displayed_table_columns:
# del table_columns2displayed_table_columns['logDice']
# if 't-score' in table_columns2displayed_table_columns:
# del table_columns2displayed_table_columns['t-score']
else: else:
del table_columns2displayed_table_columns['Absolute frequency in second treebank'] del table_columns2displayed_table_columns['Absolute frequency in second treebank']
displayed_table_columns2table_columns = {v: k for k, v in table_columns2displayed_table_columns.items()} displayed_table_columns2table_columns = {v: k for k, v in table_columns2displayed_table_columns.items()}
@ -176,9 +169,9 @@ def create_app():
sort_id = head.index(order_by) sort_id = head.index(order_by)
if order_type == 'asc': if order_type == 'asc':
# check if a number can be converted to float or int # check if a number can be converted to float or int
ordered_content = sorted(content[1:], key=lambda x: -1 * float(x[sort_id]) if x[sort_id].isnumeric() or re.match(r'^-?\d+(?:\.\d+)$', x[sort_id]) is not None else x[sort_id], reverse=True) ordered_content = sorted(content[1:], key=lambda x: -1 * float(x[sort_id]) if x[sort_id].isnumeric() or re.match(r'^-?\d+(?:\.\d+)$', x[sort_id]) is not None and order_by != 'Ratio' else x[sort_id], reverse=True)
else: else:
ordered_content = sorted(content[1:], key=lambda x: -1 * float(x[sort_id]) if x[sort_id].isnumeric() or re.match(r'^-?\d+(?:\.\d+)$', x[sort_id]) is not None else x[sort_id]) ordered_content = sorted(content[1:], key=lambda x: -1 * float(x[sort_id]) if x[sort_id].isnumeric() or re.match(r'^-?\d+(?:\.\d+)$', x[sort_id]) is not None and order_by != 'Ratio' else x[sort_id])
else: else:
ordered_content = content[1:] ordered_content = content[1:]