Fixed deps + Download button error + Order by
This commit is contained in:
parent
d31d41beef
commit
8a9609d8ff
37
app.py
37
app.py
|
@ -7,8 +7,10 @@ import random
|
|||
import re
|
||||
import shutil
|
||||
import string
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from conllu import parse
|
||||
|
||||
import requests
|
||||
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:
|
||||
annodoc += f'# visual-style {subtree_id} bgColor:lightgreen\n'
|
||||
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}
|
||||
|
||||
@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')
|
||||
else:
|
||||
file_path = path
|
||||
f_t = os.path.getmtime(file_path)
|
||||
c_t = time.time()
|
||||
file_age_seconds = c_t - f_t
|
||||
if os.path.exists(file_path):
|
||||
f_t = os.path.getmtime(file_path)
|
||||
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 os.path.isdir(path):
|
||||
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:
|
||||
sort_id = head.index(order_by)
|
||||
if order_type == 'asc':
|
||||
# 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 and order_by != 'Ratio' else x[sort_id], reverse=True)
|
||||
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, reverse=True)
|
||||
|
||||
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:
|
||||
ordered_content = content[1:]
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@ Flask==3.0.0
|
|||
requests==2.31.0
|
||||
flask-babel==4.0.0
|
||||
stark @ git+https://github.com/clarinsi/STARK@master
|
||||
conllu==6.0.0
|
|
@ -47,12 +47,12 @@ $(document).ready(function() {
|
|||
if (grew_url == 'unknown') {
|
||||
$(".grew-link").html("/");
|
||||
} 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') {
|
||||
$(".other-examples").html("/");
|
||||
} 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() {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<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;">✖ {{ _('Close') }}</button>
|
||||
<table style="border: none;">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
Binary file not shown.
|
@ -412,7 +412,7 @@ msgstr "Download complete results"
|
|||
|
||||
#: templates/result.html:29
|
||||
msgid "Close"
|
||||
msgstr ""
|
||||
msgstr "Close Visualization"
|
||||
|
||||
#: templates/result.html:33
|
||||
msgid "Visualization"
|
||||
|
|
Binary file not shown.
|
@ -413,7 +413,7 @@ msgstr "Prenesi datoteko s celotnimi rezultati"
|
|||
|
||||
#: templates/result.html:29
|
||||
msgid "Close"
|
||||
msgstr "Zapri"
|
||||
msgstr "Zapri vizualizacijo"
|
||||
|
||||
#: templates/result.html:33
|
||||
msgid "Visualization"
|
||||
|
|
Loading…
Reference in New Issue
Block a user