ODT
/
rero-ils-graphs
Archived
1
0
Fork 0

Compare commits

...

7 Commits
0.1 ... master

Author SHA1 Message Date
Olivier DOSSMANN ee9488ab7e by_json: simplify way to change RERO-ils directory 2020-02-10 14:26:19 +01:00
Olivier DOSSMANN 23b6950f88 by_json: Add a date on SVG result files 2020-02-10 12:41:19 +01:00
Olivier DOSSMANN af5872d98e by_json: Add a separator between lines in Graphviz 2020-02-07 17:15:41 +01:00
Olivier DOSSMANN 7a173006fc by_json: add description on patron types 2020-02-07 17:15:16 +01:00
Olivier DOSSMANN d2c7cda421 by_json: Generate circulation policies
* Generate a new circulation policies file: policies.svg
  * Parses Circulation policies
  * Parses Item Types
2020-02-07 16:30:48 +01:00
Olivier DOSSMANN 5cb48604c3 by_json: gen_orgas.sh refactorisation 2020-02-07 14:27:29 +01:00
Olivier DOSSMANN 7bf5972250 Structure: make it more generic
* changes `orgas` directory to `by_json` (explain what we do: using JSON
    to geneate schema)
* makes Makefile more generic to permit to generate more SVG files in
the future
2020-02-07 14:06:20 +01:00
35 changed files with 354 additions and 179 deletions

16
by_json/Makefile 100644
View File

@ -0,0 +1,16 @@
DATE := $(shell date +'%Y%m%d')
all: $(DATE)-orgas.svg $(DATE)-policies.svg
# All .dot files are generated by gen_%.sh file (gen_orgas.sh for example)
%.dot: gen_%.sh
bash "$<" "$@"
$(DATE)-%.svg: %.dot
dot -Tsvg "$<" -o "$@"
clean:
rm -f *.svg *.dot
# Keep temporary files (dot files) for debug
.PRECIOUS: %.dot

20
by_json/README.md 100644
View File

@ -0,0 +1,20 @@
# Presentation
*gen_orgas.sh* generates a diagram with **graphviz** with the link between organisations, libraries and users in *rero-ils* project.
*gen_policies.sh* do the same with link between organisations, libraries, circulation policies and patron\_type/item\_type couples.
# Requirements
* graphviz
* [jq](https://stedolan.github.io/jq/)
# Usage
* change **RERO\_DIR** variable to point your **rero-ils directory**
```
make clean && RERO_DIR="/home/moi/rero/rero-ils" make
```
Result: **2 files (orgas.svg and policies.svg)** file (can be open with Gimp for example).

View File

@ -5,6 +5,7 @@
# Built variables
outputfile="$1"
RERO_DIR="${RERO_DIR:-${HOME}/projets/rero/rero-ils}"
SRC_DIR="${RERO_DIR}/data/"
# Templates
@ -12,6 +13,14 @@ tmpl_gizmo="templates/gizmo.tmpl" # A colored polygon. Represents an entity.
tmpl_link="templates/link.tmpl" # A link between two entities.
tmpl_label="templates/label_default.tmpl" # Default label for entities.
# pastel colors (Cf. https://www.color-hex.com/color-palette/5361)
COLOR1="#ffb3ba"
COLOR2="#ffdfba"
COLOR3="#ffffba"
COLOR4="#baffc9"
COLOR5="#bae1ff"
COMP_COLOR4="#ffd8ba"
# Graph info
rankdir="RL"
title=""
@ -24,6 +33,14 @@ elif [[ -f "${outputfile}" ]]; then
echo "File already exists!"
exit 1
fi
if [[ ! -d "${RERO_DIR}" ]]; then
echo "Source directory doesn't exist: ${RERO_DIR}. Did you set RERO_DIR variable?"
exit 1
fi
if [[ ! -d "${SRC_DIR}" ]]; then
echo "No data directory found in ${RERO_DIR}. Did you set RERO_DIR variable correctly?"
exit 1
fi
# FUNCTIONS
# WRITE first argument in output file

View File

@ -0,0 +1,12 @@
.[] | {
pid,
name,
description,
organisation: .organisation."$ref",
allow_checkout,
checkout_duration,
allow_requests,
policy_library_level,
libraries: [.libraries[]?],
settings
}

View File

@ -0,0 +1,6 @@
.[] | {
pid,
name,
organisation: .organisation."$ref",
type
}

View File

@ -1,5 +1,6 @@
.[] | {
pid,
name,
description,
organisation: .organisation."$ref"
}

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# Generate a dot file to create graph of RERO-ils data
#
# Usage:
# bash gen_orgas.sh output.dot
# where `output.dot` is the output file that permit to generate a graph.
# To generate the graph:
# dot -Tsvg output.dot -o organisations.svg
# where `output.dot` is the previous file. And `organisations.svg` the final schema you want to display.
# Load commons variables, functions and statements
source commons.sh
# Graph header
title="Link between organisations, libraries and users."
save "templates/header.tmpl"
# ORGANISATIONS
source process_orgas.sh
# LIBRARIES
source process_lib.sh
# PATRON_TYPES
source process_pt.sh
# USERS
source process_users.sh
# Graph footer
save "templates/footer.tmpl"
# END of program
exit 0

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Generate a dot file to create graph of RERO-ils data
#
# Load commons variables, functions and statements
source commons.sh
# Graph header
title="Circulation policies details."
save "templates/header.tmpl"
# ORGANISATIONS
source process_orgas.sh
# LIBRARIES
source process_lib.sh
# CIRCULATION POLICIES
source process_cp.sh
# Graph footer
save "templates/footer.tmpl"
# END of program
exit 0

View File

@ -0,0 +1,59 @@
# DEPENDS ON: Organisations (process_orgas.sh), Libraries (process_lib.sh)
# Main configuration
while read cp
do
# main info
pid=$(echo $cp|jq -r .pid)
name=$(echo $cp|jq -r .name)
description=$(echo $cp|jq -r .description)
orga=$(echo $cp|jq -r .organisation)
# Additional info
checkout=$(echo $cp|jq -r .allow_checkout)
duration=$(echo $cp|jq -r .checkout_duration)
requests=$(echo $cp|jq -r .allow_requests)
library_level=$(echo $cp|jq -r .policy_library_level)
# reset values (because settings overwrites them)
shape="doubleoctagon"
color="${COLOR5}"
border_color="${COLOR5}"
additionals=""
# write result in output
identifier="CP${pid}"
label="$(render templates/label_circulation_policies.tmpl)"
save "${tmpl_gizmo}"
# Make a link with organisation if present
if [[ -n "${orga}" ]]; then
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
relation="Orga${orga_pid}"
save "${tmpl_link}"
fi
# Parse settings (if have content)
settings=$(echo $cp|jq -r .settings)
if [[ "${settings}" != "null" ]]; then
for setting in $(echo $settings|jq -c '.[]')
do
pt_pid=$(echo $setting|jq -r '.patron_type."$ref"'|rev| cut -d"/" -f1 |rev)
it_pid=$(echo $setting|jq -r '.item_type."$ref"'|rev|cut -d"/" -f1|rev)
# reset values
shape="Mrecord"
color="${COLOR4}"
border_color="black"
additionals=""
# write result in output
identifier="Setting${pid}${pt_pid}${it_pid}"
label=$(render templates/label_settings.tmpl)
save "${tmpl_gizmo}"
# Make a link between setting and Circulation Policy
relation="CP${pid}"
save "${tmpl_link}"
done
fi
done <<< $(parse_json "circulation_policies")

View File

@ -0,0 +1,27 @@
# DEPENDS ON: Organisations (process_orgas.sh)
# Colors
IT_COLOR="${COLOR4}" # item_types
# Main configuration
shape="polygon"
color="${IT_COLOR}"
additionals="sides=6"
while read it
do
pid=$(echo $it|jq -r .pid)
name=$(echo $it|jq -r .name)
orga=$(echo $it|jq -r .organisation)
itype="$(echo $it|jq -r '.type')"
# write result in output
identifier="IType${pid}"
label="$(render templates/label_item_types.tmpl)"
save "${tmpl_gizmo}"
# Make a link with organisation if present
if [[ -n "${orga}" ]]; then
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
relation="Orga${orga_pid}"
save "${tmpl_link}"
fi
done <<< $(parse_json "item_types")

View File

@ -0,0 +1,22 @@
# DEPENDS ON: Organisations (process_orgas.sh)
# Colors
LIB_COLOR="${COLOR2}" # libraries
# Main configuration
shape="house"
color="${LIB_COLOR}"
while read -r lib
do
pid=$(echo $lib|jq -r .pid)
name=$(echo $lib|jq -r .name)
code=$(echo $lib|jq -r .code)
orga=$(echo $lib|jq -r .organisation)
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
# write result in output
identifier="Lib${pid}"
label="$(render ${tmpl_label})"
save "${tmpl_gizmo}"
relation="Orga${orga_pid}"
save "${tmpl_link}"
done <<< $(parse_json "libraries")

View File

@ -0,0 +1,19 @@
# DEPENDS ON: None
# Colors
ORGA_COLOR="${COLOR1}" # organisations
# Main configuration
shape="box"
color="${ORGA_COLOR}"
while read -r 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
identifier="Orga${pid}"
label="$(render ${tmpl_label})"
save "${tmpl_gizmo}"
done <<< $(parse_json "organisations")

View File

@ -0,0 +1,29 @@
# DEPENDS ON: Organisations (process_orgas.sh)
# Colors
PT_COLOR="${COLOR3}" # patron_types
# Main configuration
shape="polygon"
color="${PT_COLOR}"
additionals="sides=7"
while read pt
do
pid=$(echo $pt|jq -r .pid)
name=$(echo $pt|jq -r .name)
# fix problems with '<' and '>' in descriptions
description=$(echo $pt|jq -r .description|sed -e 's/</\&#60;/g ; s/>/\&#62;/g')
orga=$(echo $pt|jq -r .organisation)
# write result in output
identifier="Type${pid}"
label="$(render templates/label_patron_types.tmpl)"
save "${tmpl_gizmo}"
# Make a link with organisation if present
if [[ -n "${orga}" ]]; then
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
relation="Orga${orga_pid}"
save "${tmpl_link}"
fi
done <<< $(parse_json "patron_types")

View File

@ -0,0 +1,55 @@
# DEPENDS ON: Patron types (process_pt.sh), Library (process_lib.sh)
# Colors
USER_COLOR="${COLOR5}" # users/patrons
# Main configuration
shape="ellipse"
additionals=''
color="${USER_COLOR}"
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)
barcode=$(echo $user|jq -r .barcode)
roles=$(echo $user|jq -r .roles[])
library=$(echo $user|jq -r .library)
library_pid=$(echo $library|rev|cut -d "/" -f 1|rev)
pt=$(echo $user|jq -r .pt)
# Prepare additional info
if [[ "${roles}" != "null" ]]; then
displayed_roles="roles: "
for role in ${roles}; do
displayed_roles="${displayed_roles}<font color='red' >${role}</font>, "
done
fi
# Don't display barcode if no one
info=""
if [[ "${barcode}" != "null" ]]; then
info="${info}<br/>${barcode}"
fi
# Same for roles
if [[ -n "${displayed_roles}" ]]; then
info="${info}<br/>${displayed_roles}"
fi
# write result in output
identifier="User_${email}"
label="$(render templates/label_users.tmpl)"
save "${tmpl_gizmo}"
# Display a link if library_pid is not null
if [[ "${library_pid}" != "null" ]]; then
relation="Lib${library_pid}"
save "${tmpl_link}"
fi
# Display a link if patron_type is not null
if [[ "$pt" != "null" ]]; then
pt_id=$(echo $pt|rev| cut -d "/" -f 1|rev)
relation="Type${pt_id}"
save "${tmpl_link}"
fi
done <<< $(parse_json "users")

View File

@ -0,0 +1 @@
\"${identifier}\" [shape=${shape} color=\"${border_color:-transparent}\" style=filled fillcolor=\"${color}\" label=${label} ${additionals}];

View File

@ -0,0 +1,5 @@
<${name}<br/>${description}<br/>
Checkout: ${checkout} (duration: ${duration})<br/>
Requests: ${requests}<br/>
Policy library level: ${library_level}<br />
PID: ${pid}>

View File

@ -0,0 +1 @@
<${name}<br/>(type: ${itype})<br/>PID: ${pid}>

View File

@ -0,0 +1,2 @@
<${name}<br/>${description}<br/>
PID: ${pid}>

View File

@ -0,0 +1 @@
\"Patron type PID: ${pt_pid} | Item type PID: ${it_pid}\"

View File

@ -0,0 +1 @@
\"${identifier}\" -> \"${relation}\";

View File

@ -1,12 +0,0 @@
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

View File

@ -1,19 +0,0 @@
# Presentation
*gen.sh* generates a diagram with **graphviz** with the link between organisations, libraries and users in *rero-ils* project.
# Requirements
* graphviz
* [jq](https://stedolan.github.io/jq/)
# Usage
* Open **gen.sh** file
* change **RERO\_DIR** variable to point your **rero-ils directory**
```
make clean && make
```
Result: **organisations.svg** file (can be open with Gimp for example).

View File

@ -1,145 +0,0 @@
#!/usr/bin/env bash
#
# Generate a dot file to create graph of RERO-ils data (orga, lib and users)
#
# Usage:
# bash gen.sh output.dot
# where `output.dot` is the output file that permit to generate a graph.
# To generate the graph:
# dot -Tsvg output.dot -o organisations.svg
# where `output.dot` is the previous file. And `organisations.svg` the final schema you want to display.
# CONFIG
RERO_DIR="${HOME}/projets/rero/rero-ils"
# pastel colors (Cf. https://www.color-hex.com/color-palette/5361)
COLOR1="#ffb3ba"
COLOR2="#ffdfba"
COLOR3="#ffffba"
COLOR4="#baffc9"
COLOR5="#bae1ff"
COMP_COLOR4="#ffd8ba"
# colors you choose for different objects
ORGA_COLOR="${COLOR1}" # organisations
LIB_COLOR="${COLOR2}" # libraries
PT_COLOR="${COLOR3}" # patron_types
USER_COLOR="${COLOR5}" # users/patrons
# Load commons variables, functions and statements
source commons.sh
# Graph header
title="Link between organisations, libraries and users."
save "templates/header.tmpl"
# ORGANISATIONS
shape="box"
color="${ORGA_COLOR}"
while read -r 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
identifier="Orga${pid}"
label="$(render ${tmpl_label})"
save "${tmpl_gizmo}"
done <<< $(parse_json "organisations")
# LIBRARIES
shape="house"
color="${LIB_COLOR}"
while read -r lib
do
pid=$(echo $lib|jq -r .pid)
name=$(echo $lib|jq -r .name)
code=$(echo $lib|jq -r .code)
orga=$(echo $lib|jq -r .organisation)
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
# write result in output
identifier="Lib${pid}"
label="$(render ${tmpl_label})"
save "${tmpl_gizmo}"
relation="Orga${orga_pid}"
save "${tmpl_link}"
done <<< $(parse_json "libraries")
# PATRON_TYPES
shape="polygon"
color="${PT_COLOR}"
additionals="sides=7"
while read pt
do
pid=$(echo $pt|jq -r .pid)
name=$(echo $pt|jq -r .name)
orga=$(echo $pt|jq -r .organisation)
# write result in output
identifier="Type${pid}"
label="$(render templates/label_patron_types.tmpl)"
save "${tmpl_gizmo}"
# Make a link with organisation if present
if [[ -n "${orga}" ]]; then
orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev)
relation="Orga${orga_pid}"
save "${tmpl_link}"
fi
done <<< $(parse_json "patron_types")
# USERS
shape="ellipse"
additionals=''
color="${USER_COLOR}"
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)
barcode=$(echo $user|jq -r .barcode)
roles=$(echo $user|jq -r .roles[])
library=$(echo $user|jq -r .library)
library_pid=$(echo $library|rev|cut -d "/" -f 1|rev)
pt=$(echo $user|jq -r .pt)
# Prepare additional info
if [[ "${roles}" != "null" ]]; then
displayed_roles="roles: "
for role in ${roles}; do
displayed_roles="${displayed_roles}<font color='red' >${role}</font>, "
done
fi
# Don't display barcode if no one
info=""
if [[ "${barcode}" != "null" ]]; then
info="${info}<br/>${barcode}"
fi
# Same for roles
if [[ -n "${displayed_roles}" ]]; then
info="${info}<br/>${displayed_roles}"
fi
# write result in output
identifier="User_${email}"
label="$(render templates/label_users.tmpl)"
save "${tmpl_gizmo}"
# Display a link if library_pid is not null
if [[ "${library_pid}" != "null" ]]; then
relation="Lib${library_pid}"
save "${tmpl_link}"
fi
# Display a link if patron_type is not null
if [[ "$pt" != "null" ]]; then
pt_id=$(echo $pt|rev| cut -d "/" -f 1|rev)
relation="Type${pt_id}"
save "${tmpl_link}"
fi
done <<< $(parse_json "users")
# Graph footer
save "templates/footer.tmpl"
# END of program
exit 0

View File

@ -1 +0,0 @@
\"${identifier}\" [shape=${shape} color=\"transparent\" style=filled fillcolor=\"${color}\" label=${label} ${additionals}]

View File

@ -1 +0,0 @@
<${name}<br/>PID: ${pid}>

View File

@ -1 +0,0 @@
\"${identifier}\" -> \"${relation}\"