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