Commit 68a2a795 authored by Romain Loth's avatar Romain Loth
parent cb8f9988
## This is the legacy comex app cleaned and ready for future refactoring ## comex app ready for future refactoring
It contains: It contains:
- an html index based on old bootstrap - an html index based on old bootstrap
...@@ -9,13 +9,57 @@ It contains: ...@@ -9,13 +9,57 @@ It contains:
- the python server is in comex_install/ dir - the python server is in comex_install/ dir
- run it with `python3 main.py` and reverse-proxy its host:port to `/comexAPI` location - run it with `python3 main.py` and reverse-proxy its host:port to `/comexAPI` location
- the twjs is in a legacy version, downloadable at [commit 11e7d77](https://github.com/moma/tinawebJS/tree/11e7d77b71ae096b7fad2cfbd716c3c724966ad2) - the twjs is in a legacy version, downloadable at [commit 11e7d77](https://github.com/moma/tinawebJS/tree/11e7d77b71ae096b7fad2cfbd716c3c724966ad2)
------
#### Installation ### Installation
1. clone this repo 1. clone this repo
2. get the tinawebJS contents into `./tinawebJS` 2. get the tinawebJS contents into `./tinawebJS`
3. get the community.db sqlite3 database into `./` 3. get the community.db sqlite3 database into `./`
#### TODOES for future refactoring #### TODOES for future refactoring
1. remove the legacy links to csregistry.org 1. remove the legacy links to csregistry.org
2. replace the registration/profile pages with the new [regcomex app server](https://github.com/moma/regcomex) 2. replace the registration/profile pages with the new [regcomex app server](https://github.com/moma/regcomex) [DONE]
3. replace community.db PDO connections by the new comex_shared MySQL tables 3. replace community.db PDO connections by the new comex_shared MySQL tables [IN PROGRESS]
------
### DB structure
###### Overview
- `scholars` is the main table, with a **doors_uid** as primary key
- email is also unique in this table
- we have three related tables
- `affiliations` (directly pointed by an **affiliation_id** in scholars table)
- `keywords` (pointed by an intermediate user id <=> keyword id table `sch_kw`)
- `linked_ids` (not used yet, to join the uid with external ids like ORCID)
###### More info
Full table structure is described in [this documentation file](https://github.com/moma/regcomex/blob/c5badbc/doc/table_specifications.md).
###### Exemple queries
```SQL
-- ==========================
-- FOR SCHOLAR + AFFILIATIONS
-- ==========================
SELECT
scholars.*,
affiliations.*,
FROM scholars
LEFT JOIN affiliations
ON affiliation_id = affid
-- ==================================
-- FOR SCHOLAR + KEYWORDS IN ONE LINE
-- ==================================
SELECT
scholars.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
GROUP BY uid ;
```
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
During rewrite we deactivated some retrieval to match the new sql tables from registration: During rewrite we deactivated some retrieval to match the new sql tables from registration:
- tables organizations, labs don't exist => TODO RESTORE in `directory_content.php` (and therefore empty arrays are passed to `labs_list.php` and `orga_list.php`) - tables organizations, labs are not separated and their detailed addresses don't exist => TODO RESTORE in `directory_content.php` (and therefore incomplete info are passed to `labs_list.php` and `orga_list.php`)
- in `search_scholar.php`, column nb_keywords doesn't exist (and now keywords are never 0) => TODO RESTORE - in `print_directory.php`, all the following columns are now ignored: 'css_voter', 'css_member', 'status', 'lab2', 'affiliation2', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_directory.php`, all the following columns are now ignored: 'nb_keywords', 'css_voter', 'css_member', 'keywords_ids', 'status', 'homepage', 'lab2', 'affiliation2', 'homepage', **'position'** (used in `stats_prep_from_array.php`), 'photo_url', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_scholar_directory.php` - in `print_scholar_directory.php`
- similar changes as above - similar changes as above
- additional change to keywords_ids search in old "scholars2terms" table => becomes `LIKE` search in keywords: TODO index
from sqlite3 import connect, Row from MySQLdb import connect, cursors
from networkx import Graph, DiGraph from networkx import Graph, DiGraph
from random import randint from random import randint
from math import floor from math import floor
from cgi import escape from cgi import escape
from converter import CountryConverter from converter import CountryConverter
from pprint import pprint from pprint import pprint
# from json import loads # for external FA2
class extract:
def __init__(self,dbpath): class MyExtractor:
self.connection=connect(dbpath)
print("sqlite3 connected:", self.connection) def __init__(self,dbhost):
self.connection.row_factory = Row# Magic line! self.connection=connect(
self.cursor=self.connection.cursor() host=dbhost, db="comex_shared",
print("sqlite3 gotcursor:", self.cursor) user="root", passwd="very-safe-pass"
)
print("MySQL connected:", self.connection)
self.cursor=self.connection.cursor(cursors.DictCursor)
print("MySQL gotcursor:", self.cursor)
self.scholars = {} self.scholars = {}
self.scholars_colors = {} self.scholars_colors = {}
self.terms_colors = {} self.terms_colors = {}
self.Graph = DiGraph() self.Graph = DiGraph()
self.min_num_friends=0 self.min_num_friends=0
self.imsize=80 self.imsize=80
self.terms_array = {} self.terms_dict = {}
self.unique_id = {} self.unique_id = {}
...@@ -41,29 +43,57 @@ class extract: ...@@ -41,29 +43,57 @@ class extract:
if idflag: if idflag:
ID=i ID=i
idflag=False idflag=False
if isinstance(i, (long, int)): if i is None:
continue
elif isinstance(i, int):
suma+=1 suma+=1
else: suma+=len(i) else: suma+=len(i)
return suma return suma
def getScholarsList(self,qtype,query): def getScholarsList(self,qtype,query):
# debug
# print("getScholarsList<============")
# print("qtype", qtype)
# print("query", query)
# remove quotes from id
unique_id = query[1:-1]
scholar_array = {} scholar_array = {}
sql1=None sql1=None
sql2=None sql2=None
if qtype == "unique_id": if qtype == "unique_id":
try: try:
sql1="SELECT * FROM scholars where unique_id='"+query+"'" # old way
# sql1="SELECT * FROM scholars WHERE doors_uid='"+unique_id+"'"
# TODO this query brings back doors_uid and keywords_ids
# as the old way used to do, but with keywords scholar index
# we won't need STR_keywords_ids anymore
sql1="""
SELECT
doors_uid,
COUNT(keywords.kwid) AS nb_keywords,
GROUP_CONCAT(keywords.kwid) AS keywords_ids
FROM scholars
JOIN sch_kw ON doors_uid = uid
JOIN keywords ON sch_kw.kwid = keywords.kwid
WHERE doors_uid = "%s"
GROUP BY doors_uid
""" % unique_id
STR_keywords_ids = "" STR_keywords_ids = ""
self.cursor.execute(sql1) self.cursor.execute(sql1)
results=self.cursor.fetchall() results=self.cursor.fetchall()
if len(results)==0: return [] print("getScholarsList<==len(results) =", len(results))
if len(results)==0:
return []
if len(results)==1: if len(results)==1:
self.unique_id = { query : "D::"+str(results[0]["id"]) } self.unique_id = { unique_id : "D::"+str(results[0]["doors_uid"][0:8]) }
STR_keywords_ids = results[0]["keywords_ids"] STR_keywords_ids = results[0]["keywords_ids"]
# [ Solving duplicates ] # [ Solving duplicates ]
...@@ -77,20 +107,23 @@ class extract: ...@@ -77,20 +107,23 @@ class extract:
candidates = sorted(candidates, key=lambda candit: candit[1], reverse=True) candidates = sorted(candidates, key=lambda candit: candit[1], reverse=True)
print("candidates:",candidates) print("candidates:",candidates)
self.unique_id = { query : "D::"+str(candidates[0][0]) } self.unique_id = { unique_id : "D::"+str(candidates[0]["doors_uid"][0:8]) }
STR_keywords_ids = candidates[0][2] STR_keywords_ids = candidates[0][2]
# [ / Solving duplicates ] # [ / Solving duplicates ]
keywords_ids = STR_keywords_ids.split(',') keywords_ids = STR_keywords_ids.split(',')
for keywords_id in keywords_ids: for keywords_id in keywords_ids:
# debug
# print("kwid >> ", keywords_id)
if keywords_id != "": if keywords_id != "":
sql2 = "SELECT * FROM scholars2terms where term_id="+keywords_id sql2 = "SELECT * FROM sch_kw where kwid="+keywords_id
try: try:
self.cursor.execute(sql2) self.cursor.execute(sql2)
res2=self.cursor.fetchone() res2=self.cursor.fetchone()
while res2 is not None: while res2 is not None:
scholar_array[res2['scholar']]=1 scholar_array[res2['uid']]=1
res2=self.cursor.fetchone()#res2++ res2=self.cursor.fetchone()#res2++
except Exception as error: except Exception as error:
print("sql2:\t"+sql2) print("sql2:\t"+sql2)
...@@ -106,6 +139,8 @@ class extract: ...@@ -106,6 +139,8 @@ class extract:
print("sql2:\t"+sql2) print("sql2:\t"+sql2)
print(error) print(error)
# TODO fix ('refine' button)
if qtype == "filter": if qtype == "filter":
try: try:
self.cursor.execute(query) self.cursor.execute(query)
...@@ -126,44 +161,63 @@ class extract: ...@@ -126,44 +161,63 @@ class extract:
""" """
Adding each connected scholar per unique_id Adding each connected scholar per unique_id
""" """
# debug
# print("MySQL extract scholar_array:", scholar_array)
for scholar_id in scholar_array: for scholar_id in scholar_array:
sql3='SELECT * FROM scholars where unique_id="'+scholar_id+'"' sql3='''
SELECT
scholars.*,
affiliations.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(keywords.kwid) AS keywords_ids,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON affiliation_id = affid
WHERE doors_uid = "%s"
GROUP BY doors_uid ;
''' % scholar_id
# debug # debug
# print("db.extract: sql3="+sql3) # print("db.extract: sql3="+sql3)
try: try:
self.cursor.execute(sql3) self.cursor.execute(sql3)
res3=self.cursor.fetchall() res3=self.cursor.fetchone()
n=len(res3)#in the DB, there are unique_ids duplicated
info = {}; info = {};
#With (n-1) we're fetching only the last result. # POSS: semantic short ID
ide="D::"+str(res3[n-1]['id']); # ex "D::JFK/4913d6c7"
# for now we use uid substring [0:8]
# ex ide="D::4913d6c7"
ide="D::"+res3['doors_uid'][0:8];
info['id'] = ide; info['id'] = ide;
info['unique_id'] = res3[n-1]['unique_id']; info['doors_uid'] = res3['doors_uid'];
info['photo_url'] = res3[n-1]['photo_url']; info['pic_url'] = res3['pic_url'];
info['first_name'] = res3[n-1]['first_name']; info['first_name'] = res3['first_name'];
info['initials'] = res3[n-1]['initials']; info['mid_initial'] = res3['middle_name'][0] if res3['middle_name'] else "" # TODO adapt usage
info['last_name'] = res3[n-1]['last_name']; info['last_name'] = res3['last_name'];
info['nb_keywords'] = res3[n-1]['nb_keywords']; info['keywords_nb'] = res3['keywords_nb'];
info['css_voter'] = res3[n-1]['css_voter']; info['keywords_ids'] = res3['keywords_ids'].split(',');
info['css_member'] = res3[n-1]['css_member']; info['keywords_list'] = res3['keywords_list'];
info['keywords_ids'] = res3[n-1]['keywords_ids'].split(','); info['country'] = res3['country'];
info['keywords'] = res3[n-1]['keywords']; # info['ACR'] = res3['org_acronym'] # TODO create
info['country'] = res3[n-1]['country']; #info['CC'] = res3['norm_country'];
info['ACR'] = res3[n-1]['affiliation_acronym'] info['home_url'] = res3['home_url'];
#info['CC'] = res3[n-1]['norm_country']; info['team_lab'] = res3['team_lab'];
info['homepage'] = res3[n-1]['homepage']; info['org'] = res3['org'];
info['lab'] = res3[n-1]['lab']; # info['lab2'] = res3['lab2']; # TODO restore
info['affiliation'] = res3[n-1]['affiliation']; # info['affiliation2'] = res3['affiliation2'];
info['lab2'] = res3[n-1]['lab2']; info['hon_title'] = res3['hon_title'] if res3['hon_title'] else ""
info['affiliation2'] = res3[n-1]['affiliation2']; info['position'] = res3['position'];
info['homepage'] = res3[n-1]['homepage']; info['job_looking_date'] = res3['job_looking_date'];
info['title'] = res3[n-1]['title']; info['email'] = res3['email'];
info['position'] = res3[n-1]['position']; if info['keywords_nb']>0:
info['job_market'] = res3[n-1]['job_market'];
info['login'] = res3[n-1]['login'];
if info['nb_keywords']>0:
self.scholars[ide] = info; self.scholars[ide] = info;
except Exception as error: except Exception as error:
...@@ -179,7 +233,7 @@ class extract: ...@@ -179,7 +233,7 @@ class extract:
scholarsIncluded = 0; scholarsIncluded = 0;
for i in self.scholars: for i in self.scholars:
self.scholars_colors[self.scholars[i]['login'].strip()]=0; self.scholars_colors[self.scholars[i]['email'].strip()]=0;
scholar_keywords = self.scholars[i]['keywords_ids']; scholar_keywords = self.scholars[i]['keywords_ids'];
for k in range(len(scholar_keywords)): for k in range(len(scholar_keywords)):
kw_k = scholar_keywords[k] kw_k = scholar_keywords[k]
...@@ -205,55 +259,52 @@ class extract: ...@@ -205,55 +259,52 @@ class extract:
termsMatrix[kw_k]['cooc'][kw_l] += 1 termsMatrix[kw_k]['cooc'][kw_l] += 1
else: else:
termsMatrix[kw_k]['cooc'][kw_l] = 1; termsMatrix[kw_k]['cooc'][kw_l] = 1;
sql='select login from jobs';
for res in self.cursor.execute(sql): # TODO restore job snippet 1
if res['login'].strip() in self.scholars_colors: # sql='select login from jobs';
self.scholars_colors[res['login'].strip()]+=1; # for res in self.cursor.execute(sql):
# if res['login'].strip() in self.scholars_colors:
# sql="SELECT term,id,occurrences FROM terms" # self.scholars_colors[res['login'].strip()]+=1;
# #self.cursor.execute(sql)
# cont=0 # TODO add occurrences ?
# # query = "SELECT kwstr,kwid,occurrences FROM keywords WHERE kwid IN "
## for t in termsMatrix: query = "SELECT kwstr,kwid FROM keywords WHERE kwid IN "
## if cont==0:
## sql+=' where id='+t
## cont+=1
## else: sql+=' or id='+t
## print("before crash")
## print(sql)
## print("nb terms:",len(termsMatrix))
query = "SELECT term,id,occurrences FROM terms WHERE id IN "
conditions = ' (' + ','.join(sorted(list(termsMatrix))) + ')' conditions = ' (' + ','.join(sorted(list(termsMatrix))) + ')'
# debug # debug
# print("SQL query ===============================") print("SQL query ===============================")
# print(query+conditions) print(query+conditions)
# print("/SQL query ==============================") print("/SQL query ==============================")
for res in self.cursor.execute(query+conditions):
idT = res['id'] self.cursor.execute(query+conditions)
results4 = self.cursor.fetchall()
for res in results4:
idT = res['kwid']
info = {} info = {}
info['id'] = idT info['kwid'] = idT
info['occurrences'] = res['occurrences'] # info['occurrences'] = res['occurrences'] # TODO add occurrences ?
info['term'] = res['term'] info['kwstr'] = res['kwstr']
self.terms_array[idT] = info self.terms_dict[idT] = info
count=1 count=1
for term in self.terms_array: for term in self.terms_dict:
self.terms_colors[term]=0 self.terms_colors[term]=0
sql='select term_id from jobs2terms' # TODO restore job snippet 2
for row in self.cursor.execute(sql): # sql='select term_id from jobs2terms'
if row['term_id'] in self.terms_colors: # for row in self.cursor.execute(sql):
self.terms_colors[row['term_id']]+=1 # if row['term_id'] in self.terms_colors:
# self.terms_colors[row['term_id']]+=1
cont=0 cont=0
for term in self.terms_array: for term_id in self.terms_dict:
#sql="SELECT scholar FROM scholars2terms where term_id='"+str(term)+"'"; sql="SELECT uid FROM sch_kw WHERE kwid=%i" % term_id
sql="SELECT scholars.id FROM scholars,scholars2terms where term_id='"+str(term)+"' and scholars.unique_id=scholars2terms.scholar"
term_scholars=[] term_scholars=[]
for row in self.cursor.execute(sql): self.cursor.execute(sql)
term_scholars.append("D::"+str(row['id'])) rows = self.cursor.fetchall()
for row in rows:
term_scholars.append("D::"+row['uid'][0:8])
for k in range(len(term_scholars)): for k in range(len(term_scholars)):
if term_scholars[k] in scholarsMatrix: if term_scholars[k] in scholarsMatrix:
...@@ -298,15 +349,17 @@ class extract: ...@@ -298,15 +349,17 @@ class extract:
self.Graph.add_edge( source , target , {'weight':1,'type':"bipartite"}) self.Graph.add_edge( source , target , {'weight':1,'type':"bipartite"})
#Some bipartite relations are missing (just the 1%) #Some bipartite relations are missing (just the 1%)
for term in self.terms_array: for term in self.terms_dict:
nodeId1 = self.terms_array[term]['id']; nodeId1 = self.terms_dict[term]['kwid'];
if str(nodeId1) in termsMatrix: if str(nodeId1) in termsMatrix:
neighbors = termsMatrix[str(nodeId1)]['cooc']; neighbors = termsMatrix[str(nodeId1)]['cooc'];
for i, neigh in enumerate(neighbors): for i, neigh in enumerate(neighbors):
if neigh != str(term): if neigh != str(term):
source="N::"+str(term) source="N::"+str(term)
target="N::"+neigh target="N::"+neigh
weight=neighbors[str(neigh)]/float(self.terms_array[term]['occurrences']) # TODO restore keywords.occurrences
# weight=neighbors[str(neigh)]/float(self.terms_dict[term]['occurrences'])
weight=neighbors[str(neigh)]
self.Graph.add_edge( source , target , {'weight':weight,'type':"nodes2"}) self.Graph.add_edge( source , target , {'weight':weight,'type':"nodes2"})
for scholar in self.scholars: for scholar in self.scholars:
...@@ -356,11 +409,11 @@ class extract: ...@@ -356,11 +409,11 @@ class extract:
for idNode in graph.nodes_iter(): for idNode in graph.nodes_iter():
if idNode[0]=="N":#If it is NGram if idNode[0]=="N":#If it is NGram
numID=int(idNode.split("::")[1]) numID=int(idNode.split("::")[1])
# print("DBG terms_array:", self.terms_array) # print("DBG terms_dict:", self.terms_dict)
try: try:
nodeLabel= self.terms_array[numID]['term'].replace("&"," and ") nodeLabel= self.terms_dict[numID]['term'].replace("&"," and ")
colorg=max(0,180-(100*self.terms_colors[numID])) colorg=max(0,180-(100*self.terms_colors[numID]))
term_occ = self.terms_array[numID]['occurrences'] term_occ = self.terms_dict[numID]['occurrences']
except KeyError: except KeyError:
print("WARN: couldn't find label and meta for term " + str(numID)) print("WARN: couldn't find label and meta for term " + str(numID))
...@@ -383,42 +436,51 @@ class extract: ...@@ -383,42 +436,51 @@ class extract:
nodesB+=1 nodesB+=1
if idNode[0]=='D':#If it is Document if idNode[0]=='D':#If it is Document
nodeLabel= self.scholars[idNode]['title']+" "+self.scholars[idNode]['first_name']+" "+self.scholars[idNode]['initials']+" "+self.scholars[idNode]['last_name'] nodeLabel= self.scholars[idNode]['hon_title']+" "+self.scholars[idNode]['first_name']+" "+self.scholars[idNode]['mid_initial']+" "+self.scholars[idNode]['last_name']
color="" color=""
if self.scholars_colors[self.scholars[idNode]['login']]==1: if self.scholars_colors[self.scholars[idNode]['email']]==1:
color='243,183,19' color='243,183,19'
elif self.scholars[idNode]['job_market'] == "Yes":
# TODO test the date
elif self.scholars[idNode]['job_looking_date'] is not None:
color = '139,28,28' color = '139,28,28'
else: else:
color = '78,193,127' color = '78,193,127'
content="" content=""
photo_url=self.scholars[idNode]['photo_url'] pic_url=self.scholars[idNode]['pic_url']
if photo_url != "":
content += '<img src=http://main.csregistry.org/' + photo_url + ' width=' + str(self.imsize) + 'px style=float:left;margin:5px>'; # TODO double case pic_url or pic_file
if pic_url and pic_url != "":
content += '<img src="'+pic_url+'" width=' + str(self.imsize) + 'px style=float:left;margin:5px>';
else: else:
if len(self.scholars)<2000: if len(self.scholars)<2000:
im_id = int(floor(randint(0, 11))) im_id = int(floor(randint(0, 11)))
content += '<img src=http://communityexplorer.org/img/' + str(im_id) + '.png width=' + str(self.imsize) + 'px style=float:left;margin:5px>' content += '<img src="img/'+str(im_id)+'.png" width=' + str(self.imsize) + 'px style=float:left;margin:5px>'
content += '<b>Country: </b>' + self.scholars[idNode]['country'] + '</br>' content += '<b>Country: </b>' + self.scholars[idNode]['country'] + '</br>'
if self.scholars[idNode]['position'] != "": if self.scholars[idNode]['position'] and self.scholars[idNode]['position'] != "":
content += '<b>Position: </b>' +self.scholars[idNode]['position'].replace("&"," and ")+ '</br>' content += '<b>Position: </b>' +self.scholars[idNode]['position'].replace("&"," and ")+ '</br>'
affiliation="" affiliation=""
if self.scholars[idNode]['lab'] != "": if self.scholars[idNode]['team_lab'] and self.scholars[idNode]['team_lab'] != "":
affiliation += self.scholars[idNode]['lab']+ ',' affiliation += self.scholars[idNode]['team_lab']+ ','
if self.scholars[idNode]['affiliation'] != "": if self.scholars[idNode]['org'] and self.scholars[idNode]['org'] != "":
affiliation += self.scholars[idNode]['affiliation'] affiliation += self.scholars[idNode]['org']
if self.scholars[idNode]['affiliation'] != "" or self.scholars[idNode]['lab'] != "":
content += '<b>Affiliation: </b>' + affiliation.replace("&"," and ") + '</br>' # TODO restore if not redundant with org
if len(self.scholars[idNode]['keywords']) > 3: # if self.scholars[idNode]['affiliation'] != "" or self.scholars[idNode]['lab'] != "":
content += '<b>Keywords: </b>' + self.scholars[idNode]['keywords'][:-2].replace(",",", ")+'.</br>' # content += '<b>Affiliation: </b>' + affiliation.replace("&"," and ") + '</br>'
if self.scholars[idNode]['homepage'][0:3] == "www":
content += '[ <a href=http://' +self.scholars[idNode]['homepage'].replace("&"," and ")+ ' target=blank > View homepage </a ><br/>]' if len(self.scholars[idNode]['keywords_list']) > 3:
elif self.scholars[idNode]['homepage'][0:4] == "http": content += '<b>Keywords: </b>' + self.scholars[idNode]['keywords_list'].replace(",",", ")+'.</br>'
content += '[ <a href=' +self.scholars[idNode]['homepage'].replace("&"," and ")+ ' target=blank > View homepage </a >]<br/>'
if self.scholars[idNode]['home_url']:
if self.scholars[idNode]['home_url'][0:3] == "www":
content += '[ <a href=http://' +self.scholars[idNode]['home_url'].replace("&"," and ")+ ' target=blank > View homepage </a ><br/>]'
elif self.scholars[idNode]['home_url'][0:4] == "http":
content += '[ <a href=' +self.scholars[idNode]['home_url'].replace("&"," and ")+ ' target=blank > View homepage </a >]<br/>'
node = {} node = {}
...@@ -435,7 +497,9 @@ class extract: ...@@ -435,7 +497,9 @@ class extract:
else: node["CC"]="-" else: node["CC"]="-"
# Affiliation # Affiliation
node["ACR"] = self.scholars[idNode]["ACR"] # TODO restore with org_acronym
# node["ACR"] = self.scholars[idNode]["ACR"]
node["ACR"] = self.scholars[idNode]["org"]
if node["ACR"]=="": node["ACR"]="-" if node["ACR"]=="": node["ACR"]="-"
node["term_occ"] = "12" node["term_occ"] = "12"
......
...@@ -3,20 +3,29 @@ comex helper backend to create json graphs from sqlite3 db ...@@ -3,20 +3,29 @@ comex helper backend to create json graphs from sqlite3 db
TODO integrate with new regcomex server TODO integrate with new regcomex server
""" """
from extractDataCustom import extract as SQLite from extractDataCustom import MyExtractor as MySQL
from flask import Flask from flask import Flask, request
from flask import request
from json import dumps from json import dumps
from os import environ
# ============= app creation ==============
app = Flask(__name__) app = Flask(__name__)
# ============= read environ ==============
MY_SQL_HOST = environ.get('SQL_HOST', '172.17.0.2')
# ================= views =================
# @app.route("/getJSON") # route renamed # @app.route("/getJSON") # route renamed
@app.route("/comexAPI") @app.route("/comexAPI")
def main(): def main():
db=SQLite('../community.db') # db=SQLite('../community.db')
db=MySQL(MY_SQL_HOST)
if 'query' in request.args: if 'query' in request.args:
# TODO fix ('refine' button)
# query is a json {cat:filtervalue} , not an executable SQL query !!
filteredquery = request.args['query'] filteredquery = request.args['query']
scholars = db.getScholarsList("filter",filteredquery) scholars = db.getScholarsList("filter",filteredquery)
else: else:
......
...@@ -80,7 +80,8 @@ foreach ($scholars as $scholar) { ...@@ -80,7 +80,8 @@ foreach ($scholars as $scholar) {
// echo "<p>no match :(</p>"; // echo "<p>no match :(</p>";
} }
echo "<p>mimetype:".$mimeguess."</p>"; // debug
// echo "<p>mimetype:".$mimeguess."</p>";
$content .= '<img style="margin: 7px 10px 10px 0px" src="data:'.$mimeguess.';base64,'.$perhaps_decoded.'"/>'; $content .= '<img style="margin: 7px 10px 10px 0px" src="data:'.$mimeguess.';base64,'.$perhaps_decoded.'"/>';
} }
...@@ -91,7 +92,7 @@ foreach ($scholars as $scholar) { ...@@ -91,7 +92,7 @@ foreach ($scholars as $scholar) {
} }
} }
$content .= '<h2 >' . $scholar['title'] . ' ' . $scholar['first_name'] . ' ' . $scholar['initials'] . ' ' . $scholar['last_name'] . $content .= '<h2 >' . $scholar['title'] . ' ' . $scholar['first_name'] . ' ' . $scholar['mid_initial'] . ' ' . $scholar['last_name'] .
' <small> - ' . $scholar['country'] . '</small></h2>'; ' <small> - ' . $scholar['country'] . '</small></h2>';
...@@ -224,39 +225,40 @@ if (strcmp(substr($orga_query, 0,2),'OR')==0){ ...@@ -224,39 +225,40 @@ if (strcmp(substr($orga_query, 0,2),'OR')==0){
// liste des labs //////// // liste des labs ////////
////////////////////////// //////////////////////////
$labs = array(); $labs = array();
// TODO RESTORE sort($lab_list);
// sort($lab_list);
foreach ($lab_list as $name) {
// foreach ($lab_list as $name) { if ((trim($name)) != NULL) {
// if ((trim($name)) != NULL) { // $sql = 'SELECT * FROM affiliations where team_lab="' . $name . '" OR acronym="' . $name . '"';
// $sql = 'SELECT * FROM labs where name="' . $name . '" OR acronym="' . $name . '"'; $sql = 'SELECT * FROM affiliations WHERE team_lab="' . $name . '"';
// //echo $sql.'<br/>'; //echo $sql.'<br/>';
// foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
// //echo 'toto'; //echo 'toto';
// $info = array(); $info = array();
// $info['unique_id'] = $row['id']; $info['unique_id'] = $row['affid'];
// $info['name'] = $row['name']; $info['name'] = $row['team_lab'];
// $info['acronym'] = $row['acronym']; // TODO RESTORE
// $info['homepage'] = $row['homepage']; // $info['acronym'] = $row['acronym'];
// $info['keywords'] = $row['keywords']; // $info['homepage'] = $row['homepage'];
// $info['country'] = $row['country']; // $info['keywords'] = $row['keywords'];
// $info['address'] = $row['address']; // $info['country'] = $row['country'];
// $info['organization'] = $row['organization']; // $info['address'] = $row['address'];
// $info['organization2'] = $row['organization2']; // $info['organization'] = $row['organization'];
// $orga_list[] = $row['organization']; // $info['organization2'] = $row['organization2'];
// $orga_list[] = $row['organization2']; // $orga_list[] = $row['organization'];
// $info['object'] = $row['object']; // $orga_list[] = $row['organization2'];
// $info['methods'] = $row['methods']; // $info['object'] = $row['object'];
// $info['director'] = $row['director']; // $info['methods'] = $row['methods'];
// $info['admin'] = $row['admin']; // $info['director'] = $row['director'];
// $info['phone'] = $row['phone']; // $info['admin'] = $row['admin'];
// $info['fax'] = $row['fax']; // $info['phone'] = $row['phone'];
// $info['login'] = $row['login']; // $info['fax'] = $row['fax'];
// //print_r($info); // $info['login'] = $row['login'];
// $labs[$row['id']] = $info; //print_r($info);
// } $labs[$row['id']] = $info;
// } }
// } }
}
//print_r($labs); //print_r($labs);
...@@ -265,39 +267,43 @@ $labs = array(); ...@@ -265,39 +267,43 @@ $labs = array();
////////////////////////// //////////////////////////
// liste des organizations //////// // liste des organizations ////////
////////////////////////// //////////////////////////
// debug
// $content .= var_dump($orga_list) ;
$organiz = array(); $organiz = array();
// TODO RESTORE sort($orga_list);
// sort($orga_list); foreach ($orga_list as $name) {
// foreach ($orga_list as $name) { if ((trim($name))!=NULL){
// if ((trim($name))!=NULL){ $sql = "SELECT * FROM affiliations WHERE org='" . $name. "'";
// $sql = "SELECT * FROM organizations where name='" . $name. "' OR acronym='".$name."'";
// $temp=true;
// $temp=true; foreach ($base->query($sql) as $row) {
// foreach ($base->query($sql) as $row) { if ($temp){
// if ($temp){ $info = array();
// $info = array(); $info['unique_id'] = $row['affid'];
// $info['unique_id'] = $row['id']; $info['name'] = $row['org'];
// $info['name'] = $row['name']; // TODO RESTORE
// $info['acronym'] = $row['acronym']; // $info['acronym'] = $row['acronym'];
// $info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
// $info['keywords'] = $row['keywords']; // $info['keywords'] = $row['keywords'];
// $info['country'] = $row['country']; // $info['country'] = $row['country'];
// $info['street'] = $row['street']; // $info['street'] = $row['street'];
// $info['city'] = $row['city']; // $info['city'] = $row['city'];
// $info['state'] = $row['state']; // $info['state'] = $row['state'];
// $info['postal_code'] = $row['postal_code']; // $info['postal_code'] = $row['postal_code'];
// $info['fields'] = $row['fields']; // $info['fields'] = $row['fields'];
// $info['admin'] = $row['admin']; // $info['admin'] = $row['admin'];
// $info['phone'] = $row['phone']; // $info['phone'] = $row['phone'];
// $info['fax'] = $row['fax']; // $info['fax'] = $row['fax'];
// $info['login'] = $row['login']; // $info['login'] = $row['login'];
// $organiz[$row['id']] = $info; $organiz[$row['affid']] = $info;
// $temp=false; $temp=false;
// } }
// } }
// } }
//
// } }
......
...@@ -207,10 +207,10 @@ $(function(){ ...@@ -207,10 +207,10 @@ $(function(){
<!--<a id="printname" href="#"> <strong>PRINT</strong></a>--> <!--<a id="printname" href="#"> <strong>PRINT</strong></a>-->
</p> </p>
<br/><br/> <br/><br/>
<i class="icon-user"></i> <strong>You cannot find yourself</strong> in the database, want update your data or keywords ? <a href="/regcomex">Edit your profile</a>, the database is updated every 30 min. <i class="icon-user"></i> <strong>You cannot find yourself</strong> in the database, want update your data or keywords ? <a href="/regcomex">Edit your profile</a>, the database is updated instantly.
<button id="register" class="btn btn-mini btn-info"> <button id="register" class="btn btn-mini btn-info">
Edit you profile ! Register
</button> </button>
<br/><br/> <br/><br/>
...@@ -220,7 +220,7 @@ $(function(){ ...@@ -220,7 +220,7 @@ $(function(){
<i class="icon-info-sign"></i> View our <a href="tips.html">tips</a> for best experience. This directory is <strong>open</strong> to everybody working in the field of Complex Systems science and Complexity science. Map and explore communities or generate a printable version of their directory. <i class="icon-info-sign"></i> View our <a href="tips.html">tips</a> for best experience. This directory is <strong>open</strong> to everybody working in the field of Complex Systems science and Complexity science. Map and explore communities or generate a printable version of their directory.
Updated every few minutes. Updated every few minutes.
<br/> <br/>
<!-- <i class="icon-list-alt"></i> Personal data are given on a voluntary basis and people are responsible for the validity and integrity of their data. <br/> <!-- <i class="icon-list-alt"></i> Personal data are given on a voluntary basis and people are responsible for the validity and integrity of their data. <br/>
<i class="icon-repeat"></i> Suggestions or comments ? <a href="http://moma.csregistry.org/feedback" target="BLANK">Please feedback.</a> <br/> <i class="icon-repeat"></i> Suggestions or comments ? <a href="http://moma.csregistry.org/feedback" target="BLANK">Please feedback.</a> <br/>
......
...@@ -189,7 +189,7 @@ $(document).ready(function() { ...@@ -189,7 +189,7 @@ $(document).ready(function() {
hide(".hero-unit"); hide(".hero-unit");
return $("#welcome").fadeOut("slow", function() { return $("#welcome").fadeOut("slow", function() {
show("#loading", "fast"); show("#loading", "fast");
return window.location.href="explorerjs.html?nodeidparam=" + ui.item.id; return window.location.href='explorerjs.html?type="uid"&nodeidparam="' + ui.item.id + '"';
//return loadGraph("get_scholar_graph.php?login=" + ui.item.id); //return loadGraph("get_scholar_graph.php?login=" + ui.item.id);
}); });
}); });
...@@ -239,7 +239,7 @@ $(document).ready(function() { ...@@ -239,7 +239,7 @@ $(document).ready(function() {
return $("#welcome").fadeOut("slow", function() { return $("#welcome").fadeOut("slow", function() {
show("#loading", "fast"); show("#loading", "fast");
return collectFilters(function(query) { return collectFilters(function(query) {
return window.location.href="explorerjs.html?nodeidparam=" + query; return window.location.href='explorerjs.html?type="filter"&nodeidparam="' + query +'"';
//return loadGraph("getgraph.php?query=" + query); //return loadGraph("getgraph.php?query=" + query);
}); });
}); });
......
...@@ -6,6 +6,10 @@ $content .='<br/> ...@@ -6,6 +6,10 @@ $content .='<br/>
<br/>'; <br/>';
$orga_count = 0; $orga_count = 0;
// debug
// $content .= var_dump($organiz) ;
foreach ($organiz as $orga) { foreach ($organiz as $orga) {
if ($loop % 100){ if ($loop % 100){
......
...@@ -117,7 +117,9 @@ $query_details='<ul>'; ...@@ -117,7 +117,9 @@ $query_details='<ul>';
$f = "";// requête $f = "";// requête
$labfilter=''; $labfilter='';
if ($tags) { if ($tags) {
echo '<p style="color:white">MATCHING ON tags<p>'; // debug
// echo '<p style="color:white">MATCHING ON tags<p>';
if (sizeof($tags) > 0) { if (sizeof($tags) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -139,8 +141,10 @@ if ($tags) { ...@@ -139,8 +141,10 @@ if ($tags) {
} }
if ($keywords) { if ($keywords) {
echo '<p style="color:white">MATCHING ON keywords<p>'; // debug
if (sizeof($keywords) > 0) { // echo '<p style="color:white">MATCHING ON keywords<p>';
if (sizeof($keywords) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
$query_details.='<li><strong>Working on: </strong>'; $query_details.='<li><strong>Working on: </strong>';
...@@ -153,15 +157,17 @@ if ($keywords) { ...@@ -153,15 +157,17 @@ if ($keywords) {
$query_details.=$word.', '; $query_details.=$word.', ';
if ($i > 0) if ($i > 0)
$f .= " OR "; $f .= " OR ";
$f .= 'keywords LIKE "%' . $word . '%" '; $f .= 'keywords_list LIKE "%' . $word . '%" ';
$i++; $i++;
} }
} }
$f .= ") "; $f .= ") ";
} }
if ($countries) { if ($countries) {
echo '<p style="color:white">MATCHING ON countries<p>'; // debug
if (sizeof($countries) > 0) { // echo '<p style="color:white">MATCHING ON countries<p>';
if (sizeof($countries) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
$query_details.='<li><strong>In the following country: </strong>'; $query_details.='<li><strong>In the following country: </strong>';
...@@ -179,7 +185,8 @@ if ($countries) { ...@@ -179,7 +185,8 @@ if ($countries) {
$f .= ") "; $f .= ") ";
} }
if ($laboratories) { if ($laboratories) {
echo '<p style="color:white">MATCHING ON labs<p>'; // debug
// echo '<p style="color:white">MATCHING ON labs<p>';
if (sizeof($laboratories) > 0) { if (sizeof($laboratories) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -198,8 +205,10 @@ if ($laboratories) { ...@@ -198,8 +205,10 @@ if ($laboratories) {
} }
if ($organizations) { if ($organizations) {
echo '<p style="color:white">MATCHING ON organizations<p>'; // debug
if (sizeof($organizations) > 0) { // echo '<p style="color:white">MATCHING ON organizations<p>';
if (sizeof($organizations) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
$query_details.='<li><strong>In the organization named : </strong>'; $query_details.='<li><strong>In the organization named : </strong>';
...@@ -210,7 +219,7 @@ if ($organizations) { ...@@ -210,7 +219,7 @@ if ($organizations) {
if ($org == "") continue; if ($org == "") continue;
$query_details.=$org.', '; $query_details.=$org.', ';
$f .= 'institution LIKE "%' . $org . '%" '; $f .= 'org LIKE "%' . $org . '%" ';
//'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"'; //'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"';
$i++; $i++;
} }
...@@ -236,14 +245,36 @@ $imsize = 150; ...@@ -236,14 +245,36 @@ $imsize = 150;
$content=''; $content='';
if (strlen($f)>0){ // filtered query
$sql = "SELECT * FROM comex_registrations where " . " " . $f.' ORDER BY last_name'; if (strlen($f)>0) {
}else{ $filter = "WHERE {$f}";
$sql = "SELECT * FROM comex_registrations ORDER BY last_name";
} }
// unfiltered query
//echo $sql.'<br/>'; else {
echo '<p style="color:white">query:'. $sql ."<p>"; $filter = "";
}
$sql = <<< END_QUERY
SELECT * FROM
(SELECT
scholars.*,
affiliations.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(keywords.kwid) AS keywords_ids,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON affiliation_id = affid
GROUP BY doors_uid) AS full_scholars_info
{$filter}
END_QUERY;
// debug
// echo '<p style="color:white">query:'. $sql ."<p>";
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
...@@ -252,30 +283,31 @@ $scholars = array(); ...@@ -252,30 +283,31 @@ $scholars = array();
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
// TODO RESTORE
$info = array(); $info = array();
$info['unique_id'] = $row['doors_uid']; $info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name']; $info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials']; $info['mid_initial'] = (strlen($row['middle_name']) ? substr($row['middle_name'],0,1)."." : "");
$info['last_name'] = $row['last_name']; $info['last_name'] = $row['last_name'];
$info['initials'] = $row['initials'];
// retrieved from secondary table and GROUP_CONCATenated
$info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['nb_keywords'] = $row['keywords_nb'];
$info['keywords'] = $row['keywords_list'];
// => TODO RESTORE
// $info['nb_keywords'] = $row['nb_keywords'];
// $info['css_voter'] = $row['css_voter'];
// $info['css_member'] = $row['css_member'];
// $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords'];
// $info['status'] = $row['status']; // $info['status'] = $row['status'];
$info['record_status'] = $row['record_status']; // TODO use this one
$info['country'] = $row['country']; $info['country'] = $row['country'];
// $info['homepage'] = $row['homepage']; $info['homepage'] = $row['home_url'];
$info['lab'] = $row['team_lab']; $info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['institution']; $info['affiliation'] = $row['org'];
// $info['lab2'] = $row['lab2']; // $info['lab2'] = $row['lab2'];
// $info['affiliation2'] = $row['affiliation2']; // $info['affiliation2'] = $row['affiliation2'];
// $info['homepage'] = $row['homepage']; $info['title'] = $row['hon_title'];
$info['title'] = $row['jobtitle']; $info['position'] = $row['position'];
$info['position'] = $row['jobtitle']; $info['photo_url'] = $row['pic_url'];
// $info['photo_url'] = $row['photo_url'];
$info['pic_file'] = $row['pic_file']; $info['pic_file'] = $row['pic_file'];
$info['interests'] = $row['interests_text']; $info['interests'] = $row['interests_text'];
// $info['address'] = $row['address']; // $info['address'] = $row['address'];
...@@ -290,9 +322,12 @@ foreach ($base->query($sql) as $row) { ...@@ -290,9 +322,12 @@ foreach ($base->query($sql) as $row) {
/// stats /// stats
include ('stat-prep_from_array.php');/// include ('stat-prep_from_array.php');///
// debug
// $content .= var_dump($scholars) ;
include ("directory_content.php"); include ("directory_content.php");
// liste des chercheurs // liste des chercheurs
......
...@@ -77,32 +77,39 @@ $base = new PDO($dsn, $user, $pass, $opt); ...@@ -77,32 +77,39 @@ $base = new PDO($dsn, $user, $pass, $opt);
if ($login) { if ($login) {
if (sizeof($login) > 0) { if (sizeof($login) > 0) {
// liste des chercheurs // nom du chercheur $target_name
$sql = "SELECT keywords,last_name,first_name FROM comex_registrations WHERE doors_uid='" . $login . "'"; $sql0 = "SELECT last_name,first_name FROM scholars WHERE doors_uid='" . $login . "'";
foreach ($base->query($sql) as $row) {
$keywords = explode(',', $row['keywords']); foreach ($base->query($sql0) as $row) {
$scholar_array = array(); // always one record by design of uid
$target_name=$row['first_name'].' '.$row['last_name']; $target_name=$row['first_name'].' '.$row['last_name'];
foreach ($keywords as $keyword) {
if (strlen($keyword) > 0) {
// TODO RESTORE index keywords
// $sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id);
$sql2 = "SELECT doors_uid FROM comex_registrations WHERE keywords LIKE \"%" . trim($keyword)."%\"";
// echo($sql2."<br/>");
foreach ($base->query($sql2) as $row) {
if (array_key_exists($row['doors_uid'], $scholar_array)){
$scholar_array[$row['doors_uid']] += 1;
}else{
$scholar_array[$row['doors_uid']] = 1;
}
}
}
}
} }
// liste des chercheurs
// old way in two steps without a scholars <=> keywords table
// $sql1 = "SELECT keywords,last_name,first_name FROM scholars WHERE doors_uid='" . $login . "'";
// $sql2 = "SELECT uid FROM sch_kw JOIN keywords ON sch_kw.kwid = keywords.kwid WHERE kwstr LIKE \"%" . trim($keyword)."%\"";
// new way in one query
$sql1 = <<< HERE_QUERY
SELECT second_level.uid
FROM sch_kw
LEFT JOIN sch_kw
AS second_level
ON sch_kw.kwid = second_level.kwid
WHERE sch_kw.uid = "{$login}"
AND second_level.uid != sch_kw.uid
GROUP BY second_level.uid ;
HERE_QUERY;
foreach ($base->query($sql1) as $row) {
if (array_key_exists($row['uid'], $scholar_array)){
$scholar_array[$row['uid']] += 1;
}else{
$scholar_array[$row['uid']] = 1;
}
}
} }
} }
...@@ -116,31 +123,53 @@ $scholar_id_array=array_keys($scholar_array); ...@@ -116,31 +123,53 @@ $scholar_id_array=array_keys($scholar_array);
$scholars = array(); $scholars = array();
// //
foreach ($scholar_id_array as $scholar_id){ foreach ($scholar_id_array as $scholar_id){
$sql = "SELECT * FROM comex_registrations where doors_uid='" . $scholar_id. "'"; $sql = <<< END_QUERY
SELECT
scholars.*,
affiliations.*,
COUNT(keywords.kwid) AS keywords_nb,
GROUP_CONCAT(keywords.kwid) AS keywords_ids,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON doors_uid = uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON affiliation_id = affid
WHERE doors_uid = "{$scholar_id}"
GROUP BY doors_uid
END_QUERY;
// echo var_dump($scholar_id)."<br/>" ; // echo var_dump($scholar_id)."<br/>" ;
//$query = "SELECT * FROM scholars"; //$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
$info = array(); $info = array();
$info['unique_id'] = $row['doors_uid']; $info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name']; $info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials']; $info['mid_initial'] = (strlen($row['middle_name']) ? substr($row['middle_name'],0,1)."." : "");
$info['last_name'] = $row['last_name']; $info['last_name'] = $row['last_name'];
// $info['nb_keywords'] = $row['nb_keywords']; $info['initials'] = $row['initials'];
// $info['css_voter'] = $row['css_voter'];
// $info['css_member'] = $row['css_member']; // retrieved from secondary table and GROUP_CONCATenated
// $info['keywords_ids'] = explode(',', $row['keywords_ids']); $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords']; $info['nb_keywords'] = $row['keywords_nb'];
$info['keywords'] = $row['keywords_list'];
// $info['status'] = $row['status']; // $info['status'] = $row['status'];
$info['record_status'] = $row['record_status']; // TODO use this one
$info['country'] = $row['country']; $info['country'] = $row['country'];
// $info['homepage'] = $row['homepage']; $info['homepage'] = $row['home_url'];
$info['lab'] = $row['team_lab']; $info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['institution']; $info['affiliation'] = $row['org'];
// $info['lab2'] = $row['lab2']; // $info['lab2'] = $row['lab2'];
// $info['affiliation2'] = $row['affiliation2']; // $info['affiliation2'] = $row['affiliation2'];
// $info['homepage'] = $row['homepage']; $info['title'] = $row['hon_title'];
$info['title'] = $row['jobtitle']; $info['position'] = $row['position'];
$info['position'] = $row['jobtitle']; $info['photo_url'] = $row['pic_url'];
// $info['photo_url'] = $row['photo_url'];
$info['pic_file'] = $row['pic_file']; $info['pic_file'] = $row['pic_file'];
$info['interests'] = $row['interests_text']; $info['interests'] = $row['interests_text'];
// $info['address'] = $row['address']; // $info['address'] = $row['address'];
......
...@@ -21,17 +21,19 @@ if ($category == 'country' || $category == 'countries') { ...@@ -21,17 +21,19 @@ if ($category == 'country' || $category == 'countries') {
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'organization' || $category == 'organizations') { } elseif ($category == 'organization' || $category == 'organizations') {
// POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))`` // POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))`
// (change in $cat here and in print_directory args downstream) // (change in $cat here and in print_directory args downstream)
$cat = 'institution'; $cat = 'org';
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'keyword' || $category == 'keywords') { } elseif ($category == 'keyword' || $category == 'keywords') {
$cat = "keywords"; $cat = "keywords_list";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'tag' || $category == 'tags') { }
$cat = "tags"; elseif ($category == 'tag' || $category == 'tags') {
$cat = "community_hashtags";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') { }
elseif (v == 'labs' || $category == 'laboratories' || $category == 'laboratory') {
$cat = "team_lab"; $cat = "team_lab";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} else { } else {
...@@ -47,13 +49,44 @@ function filter_word($value) { ...@@ -47,13 +49,44 @@ function filter_word($value) {
return ! in_array(strtolower($value),$filtered); return ! in_array(strtolower($value),$filtered);
} }
$req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM comex_registrations WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC"; // old way
// $req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM scholars WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC";
// TODO differentiate req's target cols earlier: above in "if ($category == X)"
$req = <<<END_QUERY
SELECT
{$cat} AS clef,
count({$cat}) AS value
FROM (
SELECT
-- we create all needed cats for the outer select
-- ==============================================
scholars.doors_uid,
scholars.country,
scholars.community_hashtags,
affiliations.org,
affiliations.team_lab,
GROUP_CONCAT(kwstr) AS keywords_list
FROM scholars
JOIN sch_kw
ON scholars.doors_uid = sch_kw.uid
JOIN keywords
ON sch_kw.kwid = keywords.kwid
LEFT JOIN affiliations
ON scholars.affiliation_id = affiliations.affid
GROUP BY doors_uid
) AS full_scholars_info
WHERE {$cat} {$query} -- <== our filter
GROUP BY $cat
ORDER BY value DESC ;
END_QUERY;
// echo $req; // echo $req;
$results = array(); $results = array();
$i = 0; $i = 0;
foreach ($base->query($req) as $row) { foreach ($base->query($req) as $row) {
$nb = $row['value']; $nb = $row['value'];
if ($cat == "keywords" || $cat == "tags") { if ($cat == "keywords_list" || $cat == "tags") {
//echo "in keywords\n"; //echo "in keywords\n";
$words = explode(",", $row["clef"]); $words = explode(",", $row["clef"]);
foreach ($words as $word) { foreach ($words as $word) {
...@@ -84,7 +117,7 @@ foreach ($base->query($req) as $row) { ...@@ -84,7 +117,7 @@ foreach ($base->query($req) as $row) {
} else { } else {
$results[ $word ] = intval($nb); $results[ $word ] = intval($nb);
} }
} }
} }
} }
......
...@@ -21,7 +21,7 @@ $q = "%".sanitize_input($login)."%"; ...@@ -21,7 +21,7 @@ $q = "%".sanitize_input($login)."%";
$query = 'concat(first_name, " ", IFNULL(middle_name,""), " ", last_name) LIKE "%'.$q.'%"'; $query = 'concat(first_name, " ", IFNULL(middle_name,""), " ", last_name) LIKE "%'.$q.'%"';
$req = "SELECT doors_uid, email, first_name, last_name, keywords FROM comex_registrations WHERE ".$query." GROUP BY doors_uid"; $req = "SELECT doors_uid, first_name, middle_name, last_name FROM scholars WHERE ".$query." GROUP BY doors_uid";
// echo "req: ".$req.";"; // echo "req: ".$req.";";
$results = array(); $results = array();
$i = 0; $i = 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