Add neww result recieving

This commit is contained in:
Stephan Porada 2020-03-23 12:14:32 +01:00
parent 94e71b41df
commit ac14bedc62
3 changed files with 27 additions and 19 deletions

View File

@ -59,9 +59,9 @@ class Subcorpus:
for match_start, match_end in match_boundaries: for match_start, match_end in match_boundaries:
left_start = max(0, match_start - context) left_start = max(0, match_start - context)
right_end = min(self.parent_corpus.size, (match_end + 1 + context)) right_end = min(self.parent_corpus.size, (match_end + 1 + context))
matches.append({'left': list(range(left_start, match_start)), matches.append({'lc': list(range(left_start, match_start)),
'hit': list(range(match_start, match_end + 1)), 'hit': list(range(match_start, match_end + 1)),
'right': list(range(match_end + 1, right_end))}) 'rc': list(range(match_end + 1, right_end))})
cpos_list = [] cpos_list = []
for match in matches: for match in matches:
cpos_list += match['lc'] + match['hit'] + match['rc'] cpos_list += match['lc'] + match['hit'] + match['rc']

View File

@ -50,14 +50,21 @@ def corpus_analysis_query(query):
context = 100 context = 100
progress = 0 progress = 0
while chunk_start <= results.size: while chunk_start <= results.size:
logger.warning("test")
chunk = results.dump_values(context=context, chunk = results.dump_values(context=context,
first_result=chunk_start, first_result=chunk_start,
num_results=chunk_size) num_results=chunk_size)
progress = ((chunk_start + chunk_size) / results.size) * 100 logger.warning(chunk)
progress = min(100, int(math.ceil(progress))) if (results.size == 0):
progress = 100
else:
progress = ((chunk_start + chunk_size) / results.size) * 100
progress = min(100, int(math.ceil(progress)))
socketio.emit('corpus_analysis_query', socketio.emit('corpus_analysis_query',
{'chunk': chunk, 'progress': progress, {'chunk': chunk,
'num_matches_total': results.size}, 'progress': progress,
'num_matches_total': results.size,
'code': 0},
room=request.sid) room=request.sid)
chunk_start += chunk_size chunk_start += chunk_size

View File

@ -32,13 +32,13 @@ function sendQuery(event) {
// full results object declaration, global declaration! // full results object declaration, global declaration!
// will always be reset if a query is sent, so that only the chunks of the // will always be reset if a query is sent, so that only the chunks of the
// current query will be saved in it // current query will be saved in it
result = {}; result = {}; // full JSON object holding match results
result["matches"] = []; result["matches"] = []; // list of all amtches with lc and rc
result["cpos_lookup"] = {}; result["cpos_lookup"] = {}; // object contains all cpos as key value pair
result["text_lookup"] = {}; result["text_lookup"] = {}; // same as above for all text ids
result["loaded_match_count"] = 0; result["loaded_match_count"] = 0; // how many matches have been recieved
result["match_count"] = 0; result["num_matches_total"]; // how many should have been recieved/total nr
result["query"] = ""; result["query"] = ""; // the query as a string
// some hiding/showing for loading animation // some hiding/showing for loading animation
queryLoadingElement.classList.remove("hide"); queryLoadingElement.classList.remove("hide");
queryResultsTableElement.classList.add("hide"); queryResultsTableElement.classList.add("hide");
@ -97,7 +97,7 @@ function recieveResults(response) {
return; // no further code execution of this code block return; // no further code execution of this code block
} }
// logs the current recieved chunk // logs the current recieved chunk
chunk = response["result"]; chunk = response["chunk"];
//chunk = response["chunk"]; //chunk = response["chunk"];
console.log("### corpus_analysis chunk ###"); console.log("### corpus_analysis chunk ###");
console.log(chunk); console.log(chunk);
@ -107,7 +107,7 @@ function recieveResults(response) {
result["matches"].push(...chunk["matches"]); result["matches"].push(...chunk["matches"]);
Object.assign(result["cpos_lookup"], chunk["cpos_lookup"]); Object.assign(result["cpos_lookup"], chunk["cpos_lookup"]);
Object.assign(result["text_lookup"], chunk["text_lookup"]); Object.assign(result["text_lookup"], chunk["text_lookup"]);
result["match_count"] = chunk["match_count"]; result["num_matches_total"] = response["num_matches_total"];
//result["match_count"] = response["match_count"]; //result["match_count"] = response["match_count"];
console.log("Before Current match count", result["loaded_match_count"]); console.log("Before Current match count", result["loaded_match_count"]);
queryData = getQueryData(queryFormElement); queryData = getQueryData(queryFormElement);
@ -120,6 +120,7 @@ function recieveResults(response) {
queryResultsElement.innerHTML = ""; queryResultsElement.innerHTML = "";
// check if query has any results // check if query has any results
console.log("CHUNKLENGTH", chunk["matches"].length);
if (chunk["matches"].length === 0) { if (chunk["matches"].length === 0) {
queryResultsTableElement.classList.add("hide"); queryResultsTableElement.classList.add("hide");
nopaque.toast("No results for this query!"); nopaque.toast("No results for this query!");
@ -144,13 +145,13 @@ function recieveResults(response) {
result["loaded_match_count"] += Object.keys(chunk["matches"]).length; result["loaded_match_count"] += Object.keys(chunk["matches"]).length;
console.log("After current match count", result["loaded_match_count"]); console.log("After current match count", result["loaded_match_count"]);
queryResultsMetadataElement = document.getElementById("query-results-metadata"); queryResultsMetadataElement = document.getElementById("query-results-metadata");
queryResultsMetadataElement.innerHTML = `<p>The query resulted in a total of ${chunk["match_count"]} matches. </p> <p> ${result["loaded_match_count"]} of ${result["match_count"]} matches in ${countCorpusFiles} corpus files have been loaded.</p><p><i class="material-icons" id="tooltip-info">help</i>The Server is still sending your results. Functions like "Export Results" and "Match Inspect" will be available after all matches have been loaded.</p>`; queryResultsMetadataElement.innerHTML = `<p>The query resulted in a total of ${result["num_matches_total"]} matches. </p> <p> ${result["loaded_match_count"]} of ${result["num_matches_total"]} matches in ${countCorpusFiles} corpus files have been loaded.</p><p><i class="material-icons" id="tooltip-info">help</i>The Server is still sending your results. Functions like "Export Results" and "Match Inspect" will be available after all matches have been loaded.</p>`;
queryResultsInteractionElement = document.getElementById("interaction-elements"); queryResultsInteractionElement = document.getElementById("interaction-elements");
queryResultsInteractionElement.appendChild(exportQueryResultsElement); queryResultsInteractionElement.appendChild(exportQueryResultsElement);
queryResultsHeadElement = document.getElementById("query-results-head"); queryResultsHeadElement = document.getElementById("query-results-head");
queryResultsHeadElement.classList.remove("hide"); queryResultsHeadElement.classList.remove("hide");
queryStatus = result["loaded_match_count"] / result["match_count"] * 100; queryStatus = response["progress"];
console.log(queryStatus); console.log("QUERY STATUS:", queryStatus);
queryResultsDeterminateElement.style["width"] = `${queryStatus}%`; queryResultsDeterminateElement.style["width"] = `${queryStatus}%`;
console.log(queryResultsDeterminateElement.style["width"]); console.log(queryResultsDeterminateElement.style["width"]);
@ -160,7 +161,7 @@ function recieveResults(response) {
queryFinished = true; // global declaration to set downlaod button and inspects buttons back to disabled for new queries queryFinished = true; // global declaration to set downlaod button and inspects buttons back to disabled for new queries
queryResultsDeterminateElement.parentNode.parentNode.classList.add("hide"); queryResultsDeterminateElement.parentNode.parentNode.classList.add("hide");
exportQueryResultsElement.classList.remove("disabled"); exportQueryResultsElement.classList.remove("disabled");
queryResultsMetadataElement.innerHTML = `<p>The query resulted in a total of ${chunk["match_count"]} matches. </p> <p> ${result["loaded_match_count"]} of ${result["match_count"]} matches in ${countCorpusFiles} corpus files have been loaded.<i class="material-icons">check_circle</i></p>`; queryResultsMetadataElement.innerHTML = `<p>The query resulted in a total of ${result["num_matches_total"]} matches. </p> <p> ${result["loaded_match_count"]} of ${result["num_matches_total"]} matches in ${countCorpusFiles} corpus files have been loaded.<i class="material-icons">check_circle</i></p>`;
activateInspect(); activateInspect();
} }
} }