2020-02-06 11:04:27 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-02-06 13:12:25 +00:00
|
|
|
#
|
|
|
|
# Generate a dot file to create graph of RERO-ils data (orga, lib and users)
|
|
|
|
#
|
2020-02-06 11:04:27 +00:00
|
|
|
|
2020-02-06 13:12:25 +00:00
|
|
|
RERO_DIR="${HOME}/projets/rero/rero-ils"
|
2020-02-06 11:04:27 +00:00
|
|
|
|
|
|
|
output="$1"
|
2020-02-06 13:12:25 +00:00
|
|
|
SRC_DIR="${RERO_DIR}/data/"
|
2020-02-06 11:04:27 +00:00
|
|
|
|
|
|
|
# start of file
|
|
|
|
echo "digraph {" > "$output"
|
2020-02-06 13:12:25 +00:00
|
|
|
echo "rankdir = RL;" >> "$output"
|
|
|
|
echo "label = \"Link between organisations, libraries and users.\";" >> "$output"
|
2020-02-06 11:04:27 +00:00
|
|
|
|
|
|
|
# ORGANISATIONS
|
2020-02-06 13:12:25 +00:00
|
|
|
orga_file="${SRC_DIR}organisations.json"
|
2020-02-06 11:04:27 +00:00
|
|
|
cat "${orga_file}"|jq -c '.[] | {
|
|
|
|
name,
|
|
|
|
pid,
|
|
|
|
code }'| while read orga
|
|
|
|
do
|
|
|
|
# take important info
|
|
|
|
pid=$(echo $orga|jq -r .pid)
|
|
|
|
code=$(echo $orga|jq -r .code)
|
|
|
|
name=$(echo $orga|jq -r .name)
|
|
|
|
# write result in output
|
2020-02-06 13:12:25 +00:00
|
|
|
echo "Orga${pid} [shape=box color=\"transparent\" style=filled fillcolor=\"#bcafff\" label=<${name}<br/>(code: ${code})>]" >> "$output"
|
2020-02-06 11:04:27 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# LIBRARIES
|
2020-02-06 13:12:25 +00:00
|
|
|
lib_file="${SRC_DIR}libraries.json"
|
2020-02-06 11:04:27 +00:00
|
|
|
cat "${lib_file}"|jq -c '.[] | {
|
|
|
|
name,
|
|
|
|
pid,
|
2020-02-06 13:12:25 +00:00
|
|
|
code,
|
2020-02-06 11:04:27 +00:00
|
|
|
organisation: .organisation."$ref"}'|while read lib
|
|
|
|
do
|
|
|
|
pid=$(echo $lib|jq -r .pid)
|
|
|
|
name=$(echo $lib|jq -r .name)
|
2020-02-06 13:12:25 +00:00
|
|
|
code=$(echo $lib|jq -r .code)
|
2020-02-06 11:04:27 +00:00
|
|
|
orga=$(echo $lib|jq -r .organisation)
|
|
|
|
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
|
|
|
|
# write result in output
|
|
|
|
l_id="Lib${pid}"
|
2020-02-06 13:12:25 +00:00
|
|
|
echo "${l_id} [shape=house color=transparent style=filled fillcolor=\"#49afff\" label=<${name}<br/>(code: ${code})>]" >> "$output"
|
2020-02-06 11:04:27 +00:00
|
|
|
echo "${l_id} -> Orga${orga_pid}" >> "$output"
|
|
|
|
done
|
|
|
|
|
|
|
|
# USERS
|
2020-02-06 13:12:25 +00:00
|
|
|
user_file="${SRC_DIR}users.json"
|
2020-02-06 11:04:27 +00:00
|
|
|
cat "${user_file}"|jq -c '.[] | {
|
|
|
|
email,
|
|
|
|
first_name,
|
|
|
|
last_name,
|
|
|
|
library: .library."$ref"} | select(.library |length >= 1)'|while read user
|
|
|
|
do
|
|
|
|
email=$(echo $user|jq -r .email)
|
|
|
|
first_name=$(echo $user|jq -r .first_name)
|
|
|
|
last_name=$(echo $user|jq -r .last_name)
|
|
|
|
library=$(echo $user|jq -r .library)
|
|
|
|
library_pid=$(echo $library|rev|cut -d "/" -f 1|rev)
|
|
|
|
# write result in output
|
|
|
|
u_id="User_${email}"
|
2020-02-06 13:12:25 +00:00
|
|
|
echo "\"${u_id}\" [label=<${first_name} ${last_name}<br/>${email}>]" >> "$output"
|
2020-02-06 11:04:27 +00:00
|
|
|
echo "\"${u_id}\" -> Lib${library_pid}" >> "$output"
|
|
|
|
done
|
|
|
|
|
|
|
|
# end of file
|
|
|
|
echo "}" >> "$output"
|
|
|
|
|
|
|
|
|
|
|
|
# END of program
|
|
|
|
exit 0
|