trace in metrics

This commit is contained in:
Cayo Puigdefabregas 2021-10-11 14:11:56 +02:00
parent 406d3d6449
commit 35e891bf5d
1 changed files with 42 additions and 1 deletions

View File

@ -479,6 +479,12 @@ class Device(Thing):
if act.type == 'Allocate':
allo = {'type': 'Allocate',
'action_type': 'Status',
'status_receiver': 'Use',
'trade_supplier': '',
'trade_receiver': '',
'trade_confirmed': '',
'action_create_by': 'Receiver',
'devicehubID': self.devicehub_id,
'finalUserCode': act.final_user_code,
'numEndUsers': act.end_users,
@ -501,6 +507,12 @@ class Device(Thing):
if act.type == 'Deallocate':
deallo = {'type': 'Deallocate',
'devicehubID': self.devicehub_id,
'action_type': 'Status',
'status_receiver': 'Use',
'trade_supplier': '',
'trade_receiver': '',
'trade_confirmed': '',
'action_create_by': 'Receiver',
'finalUserCode': '',
'numEndUsers': '',
'hid': self.hid,
@ -510,6 +522,35 @@ class Device(Thing):
'usageTimeAllocate': 0}
allocates.append(deallo)
if act.type == 'Trade':
confirm = False
if hasattr(act, 'acceptances'):
accept = act.acceptances[-1]
if accept.t == 'Confirm' and accept.user == act.user_to:
confirm = True
action_create_by = 'Receiver'
if act.author == act.user_from:
action_create_by = 'Supplier'
trade = {'type': 'Trade',
'action_type': 'Trade',
'trade_supplier': act.user_from,
'trade_receiver': act.user_to,
'trade_confirmed': confirm,
'action_create_by': action_create_by,
'trade_confirmed': confirm,
'devicehubID': self.devicehub_id,
'finalUserCode': '',
'numEndUsers': '',
'hid': self.hid,
'liveCreate': 0,
'usageTimeHdd': lifetime,
'start': act.start_time,
'status_receiver': 'Use',
'usageTimeAllocate': 0
}
allocates.append(trade)
return allocates
def __lt__(self, other):