Commit b71bf198 authored by Administrator's avatar Administrator

Merge branch 'unstable' into prod

parents b5b1d671 f6994364
...@@ -184,31 +184,7 @@ def testISTEX(request , project_id): ...@@ -184,31 +184,7 @@ def testISTEX(request , project_id):
print(request.method) print(request.method)
alist = ["bar","foo"] alist = ["bar","foo"]
# SQLAlchemy session
session = Session()
# do we have a valid project id?
try:
project_id = int(project_id)
except ValueError:
raise Http404()
# do we have a valid project?
project = (session
.query(Node)
.filter(Node.id == project_id)
.filter(Node.type_id == cache.NodeType['Project'].id)
).first()
if project is None:
raise Http404()
# do we have a valid user?
user = request.user
if not user.is_authenticated():
return redirect('/login/?next=%s' % request.path)
if project.user_id != user.id:
return HttpResponseForbidden()
if request.method == "POST": if request.method == "POST":
# print(alist) # print(alist)
...@@ -217,73 +193,63 @@ def testISTEX(request , project_id): ...@@ -217,73 +193,63 @@ def testISTEX(request , project_id):
N = 60 N = 60
if "query" in request.POST: query = request.POST["query"] if "query" in request.POST: query = request.POST["query"]
if "string" in request.POST: query_string = request.POST["string"].replace(" ","+") if "string" in request.POST: query_string = request.POST["string"].replace(" ","+")
if "N" in request.POST: N = int(request.POST["N"]) # if "N" in request.POST: N = request.POST["N"]
print(query_string , query , N) print(query_string , query , N)
urlreqs = [] # urlreqs = []
pagesize = 500 # pagesize = 50
tasks = MedlineFetcher() # tasks = MedlineFetcher()
chunks = list(tasks.chunks(range(N), pagesize)) # chunks = list(tasks.chunks(range(N), pagesize))
for k in chunks: # for k in chunks:
if (k[0]+pagesize)>N: pagesize = N-k[0] # if (k[0]+pagesize)>N: pagesize = N-k[0]
urlreqs.append("http://api.istex.fr/document/?q="+query_string+"&output=*&"+"from="+str(k[0])+"&size="+str(pagesize)) # urlreqs.append("http://api.istex.fr/document/?q="+query_string+"&output=*&"+"from="+str(k[0])+"&size="+str(pagesize))
print(urlreqs) # print(urlreqs)
# urlreqs = ["http://localhost/374255" , "http://localhost/374278" ] # urlreqs = ["http://localhost/374255" , "http://localhost/374278" ]
# print(urlreqs) # print(urlreqs)
resourcetype = cache.ResourceType["istex"] # resource_type = ResourceType.objects.get(name="istext" )
print(resourcetype)
# corpus node instanciation as a Django model # parent = Node.objects.get(id=project_id)
corpus = Node( # node_type = NodeType.objects.get(name='Corpus')
name = query, # type_id = NodeType.objects.get(name='Document').id
user_id = request.user.id, # user_id = User.objects.get( username=request.user ).id
parent_id = project_id,
type_id = cache.NodeType['Corpus'].id, # corpus = Node(
language_id = None, # user=request.user,
) # parent=parent,
session.add(corpus) # type=node_type,
session.commit() # name=query,
# )
tasks = MedlineFetcher()
for i in range(8): # corpus.save()
t = threading.Thread(target=tasks.worker2) #thing to do
t.daemon = True # thread dies when main thread (only non-daemon thread) exits. # # configuring your queue with the event
t.start() # for i in range(8):
for url in urlreqs: # t = threading.Thread(target=tasks.worker2) #thing to do
filename = MEDIA_ROOT + '/corpora/%s/%s' % (request.user, str(datetime.datetime.now().isoformat())) # t.daemon = True # thread dies when main thread (only non-daemon thread) exits.
tasks.q.put( [url , filename]) #put a task in th queue # t.start()
tasks.q.join() # wait until everything is finished # for url in urlreqs:
# filename = MEDIA_ROOT + '/corpora/%s/%s' % (request.user, str(datetime.now().microsecond))
dwnldsOK = 0 # tasks.q.put( [url , filename]) #put a task in th queue
for filename in tasks.firstResults: # tasks.q.join() # wait until everything is finished
if filename!=False: # for filename in tasks.firstResults:
print(filename) # corpus.add_resource( user=request.user, type=resource_type, file=filename )
# add the uploaded resource to the corpus
add_resource(corpus,
user_id = request.user.id, # corpus.save()
type_id = resourcetype.id, # print("DEBUG:",DEBUG)
file = filename, # # do the WorkFlow
) # try:
dwnldsOK+=1 # if DEBUG is True:
# corpus.workflow()
if dwnldsOK == 0: return JsonHttpResponse(["fail"]) # else:
# corpus.workflow.apply_async((), countdown=3)
try:
def apply_workflow(corpus): # return JsonHttpResponse(["workflow","finished"])
parse_resources(corpus) # except Exception as error:
extract_ngrams(corpus, ['title']) # print(error)
compute_tfidf(corpus)
if DEBUG:
apply_workflow(corpus)
else:
thread = threading.Thread(target=apply_workflow, args=(corpus, ), daemon=True)
thread.start()
except Exception as error:
print('WORKFLOW ERROR')
print(error)
return HttpResponseRedirect('/project/' + str(project_id))
data = [query_string,query,N] data = [query_string,query,N]
return JsonHttpResponse(data) return JsonHttpResponse(data)
......
...@@ -277,15 +277,10 @@ ...@@ -277,15 +277,10 @@
function bringDaNoise() { function bringDaNoise() {
var theresults = $("#theresults").html() var theresults = $("#theresults").html()
if( theresults && theresults.search("No results")==-1 ) { if( theresults && theresults.search("No results")==-1 ) {
var origQuery = $("#id_name").val()
console.log("we've in dynamic mode") console.log("we've in dynamic mode")
$("#simpleloader").html('<img width="30px" src="{% static "js/libs/img2/loading-bar.gif" %}"></img>') $("#simpleloader").html('<img width="30px" src="{% static "js/libs/img2/loading-bar.gif" %}"></img>')
$("#submit_thing").prop('onclick',null); $("#submit_thing").prop('onclick',null);
var theType = $("#id_type option:selected").html(); doTheQuery();
if(theType=="pubmed") doTheQuery();
if(theType=="istex") {
testISTEX(origQuery.replace(" ","+"),1000)
}
} }
else { else {
console.log("we dont have nothing inside results div") console.log("we dont have nothing inside results div")
...@@ -301,13 +296,12 @@ ...@@ -301,13 +296,12 @@
$( "#id_form" ).submit(); $( "#id_form" ).submit();
} }
} }
} }
} }
function getGlobalResults(value){ function getGlobalResults(value){
console.log("in getGlobalResults()") console.log("in getGlobalResults()")
console.log("value:")
console.log(value)
// AJAX to django // AJAX to django
var pubmedquery = $("#id_name").val() var pubmedquery = $("#id_name").val()
var Npubs = $("#id_N").val(); var Npubs = $("#id_N").val();
...@@ -318,8 +312,6 @@ ...@@ -318,8 +312,6 @@
$("#"+value.id).prop('onclick',null); $("#"+value.id).prop('onclick',null);
var theType = $("#id_type option:selected").html(); var theType = $("#id_type option:selected").html();
console.log("theType:")
console.log(theType)
if(theType=="Pubmed (xml format)") { if(theType=="Pubmed (xml format)") {
$.ajax({ $.ajax({
...@@ -357,7 +349,7 @@ ...@@ -357,7 +349,7 @@
}); });
} }
if(theType=="istex") { if(theType=="istext") {
console.log(window.location.origin+"tests/istextquery") console.log(window.location.origin+"tests/istextquery")
$.ajax({ $.ajax({
// contentType: "application/json", // contentType: "application/json",
...@@ -484,7 +476,7 @@ ...@@ -484,7 +476,7 @@
var origQuery = query var origQuery = query
var pubmedifiedQuery = { query : query , string: query , N:Npubs} var pubmedifiedQuery = { query : query , string: query }
// console.log(pubmedifiedQuery) // console.log(pubmedifiedQuery)
var projectid = window.location.href.split("project")[1].replace(/\//g, '')//replace all the slashes var projectid = window.location.href.split("project")[1].replace(/\//g, '')//replace all the slashes
...@@ -500,7 +492,7 @@ ...@@ -500,7 +492,7 @@
success: function(data) { success: function(data) {
console.log("ajax_success: in testISTEX()") console.log("ajax_success: in testISTEX()")
console.log(data) console.log(data)
location.reload(); // location.reload();
}, },
error: function(result) { error: function(result) {
console.log("in testISTEX(). Data not found"); console.log("in testISTEX(). Data not found");
......
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