move functions to info.stats.sh

This commit is contained in:
openoms 2021-10-01 13:05:03 +01:00
parent 3bb17f7fe2
commit 219c349647
No known key found for this signature in database
GPG key ID: 5BFB77609B081B65
2 changed files with 63 additions and 53 deletions

View file

@ -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
}

View file

@ -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")