commit 7f0b1cca4f1e53628c7eb0788786da9681338661 Author: Olivier DOSSMANN Date: Thu Feb 6 12:04:27 2020 +0100 Initial commit: Datagraph generator for organisations/libraries/users diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/orgas/.gitignore b/orgas/.gitignore new file mode 100644 index 0000000..1824a57 --- /dev/null +++ b/orgas/.gitignore @@ -0,0 +1,2 @@ +*.dot +*.svg diff --git a/orgas/Makefile b/orgas/Makefile new file mode 100644 index 0000000..910c999 --- /dev/null +++ b/orgas/Makefile @@ -0,0 +1,12 @@ +all: organisations.svg + + +graph.dot: gen.sh + bash gen.sh graph.dot + + +organisations.svg: graph.dot + dot -Tsvg graph.dot -o organisations.svg + +clean: + rm -f organisations.svg graph.dot diff --git a/orgas/README.md b/orgas/README.md new file mode 100644 index 0000000..f5e49e0 --- /dev/null +++ b/orgas/README.md @@ -0,0 +1,11 @@ +# Presentation + +*datagraph_generator* generates a diagram with **graphviz** with the link between organisations, libraries and users in *rero-ils* project. + +# Usage + +``` +make clean && make +``` + +Result: **datagraph.svg** file (can be open with Gimp for example). diff --git a/orgas/gen.sh b/orgas/gen.sh new file mode 100755 index 0000000..d86533b --- /dev/null +++ b/orgas/gen.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# Generate a dot file to create digraph of RERO-ils data + +output="$1" +source="/home/od/projets/rero/rero-ils/data/" + +# start of file +echo "digraph {" > "$output" + +# ORGANISATIONS +orga_file="${source}organisations.json" +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 + echo "Orga${pid} [label=\"${name}\"]" >> "$output" +done + +# LIBRARIES +lib_file="${source}libraries.json" +cat "${lib_file}"|jq -c '.[] | { + name, + pid, + organisation: .organisation."$ref"}'|while read lib +do + pid=$(echo $lib|jq -r .pid) + name=$(echo $lib|jq -r .name) + orga=$(echo $lib|jq -r .organisation) + orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev) + # write result in output + l_id="Lib${pid}" + echo "${l_id} [label=\"${name}\"]" >> "$output" + echo "${l_id} -> Orga${orga_pid}" >> "$output" +done + +# USERS +user_file="${source}users.json" +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}" + echo "\"${u_id}\" [label=\"${first_name} ${last_name}\"]" >> "$output" + echo "\"${u_id}\" -> Lib${library_pid}" >> "$output" +done + +# end of file +echo "}" >> "$output" + + +# END of program +exit 0