Commit 054df082 authored by PkSM3's avatar PkSM3

[UPDATE] Cascade ajax callbacks for all lists

parent 7eac6741
......@@ -53,10 +53,7 @@ class WorkflowTracking:
def processing_(self , corpus , step):
try:
the_query = """ UPDATE node_node SET hyperdata=\'{ \"%s\" : 1}\' WHERE id=%d """ % ( step , corpus.id )
# print(the_query)
# print(step)
# print(" = = = = = = =")
the_query = """ UPDATE node_node SET hyperdata=\'{ \"%s\" : \"%s\"}\' WHERE id=%d """ % ( "Processing", step , corpus.id )
cursor = connection.cursor()
try:
cursor.execute(the_query)
......
......@@ -43,7 +43,7 @@ def apply_workflow(corpus_id):
ngram_workflow(corpus)
#ngrams2miam(user_id=corpus.user_id, corpus_id=corpus_id)
update_state.processing_(corpus, "OK")
update_state.processing_(corpus, "0")
@shared_task
def empty_trash(corpus_id):
......
......@@ -349,7 +349,7 @@ def corpus(request, project_id, corpus_id):
except Exception as error:
print(error)
processing = 0
print('processing', processing)
print('corpus',corpus_id,' , processing', processing)
html = t.render(Context({
'debug': settings.DEBUG,
......
......@@ -102,18 +102,20 @@ class Ngrams(APIView):
http://localhost:8000/api/node/1444485/ngrams?format=json&score=tfidf,occs
'''
def get(self, request, node_id):
# print("\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
# query ngrams
ParentNode = aliased(Node)
corpus = session.query(Node).filter(Node.id==node_id).first()
group_by = []
results = ['id', 'terms']
# print("\t\tSTEP 01","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
ngrams_query = (session
.query(Ngram.id, Ngram.terms)
.join(Node_Ngram, Node_Ngram.ngram_id == Ngram.id)
.join(Node, Node.id == Node_Ngram.node_id)
)
# print("\t\tSTEP 02","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
the_score = "tfidf"
if request.GET.get('score', False) != False:
the_score = request.GET['score']
......@@ -169,6 +171,7 @@ class Ngrams(APIView):
group_by.append(Spec.score)
results.append('specificity')
# print("\t\tSTEP 03","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
order_query = request.GET.get('order', False)
if order_query == 'occs':
ngrams_query = ngrams_query.order_by(desc(occs))
......@@ -179,6 +182,7 @@ class Ngrams(APIView):
elif order_query == 'specificity':
ngrams_query = ngrams_query.order_by(desc(Spec.score))
# print("\t\tSTEP 04","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
offset = int(request.GET.get('offset', 0))
limit = int(request.GET.get('limit', 20))
......@@ -186,6 +190,7 @@ class Ngrams(APIView):
.group_by(Ngram.id, Ngram.terms, *group_by)
)
# print("\t\tSTEP 05","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
if request.GET.get('ngram_id', False) != False:
ngram_id = int(request.GET['ngram_id'])
Group = aliased(NodeNgramNgram)
......@@ -195,7 +200,8 @@ class Ngrams(APIView):
.filter(Group.ngramx_id == ngram_id)
)
# filters by list type (soon list_id to factorize it in javascript)
# print("\t\tSTEP 06","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
# # filters by list type (soon list_id to factorize it in javascript)
list_query = request.GET.get('list', 'miam')
list_id = request.GET.get('list_id', False)
if list_query == 'miam':
......@@ -237,11 +243,18 @@ class Ngrams(APIView):
.filter(CoocY.node_id == node.id)
)
# print("\t\tSTEP 07","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
# print("")
print(ngrams_query)
total = ngrams_query.count()
# print("")
# print("\t\tSTEP 07.1, count:", total ,"\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
# print("\t\tSTEP 07.2, i:", offset , ", N:", (offset+limit) ,"\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
output = []
for ngram in ngrams_query[offset : offset+limit]:
info = { "scores":{} }
info = { "scores" : {} }
try: info["id"] = ngram.id
except: pass
try: info["name"] = ngram.terms
......@@ -257,6 +270,7 @@ class Ngrams(APIView):
output.append( info )
# print("\t\tSTEP 08","\tCORPUS:",node_id," LIST:",request.GET.get('list', False) , " SCORES:",request.GET.get('score', False))
# return formatted result
return JsonHttpResponse({
......@@ -346,7 +360,7 @@ class Group(APIView):
# groups["nodes"] = get_occtfidf( ngrams , request.user.id , corpus_id , "Group")
return JsonHttpResponse(groups)
return JsonHttpResponse( { "data" : groups } )
def post(self, request, node_id):
return JsonHttpResponse( ["hola" , "mundo"] )
......
......@@ -879,13 +879,31 @@ function getIDFromURL( item ) {
return pageurl[cid+1];
}
function GET_( url , callback ) {
$.ajax({
type: "GET",
url: url,
dataType: "json",
success : function(data, textStatus, jqXHR) {
callback(data.data);
// for(var i in data.data) {
// NGrams["stop"][data.data[i].id] = data.data[i]
// }
},
error: function(exception) {
callback(false);
}
})
}
// [ = = = = = = = = = = INIT = = = = = = = = = = ]
// http://localhost:8000/api/node/84592/ngrams?format=json&score=tfidf,occs&list=miam
var corpus_id = getIDFromURL( "corpus" )
var url0=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=stop&limit=999999",
var url0=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=stop&limit=1000",
url1=window.location.origin+"/api/node/"+corpus_id+"/ngrams/group",
url2=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=map&limit=999999",
url3=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=miam&limit=999999";
url2=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=map&limit=1000",
url3=window.location.origin+"/api/node/"+corpus_id+"/ngrams?format=json&score=tfidf,occs&list=miam&limit=1000";
var NGrams = {
"group" : {},
"stop" : {},
......@@ -895,65 +913,44 @@ var NGrams = {
}
$("#corpusdisplayer").hide()
$.when(
$.ajax({
type: "GET",
url: url0,
dataType: "json",
success : function(data, textStatus, jqXHR) {
for(var i in data.data) {
NGrams["stop"][data.data[i].id] = data.data[i]
}
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
}),
$.ajax({
type: "GET",
url: url1,
dataType: "json",
success : function(data, textStatus, jqXHR) {
NGrams["group"] = data
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
}),
$.ajax({
type: "GET",
url: url2,
dataType: "json",
success : function(data, textStatus, jqXHR) {
for(var i in data.data) {
NGrams["map"][data.data[i].id] = data.data[i]
}
},
error: function(exception) {
console.log("first ajax, exception!: "+exception.status)
}
}),
$.ajax({
type: "GET",
url: url3,
dataType: "json",
success : function(data, textStatus, jqXHR) {
NGrams["main"] = {
"ngrams": data.data,
"scores": {
"initial":"occ_uniq",
"nb_docs":data.data.length,
"orig_nb_ngrams":1,
"nb_ngrams":data.data.length,
}
}
},
error: function(exception) {
console.log("second ajax, exception!: "+exception.status)
}
})
).then(function() {
// The AJAX's in cascade:
GET_( url0 , function(result) {
if(result!=false) {
for(var i in result) {
NGrams["stop"][result[i].id] = result[i]
}
}
GET_( url1 , function(result) {
if(result!=false) {
NGrams["group"] = result
}
GET_( url2 , function(result) {
if(result!=false) {
for(var i in result) {
NGrams["map"][result[i].id] = result[i]
}
}
GET_( url3 , function(result) {
if(result!=false) {
NGrams["main"] = {
"ngrams": result,
"scores": {
"initial":"occ_uniq",
"nb_docs":result.length,
"orig_nb_ngrams":1,
"nb_ngrams":result.length,
}
}
AfterAjax()
}
});
});
});
});
function AfterAjax() {
// Deleting subforms from the ngrams-table, clean start baby!
if( Object.keys(NGrams["group"].links).length>0 ) {
......@@ -1013,5 +1010,130 @@ $.when(
$("#corpusdisplayer").show()
$("#content_loader").remove()
$("#corpusdisplayer").click()
}
});
\ No newline at end of file
// hola.split("")
// $.when(
// $.ajax({
// type: "GET",
// url: url0,
// dataType: "json",
// success : function(data, textStatus, jqXHR) {
// for(var i in data.data) {
// NGrams["stop"][data.data[i].id] = data.data[i]
// }
// },
// error: function(exception) {
// console.log("first ajax, exception!: "+exception.status)
// }
// }),
// $.ajax({
// type: "GET",
// url: url1,
// dataType: "json",
// success : function(data, textStatus, jqXHR) {
// NGrams["group"] = data
// },
// error: function(exception) {
// console.log("first ajax, exception!: "+exception.status)
// }
// }),
// $.ajax({
// type: "GET",
// url: url2,
// dataType: "json",
// success : function(data, textStatus, jqXHR) {
// for(var i in data.data) {
// NGrams["map"][data.data[i].id] = data.data[i]
// }
// },
// error: function(exception) {
// console.log("first ajax, exception!: "+exception.status)
// }
// }),
// $.ajax({
// type: "GET",
// url: url3,
// dataType: "json",
// success : function(data, textStatus, jqXHR) {
// NGrams["main"] = {
// "ngrams": data.data,
// "scores": {
// "initial":"occ_uniq",
// "nb_docs":data.data.length,
// "orig_nb_ngrams":1,
// "nb_ngrams":data.data.length,
// }
// }
// },
// error: function(exception) {
// console.log("second ajax, exception!: "+exception.status)
// }
// })
// ).then(function() {
// // Deleting subforms from the ngrams-table, clean start baby!
// if( Object.keys(NGrams["group"].links).length>0 ) {
// var _forms = { "main":{} , "sub":{} }
// for(var i in NGrams["group"].links) {
// _forms["main"][i] = true
// for(var j in NGrams["group"].links[i]) {
// _forms["sub"][ NGrams["group"].links[i][j] ] = true
// }
// }
// var ngrams_data_ = []
// for(var i in NGrams["main"].ngrams) {
// if(_forms["sub"][NGrams["main"].ngrams[i].id]) {
// NGrams["group"]["nodes"][NGrams["main"].ngrams[i].id] = NGrams["main"].ngrams[i]
// } else {
// // if( _forms["main"][ NGrams["main"].ngrams[i].id ] )
// // NGrams["main"].ngrams[i].name = "*"+NGrams["main"].ngrams[i].name
// ngrams_data_.push( NGrams["main"].ngrams[i] )
// }
// }
// NGrams["main"].ngrams = ngrams_data_;
// }
// if( Object.keys(NGrams["map"]).length>0 ) {
// for(var i in NGrams["main"].ngrams) {
// if(NGrams["map"][NGrams["main"].ngrams[i].id]) {
// NGrams["main"].ngrams[i]["state"] = System[0]["statesD"]["keep"]
// }
// }
// }
// // Building the Score-Selector //NGrams["scores"]
// var FirstScore = NGrams["main"].scores.initial
// var possible_scores = Object.keys( NGrams["main"].ngrams[0].scores );
// var scores_div = '<br><select style="font-size:25px;" class="span1" id="scores_selector">'+"\n";
// scores_div += "\t"+'<option value="'+FirstScore+'">'+FirstScore+'</option>'+"\n"
// for( var i in possible_scores ) {
// if(possible_scores[i]!=FirstScore) {
// scores_div += "\t"+'<option value="'+possible_scores[i]+'">'+possible_scores[i]+'</option>'+"\n"
// }
// }
// // Initializing the Charts and Table
// console.log( NGrams["main"] )
// var result = Main_test( NGrams["main"] , FirstScore , "filter_all")
// console.log( result )
// // Listener for onchange Score-Selector
// scores_div += "<select>"+"\n";
// $("#ScoresBox").html(scores_div)
// $("#scores_selector").on('change', function() {
// console.log( this.value )
// var result = Main_test( NGrams["main"] , this.value , "filter_all")
// console.log( result )
// });
// $("#corpusdisplayer").show()
// $("#content_loader").remove()
// $("#corpusdisplayer").click()
// });
\ No newline at end of file
......@@ -45,13 +45,7 @@
</ul>
'>Manage</a>
<!--
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: 90%">
<span class="sr-only">45% Complete</span>
</div>
</div>
--!>
{% if number == 0 %}
<a class="btn btn-primary btn-lg" role="button" href="/admin/documents/corpus/{{ corpus.id }}/">Add documents</a></p>
......@@ -65,8 +59,7 @@
<center>
<a type="button" class="btn btn-default {% if view == "documents" %}active{%endif%}" href="/project/{{project.id}}/corpus/{{ corpus.id }}/documents">{{number}} Documents</a>
<a type="button" class="btn btn-default {% if view == "journals" %}active{%endif%}" href="/project/{{project.id}}/corpus/{{ corpus.id }}/journals">Journals</a>
{% if processing == 0 %}
{% if processing == 0 or processing == "0" %}
<a type="button" class="btn btn-default {% if view == "terms" %}active{%endif%}" href="/project/{{project.id}}/corpus/{{ corpus.id }}/terms">Terms (Bêta)</a>
{% endif %}
</center>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment