mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Remove all pjs!
This commit is contained in:
parent
961027a8f7
commit
69b17f350e
@ -13,30 +13,30 @@ import math
|
|||||||
' A dictionary containing lists of, with corpus ids associated, Socket.IO
|
' A dictionary containing lists of, with corpus ids associated, Socket.IO
|
||||||
' session ids (sid). {<corpus_id>: [<sid>, ...], ...}
|
' session ids (sid). {<corpus_id>: [<sid>, ...], ...}
|
||||||
'''
|
'''
|
||||||
pj_corpus_analysis_sessions = {}
|
corpus_analysis_sessions = {}
|
||||||
'''
|
'''
|
||||||
' A dictionary containing Socket.IO session id - CQi client pairs.
|
' A dictionary containing Socket.IO session id - CQi client pairs.
|
||||||
' {<sid>: CQiClient, ...}
|
' {<sid>: CQiClient, ...}
|
||||||
'''
|
'''
|
||||||
pj_corpus_analysis_clients = {}
|
corpus_analysis_clients = {}
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('pj_corpus_analysis_init')
|
@socketio.on('corpus_analysis_init')
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def pj_init_corpus_analysis(corpus_id):
|
def init_corpus_analysis(corpus_id):
|
||||||
socketio.start_background_task(pj_corpus_analysis_session_handler,
|
socketio.start_background_task(corpus_analysis_session_handler,
|
||||||
current_app._get_current_object(),
|
current_app._get_current_object(),
|
||||||
corpus_id, current_user.id, request.sid)
|
corpus_id, current_user.id, request.sid)
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('pj_corpus_analysis_query')
|
@socketio.on('corpus_analysis_query')
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def pj_corpus_analysis_query(query):
|
def corpus_analysis_query(query):
|
||||||
client = pj_corpus_analysis_clients.get(request.sid)
|
client = corpus_analysis_clients.get(request.sid)
|
||||||
if client is None:
|
if client is None:
|
||||||
response = {'code': 404, 'desc': 'No client found for this session',
|
response = {'code': 404, 'desc': 'No client found for this session',
|
||||||
'msg': 'Failed Dependency'}
|
'msg': 'Failed Dependency'}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
if client.status == 'running':
|
if client.status == 'running':
|
||||||
client.status = 'abort'
|
client.status = 'abort'
|
||||||
@ -48,7 +48,7 @@ def pj_corpus_analysis_query(query):
|
|||||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
'payload': {'code': e.code, 'desc': e.description,
|
||||||
'msg': e.name}}
|
'msg': e.name}}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
query_status = corpus.query(query)
|
query_status = corpus.query(query)
|
||||||
@ -56,7 +56,7 @@ def pj_corpus_analysis_query(query):
|
|||||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
'payload': {'code': e.code, 'desc': e.description,
|
||||||
'msg': e.name}}
|
'msg': e.name}}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
results = corpus.subcorpora.get('Results')
|
results = corpus.subcorpora.get('Results')
|
||||||
@ -64,11 +64,11 @@ def pj_corpus_analysis_query(query):
|
|||||||
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
'payload': {'code': e.code, 'desc': e.description,
|
||||||
'msg': e.name}}
|
'msg': e.name}}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
return
|
return
|
||||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||||
'payload': {**query_status, 'match_count': results.size}}
|
'payload': {**query_status, 'match_count': results.size}}
|
||||||
socketio.emit('pj_corpus_analysis_query', response, room=request.sid)
|
socketio.emit('corpus_analysis_query', response, room=request.sid)
|
||||||
chunk_size = 100
|
chunk_size = 100
|
||||||
chunk_start = 0
|
chunk_start = 0
|
||||||
context = 100
|
context = 100
|
||||||
@ -87,17 +87,17 @@ def pj_corpus_analysis_query(query):
|
|||||||
progress = min(100, int(math.ceil(progress)))
|
progress = min(100, int(math.ceil(progress)))
|
||||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||||
'payload': {'chunk': chunk, 'progress': progress}}
|
'payload': {'chunk': chunk, 'progress': progress}}
|
||||||
socketio.emit('pj_corpus_analysis_query_results', response,
|
socketio.emit('corpus_analysis_query_results', response,
|
||||||
room=request.sid)
|
room=request.sid)
|
||||||
chunk_start += chunk_size
|
chunk_start += chunk_size
|
||||||
client.status = 'ready'
|
client.status = 'ready'
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('pj_corpus_analysis_inspect_match')
|
@socketio.on('corpus_analysis_inspect_match')
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def pj_corpus_analysis_inspect_match(payload):
|
def corpus_analysis_inspect_match(payload):
|
||||||
payload = payload["payload"]
|
payload = payload["payload"]
|
||||||
client = pj_corpus_analysis_clients.get(request.sid)
|
client = corpus_analysis_clients.get(request.sid)
|
||||||
if client is None:
|
if client is None:
|
||||||
socketio.emit('query', '[424]: Failed Dependency',
|
socketio.emit('query', '[424]: Failed Dependency',
|
||||||
room=request.sid)
|
room=request.sid)
|
||||||
@ -108,22 +108,22 @@ def pj_corpus_analysis_inspect_match(payload):
|
|||||||
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
||||||
context=3, expand_lists=False)
|
context=3, expand_lists=False)
|
||||||
match_context['cpos_ranges'] = True
|
match_context['cpos_ranges'] = True
|
||||||
socketio.emit('pj_match_context',
|
socketio.emit('match_context',
|
||||||
{'payload': match_context}, room=request.sid)
|
{'payload': match_context}, room=request.sid)
|
||||||
|
|
||||||
|
|
||||||
def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
''' Setup analysis session '''
|
''' Setup analysis session '''
|
||||||
corpus = Corpus.query.get(corpus_id)
|
corpus = Corpus.query.get(corpus_id)
|
||||||
user = User.query.get(user_id)
|
user = User.query.get(user_id)
|
||||||
if corpus is None:
|
if corpus is None:
|
||||||
response = {'code': 404, 'desc': None, 'msg': 'Not Found'}
|
response = {'code': 404, 'desc': None, 'msg': 'Not Found'}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
return
|
||||||
elif not (corpus.creator == user or user.is_administrator()):
|
elif not (corpus.creator == user or user.is_administrator()):
|
||||||
response = {'code': 403, 'desc': None, 'msg': 'Forbidden'}
|
response = {'code': 403, 'desc': None, 'msg': 'Forbidden'}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
return
|
||||||
while corpus.status != 'analysing':
|
while corpus.status != 'analysing':
|
||||||
db.session.refresh(corpus)
|
db.session.refresh(corpus)
|
||||||
@ -136,22 +136,22 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
|||||||
'msg': 'Internal Server Error',
|
'msg': 'Internal Server Error',
|
||||||
'payload': {'code': e.code, 'desc': e.description,
|
'payload': {'code': e.code, 'desc': e.description,
|
||||||
'msg': e.name}}
|
'msg': e.name}}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
return
|
||||||
except gaierror:
|
except gaierror:
|
||||||
response = {'code': 500, 'desc': None,
|
response = {'code': 500, 'desc': None,
|
||||||
'msg': 'Internal Server Error'}
|
'msg': 'Internal Server Error'}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
return
|
return
|
||||||
pj_corpus_analysis_clients[session_id] = client
|
corpus_analysis_clients[session_id] = client
|
||||||
if corpus_id not in pj_corpus_analysis_sessions:
|
if corpus_id not in corpus_analysis_sessions:
|
||||||
pj_corpus_analysis_sessions[corpus_id] = [session_id]
|
corpus_analysis_sessions[corpus_id] = [session_id]
|
||||||
else:
|
else:
|
||||||
pj_corpus_analysis_sessions[corpus_id].append(session_id)
|
corpus_analysis_sessions[corpus_id].append(session_id)
|
||||||
client.status = 'ready'
|
client.status = 'ready'
|
||||||
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
response = {'code': 200, 'desc': None, 'msg': 'OK',
|
||||||
'payload': {**connect_status}}
|
'payload': {**connect_status}}
|
||||||
socketio.emit('pj_corpus_analysis_init', response, room=session_id)
|
socketio.emit('corpus_analysis_init', response, room=session_id)
|
||||||
''' Observe analysis session '''
|
''' Observe analysis session '''
|
||||||
while session_id in connected_sessions:
|
while session_id in connected_sessions:
|
||||||
socketio.sleep(3)
|
socketio.sleep(3)
|
||||||
@ -164,9 +164,9 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id):
|
|||||||
client.disconnect()
|
client.disconnect()
|
||||||
except cqi.errors.CQiException:
|
except cqi.errors.CQiException:
|
||||||
pass
|
pass
|
||||||
pj_corpus_analysis_clients.pop(session_id, None)
|
corpus_analysis_clients.pop(session_id, None)
|
||||||
pj_corpus_analysis_sessions[corpus_id].remove(session_id)
|
corpus_analysis_sessions[corpus_id].remove(session_id)
|
||||||
if not pj_corpus_analysis_sessions[corpus_id]:
|
if not corpus_analysis_sessions[corpus_id]:
|
||||||
pj_corpus_analysis_sessions.pop(corpus_id, None)
|
corpus_analysis_sessions.pop(corpus_id, None)
|
||||||
corpus.status = 'stop analysis'
|
corpus.status = 'stop analysis'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -6,11 +6,11 @@ class CorpusAnalysisClient {
|
|||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
|
||||||
// socket on event fpr corpous analysis initialization
|
// socket on event fpr corpous analysis initialization
|
||||||
socket.on("pj_corpus_analysis_init", (response) => {
|
socket.on("corpus_analysis_init", (response) => {
|
||||||
var errorText;
|
var errorText;
|
||||||
|
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
console.log(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`);
|
console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`);
|
||||||
if (this.callbacks.init != undefined) {
|
if (this.callbacks.init != undefined) {
|
||||||
this.callbacks.init(response.payload);
|
this.callbacks.init(response.payload);
|
||||||
}
|
}
|
||||||
@ -25,16 +25,16 @@ class CorpusAnalysisClient {
|
|||||||
if (this.displays.init != undefined) {
|
if (this.displays.init != undefined) {
|
||||||
this.displays.init.setVisibilityByStatus("error");
|
this.displays.init.setVisibilityByStatus("error");
|
||||||
}
|
}
|
||||||
console.error(`pj_corpus_analysis_init: ${errorText}`);
|
console.error(`corpus_analysis_init: ${errorText}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// socket on event for recieveing query results
|
// socket on event for recieveing query results
|
||||||
socket.on("pj_corpus_analysis_query", (response) => {
|
socket.on("corpus_analysis_query", (response) => {
|
||||||
var errorText;
|
var errorText;
|
||||||
|
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
console.log(`pj_corpus_analysis_query: ${response.code} - ${response.msg}`);
|
console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`);
|
||||||
if (this.callbacks.query != undefined) {
|
if (this.callbacks.query != undefined) {
|
||||||
this.callbacks.query(response.payload);
|
this.callbacks.query(response.payload);
|
||||||
}
|
}
|
||||||
@ -50,11 +50,11 @@ class CorpusAnalysisClient {
|
|||||||
if (this.displays.query != undefined) {
|
if (this.displays.query != undefined) {
|
||||||
this.displays.query.setVisibilityByStatus("error");
|
this.displays.query.setVisibilityByStatus("error");
|
||||||
}
|
}
|
||||||
console.error(`pj_corpus_analysis_query: ${errorText}`);
|
console.error(`corpus_analysis_query: ${errorText}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("pj_corpus_analysis_query_results", (response) => {
|
socket.on("corpus_analysis_query_results", (response) => {
|
||||||
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);}
|
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class CorpusAnalysisClient {
|
|||||||
if (this.displays.init != undefined) {
|
if (this.displays.init != undefined) {
|
||||||
this.displays.init.setVisibilityByStatus("waiting");
|
this.displays.init.setVisibilityByStatus("waiting");
|
||||||
}
|
}
|
||||||
this.socket.emit("pj_corpus_analysis_init", this.corpusId);
|
this.socket.emit("corpus_analysis_init", this.corpusId);
|
||||||
}
|
}
|
||||||
|
|
||||||
query(queryStr) {
|
query(queryStr) {
|
||||||
@ -79,7 +79,7 @@ class CorpusAnalysisClient {
|
|||||||
if (this.displays.query != undefined) {
|
if (this.displays.query != undefined) {
|
||||||
this.displays.query.setVisibilityByStatus("waiting");
|
this.displays.query.setVisibilityByStatus("waiting");
|
||||||
}
|
}
|
||||||
nopaque.socket.emit("pj_corpus_analysis_query", queryStr);
|
nopaque.socket.emit("corpus_analysis_query", queryStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
setCallback(type, callback) {
|
setCallback(type, callback) {
|
||||||
|
@ -94,7 +94,7 @@ function inspect(dataIndex) {
|
|||||||
contextResultsElement = document.getElementById("context-results");
|
contextResultsElement = document.getElementById("context-results");
|
||||||
contextResultsElement.innerHTML = ""; // clear it from old inspects
|
contextResultsElement.innerHTML = ""; // clear it from old inspects
|
||||||
contextModal.open();
|
contextModal.open();
|
||||||
nopaque.socket.emit("pj_corpus_analysis_inspect_match",
|
nopaque.socket.emit("corpus_analysis_inspect_match",
|
||||||
{payload: {
|
{payload: {
|
||||||
first_cpos: results.resultsJSON.matches[dataIndex].c[0],
|
first_cpos: results.resultsJSON.matches[dataIndex].c[0],
|
||||||
last_cpos: results.resultsJSON.matches[dataIndex].c[1]
|
last_cpos: results.resultsJSON.matches[dataIndex].c[1]
|
||||||
|
@ -328,7 +328,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// get context of one match if inspected via socket.io
|
// get context of one match if inspected via socket.io
|
||||||
nopaque.socket.on("pj_match_context", showMatchContext);
|
nopaque.socket.on("match_context", showMatchContext);
|
||||||
|
|
||||||
// live update of hits per page if hits per page value is changed
|
// live update of hits per page if hits per page value is changed
|
||||||
hitsPerPageInputElement = document.getElementById("display-options-form-results_per_page");
|
hitsPerPageInputElement = document.getElementById("display-options-form-results_per_page");
|
||||||
|
Loading…
Reference in New Issue
Block a user