Time periods for conferences stats.
parent
b10e73c7e1
commit
90744a8580
107
jilo-cli
107
jilo-cli
|
@ -41,18 +41,22 @@ MYSQL_DB=${MYSQL_DB:-$DEFAULT_MYSQL_DB}
|
|||
db_stats_conferences_all_template="SELECT * FROM conferences;"
|
||||
db_stats_conferences_name_template="SELECT * FROM conferences WHERE conference_name='%s';"
|
||||
db_stats_conferences_id_template="SELECT * FROM conferences WHERE conference_id='%s';"
|
||||
|
||||
db_stats_conferences_time_template="SELECT * FROM conferences WHERE start >= '%s' AND end <= '%s';"
|
||||
|
||||
db_stats_participants_all_template="SELECT * FROM participants;"
|
||||
db_stats_participants_conference_template="SELECT * FROM participants WHERE conference_id='%s';"
|
||||
db_stats_participants_event_template="SELECT * FROM participants WHERE event_type LIKE '%%%s%%';"
|
||||
db_stats_participants_endpoint_template="SELECT * FROM participants WHERE endpoint_id='%s';"
|
||||
db_stats_participants_statsid_template="SELECT * FROM participants WHERE stats_id='%s';"
|
||||
db_stats_participants_statsid_template="SELECT * FROM participants WHERE stats_id LIKE '%%%s%%';"
|
||||
db_stats_participants_ip_template="SELECT * FROM participants WHERE participant_ip='%s';"
|
||||
|
||||
|
||||
help="Usage:
|
||||
$0 [OPTION]
|
||||
Options:
|
||||
--conference|-c [conference ID or name] - show specific conference, all of empty
|
||||
--participant|-p [conference ID, participant IP or word from the event type] - show specific participant, all if empty
|
||||
--conference|-c [conference ID or name] - show specific conference(s), all of empty
|
||||
--participant|-p [conference ID, participant IP, or word from the event type or stats ID] - show specific participant(s), all if empty
|
||||
--time|-t - show stats for a time interval"
|
||||
|
||||
###
|
||||
|
@ -92,11 +96,92 @@ db_query() {
|
|||
fi
|
||||
}
|
||||
|
||||
### input parameters parsing
|
||||
|
||||
# time parameters
|
||||
parse_time_range() {
|
||||
local time_range="$1"
|
||||
|
||||
## exact times
|
||||
# exact date given (YYYY-MM-DD)
|
||||
if [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
|
||||
from_time="${BASH_REMATCH[0]}"
|
||||
until_time="${BASH_REMATCH[0]}"
|
||||
# exact month given (YYYY-MM)
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})$ ]]; then
|
||||
from_time="${BASH_REMATCH[0]}-01"
|
||||
until_time="${BASH_REMATCH[0]}-31"
|
||||
# exact year given (YYYY)
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})$ ]]; then
|
||||
from_time="${BASH_REMATCH[0]}-01-01"
|
||||
until_time="${BASH_REMATCH[0]}-12-31"
|
||||
|
||||
## exact periods
|
||||
# from date to date
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2}):([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
|
||||
until_time="${BASH_REMATCH[4]}-${BASH_REMATCH[5]}-${BASH_REMATCH[6]}"
|
||||
# from month to month
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2}):([0-9]{4})-([0-9]{2})$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-01"
|
||||
until_time="${BASH_REMATCH[3]}-${BASH_REMATCH[4]}-31"
|
||||
# from year to year
|
||||
elif [[ "$time_range" =~ ^([0-9]{4}):([0-9]{4})$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-01-01"
|
||||
until_time="${BASH_REMATCH[2]}-12-31"
|
||||
|
||||
## only end time given
|
||||
# from begining until date (:YYYY-MM-DD)
|
||||
elif [[ "$time_range" =~ ^:([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
|
||||
from_time="0000-01-01"
|
||||
until_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
|
||||
# from begining until month (:YYYY-MM)
|
||||
elif [[ "$time_range" =~ ^:([0-9]{4})-([0-9]{2})$ ]]; then
|
||||
from_time="0000-01-01"
|
||||
until_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-31"
|
||||
# from begining until year (:YYYY)
|
||||
elif [[ "$time_range" =~ ^:([0-9]{4})$ ]]; then
|
||||
from_time="0000-01-01"
|
||||
until_time="${BASH_REMATCH[0]}-12-31"
|
||||
|
||||
## only start time given
|
||||
# from date until end (YYYY-MM-DD:)
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2}):$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
|
||||
until_time="9999-12-31"
|
||||
# from month until end (YYYY-MM:)
|
||||
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2}):$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-01"
|
||||
until_time="9999-12-31"
|
||||
# from year until end (YYYY:)
|
||||
elif [[ "$time_range" =~ ^([0-9]{4}):$ ]]; then
|
||||
from_time="${BASH_REMATCH[1]}-01-01"
|
||||
until_time="9999-12-31"
|
||||
|
||||
else
|
||||
echo -e "Invalid time range. Expected formats:
|
||||
- exact times
|
||||
YYYY-MM-DD, YYYY-MM, YYYY
|
||||
- exact periods
|
||||
YYYY-MM-DD:YYYY-MM-DD, YYYY-MM:YYYY-MM, YYYY:YYYY
|
||||
- from begining to given time
|
||||
:YYYY-MM-DD, :YYYY-MM, :YYYY
|
||||
- from given time until end
|
||||
YYYY-MM-DD:, YYYY-MM:, YYYY:" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
time_range_specified=true
|
||||
}
|
||||
|
||||
### commandline options
|
||||
|
||||
cmd=""
|
||||
conference_arg=""
|
||||
participant_arg=""
|
||||
from_time=""
|
||||
until_time=""
|
||||
time_range_specified=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
|
@ -120,7 +205,13 @@ while [[ $# -gt 0 ]]; do
|
|||
;;
|
||||
-t | --time)
|
||||
cmd="--time"
|
||||
sift
|
||||
if [[ -n "$2" && "$2" != -* ]]; then
|
||||
parse_time_range "$2"
|
||||
shift 2
|
||||
else
|
||||
echo "Option -t needs time range argument in format 'from-time - until-time', YYYY-MM-DD - YYYY-MM-DD" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
-h | --help)
|
||||
echo -e "$help"
|
||||
|
@ -171,10 +262,10 @@ case "$cmd" in
|
|||
;;
|
||||
|
||||
--time)
|
||||
db_stats_conferences=$(printf "$db_stats_conferences_template" )
|
||||
db_query "$db_stats_conferences"
|
||||
db_stats_participants=$(printf "$db_stats_participants_template" )
|
||||
db_query "$db_stats_participants"
|
||||
if [[ "$time_range_specified" == true ]]; then
|
||||
db_stats_conferences_time=$(printf "$db_stats_conferences_time_template" "$from_time" "$until_time")
|
||||
db_query "$db_stats_conferences_time"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
|
||||
|
|
Loading…
Reference in New Issue