consider dataitem in output
This commit is contained in:
parent
c2e8fb875a
commit
eaea327077
@ -48,6 +48,7 @@ try:
|
||||
|
||||
query = """
|
||||
SELECT d.description, d.address,
|
||||
di.description,
|
||||
cd.ts,
|
||||
cd.value, cd.id
|
||||
FROM device_t d,
|
||||
@ -57,26 +58,25 @@ SELECT d.description, d.address,
|
||||
WHERE ddi.device = d.id AND
|
||||
ddi.dataitem = di.id AND
|
||||
cd.devicedataitem = ddi.id AND
|
||||
di.description = %s AND
|
||||
cd.ts BETWEEN %s AND %s
|
||||
ORDER BY cd.id
|
||||
|
||||
"""
|
||||
|
||||
# itemType = 'totalPages'
|
||||
itemType = 'WAN ifHCOutOctets'
|
||||
cur.execute(query, (itemType, datetime.datetime(1970, 1, 1), datetime.datetime(2100, 12, 31)))
|
||||
cur.execute(query, (datetime.datetime(1970, 1, 1), datetime.datetime(2100, 12, 31)))
|
||||
|
||||
devices = {}
|
||||
|
||||
for (deviceName, deviceAddress, timestamp, value, id) in cur:
|
||||
for (deviceName, deviceAddress, dataItem, 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}}
|
||||
key = deviceAddress + ' ' + dataItem
|
||||
if not devices.has_key(key):
|
||||
devices[key] = {'name': deviceName, 'address': deviceAddress,
|
||||
'dataItem': dataItem,
|
||||
'first': {'timestamp': timestamp, 'value': value},
|
||||
'last': {'timestamp': timestamp, 'value': value}}
|
||||
else:
|
||||
devices[deviceAddress]['last'] = {'timestamp': timestamp, 'value': value}
|
||||
devices[key]['last'] = {'timestamp': timestamp, 'value': value}
|
||||
|
||||
|
||||
secondsPerMonth = datetime.timedelta(30).total_seconds()
|
||||
@ -86,6 +86,7 @@ SELECT d.description, d.address,
|
||||
mySheet = MySheet(xls.add_sheet('Sheet 1'))
|
||||
mySheet.writeFirstFirst('Name')
|
||||
mySheet.writeSameNext('Address')
|
||||
mySheet.writeSameNext('DataItem')
|
||||
mySheet.writeSameNext('First Sample Date')
|
||||
mySheet.writeSameNext('First Sample Value')
|
||||
mySheet.writeSameNext('Last Sample Date')
|
||||
@ -99,9 +100,10 @@ SELECT d.description, d.address,
|
||||
|
||||
for device in devices.values():
|
||||
|
||||
print("Device: %s, %s" % (device['name'], device['address']))
|
||||
print("Device: %s, %s, %s" % (device['name'], device['address'], device['dataItem']))
|
||||
mySheet.writeNextFirst(device['name'])
|
||||
mySheet.writeSameNext(device['address'])
|
||||
mySheet.writeSameNext(device['dataItem'])
|
||||
|
||||
print(" First: %s, %s" % (device['first']['timestamp'], device['first']['value']))
|
||||
mySheet.writeSameNext(device['first']['timestamp'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user