From 2bebd0256c28cae811666a92680266a2e9924681 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Tue, 12 Nov 2019 13:23:54 +0100
Subject: [PATCH] Implement logger in another way.
---
app/__init__.py | 2 ++
app/corpora/events.py | 19 +++++++++----------
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/app/__init__.py b/app/__init__.py
index aa40c14b..6db6d4c9 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -4,9 +4,11 @@ from flask_login import LoginManager
from flask_mail import Mail
from flask_socketio import SocketIO
from flask_sqlalchemy import SQLAlchemy
+import logging
db = SQLAlchemy()
+logger = logging.getLogger(__name__)
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
mail = Mail()
diff --git a/app/corpora/events.py b/app/corpora/events.py
index ea89cf49..fef105d5 100644
--- a/app/corpora/events.py
+++ b/app/corpora/events.py
@@ -1,11 +1,9 @@
-from app import db, socketio
+from app import db, logger, socketio
from app.events import connected_sessions
from app.models import Corpus
from flask import current_app, request
from flask_login import current_user, login_required
from .CQiWrapper.CQiWrapper import CQiWrapper
-import logging
-import json
'''
@@ -40,24 +38,22 @@ def init_corpus_analysis(corpus_id):
@socketio.on('query_event')
@login_required
def recv_query(message):
- logger = logging.getLogger(__name__)
logger.warning(message)
analysis_client = analysis_clients[request.sid]
corpus_name = 'CORPUS'
- result_subcorpus_name = 'Query-results'
+ result_subcorpus_name = 'Query-results' # should be set by the user somehow
query = message['query']
analysis_client.set_corpus_name(corpus_name)
analysis_client.create_attribute_strings()
analysis_client.query_subcorpus(result_subcorpus_name, query)
- results = analysis_client.show_results()
+ logger.warning('Vorher')
+ #results = analysis_client.show_results()
+ results = analysis_client.get_cpos_info([1995, 2000], analysis_client)
+ logger.warning('Nacher')
logger.warning('Query results: {}'.format(str(results)))
- json_results = json.dumps(results)
- logger.warning('JSON results are {}'.format(json_results))
- socketio.emit('query_results', json_results)
def observe_corpus_analysis_connection(app, corpus_id, session_id):
- logger = logging.getLogger(__name__)
with app.app_context():
corpus = Corpus.query.filter_by(id=corpus_id).first()
while corpus.status != 'analysing':
@@ -70,6 +66,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
analysis_clients[session_id] = analysis_client
socketio.emit('init_corpus_analysis', 'Ready', room=session_id)
while session_id in connected_sessions:
+ '''
try:
analysis_client.ctrl_ping()
except Exception as err:
@@ -77,6 +74,8 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
break
else:
socketio.sleep(3)
+ '''
+ socketio.sleep(3)
analysis_client.disconnect()
analysis_clients.pop(session_id, None)
analysis_sessions[str(corpus_id)].remove(session_id)