Orgas: export jq filtering outside gen.sh code (simplification)
This commit is contained in:
parent
86224fef7f
commit
9f9feb2a93
@ -1,6 +1,5 @@
|
|||||||
# TODO list
|
# TODO list
|
||||||
|
|
||||||
* item -> item_types -> patron_types -> circulation policies + organisations
|
* item -> item_types -> patron_types -> circulation policies + organisations
|
||||||
* patron_types on organisations.svg
|
|
||||||
* do it in Python
|
* do it in Python
|
||||||
* use http://localhost:9200/patrons/_search?size=50 and similar to create all graphs? => problem: you need to launch docker-compose and load data (setup), which takes time
|
* use http://localhost:9200/patrons/_search?size=50 and similar to create all graphs? => problem: you need to launch docker-compose and load data (setup), which takes time
|
||||||
|
@ -40,6 +40,12 @@ save() {
|
|||||||
rendered_template="$(render $1)"
|
rendered_template="$(render $1)"
|
||||||
send "${rendered_template}"
|
send "${rendered_template}"
|
||||||
}
|
}
|
||||||
|
# parse_json: read JSON file (filename given in $1) and applying filter (same name as $1)
|
||||||
|
parse_json() {
|
||||||
|
filepath="${SRC_DIR}/$1.json"
|
||||||
|
filter="filters/$1"
|
||||||
|
cat "$filepath" | jq -cf "$filter"
|
||||||
|
}
|
||||||
|
|
||||||
# Output file initialization
|
# Output file initialization
|
||||||
echo "" > "$outputfile" # flush output file
|
echo "" > "$outputfile" # flush output file
|
||||||
|
6
orgas/filters/libraries
Normal file
6
orgas/filters/libraries
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.[] | {
|
||||||
|
name,
|
||||||
|
pid,
|
||||||
|
code,
|
||||||
|
organisation: .organisation."$ref"
|
||||||
|
}
|
5
orgas/filters/organisations
Normal file
5
orgas/filters/organisations
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.[] | {
|
||||||
|
name,
|
||||||
|
pid,
|
||||||
|
code
|
||||||
|
}
|
5
orgas/filters/patron_types
Normal file
5
orgas/filters/patron_types
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.[] | {
|
||||||
|
pid,
|
||||||
|
name,
|
||||||
|
organisation: .organisation."$ref"
|
||||||
|
}
|
9
orgas/filters/users
Normal file
9
orgas/filters/users
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
.[] | {
|
||||||
|
email,
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
barcode,
|
||||||
|
roles,
|
||||||
|
library: .library."$ref",
|
||||||
|
pt: .patron_type."$ref"
|
||||||
|
}
|
38
orgas/gen.sh
38
orgas/gen.sh
@ -33,13 +33,9 @@ title="Link between organisations, libraries and users."
|
|||||||
save "templates/header.tmpl"
|
save "templates/header.tmpl"
|
||||||
|
|
||||||
# ORGANISATIONS
|
# ORGANISATIONS
|
||||||
orga_file="${SRC_DIR}organisations.json"
|
|
||||||
shape="box"
|
shape="box"
|
||||||
color="${ORGA_COLOR}"
|
color="${ORGA_COLOR}"
|
||||||
cat "${orga_file}"|jq -c '.[] | {
|
while read -r orga
|
||||||
name,
|
|
||||||
pid,
|
|
||||||
code }'| while read orga
|
|
||||||
do
|
do
|
||||||
# take important info
|
# take important info
|
||||||
pid=$(echo $orga|jq -r .pid)
|
pid=$(echo $orga|jq -r .pid)
|
||||||
@ -49,17 +45,12 @@ do
|
|||||||
identifier="Orga${pid}"
|
identifier="Orga${pid}"
|
||||||
label="$(render ${tmpl_label})"
|
label="$(render ${tmpl_label})"
|
||||||
save "${tmpl_gizmo}"
|
save "${tmpl_gizmo}"
|
||||||
done
|
done <<< $(parse_json "organisations")
|
||||||
|
|
||||||
# LIBRARIES
|
# LIBRARIES
|
||||||
lib_file="${SRC_DIR}libraries.json"
|
|
||||||
shape="house"
|
shape="house"
|
||||||
color="${LIB_COLOR}"
|
color="${LIB_COLOR}"
|
||||||
cat "${lib_file}"|jq -c '.[] | {
|
while read -r lib
|
||||||
name,
|
|
||||||
pid,
|
|
||||||
code,
|
|
||||||
organisation: .organisation."$ref"}'|while read lib
|
|
||||||
do
|
do
|
||||||
pid=$(echo $lib|jq -r .pid)
|
pid=$(echo $lib|jq -r .pid)
|
||||||
name=$(echo $lib|jq -r .name)
|
name=$(echo $lib|jq -r .name)
|
||||||
@ -72,17 +63,13 @@ do
|
|||||||
save "${tmpl_gizmo}"
|
save "${tmpl_gizmo}"
|
||||||
relation="Orga${orga_pid}"
|
relation="Orga${orga_pid}"
|
||||||
save "${tmpl_link}"
|
save "${tmpl_link}"
|
||||||
done
|
done <<< $(parse_json "libraries")
|
||||||
|
|
||||||
# PATRON_TYPES
|
# PATRON_TYPES
|
||||||
pt_file="${SRC_DIR}patron_types.json"
|
|
||||||
shape="polygon"
|
shape="polygon"
|
||||||
color="${PT_COLOR}"
|
color="${PT_COLOR}"
|
||||||
additionals="sides=7"
|
additionals="sides=7"
|
||||||
cat "${pt_file}" |jq -c '.[] | {
|
while read pt
|
||||||
pid,
|
|
||||||
name,
|
|
||||||
organisation: .organisation."$ref"}'|while read pt
|
|
||||||
do
|
do
|
||||||
pid=$(echo $pt|jq -r .pid)
|
pid=$(echo $pt|jq -r .pid)
|
||||||
name=$(echo $pt|jq -r .name)
|
name=$(echo $pt|jq -r .name)
|
||||||
@ -98,21 +85,13 @@ do
|
|||||||
relation="Orga${orga_pid}"
|
relation="Orga${orga_pid}"
|
||||||
save "${tmpl_link}"
|
save "${tmpl_link}"
|
||||||
fi
|
fi
|
||||||
done
|
done <<< $(parse_json "patron_types")
|
||||||
|
|
||||||
# USERS
|
# USERS
|
||||||
user_file="${SRC_DIR}users.json"
|
|
||||||
shape="ellipse"
|
shape="ellipse"
|
||||||
additionals=''
|
additionals=''
|
||||||
color="${USER_COLOR}"
|
color="${USER_COLOR}"
|
||||||
cat "${user_file}"|jq -c '.[] | {
|
while read user
|
||||||
email,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
barcode,
|
|
||||||
roles,
|
|
||||||
library: .library."$ref",
|
|
||||||
pt: .patron_type."$ref"}'|while read user
|
|
||||||
do
|
do
|
||||||
email=$(echo $user|jq -r .email)
|
email=$(echo $user|jq -r .email)
|
||||||
first_name=$(echo $user|jq -r .first_name)
|
first_name=$(echo $user|jq -r .first_name)
|
||||||
@ -157,11 +136,10 @@ do
|
|||||||
relation="Type${pt_id}"
|
relation="Type${pt_id}"
|
||||||
save "${tmpl_link}"
|
save "${tmpl_link}"
|
||||||
fi
|
fi
|
||||||
done
|
done <<< $(parse_json "users")
|
||||||
|
|
||||||
# Graph footer
|
# Graph footer
|
||||||
save "templates/footer.tmpl"
|
save "templates/footer.tmpl"
|
||||||
|
|
||||||
|
|
||||||
# END of program
|
# END of program
|
||||||
exit 0
|
exit 0
|
||||||
|
Reference in New Issue
Block a user