Application to Print IPSC Stats
This commit is contained in:
parent
d7f11d955c
commit
1285ddedff
@ -1,8 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from cPickle import load
|
||||
from pprint import pprint
|
||||
from os.path import getmtime
|
||||
from time import sleep
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet import task
|
||||
from binascii import b2a_hex as h
|
||||
|
||||
|
||||
# This is the only user-configuration necessary
|
||||
@ -10,8 +11,8 @@ from time import sleep
|
||||
stat_file = 'dmrlink_stats.pickle'
|
||||
|
||||
|
||||
last = getmtime(stat_file)
|
||||
|
||||
def int_id(_hex_string):
|
||||
return int(h(_hex_string), 16)
|
||||
|
||||
def read_dict():
|
||||
try:
|
||||
@ -23,12 +24,21 @@ def read_dict():
|
||||
except EOFError:
|
||||
print('EOFError')
|
||||
|
||||
def print_stats():
|
||||
NETWORK = read_dict()
|
||||
if NETWORK != "None":
|
||||
for ipsc in NETWORK:
|
||||
stat = NETWORK[ipsc]['MASTER']['STATUS']
|
||||
print(ipsc)
|
||||
print(' MASTER Information:')
|
||||
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {}'.format(str(int_id(NETWORK[ipsc]['MASTER']['RADIO_ID'])).rjust(8,'0'),stat['CONNECTED'],stat['KEEP_ALIVES_SENT'],stat['KEEP_ALIVES_RECEIVED'],stat['KEEP_ALIVES_MISSED']))
|
||||
print(' PEER Information:')
|
||||
for peer in NETWORK[ipsc]['PEERS']:
|
||||
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
|
||||
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {}'.format(str(int_id(peer)).rjust(8,'0'),stat['CONNECTED'],stat['KEEP_ALIVES_SENT'],stat['KEEP_ALIVES_RECEIVED'],stat['KEEP_ALIVES_MISSED']))
|
||||
print()
|
||||
|
||||
pprint(read_dict())
|
||||
|
||||
while 1:
|
||||
sleep(1)
|
||||
now = getmtime(stat_file)
|
||||
if now > last:
|
||||
last = now
|
||||
pprint(read_dict())
|
||||
if __name__ == '__main__':
|
||||
output_stats = task.LoopingCall(print_stats)
|
||||
output_stats.start(10)
|
||||
reactor.run()
|
28
report.py
28
report.py
@ -1,28 +0,0 @@
|
||||
from __future__ import print_function
|
||||
from pprint import pprint
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet import task
|
||||
from binascii import b2a_hex as h
|
||||
|
||||
import cPickle as pickle
|
||||
|
||||
def int_id(_hex_string):
|
||||
return int(h(_hex_string), 16)
|
||||
|
||||
def print_stats(_request, _client_address, _server):
|
||||
stats_file = open('stats.py', 'r')
|
||||
NETWORK = pickle.load(stats_file)
|
||||
stats_file.close()
|
||||
for ipsc in NETWORK:
|
||||
print(ipsc)
|
||||
print(' MASTER Information:')
|
||||
print(' RADIO ID: ', int_id(NETWORK[ipsc]['MASTER']['RADIO_ID']))
|
||||
print(' CONNECTED: ', NETWORK[ipsc]['MASTER']['STATUS']['CONNECTED'])
|
||||
print(' KEEP ALIVES SENT: ', NETWORK[ipsc]['MASTER']['STATUS']['KEEP_ALIVES_SENT'])
|
||||
print(' KEEP ALIVES RECEIVED: ', NETWORK[ipsc]['MASTER']['STATUS']['KEEP_ALIVES_RECEIVED'])
|
||||
print(' KEEP ALIVES MISSED: ', NETWORK[ipsc]['MASTER']['STATUS']['KEEP_ALIVES_MISSED'])
|
||||
#pprint(NETWORK[ipsc]['MASTER']['STATUS'])
|
||||
|
||||
output_stats = task.LoopingCall(print_stats)
|
||||
output_stats.start(10)
|
||||
reactor.run()
|
Loading…
Reference in New Issue
Block a user