mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Multiple analyses sessions perfectly implemented.
This commit is contained in:
parent
87b7f07d26
commit
8a607b6dc0
@ -7,6 +7,7 @@ from .CQiWrapper.CQiWrapper import CQiWrapper
|
||||
import logging
|
||||
|
||||
|
||||
analysis_sessions = {}
|
||||
analysis_clients = {}
|
||||
|
||||
|
||||
@ -14,17 +15,18 @@ analysis_clients = {}
|
||||
@login_required
|
||||
def init_corpus_analysis(corpus_id):
|
||||
''' TODO: Check if current_user is allowed to subscribe to this '''
|
||||
if str(corpus_id) not in analysis_sessions:
|
||||
analysis_sessions[str(corpus_id)] = [request.sid]
|
||||
socketio.start_background_task(observe_corpus_analysis_connection,
|
||||
current_app._get_current_object(),
|
||||
corpus_id,
|
||||
request.sid)
|
||||
corpus_id, request.sid)
|
||||
|
||||
|
||||
@socketio.on('query_event')
|
||||
def recv_query(message):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning(message)
|
||||
analysis_client = analysis_clients[request.sid]
|
||||
# analysis_client = analysis_clients[request.sid]
|
||||
|
||||
|
||||
def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
||||
@ -34,10 +36,11 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
||||
while corpus.status != 'analysing':
|
||||
db.session.refresh(corpus)
|
||||
socketio.sleep(3)
|
||||
analysis_client = CQiWrapper(username='opaque', password='opaque',
|
||||
host='{}_analysis_container{}'.format(corpus.creator.username, corpus.id), port=4877)
|
||||
analysis_clients[session_id] = analysis_client
|
||||
analysis_client = CQiWrapper(host='{}_analysis_container{}'.format(corpus.creator.username, corpus.id),
|
||||
password='opaque', port=4877,
|
||||
username='opaque')
|
||||
analysis_client.connect()
|
||||
analysis_clients['session_id'] = analysis_client
|
||||
corpus_name = 'CORPUS'
|
||||
result_subcorpus_name = 'Query-results' # should be set by the user somehow
|
||||
query = '"and";'
|
||||
@ -50,5 +53,8 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
||||
logger.warning(analysis_client.ctrl_ping())
|
||||
socketio.sleep(3)
|
||||
analysis_clients.pop(session_id, None)
|
||||
corpus.status = 'stop analysis'
|
||||
analysis_sessions[str(corpus_id)].remove(session_id)
|
||||
if not analysis_sessions[str(corpus_id)]:
|
||||
analysis_sessions.pop(str(corpus_id), None)
|
||||
corpus.status = 'stop analysis'
|
||||
db.session.commit()
|
||||
|
@ -54,14 +54,15 @@ def corpus(corpus_id):
|
||||
def corpus_analysis(corpus_id):
|
||||
logger = logging.getLogger(__name__)
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
corpus.status = 'start analysis'
|
||||
if corpus.status == 'prepared':
|
||||
corpus.status = 'start analysis'
|
||||
db.session.commit()
|
||||
query = request.args.get('query')
|
||||
logger.warning('Query first: {}'.format(query))
|
||||
hits_per_page = request.args.get('hits_per_page', 30)
|
||||
context = request.args.get('context', 10)
|
||||
dl_form = QueryDownloadForm()
|
||||
form = QueryForm(hits_per_page=hits_per_page, context=context, query=query)
|
||||
db.session.commit()
|
||||
if form.validate_on_submit():
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning('Data has been sent!')
|
||||
|
@ -62,9 +62,9 @@
|
||||
statusElement.classList.add(CorpusList.STATUS_COLORS[status] || CorpusList.STATUS_COLORS['default']);
|
||||
statusElement.innerText = status;
|
||||
var analyseBtn = document.getElementById('analyse');
|
||||
if (status === 'prepared') {
|
||||
if (status === 'prepared' || status === 'analysing') {
|
||||
analyseBtn.classList.remove('hide', 'disabled');
|
||||
} else if (status === 'analysing' || status === 'start analysis' || status === 'stop analysis') {
|
||||
} else if (status === 'start analysis' || status === 'stop analysis') {
|
||||
analyseBtn.classList.remove('hide');
|
||||
analyseBtn.classList.add('disabled');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user