2019-11-06 13:45:08 +00:00
|
|
|
from app import db, socketio
|
2019-11-06 13:35:33 +00:00
|
|
|
from app.events import connected_sessions
|
2019-11-06 13:45:08 +00:00
|
|
|
from app.models import Corpus
|
2019-11-06 13:35:33 +00:00
|
|
|
from flask import current_app, request
|
|
|
|
from flask_login import login_required
|
2019-11-07 14:51:01 +00:00
|
|
|
from .CQiWrapper.CQiWrapper import CQiWrapper
|
2019-11-06 13:35:33 +00:00
|
|
|
import logging
|
2019-11-07 12:56:21 +00:00
|
|
|
import time
|
2019-11-06 13:35:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@socketio.on('init_corpus_analysis')
|
|
|
|
@login_required
|
|
|
|
def init_corpus_analysis(corpus_id):
|
2019-11-06 14:44:06 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.warning('init_corpus_analysis')
|
2019-11-06 13:35:33 +00:00
|
|
|
''' TODO: Check if current_user is allowed to subscribe to this '''
|
2019-11-06 13:45:08 +00:00
|
|
|
socketio.start_background_task(observe_corpus_analysis_connection,
|
2019-11-06 13:35:33 +00:00
|
|
|
current_app._get_current_object(),
|
|
|
|
corpus_id,
|
|
|
|
request.sid)
|
|
|
|
|
|
|
|
|
|
|
|
@socketio.on('query_event')
|
|
|
|
def recv_query(message):
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.warning(message)
|
|
|
|
|
|
|
|
|
2019-11-06 13:45:08 +00:00
|
|
|
def observe_corpus_analysis_connection(app, corpus_id, session_id):
|
2019-11-06 13:35:33 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
with app.app_context():
|
2019-11-07 12:56:21 +00:00
|
|
|
time.sleep(5) # wait for IP of container only for dev
|
2019-11-07 09:55:23 +00:00
|
|
|
corpus = Corpus.query.filter_by(id=corpus_id).first()
|
2019-11-07 12:56:21 +00:00
|
|
|
logger.warning('IP adress is: {}'.format(corpus.analysis_container_ip))
|
2019-11-07 14:51:01 +00:00
|
|
|
cqi_session = CQiWrapper(username='opaque', password='opaque',
|
|
|
|
host=corpus.analysis_container_ip, port=4877)
|
|
|
|
cqi_session.connect()
|
|
|
|
logger.warning(cqi_session.corpus_list_corpora())
|
|
|
|
corpus_name = 'CORPUS'
|
|
|
|
result_subcorpus_name = 'Query-results' # should be set by the user somehow
|
|
|
|
query = '"and";'
|
|
|
|
cqi_session.create_attribute_strings(corpus_name)
|
|
|
|
logger.warning('Log after create_attribute_strings.')
|
|
|
|
cqi_session.query_subcorpus(corpus_name, result_subcorpus_name, query)
|
|
|
|
logger.warning('Log after query_subcorpus.')
|
2019-11-06 13:35:33 +00:00
|
|
|
while session_id in connected_sessions:
|
|
|
|
logger.warning('Run container, run!')
|
|
|
|
socketio.sleep(3)
|
2019-11-06 13:45:08 +00:00
|
|
|
corpus.status = 'stop analysis'
|
|
|
|
db.session.commit()
|
|
|
|
logger.warning('Stop container, stop!')
|