test status vs punch
This commit is contained in:
parent
71c77d5878
commit
b6cfd862f9
@ -197,7 +197,7 @@ try:
|
|||||||
i = 0
|
i = 0
|
||||||
for att in attendance:
|
for att in attendance:
|
||||||
i +=1
|
i +=1
|
||||||
print ("ATT {:>6}: uid:{:>3}, user_id:{:>8} t: {}, s:{}".format(i, att.uid, att.user_id, att.timestamp, att.status))
|
print ("ATT {:>6}: uid:{:>3}, user_id:{:>8} t: {}, s:{} p:{}".format(i, att.uid, att.user_id, att.timestamp, att.status, att.punch))
|
||||||
print (' took {:.3f}[s]'.format(final - inicio))
|
print (' took {:.3f}[s]'.format(final - inicio))
|
||||||
print ('')
|
print ('')
|
||||||
print ('--- sizes & capacity ---')
|
print ('--- sizes & capacity ---')
|
||||||
@ -217,7 +217,7 @@ try:
|
|||||||
#counter += 1 #enable to implemet a poorman timeout
|
#counter += 1 #enable to implemet a poorman timeout
|
||||||
print ("timeout {}".format(counter))
|
print ("timeout {}".format(counter))
|
||||||
else:
|
else:
|
||||||
print ("ATT {:>6}: uid:{:>3}, user_id:{:>8} t: {}, s:{}".format(counter, att.uid, att.user_id, att.timestamp, att.status))
|
print ("ATT {:>6}: uid:{:>3}, user_id:{:>8} t: {}, s:{} p:{}".format(counter, att.uid, att.user_id, att.timestamp, att.status, att.punch))
|
||||||
if counter >= 10:
|
if counter >= 10:
|
||||||
conn.end_live_capture = True
|
conn.end_live_capture = True
|
||||||
print('')
|
print('')
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
class Attendance(object):
|
class Attendance(object):
|
||||||
def __init__(self, uid, user_id, timestamp, status):
|
def __init__(self, uid, user_id, timestamp, status, punch=0):
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.status = status
|
self.status = status
|
||||||
|
self.punch = punch
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '<Attendance>: {} : {}'.format(self.user_id, self.timestamp)
|
return '<Attendance>: {} : {}'.format(self.user_id, self.timestamp)
|
||||||
|
22
zk/base.py
22
zk/base.py
@ -1292,8 +1292,8 @@ class ZK(object):
|
|||||||
"""if len (data) == 5:
|
"""if len (data) == 5:
|
||||||
|
|
||||||
continue"""
|
continue"""
|
||||||
if len(data) == 12: #class 1 attendance
|
if len(data) == 12: #class 1 attendance #TODO: RETEST ZK6
|
||||||
user_id, status, match, timehex = unpack('<IBB6s', data)
|
user_id, status, punch, timehex = unpack('<IBB6s', data)
|
||||||
user_id = str(user_id)
|
user_id = str(user_id)
|
||||||
timestamp = self.__decode_timehex(timehex)
|
timestamp = self.__decode_timehex(timehex)
|
||||||
tuser = list(filter(lambda x: x.user_id == user_id, users))
|
tuser = list(filter(lambda x: x.user_id == user_id, users))
|
||||||
@ -1303,7 +1303,7 @@ class ZK(object):
|
|||||||
uid = tuser[0].uid
|
uid = tuser[0].uid
|
||||||
yield Attendance(uid, user_id, timestamp, status)
|
yield Attendance(uid, user_id, timestamp, status)
|
||||||
elif len(data) == 36: #class 2 attendance
|
elif len(data) == 36: #class 2 attendance
|
||||||
user_id, status, match, timehex, res = unpack('<24sBB6sI', data)
|
user_id, status, punch, timehex, res = unpack('<24sBB6sI', data)
|
||||||
user_id = (user_id.split(b'\x00')[0]).decode(errors='ignore')
|
user_id = (user_id.split(b'\x00')[0]).decode(errors='ignore')
|
||||||
timestamp = self.__decode_timehex(timehex)
|
timestamp = self.__decode_timehex(timehex)
|
||||||
tuser = list(filter(lambda x: x.user_id == user_id, users))
|
tuser = list(filter(lambda x: x.user_id == user_id, users))
|
||||||
@ -1311,7 +1311,7 @@ class ZK(object):
|
|||||||
uid = int(user_id)
|
uid = int(user_id)
|
||||||
else:
|
else:
|
||||||
uid = tuser[0].uid
|
uid = tuser[0].uid
|
||||||
yield Attendance(uid, user_id, timestamp, status)
|
yield Attendance(uid, user_id, timestamp, status, punch)
|
||||||
else:
|
else:
|
||||||
if self.verbose: print (codecs.encode(data, 'hex')), len(data)
|
if self.verbose: print (codecs.encode(data, 'hex')), len(data)
|
||||||
yield codecs.encode(data, 'hex')
|
yield codecs.encode(data, 'hex')
|
||||||
@ -1546,8 +1546,8 @@ class ZK(object):
|
|||||||
if self.verbose: print ("record_size is ", record_size)
|
if self.verbose: print ("record_size is ", record_size)
|
||||||
attendance_data = attendance_data[4:] #total size not used
|
attendance_data = attendance_data[4:] #total size not used
|
||||||
if record_size == 8 : #ultra old format
|
if record_size == 8 : #ultra old format
|
||||||
while len(attendance_data) >= 8:
|
while len(attendance_data) >= 8:#TODO RETEST ZK6!!!
|
||||||
uid, status, timestamp = unpack('HH4s', attendance_data.ljust(8, b'\x00')[:8])
|
uid, status, timestamp, punch = unpack('HB4sB', attendance_data.ljust(8, b'\x00')[:8])
|
||||||
if self.verbose: print (codecs.encode(attendance_data[:8], 'hex'))
|
if self.verbose: print (codecs.encode(attendance_data[:8], 'hex'))
|
||||||
attendance_data = attendance_data[8:]
|
attendance_data = attendance_data[8:]
|
||||||
tuser = list(filter(lambda x: x.uid == uid, users))
|
tuser = list(filter(lambda x: x.uid == uid, users))
|
||||||
@ -1559,8 +1559,8 @@ class ZK(object):
|
|||||||
attendance = Attendance(uid, user_id, timestamp, status)
|
attendance = Attendance(uid, user_id, timestamp, status)
|
||||||
attendances.append(attendance)
|
attendances.append(attendance)
|
||||||
elif record_size == 16: # extended
|
elif record_size == 16: # extended
|
||||||
while len(attendance_data) >= 16:
|
while len(attendance_data) >= 16: #TODO RETEST ZK6
|
||||||
user_id, timestamp, status, verified, reserved, workcode = unpack('<I4sBB2sI', attendance_data.ljust(16, b'\x00')[:16])
|
user_id, timestamp, status, punch, reserved, workcode = unpack('<I4sBB2sI', attendance_data.ljust(16, b'\x00')[:16])
|
||||||
user_id = str(user_id)
|
user_id = str(user_id)
|
||||||
if self.verbose: print(codecs.encode(attendance_data[:16], 'hex'))
|
if self.verbose: print(codecs.encode(attendance_data[:16], 'hex'))
|
||||||
attendance_data = attendance_data[16:]
|
attendance_data = attendance_data[16:]
|
||||||
@ -1577,17 +1577,17 @@ class ZK(object):
|
|||||||
else:
|
else:
|
||||||
uid = tuser[0].uid
|
uid = tuser[0].uid
|
||||||
timestamp = self.__decode_time(timestamp)
|
timestamp = self.__decode_time(timestamp)
|
||||||
attendance = Attendance(uid, user_id, timestamp, status)
|
attendance = Attendance(uid, user_id, timestamp, status, punch)
|
||||||
attendances.append(attendance)
|
attendances.append(attendance)
|
||||||
else:
|
else:
|
||||||
while len(attendance_data) >= 40:
|
while len(attendance_data) >= 40:
|
||||||
uid, user_id, sparator, timestamp, status, space = unpack('<H24sc4sB8s', attendance_data.ljust(40, b'\x00')[:40])
|
uid, user_id, status, timestamp, punch, space = unpack('<H24sB4sB8s', attendance_data.ljust(40, b'\x00')[:40])
|
||||||
if self.verbose: print (codecs.encode(attendance_data[:40], 'hex'))
|
if self.verbose: print (codecs.encode(attendance_data[:40], 'hex'))
|
||||||
user_id = (user_id.split(b'\x00')[0]).decode(errors='ignore')
|
user_id = (user_id.split(b'\x00')[0]).decode(errors='ignore')
|
||||||
timestamp = self.__decode_time(timestamp)
|
timestamp = self.__decode_time(timestamp)
|
||||||
#status = int(status.encode("hex"), 16)
|
#status = int(status.encode("hex"), 16)
|
||||||
|
|
||||||
attendance = Attendance(uid, user_id, timestamp, status)
|
attendance = Attendance(uid, user_id, timestamp, status, punch)
|
||||||
attendances.append(attendance)
|
attendances.append(attendance)
|
||||||
attendance_data = attendance_data[40:]
|
attendance_data = attendance_data[40:]
|
||||||
return attendances
|
return attendances
|
||||||
|
Loading…
Reference in New Issue
Block a user