extend to bandwidth evaluation
This commit is contained in:
parent
7345073bb0
commit
c2e8fb875a
@ -57,24 +57,26 @@ SELECT d.description, d.address,
|
||||
WHERE ddi.device = d.id AND
|
||||
ddi.dataitem = di.id AND
|
||||
cd.devicedataitem = ddi.id AND
|
||||
di.description = 'totalPages' AND
|
||||
di.description = %s AND
|
||||
cd.ts BETWEEN %s AND %s
|
||||
ORDER BY cd.id
|
||||
|
||||
"""
|
||||
|
||||
cur.execute(query, (datetime.datetime(1970, 1, 1), datetime.datetime(2100, 12, 31)))
|
||||
# itemType = 'totalPages'
|
||||
itemType = 'WAN ifHCOutOctets'
|
||||
cur.execute(query, (itemType, datetime.datetime(1970, 1, 1), datetime.datetime(2100, 12, 31)))
|
||||
|
||||
printers = {}
|
||||
devices = {}
|
||||
|
||||
for (printerName, printerAddress, timestamp, totalPages, id) in cur:
|
||||
totalPages = int(totalPages)
|
||||
if not printers.has_key(printerAddress):
|
||||
printers[printerAddress] = {'name': printerName, 'address': printerAddress,
|
||||
'first': {'timestamp': timestamp, 'value': totalPages},
|
||||
'last': {'timestamp': timestamp, 'value': totalPages}}
|
||||
for (deviceName, deviceAddress, timestamp, value, id) in cur:
|
||||
value = int(value)
|
||||
if not devices.has_key(deviceAddress):
|
||||
devices[deviceAddress] = {'name': deviceName, 'address': deviceAddress,
|
||||
'first': {'timestamp': timestamp, 'value': value},
|
||||
'last': {'timestamp': timestamp, 'value': value}}
|
||||
else:
|
||||
printers[printerAddress]['last'] = {'timestamp': timestamp, 'value': totalPages}
|
||||
devices[deviceAddress]['last'] = {'timestamp': timestamp, 'value': value}
|
||||
|
||||
|
||||
secondsPerMonth = datetime.timedelta(30).total_seconds()
|
||||
@ -95,22 +97,22 @@ SELECT d.description, d.address,
|
||||
mySheet.writeSameNext('Week Average/Forecast')
|
||||
|
||||
|
||||
for printer in printers.values():
|
||||
for device in devices.values():
|
||||
|
||||
print("Printer: %s, %s" % (printer['name'], printer['address']))
|
||||
mySheet.writeNextFirst(printer['name'])
|
||||
mySheet.writeSameNext(printer['address'])
|
||||
print("Device: %s, %s" % (device['name'], device['address']))
|
||||
mySheet.writeNextFirst(device['name'])
|
||||
mySheet.writeSameNext(device['address'])
|
||||
|
||||
print(" First: %s, %s" % (printer['first']['timestamp'], printer['first']['value']))
|
||||
mySheet.writeSameNext(printer['first']['timestamp'])
|
||||
mySheet.writeSameNext(printer['first']['value'])
|
||||
print(" First: %s, %s" % (device['first']['timestamp'], device['first']['value']))
|
||||
mySheet.writeSameNext(device['first']['timestamp'])
|
||||
mySheet.writeSameNext(device['first']['value'])
|
||||
|
||||
print(" Last: %s, %s" % (printer['last']['timestamp'], printer['last']['value']))
|
||||
mySheet.writeSameNext(printer['last']['timestamp'])
|
||||
mySheet.writeSameNext(printer['last']['value'])
|
||||
print(" Last: %s, %s" % (device['last']['timestamp'], device['last']['value']))
|
||||
mySheet.writeSameNext(device['last']['timestamp'])
|
||||
mySheet.writeSameNext(device['last']['value'])
|
||||
|
||||
deltaTime = printer['last']['timestamp'] - printer['first']['timestamp']
|
||||
deltaValue = printer['last']['value'] - printer['first']['value']
|
||||
deltaTime = device['last']['timestamp'] - device['first']['timestamp']
|
||||
deltaValue = device['last']['value'] - device['first']['value']
|
||||
print(" Diff: %s, %s" % (deltaTime, deltaValue))
|
||||
mySheet.writeSameNext(deltaValue)
|
||||
|
||||
@ -130,7 +132,7 @@ except mysql.connector.Error as err:
|
||||
print("Failure when using database: %s" % (err))
|
||||
finally:
|
||||
if xls is not None:
|
||||
xls.save('printerStats.xls')
|
||||
xls.save('deviceStats.xls')
|
||||
if cur is not None:
|
||||
cur.close()
|
||||
if dbh is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user