diff --git a/app/corpora/events.py b/app/corpora/events.py index 6c793222..887a511d 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -1,11 +1,11 @@ from app import db, logger, socketio from app.events import connected_sessions from app.models import Corpus, User -# from .cqi import CQiClient -from .cqi import CQiWrapper +from .cqi import CQiClient from flask import current_app, request from flask_login import current_user, login_required -# import math +import math + ''' ' A dictionary containing lists of, with corpus ids associated, Socket.IO @@ -35,11 +35,9 @@ def corpus_analysis_query(query): if client is None: socketio.emit('query', '[424]: Failed Dependency', room=request.sid) return - client.select_corpus('CORPUS') - # corpus = client.corpora.get('CORPUS') + corpus = client.corpora.get('CORPUS') try: - client.query_subcorpus(query) - # results = corpus.query(query) + results = corpus.query(query) except Exception as e: logger.warning(e) response = str(e) @@ -47,32 +45,21 @@ def corpus_analysis_query(query): response = {'code': 1} socketio.emit('corpus_analysis_query', response, room=request.sid) else: - chunk_size = 100 - chunk_start = 0 - context = 100 - while chunk_start < client.match_count: - chunk = client.show_query_results(result_len=chunk_size, - context_len=context, - result_offset=chunk_start) - socketio.emit('corpus_analysis_query', chunk, room=request.sid) - chunk_start += chunk_size - ''' chunk_size = 100 chunk_start = 0 context = 100 progress = 0 while chunk_start <= results.size: - chunk = results.dump_results(context=context, - first_result=chunk_start, - num_results=chunk_size) + chunk = results.dump_values(context=context, + first_result=chunk_start, + num_results=chunk_size) progress = ((chunk_start + chunk_size) / results.size) * 100 progress = min(100, int(math.ceil(progress))) socketio.emit('corpus_analysis_query', {'chunk': chunk, 'progress': progress, - 'match_count': results.size}, + 'num_matches_total': results.size}, room=request.sid) chunk_start += chunk_size - ''' @socketio.on('inspect_match') @@ -106,8 +93,7 @@ def corpus_analysis_session_handler(app, corpus_id, user_id, session_id): while corpus.status != 'analysing': db.session.refresh(corpus) socketio.sleep(3) - client = CQiWrapper(host='corpus_{}_analysis'.format(corpus_id)) - # client = CQiClient('corpus_{}_analysis'.format(corpus_id)) + client = CQiClient('corpus_{}_analysis'.format(corpus_id)) try: client.connect() except Exception: diff --git a/app/static/js/nopaque.analyse_corpus.js b/app/static/js/nopaque.analyse_corpus.js index 1997a734..9c89abdd 100644 --- a/app/static/js/nopaque.analyse_corpus.js +++ b/app/static/js/nopaque.analyse_corpus.js @@ -77,6 +77,8 @@ function recieveResults(response) { let queryStatus; queryFinished = false; + console.log(response); + // ERROR code checking if (response["code"] === 0) { console.log("[SUCCESS] corpus_analysis_init");