Print meaningful time spans on rainactive

This commit is contained in:
moneromooo 2015-01-18 22:18:46 +00:00
parent 8007d6c7e3
commit 5ce0d1da50
2 changed files with 26 additions and 2 deletions

View file

@ -281,8 +281,8 @@ def RainActive(nick,chan,cmd):
return
pipe.execute()
log_info("%s rained %s - %s (total %s, acc %s) on the %d nicks active in the last %f hours" % (nick, AmountToString(minu), AmountToString(maxu), AmountToString(units), AmountToString(rained_units), nnicks, hours))
SendTo(chan, "%s rained %s - %s on the %d nicks active in the last %f hours" % (nick, AmountToString(minu), AmountToString(maxu), nnicks, hours))
log_info("%s rained %s - %s (total %s, acc %s) on the %d nicks active in the last %s" % (nick, AmountToString(minu), AmountToString(maxu), AmountToString(units), AmountToString(rained_units), nnicks, TimeToString(seconds)))
SendTo(chan, "%s rained %s - %s on the %d nicks active in the last %s" % (nick, AmountToString(minu), AmountToString(maxu), nnicks, TimeToString(seconds)))
except Exception,e:
log_error('Rain: exception: %s' % str(e))

View file

@ -78,6 +78,30 @@ def AmountToString(amount):
samount = "%.16g %s" % (float(lamount) / coinspecs.atomic_units, coinspecs.name)
return samount
def TimeToString(seconds):
seconds=float(seconds)
if seconds < 1e-3:
return "%.2f microseconds" % (seconds*1e6)
if seconds < 1:
return "%.2f milliseconds" % (seconds*1e3)
if seconds < 60:
return "%.2f seconds" % (seconds)
if seconds < 3600:
return "%.2f minutes" % (seconds / 60)
if seconds < 3600 * 24:
return "%.2f hours" % (seconds / 3600)
if seconds < 3600 * 24 * 30.5:
return "%.2f days" % (seconds / (3600*24))
if seconds < 3600 * 24 * 365.25:
return "%.2f months" % (seconds / (3600*24*30.5))
if seconds < 3600 * 24 * 365.25 * 100:
return "%.2f years" % (seconds / (3600*24*365.25))
if seconds < 3600 * 24 * 365.25 * 1000:
return "%.2f centuries" % (seconds / (3600*24*365.25 * 100))
if seconds < 3600 * 24 * 365.25 * 1000000:
return "%.2f millenia" % (seconds / (3600*24*365.25 * 100))
return " like, forever, dude"
def SendJSONRPCCommand(host,port,method,params):
try:
http = httplib.HTTPConnection(host,port,timeout=20)