Skip to content

Commit

Permalink
Adding in some basic stats to the shell.py allowing for basic
Browse files Browse the repository at this point in the history
inspection of the health of the network.
  • Loading branch information
boyter committed Dec 2, 2013
1 parent 993d5b0 commit d50cf09
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import threading
import urllib
import get_db
import sys
import operator

class zc(cmd.Cmd):
prompt = "zShell$ "
intro = "Welcome to the zCoin shell, type `help` to get started."
def do_send(self, line):
self.lastcmd = ""
line = line.split()
try:
to = line[0]
Expand All @@ -20,18 +19,17 @@ def do_send(self, line):
else:
print "Coins are being sent"
threading.Thread(target=send_coin.send, args=(to, amount)).start()
print("zShell$"),


def do_check(self, lines):
self.lastcmd = ""
get_db.send()

def do_totalcoins(self, line):
coin = config.db.find("coins", "all")
if not coin:
coin = 0
else:
coin = len(coin)
print "Ther are "+str(coin)+" coins in existence."
print "There are "+str(coin)+" coins in existence."

def do_coins(self, line):
addr = config.wallet.find("data", "all")[0]
Expand Down Expand Up @@ -67,7 +65,6 @@ def do_transactions(self, line):


def do_update(self, line):
self.lastcmd = ""
files = {
"check_coin.py":"https://raw.github.com/Max00355/zCoin/master/check_coin.py",
"coin_count.py":"https://raw.github.com/Max00355/zCoin/master/coin_count.py",
Expand All @@ -83,7 +80,6 @@ def do_update(self, line):
"send_command.py":"https://raw.github.com/Max00355/zCoin/master/send_command.py",
"shell.py":"https://raw.github.com/Max00355/zCoin/master/shell.py",
"zcoin.py":"https://raw.github.com/Max00355/zCoin/master/zcoin.py",
"zcoingui.py":"https://raw.github.com/Max00355/zCoin/master/zcoingui.py",

}

Expand All @@ -92,6 +88,42 @@ def do_update(self, line):
with open(x,'wb') as file:
file.write(urllib.urlopen(files[x]).read())

def do_stats(self, line):
coins = config.db.find("coins", "all")
trans = config.db.find("transactions","all")

if not coins or not trans:
print "Error working out stats"
else:
total = len(coins)
coincounts = {}
recievercounts = {}
sendercounts = {}

for coin in coins:
try:
coincounts[coin['address']] += 1
except:
coincounts[coin['address']] = 1
for tran in trans:
try:
recievercounts[tran['to']] += tran['amount']
sendercounts[tran['from']] += tran['amount']
except:
recievercounts[tran['to']] = tran['amount']
sendercounts[tran['from']] = tran['amount']

print "\nAddress".ljust(52),"Amt".ljust(len(str(total))),"%","\n","-"*63
for address,count in sorted(coincounts.iteritems(), key=operator.itemgetter(1), reverse=True):
print '%s %s %.2f%%'%(address.ljust(51), str(count).ljust(len(str(total))), (float(count)/float(total))*100)

print "\nReceivers".ljust(52),"Trans Count","\n","-"*63
for to,count in sorted(recievercounts.iteritems(), key=operator.itemgetter(1), reverse=True):
print to.ljust(51),count

print "\nSenders".ljust(52),"Trans Count","\n","-"*63
for to,count in sorted(sendercounts.iteritems(), key=operator.itemgetter(1), reverse=True):
print to.ljust(51),count

def do_help(self, line):
print """
Expand All @@ -105,6 +137,7 @@ def do_help(self, line):
update - Updates the source code
addr - Displays your address
check - Updates db.db manually. Useful when expecting payments
stats - Get basic % counts and transaction info
"""

Expand Down

0 comments on commit d50cf09

Please sign in to comment.