Commit b830295e authored by PkSM3's avatar PkSM3

Merge branch 'unstable' of ssh://delanoe.org:1979/gargantext into samuel

parents f2efbaa2 fb804833
...@@ -135,7 +135,7 @@ class ModelCache(dict): ...@@ -135,7 +135,7 @@ class ModelCache(dict):
self.preload() self.preload()
def __missing__(self, key): def __missing__(self, key):
print(key) #print(key)
conditions = [ conditions = [
(column == str(key)) (column == str(key))
for column in self._columns for column in self._columns
......
...@@ -2,7 +2,7 @@ from django.shortcuts import redirect ...@@ -2,7 +2,7 @@ from django.shortcuts import redirect
from django.shortcuts import render from django.shortcuts import render
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseForbidden
from sqlalchemy import func from sqlalchemy import func, and_, or_
from sqlalchemy.orm import aliased from sqlalchemy.orm import aliased
from collections import defaultdict from collections import defaultdict
...@@ -48,22 +48,33 @@ def project(request, project_id): ...@@ -48,22 +48,33 @@ def project(request, project_id):
# Let's find out about the children nodes of the project # Let's find out about the children nodes of the project
ChildrenNode = aliased(Node) ChildrenNode = aliased(Node)
# This query is giving you the wrong number of docs from the pubmedquerier (x 5) # This query is giving you the wrong number of docs from the pubmedquerier (x 5)
# ... sqlalchemy.func is the guilty # ... sqlalchemy.func by Resource.type_id is the guilty
# ISSUE L51
corpus_query = (session corpus_query = (session
.query(Node.id, Node.name, Resource.type_id, func.count(ChildrenNode.id)) .query(Node.id, Node.name, func.count(ChildrenNode.id))
.outerjoin(ChildrenNode, ChildrenNode.parent_id == Node.id) #.query(Node.id, Node.name, Resource.type_id, func.count(ChildrenNode.id))
.outerjoin(Node_Resource, Node_Resource.node_id == Node.id) #.join(Node_Resource, Node_Resource.node_id == Node.id)
.outerjoin(Resource, Resource.id == Node_Resource.resource_id) #.join(Resource, Resource.id == Node_Resource.resource_id)
.filter(Node.parent_id == project.id) .filter(Node.parent_id == project.id)
.filter(Node.type_id == cache.NodeType['Corpus'].id) .filter(Node.type_id == cache.NodeType['Corpus'].id)
.group_by(Node.id, Node.name, Resource.type_id) .filter(and_(ChildrenNode.parent_id == Node.id, ChildrenNode.type_id == cache.NodeType['Document'].id))
.group_by(Node.id, Node.name)
.order_by(Node.name) .order_by(Node.name)
.all()
) )
corpora_by_resourcetype = defaultdict(list) corpora_by_resourcetype = defaultdict(list)
documents_count_by_resourcetype = defaultdict(int) documents_count_by_resourcetype = defaultdict(int)
corpora_count = 0 corpora_count = 0
corpusID_dict = {} corpusID_dict = {}
for corpus_id, corpus_name, resource_type_id, document_count in corpus_query: for corpus_id, corpus_name, document_count in corpus_query:
# Not optimized GOTO ISSUE L51
resource_type_id = (session.query(Resource.type_id)
.join(Node_Resource, Node_Resource.resource_id == Resource.id)
.join(Node, Node.id == Node_Resource.node_id )
.filter(Node.id==corpus_id)
.first())[0]
if not corpus_id in corpusID_dict: if not corpus_id in corpusID_dict:
if resource_type_id is None: if resource_type_id is None:
resourcetype_name = '(no resource)' resourcetype_name = '(no resource)'
......
...@@ -4,11 +4,13 @@ import os ...@@ -4,11 +4,13 @@ import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gargantext_web.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gargantext_web.settings")
os.environ.setdefault("DJANGO_HSTORE_GLOBAL_REGISTER", "False") os.environ.setdefault("DJANGO_HSTORE_GLOBAL_REGISTER", "False")
# We're gonna use all the models! # We're gonna use all the models!
from node.models import * # Django models
from node import models
# SQLA models
from gargantext_web.db import *
# Reset: all data # Reset: all data
# #
...@@ -42,7 +44,7 @@ metadata = { ...@@ -42,7 +44,7 @@ metadata = {
'journal': 'string', 'journal': 'string',
} }
for name, type in metadata.items(): for name, type in metadata.items():
Metadata(name=name, type=type).save() models.Metadata(name=name, type=type).save()
# Integration: languages # Integration: languages
...@@ -66,12 +68,16 @@ french = Language.objects.get(iso2='fr') ...@@ -66,12 +68,16 @@ french = Language.objects.get(iso2='fr')
# Integration: users # Integration: users
print('Initialize users...') print('Initialize users...')
try: me = models.User.objects.get_or_create(username='alexandre')
me = User.objects.get(username='alexandre') gargantua = models.User.objects.get_or_create(username='gargantua')
except: node_root = Node(user_id=gargantua.id, type_id=cache.NodeType['Root'].id, name='Root')
me = User(username='alexandre') node_stem = Node(user_id=gargantua.id, type_id=cache.NodeType['Stem'].id, name='Stem', parent_id=node_root.id)
me.save() node_lem = Node(user_id=gargantua.id, type_id=cache.NodeType['Lem'].id, name='Lem', parent_id=node_root.id)
session.add(node_root)
session.add(node_stem)
session.add(node_lem)
session.commit()
# Integration: node types # Integration: node types
...@@ -87,7 +93,7 @@ node_types = [ ...@@ -87,7 +93,7 @@ node_types = [
] ]
for node_type in node_types: for node_type in node_types:
NodeType.objects.get_or_create(name=node_type) models.NodeType.objects.get_or_create(name=node_type)
# Integration: resource types # Integration: resource types
...@@ -97,7 +103,8 @@ resources = [ ...@@ -97,7 +103,8 @@ resources = [
'pubmed', 'isi', 'ris', 'europress_french', 'europress_english'] 'pubmed', 'isi', 'ris', 'europress_french', 'europress_english']
for resource in resources: for resource in resources:
ResourceType.objects.get_or_create(name=resource) models.ResourceType.objects.get_or_create(name=resource)
# TODO # TODO
...@@ -145,7 +152,6 @@ for resource in resources: ...@@ -145,7 +152,6 @@ for resource in resources:
from gargantext_web.db import *
# Instantiante table NgramTag: # Instantiante table NgramTag:
f = open("part_of_speech_labels.txt", 'r') f = open("part_of_speech_labels.txt", 'r')
......
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
console.log("enabling "+"#"+value.id) console.log("enabling "+"#"+value.id)
$("#"+value.id).attr('onclick','getGlobalResults(this);'); $("#"+value.id).attr('onclick','getGlobalResults(this);');
// $("#submit_thing").prop('disabled' , false) // $("#submit_thing").prop('disabled' , false)
$("#submit_thing").html("Process a 100 sample!") $("#submit_thing").html("Process a 1000 sample!")
thequeries = data thequeries = data
var N=0,k=0; var N=0,k=0;
......
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