Commit 72859dbf authored by Romain Loth's avatar Romain Loth

adapt dbdatapi for new org tables (+ gui autocomplete 1/2)

parent 9fb58f01
...@@ -189,90 +189,104 @@ $loop = 0; ...@@ -189,90 +189,104 @@ $loop = 0;
// all lab orgids except _NULL // all lab orgids except _NULL
$ids_str = implode(',', array_keys($lab_counts)); $lab_ids = array_filter(array_keys($lab_counts));
sort($lab_ids);
// print_r("all lab ids here:");
// print_r($ids_str);
// print_r("<br/>");
// all lab infos to retrieve
$labs = array(); $labs = array();
// normal query would be enough for everything except parent org // paging
// POSS page the request in nb of ids >= mysql technical limit for IN $step = 2000;
// $sql = 'SELECT * FROM orgs WHERE orgid IN ('.$ids_str.') ORDER BY name, acro' ; $n_steps = ceil(count($lab_ids)/$step);
// variant with parent org for($i = 0; $i < $n_steps; $i++) {
// unique org1 (=> unique pairs (sch_org => sch_org2) $batch = array_slice($lab_ids, $step * $i, $step);
// => org2 info) $ids_str = implode(',', $batch);
//
// it's much longer in code but fast because of indexes // print_r("<br>step: ".$i." / ids_str".$ids_str."<br>");
//
// a POSS alternative would be to // normal query would be enough for everything except parent org
// create an org_org table // POSS page the request in nb of ids >= mysql technical limit for IN
// at record time // $sql = 'SELECT * FROM orgs WHERE orgid IN ('.$ids_str.')'; // ORDER BY name, acro' ;
$sql = <<< LABSQLEXTENDED // variant query with parent org
SELECT orgs.*, // unique org1 (=> unique pairs (sch_org => sch_org2)
GROUP_CONCAT( tgt_tostring ORDER BY tgt_freq DESC SEPARATOR '%%%') // => org2 info)
AS related_insts //
FROM orgs // it's much longer in code but fast because of indexes
LEFT JOIN ( //
SELECT sch_org.orgid AS src_orgid, // a POSS alternative would be to
sch_org2.orgid AS tgt_orgid, // create an org_org table
orgs2.tostring AS tgt_tostring, // at record time
count(*) AS tgt_freq //
FROM sch_org $sql = <<< LABSQLEXTENDED
LEFT JOIN sch_org AS sch_org2 SELECT orgs.*,
ON sch_org.uid = sch_org2.uid GROUP_CONCAT( tgt_tostring ORDER BY tgt_freq DESC SEPARATOR '%%%')
JOIN orgs AS orgs2 AS related_insts
ON sch_org2.orgid = orgs2.orgid FROM orgs
WHERE orgs2.class = 'inst' LEFT JOIN (
AND sch_org.orgid != sch_org2.orgid SELECT sch_org.orgid AS src_orgid,
GROUP BY sch_org.orgid, sch_org2.orgid sch_org2.orgid AS tgt_orgid,
) AS lab_relationship_to_inst_via_scholars ON src_orgid = orgs.orgid orgs2.tostring AS tgt_tostring,
WHERE orgs.orgid IN ( {$ids_str} ) count(*) AS tgt_freq
AND orgs.name != '_NULL' FROM sch_org
GROUP BY orgs.orgid LEFT JOIN sch_org AS sch_org2
ORDER BY orgs.name, orgs.acro ON sch_org.uid = sch_org2.uid
JOIN orgs AS orgs2
ON sch_org2.orgid = orgs2.orgid
WHERE orgs2.class = 'inst'
AND sch_org.orgid != sch_org2.orgid
GROUP BY sch_org.orgid, sch_org2.orgid
) AS lab_relationship_to_inst_via_scholars ON src_orgid = orgs.orgid
WHERE orgs.orgid IN ( {$ids_str} )
AND orgs.name != '_NULL'
GROUP BY orgs.orgid
ORDER BY orgs.name, orgs.acro
LABSQLEXTENDED; LABSQLEXTENDED;
// print_r($sql); // print_r($sql);
foreach ($base->query($sql) as $row) {
$info = array();
$info['unique_id'] = $row['orgid'];
foreach ($base->query($sql) as $row) { // print_r($row);
$info = array(); // print_r("<br/>");
$info['unique_id'] = $row['orgid'];
// print_r($row); $info['name'] = $row['name'];
// print_r("<br/>");
$info['name'] = $row['name']; $info['acronym'] = $row['acro'] ?? '';
$info['homepage'] = $row['url'] ?? '';
$info['lab_code'] = $row['lab_code'] ?? '';
$info['locname'] = $row['locname'] ?? ''; // ex: 'Barcelona, Spain'
// 'London, UK'
// 'UK'
$info['acronym'] = $row['acro'] ?? ''; // keywords : POSS with an org <=> keywords map
$info['homepage'] = $row['url'] ?? ''; // cf. doc/data_mining_exemples/correlated_kws.sql
$info['lab_code'] = $row['lab_code'] ?? ''; // $info['keywords'] = $row['keywords'];
$info['locname'] = $row['locname'] ?? ''; // ex: 'Barcelona, Spain'
// 'London, UK'
// 'UK'
// keywords : POSS with an org <=> keywords map // most frequent parent orgs (max = 3)
// cf. doc/data_mining_exemples/correlated_kws.sql $related_insts = array_slice(explode('%%%', $row['related_insts'] ?? ""),0,3) ;
// $info['keywords'] = $row['keywords']; $info['related_insts'] = $related_insts;
// most frequent parent orgs (max = 3) // also add them to orga_list
$related_insts = array_slice(explode('%%%', $row['related_insts'] ?? ""),0,3) ; $all_orga_list[] = $related_insts;
$info['related_insts'] = $related_insts;
// also add them to orga_list $info['admin'] = ucwords($row['contact_name'] ?? '');
$all_orga_list[] = $related_insts; if ($row['contact_email']) {
$safe_contact_email = safe_email($row['contact_email']);
$info['admin'] .= '<br><span class=code>'.$safe_contact_email.'</span>';
}
// print_r($info);
$labs[$row['orgid']] = $info;
$info['admin'] = ucwords($row['contact_name'] ?? ''); // finished batch
if ($row['contact_email']) {
$safe_contact_email = safe_email($row['contact_email']);
$info['admin'] .= '<br><span class=code>'.$safe_contact_email.'</span>';
} }
// print_r($info); // finished all labs
$labs[$row['orgid']] = $info;
} }
// //
// print_r("all labs here:"); // print_r("all labs here:");
// print_r($labs); // print_r($labs);
...@@ -284,7 +298,7 @@ foreach ($base->query($sql) as $row) { ...@@ -284,7 +298,7 @@ foreach ($base->query($sql) as $row) {
// debug // debug
// $content .= var_dump($all_orga_list) ; // $content .= var_dump($all_orga_list) ;
//
// $organiz = array(); // $organiz = array();
// sort($all_orga_list); // sort($all_orga_list);
// foreach ($all_orga_list as $name) { // foreach ($all_orga_list as $name) {
...@@ -318,7 +332,7 @@ foreach ($base->query($sql) as $row) { ...@@ -318,7 +332,7 @@ foreach ($base->query($sql) as $row) {
// } // }
// //
// } // }
//
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
......
...@@ -6,17 +6,19 @@ ...@@ -6,17 +6,19 @@
*/ */
// parameters : threshold to display orgs (labs / institutions) diagrams
$MIN_DISTINCT_LABS = 1 ;
$MIN_DISTINCT_LABS_SCHOLARS_SHARE = .25;
// paramters : threshold to display orgs (labs / institutions) diagrams $MIN_DISTINCT_INSTS = 1 ;
$MIN_DISTINCT_LABS = 5 ; $MIN_DISTINCT_INSTS_SCHOLARS_SHARE = .20;
$MIN_DISTINCT_INSTS = 4 ;
// main vars
$country_list = array(); $country_list = array();
$position_list = array(); $position_list = array();
$title_list = array(); $title_list = array();
// not needed already factorized in lab_counts, inst_counts // not needed already factorized in lab_counts, inst_counts
// $labs_list = array(); // $labs_list = array();
// $insts_list = array(); // $insts_list = array();
...@@ -129,16 +131,18 @@ asort($inst_counts); ...@@ -129,16 +131,18 @@ asort($inst_counts);
// TODO factorize all this // TODO factorize all this
// we are creating highcharts' arguments for pie chart
// eg position_data: data: [["senior researcher",11],["assistant professor",23],["lecturer",25],["engineer",26],["associate professor",28],["student",28],["post-doc",48],["professor",51],["phd student",53],["research director",64],["researcher",68],["Missing data",467],["Others",210]]
// NB escaping: no need to do htmlspeciazlchars($key, ENT_HTML5 | ENT_QUOTES, 'UTF-8'); because the target language is js (doesn't need html entities) // NB escaping: no need to do htmlspeciazlchars($key, ENT_HTML5 | ENT_QUOTES, 'UTF-8'); because the target language is js (doesn't need html entities)
// données des pays // données des pays
$country_data = "data: ["; $country_data = "data: [";
foreach ($country_list as $key => $value) { foreach ($country_list as $key => $value) {
$key = addslashes($key); $thresh = min(9, count($country_list) / 10);
if ($value > $thresh) {
if ($value > min(9, count($country_list) / 10)) { $country_data.='["' . addslashes($key) . '",' . $value . '],';
$country_data.='["' . $key . '",' . $value . '],';
} else { } else {
$other_country+=$value; $other_country+=$value;
} }
...@@ -162,9 +166,9 @@ $country_data.=']'; ...@@ -162,9 +166,9 @@ $country_data.=']';
// données des position // données des position
$position_data = "data: ["; $position_data = "data: [";
foreach ($position_list as $key => $value) { foreach ($position_list as $key => $value) {
$key = addslashes($key); $thresh = min(9, count($position_list) / 10);
if ($value > min(9, count($position_list) / 10)) { if ($value > $thresh) {
$position_data.='["' . $key . '",' . $value . '],'; $position_data.='["' . addslashes($key) . '",' . $value . '],';
} else { } else {
$other_position+=$value; $other_position+=$value;
} }
...@@ -207,16 +211,26 @@ $title_data.=']'; ...@@ -207,16 +211,26 @@ $title_data.=']';
$labs_data = "data: ["; $labs_data = "data: [";
$n_labs = count($lab_counts); $n_labs = count($lab_counts);
$n_shown_labs = 0 ; $n_shown_labs = 0 ;
$tot_shown_labs = 0;
$labs_total_responses = 0;
foreach ($lab_counts as $key => $value) { foreach ($lab_counts as $key => $value) {
// $key is the orgid, but we need the name
$label = $org_id_to_label[$key];
$thresh = min(9, $n_labs / 15);
$key = addslashes($key); if (!$label || $label == "_NULL") {
if ($value > min(9, $n_labs / 15)) { $missing_labs += $value;
$labs_data.='["' . $key . '",' . $value . '],'; }
elseif ($value > $thresh) {
$labs_data.='["' . addslashes($label) . '",' . $value . '],';
$n_shown_labs += 1; $n_shown_labs += 1;
$tot_shown_labs += $value;
} else { } else {
$other_labs+=$value; $other_labs+=$value;
} }
# doesn't include missing, but we can compare to n_scholars to know
$labs_total_responses += $value;
} }
if ($missing_labs>0){ if ($missing_labs>0){
$labs_data.='["Missing data",' . $missing_labs . '],'; $labs_data.='["Missing data",' . $missing_labs . '],';
...@@ -230,19 +244,31 @@ if ($other_labs>0){ ...@@ -230,19 +244,31 @@ if ($other_labs>0){
$labs_data.=']'; $labs_data.=']';
// $share_of_shown_labs = sprintf("%.6f", $tot_shown_labs/$labs_total_responses);
$share_of_shown_labs = sprintf("%.6f", $tot_shown_labs/count($scholars));
$insts_data = "data: ["; $insts_data = "data: [";
$n_insts = count($inst_counts); $n_insts = count($inst_counts);
$n_shown_insts = 0 ; $n_shown_insts = 0 ;
$tot_shown_insts = 0;
$insts_total_responses = 0;
foreach ($inst_counts as $key => $value) { foreach ($inst_counts as $key => $value) {
$label = $org_id_to_label[$key];
$thresh = min(9, $n_insts / 15);
$key = addslashes($key); if (!$label) {
if ($value > min(9, $n_insts / 15)) { $missing_insts += $value;
$insts_data.='["' . $key . '",' . $value . '],'; }
elseif ($value > $thresh) {
$insts_data.='["' . addslashes($label) . '",' . $value . '],';
$n_shown_insts += 1; $n_shown_insts += 1;
$tot_shown_insts += $value;
} else { } else {
$other_insts+=$value; $other_insts+=$value;
} }
$insts_total_responses+=$value;
} }
if ($missing_insts>0){ if ($missing_insts>0){
$insts_data.='["Missing data",' . $missing_insts . '],'; $insts_data.='["Missing data",' . $missing_insts . '],';
...@@ -256,7 +282,10 @@ if ($other_labs>0){ ...@@ -256,7 +282,10 @@ if ($other_labs>0){
$insts_data.=']'; $insts_data.=']';
// $share_of_shown_insts = sprintf("%.6f", $tot_shown_insts/$insts_total_responses);
$share_of_shown_insts = sprintf("%.6f", $tot_shown_insts/count($scholars));
// print_r("shown_insts_total % ".$share_of_shown_insts);
// TODO separate this Highcharts js to factorize and expose as functions // TODO separate this Highcharts js to factorize and expose as functions
// (or replace it by D3 and also separate) // (or replace it by D3 and also separate)
...@@ -372,7 +401,13 @@ $(document).ready(function() { ...@@ -372,7 +401,13 @@ $(document).ready(function() {
'}] '}]
}); });
if (parseInt('.$n_shown_labs.') >= parseInt('.$MIN_DISTINCT_LABS.')) { var MIN_DISTINCT_LABS = parseInt('.$MIN_DISTINCT_LABS.')
var MIN_DISTINCT_LABS_SCHOLARS_SHARE = parseFloat('.$MIN_DISTINCT_LABS_SCHOLARS_SHARE.')
if (
parseInt('.$n_shown_labs.') >= MIN_DISTINCT_LABS
&& parseFloat('.$share_of_shown_labs.') >= MIN_DISTINCT_LABS_SCHOLARS_SHARE
) {
labs= new Highcharts.Chart({ labs= new Highcharts.Chart({
chart: { chart: {
...@@ -412,7 +447,12 @@ $(document).ready(function() { ...@@ -412,7 +447,12 @@ $(document).ready(function() {
document.getElementById("labs_div").style.display = "none" document.getElementById("labs_div").style.display = "none"
} }
if (parseInt('.$n_shown_insts.') >= parseInt('.$MIN_DISTINCT_INSTS.')) { var MIN_DISTINCT_INSTS = parseInt('.$MIN_DISTINCT_INSTS.')
var MIN_DISTINCT_INSTS_SCHOLARS_SHARE = parseFloat('.$MIN_DISTINCT_INSTS_SCHOLARS_SHARE.')
if ( parseInt('.$n_shown_insts.') >= MIN_DISTINCT_INSTS
&& parseFloat('.$share_of_shown_insts.') >= MIN_DISTINCT_INSTS_SCHOLARS_SHARE
) {
insts= new Highcharts.Chart({ insts= new Highcharts.Chart({
chart: { chart: {
......
...@@ -3,8 +3,6 @@ include ("php_library/comex_library.php"); ...@@ -3,8 +3,6 @@ include ("php_library/comex_library.php");
include ("php_library/parametres.php"); include ("php_library/parametres.php");
include ("php_library/normalize.php"); include ("php_library/normalize.php");
//include("../common/library/fonctions_php.php");
$meta = '<!DOCTYPE html> $meta = '<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
...@@ -86,6 +84,7 @@ function objectToArray($d) { ...@@ -86,6 +84,7 @@ function objectToArray($d) {
$data = objectToArray($data); $data = objectToArray($data);
// REST query params
$categorya = $data["categorya"] ?? []; $categorya = $data["categorya"] ?? [];
$categoryb = $data["categoryb"] ?? []; $categoryb = $data["categoryb"] ?? [];
$countries = $data["countries"] ?? []; $countries = $data["countries"] ?? [];
...@@ -195,9 +194,6 @@ if ($countries) { ...@@ -195,9 +194,6 @@ if ($countries) {
$f .= ") "; $f .= ") ";
} }
// £TODO_ORGS FILTER x 2
if ($laboratories) { if ($laboratories) {
// debug // debug
// echo '<p style="color:white">MATCHING ON labs<p>'; // echo '<p style="color:white">MATCHING ON labs<p>';
...@@ -211,8 +207,8 @@ if ($laboratories) { ...@@ -211,8 +207,8 @@ if ($laboratories) {
if ($lab == "") continue; if ($lab == "") continue;
if ($i > 0) if ($i > 0)
$f .= " OR "; $f .= " OR ";
$f .= 'team_lab LIKE "%' . $lab . '%" '; $f .= 'labs_list LIKE "%' . $lab . '%" ';
$query_details.=$lab.', '; $query_details.=$lab.', ';
$i++; $i++;
} }
$f .= ") "; $f .= ") ";
...@@ -230,11 +226,11 @@ if ($organizations) { ...@@ -230,11 +226,11 @@ if ($organizations) {
foreach ($organizations as $org) { foreach ($organizations as $org) {
// echo '<p style="color:white">========> org =====> '. $org ."<p>"; // echo '<p style="color:white">========> org =====> '. $org ."<p>";
$org = sanitize_input(trim(strtolower($org))); $org = sanitize_input(trim(strtolower($org)));
if ($org == "") continue; if ($org == "") continue;
$query_details.=$org.', '; if ($i > 0)
$f .= 'org LIKE "%' . $org . '%" '; $f .= " OR ";
//'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"'; $f .= 'insts_list LIKE "%' . $org . '%" ';
$query_details.=$org.', ';
$i++; $i++;
} }
$f .= ") "; $f .= ") ";
...@@ -242,6 +238,9 @@ if ($organizations) { ...@@ -242,6 +238,9 @@ if ($organizations) {
$query_details.='</ul>'; $query_details.='</ul>';
// debug SQL filters
// print_r("query filters: ". $f);
$base = new PDO($dsn, $user, $pass, $opt); $base = new PDO($dsn, $user, $pass, $opt);
$termsMatrix = array(); // liste des termes présents chez les scholars avec leurs cooc avec les autres termes $termsMatrix = array(); // liste des termes présents chez les scholars avec leurs cooc avec les autres termes
$scholarsMatrix = array(); // liste des scholars avec leurs cooc avec les autres termes $scholarsMatrix = array(); // liste des scholars avec leurs cooc avec les autres termes
...@@ -301,7 +300,7 @@ SELECT * FROM ( ...@@ -301,7 +300,7 @@ SELECT * FROM (
GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids, GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids,
GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list
FROM scholars FROM scholars
LEFT JOIN sch_org AS map_labs LEFT JOIN sch_org AS map_labs
ON map_labs.uid = luid ON map_labs.uid = luid
LEFT JOIN ( LEFT JOIN (
SELECT * FROM orgs WHERE class='lab' SELECT * FROM orgs WHERE class='lab'
...@@ -338,7 +337,7 @@ SELECT * FROM ( ...@@ -338,7 +337,7 @@ SELECT * FROM (
END_QUERY; END_QUERY;
// debug // debug
// echo '<p style="color:white">query:'. $sql ."<p>"; // echo '<p style="color:grey;">query:<br>'. $sql ."<p>";
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
...@@ -491,11 +490,8 @@ $header = '<div class="row" id="welcome"> ...@@ -491,11 +490,8 @@ $header = '<div class="row" id="welcome">
<br/> <br/>
<br/> <br/>
<p> <p>
This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a> and <a href="#labs">'. count($labs).' labs</a> in the field of Complex Systems'; This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a>, <a href="#labs">'. count($labs).' labs</a> and <a href="#orga">'.$orga_count.' organizations</a> in the field of Complex Systems';
// TODO restore old version before duplicate lab/orga
// This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a>, <a href="#labs">'. count($labs).' labs</a> and <a href="#orga">'.$orga_count.' organizations</a> in the field of Complex Systems';
if (strlen(trim($query_details))>3){ if (strlen(trim($query_details))>3){
......
...@@ -70,6 +70,13 @@ $base = new PDO($dsn, $user, $pass, $opt); ...@@ -70,6 +70,13 @@ $base = new PDO($dsn, $user, $pass, $opt);
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
// these stats are useful BOTH in stat-prep and directory_content
// => should be prepared right now (the label mapping contain all orgs ie both labs and institutions)
$lab_counts = array();
$inst_counts = array();
$org_id_to_label = array();
if ($userid) { if ($userid) {
// query idea: // query idea:
...@@ -118,27 +125,30 @@ if ($userid) { ...@@ -118,27 +125,30 @@ if ($userid) {
FROM ( FROM (
SELECT SELECT
scholars.*, scholars.*,
-- GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids, GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids,
GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list
FROM scholars FROM scholars
LEFT JOIN sch_org AS map_labs LEFT JOIN sch_org AS map_labs
ON map_labs.uid = luid ON map_labs.uid = luid
JOIN orgs AS labs LEFT JOIN (
ON map_labs.orgid = labs.orgid SELECT * FROM orgs WHERE class='lab'
WHERE (record_status = 'active' ) AS labs
OR (record_status = 'legacy' AND valid_date >= NOW())) ON map_labs.orgid = labs.orgid
AND labs.class = 'lab' WHERE (record_status = 'active'
OR (record_status = 'legacy' AND valid_date >= NOW()))
GROUP BY luid
) AS scholars_and_labs
LEFT JOIN sch_org AS map_insts
ON map_insts.uid = luid
LEFT JOIN (
SELECT * FROM orgs WHERE class='inst'
) AS insts
ON map_insts.orgid = insts.orgid
GROUP BY luid GROUP BY luid
) AS scholars_and_labs
LEFT JOIN sch_org AS map_insts
ON map_insts.uid = luid
JOIN orgs AS insts
ON map_insts.orgid = insts.orgid
AND insts.class = 'inst'
GROUP BY luid
) AS scholars_and_orgs ) AS scholars_and_orgs
-- expansion (+kw info)
LEFT JOIN sch_kw AS second_level LEFT JOIN sch_kw AS second_level
ON second_level.uid = scholars_and_orgs.luid ON second_level.uid = scholars_and_orgs.luid
JOIN sch_kw ON sch_kw.kwid = second_level.kwid JOIN sch_kw ON sch_kw.kwid = second_level.kwid
...@@ -172,18 +182,14 @@ HERE_QUERY; ...@@ -172,18 +182,14 @@ HERE_QUERY;
$info['country'] = $row['country']; $info['country'] = $row['country'];
$info['homepage'] = $row['home_url']; $info['homepage'] = $row['home_url'];
// recreated arrays
// TODO recreate difference between lab and org --------->8--------
$info['labs'] = explode('%%%', $row['labs_list'] ?? "") ; $info['labs'] = explode('%%%', $row['labs_list'] ?? "") ;
$info['institutions'] = explode('%%%', $row['insts_list'] ?? "") ; $info['institutions'] = explode('%%%', $row['insts_list'] ?? "") ;
// right now duplicate treatment short-circuited like this $info['labs_ids'] = explode(',', $row['labs_ids'] ?? "") ;
// (effect visible in stat-prep_from_array) $info['insts_ids'] = explode(',', $row['insts_ids'] ?? "") ;
$info['affiliation'] = $row['org'] . $row['team_lab'];
$info['affiliation_id'] = $row['affiliation_id'];
// ----------------------------------------------------->8---------
// $info['lab2'] = $row['lab2'];
// $info['affiliation2'] = $row['affiliation2'];
$info['title'] = $row['hon_title']; $info['title'] = $row['hon_title'];
$info['position'] = $row['position']; $info['position'] = $row['position'];
$info['pic_src'] = $row['pic_fname'] ? '/data/shared_user_img/'.$row['pic_fname'] : $row['pic_url'] ; $info['pic_src'] = $row['pic_fname'] ? '/data/shared_user_img/'.$row['pic_fname'] : $row['pic_url'] ;
...@@ -196,11 +202,53 @@ HERE_QUERY; ...@@ -196,11 +202,53 @@ HERE_QUERY;
// $info['fax'] = $row['fax']; // $info['fax'] = $row['fax'];
// $info['affiliation_acronym'] = $row['affiliation_acronym']; // $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars[$row['luid']] = $info; $scholars[$row['luid']] = $info;
// we prepare the agregated lab stats in this loop too
foreach ( array(
array('labs','labs_ids', &$lab_counts),
array('institutions','insts_ids', &$inst_counts)
) as $cat) {
// var_dump($cat);
$namekey = $cat[0];
$idkey = $cat[1];
$counthash_ref = &$cat[2];
// £TODO_ORGS we'll need a missing_labs
$j = -1 ;
foreach ($info[$idkey] as $org_id) {
$j++;
$org_label = $info[$namekey][$j];
$org_label = trim($org_label);
if (strcmp($org_label, "") == 0) {
$org_label = null;
} else {
$org_label = weedout_alt_nulls($org_label);
}
// all non-values are there as null
$org_id_to_label[$org_id] = $org_label;
if (array_key_exists($org_id, $counthash_ref)) {
$counthash_ref[$org_id]+=1;
} else {
$counthash_ref[$org_id] = 1;
}
}
}
} }
} }
// both our stats have been filled
// var_dump($lab_counts) ;
// var_dump($inst_counts) ;
// creates js for stats visualisations // creates js for stats visualisations and counts (we re-use the orgs counts)
include ("php_library/stat-prep_from_array.php"); include ("php_library/stat-prep_from_array.php");
// debug // debug
...@@ -211,8 +259,6 @@ include ("php_library/directory_content.php"); ...@@ -211,8 +259,6 @@ include ("php_library/directory_content.php");
$content .= '</div>'; $content .= '</div>';
$content .= '</div> $content .= '</div>
<footer style="color:white"> <footer style="color:white">
...@@ -261,12 +307,10 @@ $header = '<div class="row" id="welcome"> ...@@ -261,12 +307,10 @@ $header = '<div class="row" id="welcome">
<br/> <br/>
<br/> <br/>
<p> <p>
This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a> and <a href="#labs">'. count($labs).' labs</a> in the field of Complex Systems This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a>, <a href="#labs">'. count($labs).' labs</a> and <a href="#orga">'.$orga_count.' organizations</a> in the field of Complex Systems
<br/> <br/>
Scholars have been selected from the complex systems directory when sharing common keywords with '.$target_name.' Scholars have been selected from the complex systems directory when sharing common keywords with '.$target_name.'
<!-- TODO restore old version before duplicate lab/orga with $orga_count -->
</p> </p>
<h4>About the complex systems directory</h4> <h4>About the complex systems directory</h4>
<p> <p>
...@@ -287,7 +331,11 @@ Contributions and ideas are welcome to improve this directory. ...@@ -287,7 +331,11 @@ Contributions and ideas are welcome to improve this directory.
<div id="country" style="width: 800px; height: 300px; margin: 0 auto"></div> <div id="country" style="width: 800px; height: 300px; margin: 0 auto"></div>
<div id="title" style="width: 800px; height: 300px; margin: 0 auto"></div> <div id="title" style="width: 800px; height: 300px; margin: 0 auto"></div>
<div id="position" style="width: 800px; height: 300px; margin: 0 auto"></div> <div id="position" style="width: 800px; height: 300px; margin: 0 auto"></div>
<div id="organizations" style="width: 800px; height: 300px; margin: 0 auto"></div>
<!-- these two are displayed only if the distribution has
at least 3 big groups (cf. n_shown in stats-prep) -->
<div id="labs_div" style="width: 800px; height: 300px; margin: 0 auto"></div>
<div id="insts_div" style="width: 800px; height: 300px; margin: 0 auto"></div>
<br/> <br/>
...@@ -301,6 +349,8 @@ Contributions and ideas are welcome to improve this directory. ...@@ -301,6 +349,8 @@ Contributions and ideas are welcome to improve this directory.
echo $meta.' '.$stats.'</head>'; echo $meta.' '.$stats.'</head>';
if (count($scholars)==0){ if (count($scholars)==0){
// TODO message in modal panel
echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot process its network.</h2><br/> echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot process its network.</h2><br/>
If you are '.$target_name.', you can <a href="/services/user/profile" target="_BLANK">modify your profile</a> and see your If you are '.$target_name.', you can <a href="/services/user/profile" target="_BLANK">modify your profile</a> and see your
network in few minutes.'; network in few minutes.';
...@@ -308,5 +358,6 @@ echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot pr ...@@ -308,5 +358,6 @@ echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot pr
echo $header; echo $header;
echo $content; echo $content;
} }
exit(0);
?> ?>
This diff is collapsed.
-- if serialization must be parsable, separators need to be absent tokens
SELECT
-- our convention (eg in dbdatapi.extract)
CONCAT(name, '((', acro, '))', ";;", locname)
FROM orgs
ORDER BY RAND()
LIMIT 10;
-- if serialization is just for display : for human-readable labels
-- with CONCAT_WS => nice because removes null segments eg '('+NULL+')'
SELECT
name,
acro,
locname,
CONCAT_WS( '',
CONCAT(name, ' '),
CONCAT('(',acro,')'),
CONCAT(', ', locname) )
FROM orgs
ORDER BY RAND()
LIMIT 10;
-- with CASE
SELECT
name,
acro,
locname,
-- 3 vars NULL or not => 8 cases
-- but by def either acro or name is not null => 7 cases
CASE
WHEN name IS NULL AND acro IS NULL AND locname IS NULL
THEN "_NULL"
WHEN name IS NULL AND locname IS NULL
THEN acro
WHEN acro IS NULL AND locname IS NULL
THEN name
WHEN locname IS NULL
THEN CONCAT (acro, ' (' ,name,')')
-- locname cases
WHEN name IS NULL
THEN CONCAT (acro, ', ', locname)
WHEN acro IS NULL
THEN CONCAT (name, ', ', locname)
-- eg "I3S (Laboratoire d'Informatique, Signaux et Systèmes), Sophia Antipolis, France"
ELSE CONCAT (acro, ' (' ,name,'), ', locname)
END AS tostring
FROM orgs
ORDER BY RAND()
LIMIT 10;
-- EXEMPLES:
-- +-----------------------------------------------------+-------------+--------------------------+----------------------------------------------------------------------------------+
-- | name | acro | locname | tostring |
-- +-----------------------------------------------------+-------------+--------------------------+----------------------------------------------------------------------------------+
-- | Dynamiques et écologie des paysages agroforestiers | DYNAFOR | NULL | DYNAFOR (Dynamiques et écologie des paysages agroforestiers) |
-- | University of Waterloo | NULL | Waterloo, Canada | University of Waterloo, Waterloo, Canada |
-- | University of Arizona | NULL | Tucson, Arizona, USA | University of Arizona, Tucson, Arizona, USA |
-- | Laboratoire d'Informatique, Signaux et Systèmes | I3S | Sophia Antipolis, France | I3S (Laboratoire d'Informatique, Signaux et Systèmes), Sophia Antipolis, France |
-- | Visvesvaraya National Institute of Technology | NULL | NULL | Visvesvaraya National Institute of Technology |
-- | Sciences Po | NULL | Paris, France | Sciences Po, Paris, France |
-- | School of Human Evolution and Social Change | SHESC | NULL | SHESC (School of Human Evolution and Social Change) |
-- | NULL | DSSCQ | NULL | DSSCQ |
-- +-----------------------------------------------------+-------------+--------------------------+----------------------------------------------------------------------------------+
...@@ -123,6 +123,11 @@ ...@@ -123,6 +123,11 @@
onclick='$(this).parents(".dropdown-menu").toggle();'> onclick='$(this).parents(".dropdown-menu").toggle();'>
Filter by laboratory</a> Filter by laboratory</a>
</li> </li>
<li>
<a id="addfilterorganization" href="#"
onclick='$(this).parents(".dropdown-menu").toggle();'>
Filter by organization</a>
</li>
</ul> </ul>
</li> </li>
<li class="comex-nav-item"> <li class="comex-nav-item">
......
...@@ -160,6 +160,5 @@ ...@@ -160,6 +160,5 @@
// --------- // ---------
var uinfo = {{ (current_user.json_info | safe) if current_user.info else ("null" | safe) }}; var uinfo = {{ (current_user.json_info | safe) if current_user.info else ("null" | safe) }};
</script> </script>
<script src="{{ url_for('static', filename='js/comex_page_rootindex.js') }}"></script>
{% endblock %} {% endblock %}
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