libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 746756605b41d22e49454e95b38338b6fdb07059
parent af3a5e50d7d25011db76c5a2e694577217841a94
Author: MS <ms@taler.net>
Date:   Mon, 27 Nov 2023 14:06:10 +0100

populating stats

Diffstat:
Mcontrib/populate-stats.sh | 83++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 46 insertions(+), 37 deletions(-)

diff --git a/contrib/populate-stats.sh b/contrib/populate-stats.sh @@ -3,9 +3,13 @@ # This script populates the stats table, to test the /monitor API. usage() { - echo "Usage: ./populate-stats.sh CONFIG_FILE" + echo "Usage: ./populate-stats.sh CONFIG_FILE [--one]" echo echo "Populates the stats table with random data" + echo + echo Parameters: + echo + echo --one instead of random amounts, it always uses 1.0 } # Detecting the help case. @@ -13,8 +17,13 @@ if test "$1" = "--help" -o "$1" = "-h" -o -z ${1:-}; then usage exit fi -set -eu +HAS_ONE=0 +if test "$2" = "--one"; + then HAS_ONE=1 +fi + +set -eu DB_NAME=$(taler-config -c $1 -s libeufin-bankdb-postgres -o config) echo Running on the database: $DB_NAME @@ -23,7 +32,36 @@ rnd () { shuf -i $1-$2 -n1 } -insert_stat () { +insert_stat_one () { + echo " + SET search_path TO libeufin_bank; + CALL libeufin_bank.stats_register_payment ( + 'taler_in'::text + ,TO_TIMESTAMP($1)::timestamp + ,(1, 0)::taler_amount + ,null + ); + CALL libeufin_bank.stats_register_payment ( + 'taler_out'::text + ,TO_TIMESTAMP($1)::timestamp + ,(1, 0)::taler_amount + ,null + ); + CALL libeufin_bank.stats_register_payment ( + 'cashin'::text + ,TO_TIMESTAMP($1)::timestamp + ,(1, 0)::taler_amount + ,(1, 0)::taler_amount + ); + CALL libeufin_bank.stats_register_payment ( + 'cashout'::text + ,TO_TIMESTAMP($1)::timestamp + ,(1, 0)::taler_amount + ,(1, 0)::taler_amount + );" +} + +insert_stat_rand () { echo " SET search_path TO libeufin_bank; CALL libeufin_bank.stats_register_payment ( @@ -52,41 +90,12 @@ insert_stat () { );" } -# $1 == timestamp -insert_cmd () { - echo " - INSERT INTO libeufin_bank.bank_stats ( - timeframe - ,start_time - ,taler_in_count - ,taler_in_volume - ,taler_out_count - ,taler_out_volume - ,cashin_count - ,cashin_regional_volume - ,cashin_fiat_volume - ,cashout_count - ,cashout_regional_volume - ,cashout_fiat_volume - ) VALUES ( - 'hour' - ,date_trunc('hour', TO_TIMESTAMP($1)) - ,$(rnd 1 3000) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - ,$(rnd 1 3000) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - ,$(rnd 1 3000) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - ,$(rnd 1 3000) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - ,($(rnd 1 1000000), $(rnd 0 99999999)) - );" -} - for n_hour_ago in `seq 1 100`; do echo -n . TIMESTAMP=$(date --date="${n_hour_ago} hour ago" +%s) - # psql $DB_NAME -c "$(insert_cmd ${TIMESTAMP})" > /dev/null - psql $DB_NAME -c "$(insert_stat ${TIMESTAMP})" > /dev/null + if test $HAS_ONE = 1; then + psql $DB_NAME -c "$(insert_stat_one ${TIMESTAMP})" > /dev/null + else + psql $DB_NAME -c "$(insert_stat_rand ${TIMESTAMP})" > /dev/null + fi done