-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkin.py
executable file
·219 lines (174 loc) · 8.64 KB
/
checkin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from datetime import *
# The Spark Challenge Fall 2021
# Student Check-In Validation and Tracking
# Date Modified : 12/06/2021
# Import ECE Student PUID from verification file
# Import Matching Data From Records
# Track the number of visits
# Logs the transcript of visits
# Time Check
# now = datetime.now()
# current_time = now.strftime(TIME_FORMAT)
# Visit Limit
COUNT_LIMIT = 1
# Import verification
STUDENT_ID_FILE = 'verification.txt'
# Visit Logs
VISITATION_LOG_FILE = 'checkout_logs.txt'
# datetime standard format
TIME_FORMAT = '%H:%M:%S'
# Data Structures
class student:
def __init__(self, puid):
self.puid = puid
self.count = 1
#Import Student ID's from verification file
def initialize():
print('Reading the Database...')
# Load ECE student IDs from file
with open(STUDENT_ID_FILE, 'r') as myFile:
for line in myFile.readlines():
ECEStudents.append(line.strip())
print('Validating visit history...')
# Load visit transcript file - populate student dictionary
with open(VISITATION_LOG_FILE, 'r') as myFile:
for line in myFile.readlines():
line = line.split('-')
# Input verification check
if(len(line) != 3):
print('ERROR READING IN STUDENT HISTORY DATABASE')
return
#Extract information from line
[PUID, count, time] = line
if PUID in studentDB.keys():
# Student previously added - UPDATE COUNT
if int(count) > studentDB[PUID].count:
studentDB[PUID].count = int(count)
else:
# New Student, add to dictionary
newstudent = student(PUID.strip())
studentDB[PUID.strip()] = newstudent
studentDB[PUID].count = int(count)
#populates the student list with checkin_puid.txt
with open("checkin_logs.txt", 'r') as myFile:
for line in myFile.readlines():
line = line.split('-')
# Input verification check
if(len(line) != 3):
print('ERROR READING IN STUDENT HISTORY DATABASE')
return
#Extract information from line
[PUID, count, time] = line
if PUID in studentDB.keys():
# Student previously added - UPDATE COUNT
if int(count) > studentDB[PUID].count:
studentDB[PUID].count = int(count)
else:
# New Student, add to dictionary
newstudent = student(PUID.strip())
studentDB[PUID.strip()] = newstudent
studentDB[PUID].count = int(count)
print(studentDB.keys);
def verfifyStudent():
PUID = ''
count = 0
# Get PUID Number from scanner
while PUID == '':
PUID = input('Swipe PUID...')
PUID = PUID.strip()
PUID = PUID.split('=')
try:
PUID = PUID[2]
except IndexError:
print('ERROR READING CARD')
PUID = '' # Your while loop is running when PUID is empty --> Need to reset to prevent continuing to next part even though the swipe failed because it still produces something
PUID = PUID[1:] #commented out so I don't have to go brain damage mode to input my stuff and test
#uncomment the following ^ line based on verification file: PUID = PUID[1:] if verification file is in the format:
# 12312312 as opposed to 0012312312
if PUID == 'exit':
print('Exit Success')
exit(0)
print(studentDB.keys())
# Check if student has visited before
if PUID in studentDB.keys():
# Verify visit is valid
if studentDB[PUID].count >= 2:
print('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!!!Already Checked-Out!!!\n')
print(f'Swipe Count More Than {studentDB[PUID].count}\n')
else:
#Add Vivek's code here after checking with altay
#if time <30 mins, send a print statement that asks if they are sure they want to check out
#If response == no|NO|No|nO or whatever, break, do not execute the rest of the loop
#Else respnse == YESSIR IDGAF ABOUT MY GRADE, excecute the below statement
#checkout() should be its own helper function rather than a subfunction of checkin.py
#Is this the checkout?
##Gets the amount of time the student has been there
with open('checkin_logs.txt', 'r') as logs:
for line in logs.readlines():
# Finding check in time based on PUID
if (line.split('-')[0] == PUID):
checkinTime = line.split('-')[2][:-1]
checkoutTime = datetime.now().strftime(TIME_FORMAT)
checkoutTime = datetime.strptime(checkoutTime, TIME_FORMAT)
checkinTime = datetime.strptime(checkinTime, TIME_FORMAT)
diff = checkoutTime - checkinTime
if diff.total_seconds() > 1800: #If the student has been there for more than 30(1800s) minutes, they can checkout
studentDB[PUID].count += 1
count = studentDB[PUID].count
print('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCheck-Out Successful!')
print(f'Swipe Count: {studentDB[PUID].count}')
checkoutTime = datetime.now().strftime(TIME_FORMAT)
print(f'\nCheckout Time: {checkoutTime}')
# Converts to datetime object
checkoutTime = datetime.strptime(checkoutTime, TIME_FORMAT)
# Add visit information to transcript log
with open('checkout_logs.txt', 'a') as myFile:
myFile.writelines(f'{PUID}-{count}-{datetime.now().strftime(TIME_FORMAT)}\n')
with open('checkout_puid.txt', 'a') as myFile:
myFile.writelines(f'{PUID}\n')
with open('checkout_time.txt', 'a') as myFile:
myFile.writelines(f'{checkoutTime}\n')
# Opening previous logs with PUID, num checkin, and time checkin
with open('checkin_logs.txt', 'r') as logs:
for line in logs.readlines():
# Finding check in time based on PUID
if (line.split('-')[0] == PUID):
checkinTime = line.split('-')[2][:-1] # The [:-2] ignores the last two characters "\n"
print(f'Checkin Time: {checkinTime}')
# Converts to datetime object
checkinTime = datetime.strptime(checkinTime, TIME_FORMAT)
# Calculates difference between checkout time and check in time
diff = checkoutTime - checkinTime
print(f'Time Stayed: {diff}')
# Write the time difference to file
with open('checkout_difference.txt', 'a') as myFile:
myFile.writelines(f'{PUID}-{str(diff)}\n')
else: #Print saying what conditions are not met
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n30 minutes have not elapsed yet.\nTime left till 30 minutes have elapsed:", (int)(30 - diff.total_seconds()/60))
# New Student visitor, verify ECE student and add to transcript
else:
if PUID in ECEStudents:
checkinTime = datetime.now().strftime(TIME_FORMAT)
studentDB[PUID] = student(PUID)
print('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCheck-In Successful!')
print(f'Check-In Time : {checkinTime}')
print(f'Swipe Count : {studentDB[PUID].count}\n')
with open('checkin_logs.txt', 'a') as myFile:
myFile.writelines(f'{PUID}-1-{checkinTime}\n')
with open('checkin_puid.txt', 'a') as myFile:
myFile.writelines(f'{PUID}\n')
with open('checkin_time.txt', 'a') as myFile:
myFile.writelines(f'{checkinTime}\n')
else:
print('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!!!NOT AN ECE STUDENT!!!')
if __name__ == "__main__":
# Establish Data Structures
studentDB = {}
ECEStudents = []
# Initialize
print('Spark Check-In Script Initalizing')
initialize()
print('System initialized successfully. Type exit to halt program safely.\n\n')
# Begin program
while(True):
response = verfifyStudent()