I have data regarding to employees punch time clock.
Employee can report his starting time by an automated process (by his key card or by finger print), or manually through a simple web form.
The problem is that there are employees who accidentally reported time on more than one method
The input stream data comes in two dictionaries with value as list as the following:
I'm trying to iterate on both dictionaries and count (not sum) if employee made login on the specific date.
def count_type(logins, punch_clock_data):
counter = 0
ans_dict = {}
for punch_clock_key, punch_clock_value in punch_clock_data.items():
for element in punch_clock_value:
if element not in ans_dict:
l1 = logins.get(element)
for i in range(len(l1)):
if i == 1:
counter+=1
break
ans_dict[punch_clock_key] = counter
print(f'this employee was at work {counter} days this week by {punch_clock_key} login')
return ans_dict
# each item in the array is a representation of weekday. for example,
# on Sunday there was not any log in data.
# on Tuesday, this employee reported login both on web form and by
# card(flag = 1) etc.
logins = { 'card' :[0, 1, 1, 0, 0, 0, 0],
'fingerprint' :[0, 0, 0, 1, 1, 0, 0],
'web form' :[0, 0, 1, 1, 0, 1, 1]
}
# dictionary contains data on types of punch clock
punch_clock_data = { 'automated' :['card', 'fingerprint'],
'manual' :['web form'],
'all_types' :['card', 'fingerprint', 'web form']
}
res = count_type(logins, punch_clock_data)
print(res)
My output is not as expected. This is my output
{'automated': 2, 'manual': 3, 'all_types': 6}
But I'm trying to get is:
{'automated': 4, 'manual': 4, 'all_types': 6}
- automated should be 4 because the are four days where flag equal to 1 (Monday, Tuesday by card and Wednesday, Thursday by fingerprint
- manual should be 4 because the are four days where flag equal to 1 (Tuesday, Wednesday, Friday, Saturday)
- all_types should be 6 because the are six days where at least one flag is equal to 1
I think that my problem is that I need to iterate on all of the weekdays list by index, and not by the value. For each day of the week, get the right index and than count it (vertically and not horizontally)