From 219c349647898aa89de8358bd6cb71cbcab2d760 Mon Sep 17 00:00:00 2001 From: openoms Date: Fri, 1 Oct 2021 13:05:03 +0100 Subject: [PATCH] move functions to info.stats.sh --- scripts/_functions.sh | 56 +++++----------------------------------- scripts/info.stats.sh | 60 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 53 deletions(-) diff --git a/scripts/_functions.sh b/scripts/_functions.sh index 9927e09..c614303 100755 --- a/scripts/_functions.sh +++ b/scripts/_functions.sh @@ -159,58 +159,14 @@ function stopYG() { fi } -function feereport() { - # puts the fees earned as a Maker into variables - INPUT=/home/joinmarket/.joinmarket/logs/yigen-statement.csv - allEarned=0 - allCoinjoins=0 - monthEarned=0 - monthCoinjoins=0 - weekEarned=0 - weekCoinjoins=0 - dayEarned=0 - dayCoinjoins=0 - unixtimeMonthAgo=$(date -d "1 month ago" +%s) - unixtimeWeekAgo=$(date -d "1 week ago" +%s) - unixtimeDayAgo=$(date -d "1 day ago" +%s) - OLDIFS=$IFS - IFS="," - [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } - #timestamp cj amount/satoshi my input count my input value/satoshi cjfee/satoshi earned/satoshi confirm time/min notes - while read -r timestamp cj_amount_satoshi my_input_count my_input_value_satoshi cjfee_satoshi earned_satoshi confirm_time_min notes - do - unixtimeEvent=$(date -d "$timestamp" +%s 2>/dev/null) - if [ "$my_input_count" -gt 0 ]; then - allEarned=$(( allEarned + earned_satoshi )) - allCoinjoins=$(( allCoinjoins + 1 )) - if [ "$unixtimeEvent" -gt "$unixtimeMonthAgo" ]; then - monthEarned=$(( monthEarned + earned_satoshi )) - monthCoinjoins=$(( monthCoinjoins + 1 )) - if [ "$unixtimeEvent" -gt "$unixtimeWeekAgo" ]; then - weekEarned=$(( weekEarned + earned_satoshi )) - weekCoinjoins=$((weekCoinjoins+1)) - if [ "$unixtimeEvent" -gt "$unixtimeDayAgo" ]; then - dayEarned=$((dayEarned+earned_satoshi)) - dayCoinjoins=$((dayCoinjoins+1)) - fi - fi - fi - fi 2>/dev/null - done < "$INPUT" - IFS=$OLDIFS -} - -function YGuptime() { - # puts the Yield Generator uptime to $JMUptime - JMpid=$(pgrep -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin" 2>/dev/null | head -1) - JMUptimeInSeconds=$(ps -p $JMpid -oetime= 2>/dev/null | tr '-' ':' | awk -F: '{ total=0; m=1; } { for (i=0; i < NF; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print total}') - JMUptime=$(printf '%dd:%dh:%dm\n' $((JMUptimeInSeconds/86400)) $((JMUptimeInSeconds%86400/3600)) $((JMUptimeInSeconds%3600/60))) -} - function YGnickname() { # Retrieves nickname from the latest NickServ message in the newest logfile - newest_log=$(ls -td /home/joinmarket/.joinmarket/logs/* | grep J5 | head -n 1) - name=$(grep NickServ $newest_log | tail -1 | awk '{print $9}') + if ls -td /home/joinmarket/.joinmarket/logs/* 2>/dev/null ; then + newest_log=$(ls -td /home/joinmarket/.joinmarket/logs/* | grep J5 | head -n 1) + name=$(grep NickServ $newest_log | tail -1 | awk '{print $9}') + else + name="waiting__to__run" + fi echo $name } diff --git a/scripts/info.stats.sh b/scripts/info.stats.sh index d211b5f..6258046 100755 --- a/scripts/info.stats.sh +++ b/scripts/info.stats.sh @@ -2,12 +2,66 @@ source /home/joinmarket/_functions.sh -feereport -YGuptime sixteencharname=$(YGnickname) +# feereport +# puts the fees earned as a Maker into variables +INPUT=/home/joinmarket/.joinmarket/logs/yigen-statement.csv +allEarned=0 +allCoinjoins=0 +monthEarned=0 +monthCoinjoins=0 +weekEarned=0 +weekCoinjoins=0 +dayEarned=0 +dayCoinjoins=0 +unixtimeMonthAgo=$(date -d "1 month ago" +%s) +unixtimeWeekAgo=$(date -d "1 week ago" +%s) +unixtimeDayAgo=$(date -d "1 day ago" +%s) +OLDIFS=$IFS +IFS="," +[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } +#timestamp cj amount/satoshi my input count my input value/satoshi cjfee/satoshi earned/satoshi confirm time/min notes +while read -r timestamp cj_amount_satoshi my_input_count my_input_value_satoshi cjfee_satoshi earned_satoshi confirm_time_min notes +do + unixtimeEvent=$(date -d "$timestamp" +%s 2>/dev/null) + if [ "$my_input_count" -gt 0 ]; then + allEarned=$(( allEarned + earned_satoshi )) + allCoinjoins=$(( allCoinjoins + 1 )) + if [ "$unixtimeEvent" -gt "$unixtimeMonthAgo" ]; then + monthEarned=$(( monthEarned + earned_satoshi )) + monthCoinjoins=$(( monthCoinjoins + 1 )) + if [ "$unixtimeEvent" -gt "$unixtimeWeekAgo" ]; then + weekEarned=$(( weekEarned + earned_satoshi )) + weekCoinjoins=$((weekCoinjoins+1)) + if [ "$unixtimeEvent" -gt "$unixtimeDayAgo" ]; then + dayEarned=$((dayEarned+earned_satoshi)) + dayCoinjoins=$((dayCoinjoins+1)) + fi + fi + fi + fi 2>/dev/null +done < "$INPUT" +IFS=$OLDIFS + +# YGuptime +# puts the Yield Generator uptime to $JMUptime +JMpid=$(pgrep -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin" 2>/dev/null | head -1) +JMUptimeInSeconds=$(ps -p $JMpid -oetime= 2>/dev/null | tr '-' ':' | awk -F: '{ total=0; m=1; } { for (i=0; i < NF; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print total}') +JMUptime=$(printf '%dd:%dh:%dm\n' $((JMUptimeInSeconds/86400)) $((JMUptimeInSeconds%86400/3600)) $((JMUptimeInSeconds%3600/60))) + +trap 'rm -f "$JMstats"' EXIT +JMstats=$(mktemp -p /dev/shm) + echo "\ JoinMarket stats:day:week:month coinjoins as a Maker:$dayCoinjoins:$weekCoinjoins:$monthCoinjoins sats earned:$dayEarned:$weekEarned:$monthEarned -$sixteencharname up:$JMUptime" | column -t -s: +$sixteencharname up:$JMUptime" | column -t -s: > $JMstats + +cat "$JMstats" + +JMstatsL1=$(sed -n 1p < "$JMstats") +JMstatsL2=$(sed -n 2p < "$JMstats") +JMstatsL3=$(sed -n 3p < "$JMstats") +JMstatsL4=$(sed -n 4p < "$JMstats")