add filter option -- sometimes want to see devices not in a current game.

This commit is contained in:
Eric House 2013-09-18 07:03:25 -07:00
parent aa13fa07a7
commit 9650000fce

View file

@ -2,10 +2,12 @@
set -e -u
FILTER=""
LIMIT=10000
usage() {
echo "usage: $0 [--limit <n>]"
echo "usage: $0 [--limit <n>] [--filter]"
exit 1
}
@ -15,6 +17,9 @@ while [ $# -gt 0 ]; do
LIMIT=$2
shift
;;
--filter)
FILTER=1
;;
*) usage
;;
esac
@ -27,16 +32,23 @@ echo -n "Device (pid) count: $(pidof xwords | wc | awk '{print $2}')"
echo "; relay pid[s]: $(pidof xwrelay)"
echo "Row count:" $(psql -t xwgames -c "select count(*) FROM games $QUERY;")
# Games
echo "SELECT dead as d,connname,cid,room,lang as lg,clntVers as cv ,ntotal as t,nperdevice as nPerDev,nsents as snts, seeds,devids,tokens,ack, mtimes "\
"FROM games $QUERY ORDER BY NOT dead, connname LIMIT $LIMIT;" \
| psql xwgames
# Messages
echo "SELECT connname, hid, devid, count(*), sum(msglen) "\
"FROM msgs where connname in (SELECT connname from games where not games.dead group by connname) "\
"OR devid IN (SELECT unnest(devids) from games where not games.dead) "\
"GROUP BY connname, hid, devid ORDER BY connname LIMIT $LIMIT;" \
| psql xwgames
echo "SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes[1] as dTyp, devids[1] as devid FROM devices WHERE id IN (select UNNEST(devids) FROM games $QUERY) ORDER BY id LIMIT $LIMIT;" \
| psql xwgames
# Devices
LINE="SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes[1] as dTyp, devids[1] as devid FROM devices "
if [ -n "$FILTER" ]; then
LINE="${LINE} WHERE id IN (select UNNEST(devids) FROM games $QUERY)"
fi
LINE="$LINE ORDER BY mtimes[1] DESC LIMIT $LIMIT;"
echo "$LINE" | psql xwgames