Fixed deps + Download button error + Order by

This commit is contained in:
lkrsnik 2025-02-02 11:38:10 +01:00
parent d31d41beef
commit 8a9609d8ff
8 changed files with 36 additions and 12 deletions

37
app.py
View File

@ -7,8 +7,10 @@ import random
import re import re
import shutil import shutil
import string import string
import sys
import time import time
from pathlib import Path from pathlib import Path
from conllu import parse
import requests import requests
from flask import Flask, render_template, request, send_file, redirect, url_for from flask import Flask, render_template, request, send_file, redirect, url_for
@ -131,7 +133,14 @@ def create_app():
for subtree_id in subtree_ids: for subtree_id in subtree_ids:
annodoc += f'# visual-style {subtree_id} bgColor:lightgreen\n' annodoc += f'# visual-style {subtree_id} bgColor:lightgreen\n'
with open(os.path.join('media', result_id, 'annodoc', sentence_id), 'r') as rf: with open(os.path.join('media', result_id, 'annodoc', sentence_id), 'r') as rf:
annodoc += rf.read() + '\n\n' read_annodoc = rf.read()
sentences = parse(read_annodoc)
# delete `deps` column
for token in sentences[0]:
token['deps'] = None
annodoc += sentences[0].serialize()
return {'annodoc': annodoc} return {'annodoc': annodoc}
@app.route('/stark/result/<result_id>/<subtree_hash>', methods=['GET']) @app.route('/stark/result/<result_id>/<subtree_hash>', methods=['GET'])
@ -200,9 +209,13 @@ def create_app():
file_path = os.path.join('media', filename, 'result.tsv') file_path = os.path.join('media', filename, 'result.tsv')
else: else:
file_path = path file_path = path
f_t = os.path.getmtime(file_path) if os.path.exists(file_path):
c_t = time.time() f_t = os.path.getmtime(file_path)
file_age_seconds = c_t - f_t c_t = time.time()
file_age_seconds = c_t - f_t
else:
# delete empty folders
file_age_seconds = 10000000
if file_age_seconds > DAYS_BEFORE_DELETION * 86400: if file_age_seconds > DAYS_BEFORE_DELETION * 86400:
if os.path.isdir(path): if os.path.isdir(path):
shutil.rmtree(os.path.join('media', filename), ignore_errors=True) shutil.rmtree(os.path.join('media', filename), ignore_errors=True)
@ -245,10 +258,20 @@ def create_app():
if order_by is not None and order_by in head: if order_by is not None and order_by in head:
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 def sort_func(x):
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) if x[sort_id] == 'NaN':
return float('-inf')
return -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=sort_func, 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 and order_by != 'Ratio' else x[sort_id]) def sort_func(x):
if x[sort_id] == 'NaN':
return float('inf')
return -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=sort_func)
else: else:
ordered_content = content[1:] ordered_content = content[1:]

View File

@ -2,3 +2,4 @@ Flask==3.0.0
requests==2.31.0 requests==2.31.0
flask-babel==4.0.0 flask-babel==4.0.0
stark @ git+https://github.com/clarinsi/STARK@master stark @ git+https://github.com/clarinsi/STARK@master
conllu==6.0.0

View File

@ -47,12 +47,12 @@ $(document).ready(function() {
if (grew_url == 'unknown') { if (grew_url == 'unknown') {
$(".grew-link").html("/"); $(".grew-link").html("/");
} else { } else {
$(".grew-link").html("<a href=" + grew_url + ">" + grew_link_text + "</a>"); $(".grew-link").html("<a href=" + grew_url + " target='_blank'>" + grew_link_text + "</a>");
} }
if (other_examples == 'unknown') { if (other_examples == 'unknown') {
$(".other-examples").html("/"); $(".other-examples").html("/");
} else { } else {
$(".other-examples").html("<a href=" + other_examples + ">" + other_examples_text + "</a>"); $(".other-examples").html("<a href=" + other_examples + " target='_blank'>" + other_examples_text + "</a>");
} }
}); });
$(".close-visualization").click(function() { $(".close-visualization").click(function() {

View File

@ -26,7 +26,7 @@
</div> </div>
</div> </div>
<div class="visualization-table"> <div class="visualization-table">
<button class="close-visualization btn-flat grey-text text-darken-1" style="float: right; margin: 10px;">{{ _('Close') }}</button> <button class="close-visualization btn-flat grey-text text-darken-1" style="float: right; margin: 10px;">&#10006; {{ _('Close') }}</button>
<table style="border: none;"> <table style="border: none;">
<thead> <thead>
<tr> <tr>

View File

@ -412,7 +412,7 @@ msgstr "Download complete results"
#: templates/result.html:29 #: templates/result.html:29
msgid "Close" msgid "Close"
msgstr "" msgstr "Close Visualization"
#: templates/result.html:33 #: templates/result.html:33
msgid "Visualization" msgid "Visualization"

View File

@ -413,7 +413,7 @@ msgstr "Prenesi datoteko s celotnimi rezultati"
#: templates/result.html:29 #: templates/result.html:29
msgid "Close" msgid "Close"
msgstr "Zapri" msgstr "Zapri vizualizacijo"
#: templates/result.html:33 #: templates/result.html:33
msgid "Visualization" msgid "Visualization"