diff --git a/html_confbridge_stats.py b/html_confbridge_stats.py
index 1065ad2..d983093 100755
--- a/html_confbridge_stats.py
+++ b/html_confbridge_stats.py
@@ -21,11 +21,12 @@
from __future__ import print_function
from cPickle import load
from pprint import pprint
-from time import ctime
+from time import time, strftime, localtime
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
from dmr_utils.utils import int_id, get_alias
+from os.path import getmtime
__autdor__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2017 Cortney T. Buffington, N0MJS'
@@ -40,13 +41,13 @@ __email__ = 'n0mjs@me.com'
# Tell the program how often to print a report -- should match dmrlink report period
stat_file = '../confbridge_stats.pickle'
html_table_file = '../confbridge_stats.html'
-frequency = 30
+frequency = 10
def read_dict():
try:
with open(stat_file, 'rb') as file:
- NETWORK = load(file)
- return NETWORK
+ BRIDGES = load(file)
+ return BRIDGES
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
@@ -63,71 +64,82 @@ def write_file(_string):
print('EOFError')
def build_table():
- NETWORK = read_dict()
- if NETWORK != 'None':
- stuff = 'Last Update: {}'.format(ctime())
- stuff += ''
+ _now = time()
+ _last_update = strftime('%Y-%m-%d %H:%M:%S', localtime(getmtime(stat_file)))
+ _cnow = strftime('%Y-%m-%d %H:%M:%S', localtime(_now))
+ BRIDGES = read_dict()
+ if BRIDGES != 'None':
- for ipsc in NETWORK:
- stat = NETWORK[ipsc]['MASTER']['STATUS']
- master = NETWORK[ipsc]['LOCAL']['MASTER_PEER']
-
- stuff += '
'
-
+ stuff = 'Table Generated: {}
'.format(_cnow)
+ stuff += 'Last Stat Data Recieved: {}
'.format(_last_update)
+
+ #style="font: 10pt arial, sans-serif;"
+
+ for bridge in BRIDGES:
+ stuff += ''
+ stuff += ''
stuff += '\
- \
- \
\
+ \
+ \
+ \
+ \
+ \
+ \
\
- \
- \
\
'
+ stuff += '{}'.format(bridge)
+ stuff += 'System | \
+ Slot | \
+ TGID | \
+ Status | \
+ Timeout | \
+ Timeout Action | \
+ ON Triggers | \
+ OFF Triggers |
'
- stuff += '{} '.format(ipsc)
- if master:
- stuff += '(master)'
- else:
- stuff += '(peer)'
- stuff +='Type | \
- Radio ID | \
- IP Address | \
- Connected | \
- Keep Alives | \
- Sent | Received | Missed |
'
+ for system in BRIDGES[bridge]:
+ on = ''
+ off = ''
+ active = 'Unknown | '
+
+ if system['TO_TYPE'] == 'ON' or system['TO_TYPE'] == 'OFF':
+ if system['TIMER'] - _now > 0:
+ exp_time = int(system['TIMER'] - _now)
+ else:
+ exp_time = 'Expired'
+ if system['TO_TYPE'] == 'ON':
+ to_action = 'Turn OFF'
+ else:
+ to_action = 'Turn ON'
+ else:
+ exp_time = 'N/A'
+ to_action = 'None'
+
+ if system['ACTIVE'] == True:
+ active = 'Connected | '
+ elif system['ACTIVE'] == False:
+ active = 'Disconnected | '
- if not master:
- stuff += 'Master | {} | {} | {} | {} | {} | {} |
'.format(\
- str(int_id(NETWORK[ipsc]['MASTER']['RADIO_ID'])).rjust(8,'0'),\
- NETWORK[ipsc]['MASTER']['IP'],\
- stat['CONNECTED'],\
- stat['KEEP_ALIVES_SENT'],\
- stat['KEEP_ALIVES_RECEIVED'],\
- stat['KEEP_ALIVES_MISSED'],)
-
- if master:
- for peer in NETWORK[ipsc]['PEERS']:
- stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
- stuff += 'Peer | {} | {} | {} | n/a | {} | n/a |
'.format(\
- str(int_id(peer)).rjust(8,'0'),\
- NETWORK[ipsc]['PEERS'][peer]['IP'],\
- stat['CONNECTED'],\
- stat['KEEP_ALIVES_RECEIVED'])
+ for trigger in system['ON']:
+ on += str(int_id(trigger)) + ' '
- else:
- for peer in NETWORK[ipsc]['PEERS']:
- stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
- if peer != NETWORK[ipsc]['LOCAL']['RADIO_ID']:
- stuff += 'Peer | {} | {} | {} | {} | {} | {} |
'.format(\
- str(int_id(peer)).rjust(8,'0'),\
- NETWORK[ipsc]['PEERS'][peer]['IP'],\
- stat['CONNECTED'],\
- stat['KEEP_ALIVES_SENT'],\
- stat['KEEP_ALIVES_RECEIVED'],\
- stat['KEEP_ALIVES_MISSED'])
- stuff += '
'
+ for trigger in system['OFF']:
+ off += str(int_id(trigger)) + ' '
+
+ stuff += ' {} | {} | {} | {} {} | {} | {} | {} |
'.format(\
+ system['SYSTEM'],\
+ system['TS'],\
+ int_id(system['TGID']),\
+ active,\
+ exp_time,\
+ to_action,\
+ on,\
+ off)
+
+ stuff += '
'
write_file(stuff)
diff --git a/html_stats.py b/html_stats.py
index 3edd1cf..99de401 100755
--- a/html_stats.py
+++ b/html_stats.py
@@ -21,7 +21,7 @@
from __future__ import print_function
from cPickle import load
from pprint import pprint
-from time import ctime
+from time import time, strftime, localtime
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
@@ -65,14 +65,15 @@ def write_file(_string):
def build_table():
NETWORK = read_dict()
if NETWORK != 'None':
- stuff = 'Last Update: {}'.format(ctime())
+ _cnow = strftime('%Y-%m-%d %H:%M:%S', localtime(time()))
+ stuff = 'Last Update: {}'.format(_cnow)
stuff += ''
for ipsc in NETWORK:
stat = NETWORK[ipsc]['MASTER']['STATUS']
master = NETWORK[ipsc]['LOCAL']['MASTER_PEER']
- stuff += '
'
+ stuff += ''
stuff += '\
\
@@ -89,7 +90,7 @@ def build_table():
stuff += '(master)'
else:
stuff += '(peer)'
- stuff +=''
stuff += 'Type | \
Radio ID | \
@@ -127,7 +128,7 @@ def build_table():
stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
stat['KEEP_ALIVES_MISSED'])
- stuff += '
---|
'
+ stuff += '
'
write_file(stuff)