Updates jilo-cli to filter conferences by time period.

main
Yasen Pramatarov 2024-06-13 21:09:44 +03:00
parent da0011869d
commit d5a9a74879
2 changed files with 87 additions and 48 deletions

View File

@ -15,6 +15,9 @@ All notable changes to this project will be documented in this file.
### Added
- Initial changelog following the keepachangelog.com format
### Changed
- Updated the way jilo-cli handles multiple options, added filtering conferences by time period
---
## 0.1 - 2024-06-12

132
jilo-cli
View File

@ -68,6 +68,9 @@ JOIN (
GROUP BY
conference_name
) AS name_counts ON c.conference_name = name_counts.conference_name
JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE (ce.time >= '%s' AND ce.time <= '%s')
ORDER BY
c.id;"
db_conferences_id_template="SELECT * FROM conferences WHERE conference_id='%s';"
@ -93,6 +96,7 @@ LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_id = '%s'
AND (pe.time >= '%s' AND pe.time <= '%s')
UNION
@ -111,6 +115,7 @@ LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
c.conference_id = '%s'
AND (event_time >= '%s' AND event_time <= '%s')
ORDER BY
pe.time;"
@ -134,6 +139,7 @@ LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_name = '%s'
AND (pe.time >= '%s' AND pe.time <= '%s')
UNION
@ -152,6 +158,7 @@ LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
c.conference_name = '%s'
AND (event_time >= '%s' AND event_time <= '%s')
ORDER BY
pe.time;"
@ -516,15 +523,19 @@ parse_time_range() {
cmd=""
conference_arg=""
conference_option=false
participant_arg=""
from_time=""
until_time=""
participant_option=false
from_time="0000-00-00"
until_time="9999-12-31"
time_option=false
time_range_specified=false
while [[ $# -gt 0 ]]; do
case "$1" in
-c | --conference )
cmd="--conference"
conference_option=true
if [[ -n "$2" && "$2" != -* ]]; then
conference_arg="$2"
shift 2
@ -534,6 +545,7 @@ while [[ $# -gt 0 ]]; do
;;
-p | --participant)
cmd="--participant"
participant_option=true
if [[ -n "$2" && "$2" != -* ]]; then
participant_arg="$2"
shift 2
@ -543,7 +555,9 @@ while [[ $# -gt 0 ]]; do
;;
-t | --time)
cmd="--time"
time_option=true
if [[ -n "$2" && "$2" != -* ]]; then
time_arg="$2"
parse_time_range "$2"
shift 2
else
@ -551,6 +565,10 @@ while [[ $# -gt 0 ]]; do
exit 1
fi
;;
-v | --verbose)
verbose=true
shift
;;
-h | --help)
echo -e "$help"
exit 0
@ -567,57 +585,58 @@ while [[ $# -gt 0 ]]; do
esac
done
case "$cmd" in
if [[ "$conference_option" == true ]]; then
--conference)
# the argument to "--conference" can be either ID or name
if [[ -n "$conference_arg" ]]; then
# the argument to "--conference" can be either ID or name
if [[ -n "$conference_arg" ]]; then
db_conferences_id=$(printf "$db_conferences_id_template" "$conference_arg")
conferences_id=$(db_query "$db_conferences_id")
# check for conferences match within a time period (or all if not period given)
db_conferences_id=$(printf "$db_conference_by_id_template" "$conference_arg" "$from_time" "$until_time" "$conference_arg" "$from_time" "$until_time")
mapfile -t conferences_id < <(db_query "$db_conferences_id")
db_conferences_name=$(printf "$db_conference_by_name_template" "$conference_arg" "$from_time" "$until_time" "$conference_arg" "$from_time" "$until_time")
mapfile -t conferences_name < <(db_query "$db_conferences_name")
db_conferences_name=$(printf "$db_conferences_name_template" "$conference_arg")
conferences_name=$(db_query "$db_conferences_name")
# we check if the argument to "--conference" is a conference ID
# conference ID is unique, so we show that conference
if [[ "${#conferences_id[@]}" -gt 0 ]]; then
# prepare the header
output="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
# prepare the formatted rows
for row in "${conferences_id[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$IMPORTANT_TEXT$conference_id$NORMAL_TEXT\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# we check if the argument to "--conference" is a conference ID
# conference ID is unique, so we show that conference
if [[ -n "$conferences_id" ]]; then
db_conference=$(printf "$db_conference_by_id_template" "$conference_arg" "$conference_arg")
mapfile -t conference_array < <(db_query "$db_conference")
# prepare the header
output="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
# prepare the formatted rows
for row in "${conference_array[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$IMPORTANT_TEXT$conference_id$NORMAL_TEXT\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# then we check if the argument to "--conference" is a conference name
# if so, we show all matching conferences (conference names are not unique)
elif [[ "${#conferences_name[@]}" -gt 0 ]]; then
# prepare the header
output="time\tconf ID\tconf name\tconf host\tloglevel\tparticipant ID\tevent\tparameter\n"
# prepare the formatted rows
for row in "${conferences_name[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$IMPORTANT_TEXT$conference_name$NORMAL_TEXT\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# then we check if the argument to "--conference" is a conference name
# if so, we show all matching conferences (conference names are not unique)
elif [[ -n "$conferences_name" ]]; then
db_conference=$(printf "$db_conference_by_name_template" "$conference_arg" "$conference_arg")
mapfile -t conference_array < <(db_query "$db_conference")
# prepare the header
output="time\tconf ID\tconf name\tconf host\tloglevel\tparticipant ID\tevent\tparameter\n"
# prepare the formatted rows
for row in "${conference_array[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$IMPORTANT_TEXT$conference_name$NORMAL_TEXT\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# nothing found for neither conference ID or name
else
echo "No match found for \"$conference_arg\""
fi
exit 0
# nothing found for neither conference ID or name
else
# if no argument is given, we show all the conferences
mapfile -t conference_array < <(db_query "$db_conferences_all_formatted_template")
echo "No match found for \"$conference_arg\""
if [[ "$time_range_specified" == true ]]; then
echo "and time period $from_time - $until_time"
fi
fi
exit 0
else
# if no argument is given, we show all the conferences
db_conferences_all=$(printf "$db_conferences_all_formatted_template" "$from_time" "$until_time")
mapfile -t conference_array < <(db_query "$db_conferences_all")
# we only format the outrput if there are conferences to show
if [[ "${#conference_array[@]}" -gt 0 ]]; then
# prepare the header
output="component\tconference ID\tconference name\tname count\tconference host\n"
# prepare the formatted rows
@ -627,8 +646,25 @@ case "$cmd" in
done
# output
echo -e "$output" | column -t -s $'\t'
exit 0
else
echo -n "No conferences found"
if [[ "$time_range_specified" == true ]]; then
echo -n " for the time period \"$from_time - $until_time\""
fi
echo "."
fi
exit 0
fi
elif [[ "$participant_option" == true ]]; then
echo 'hi'
elif [[ "$time_option" == true ]]; then
echo 'hi'
fi
case "$cmd" in
--conference)
;;
--participant)