Stages of code

During the coding process, I made several “test benches” to test out and fix separate parts of my code. Each one shows a different level of when I used my code and what I built on.

BENCH FOR TESTING TIME DELAY CODE

import time

time1=time.time()
time2=time.time()

while True:
    time.sleep(2)
    time2=time.time()
    print(time2-time1)
    time1=time2

This code was tested to help make it so when a student passed the sensor, his/her time would show less chaotically and to help keep the sensor from tracking them multiple times.

CODE FOR FIGURING OUT HOW TO DEFINE EACH STUDENT ID

This code was used to help me figure out how to define each student as an individual and I was stuck on this for a long time before Mr. Lin helped me.

import time

cardId1 = "300833B2DDD9014000000014"
scanner = raw_input()
if scanner == cardId1:
print "good"
elif scanner != cardId1:
print "no"

cardId2 = "300833B2DDD9014000000013"
scanner = raw_input()
if scanner == cardId2:
print "good"
elif scanner != cardId2:
print "no"

scanner = ["cardId1","cardId2"]
print scanner

#studentname2 = "Hamlet"
#print (studentname == studentname2)



#
# CARDS = ['300833B2DDD9014000000014']
# len(['300833B2DDD9014000000014'])
#
# if CARDS == True:
#     print (time.strftime("%I:%M:%S, Philip"))
# else:
#     print "Wrong card"

MY FIRST FINISHED PROTOTYPE CODE 

This was an alternate version of my first final code as I lost the original. In this alternate one, I have changed the ID numbers with names and removed the code required for the sensor to detect the ID cards. The reason for this is because I did have a sensor and I could use this code without needing one. What this code does, compared to my current final one is that instead of tracking the time between laps (I didn’t know how to do this before) it just listed the exact time (hour, minute, second) when the card passed the sensor (or in this alternate, written down). This code was in my opinion, more user-friendly except it required using math to determine the time it took between laps. This is the code I built up from.

 

import time
from datetime import datetime


time = datetime.now()

lap1 = 0
lap2 = 0
lap3 = 0

cardId1 = "Philip"
cardId2 = "Jack"
cardId3 = "Charlie"
while True:
    scanner = raw_input()
    if scanner == cardId1:
        lap1 += 1
print str(lap1) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId2:
        lap2 += 1
print str(lap2) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId3:
       lap3 += 1
print str(lap3) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"

FINAL CODE

This is my final code and you can find parts of what I used in each stage inside it. The code here can track an individual’s laps and his time between laps. NOTIFY: Not all of my stages are in here, unfortunately, as I lost them over time.

import time
from datetime import datetime
import serial

ser = serial.Serial('/dev/tty.SLAB_USBtoUART',baudrate=115200) #defaults to 8N1

#ser.open()
#ser.isOpen()

# For each student added, simply repeat the code below.
# Each student requires two numbers. EX. Fourth student would be "time7 = time.time() and time8 = time.time()"
time1 = time.time()
time2 = time.time()

time3 = time.time()
time4 = time.time()

time5 = time.time()
time6 = time.time()

# Same as above, add a new lap with a new number for a new student
lap1 = 0
lap2 = 0
lap3 = 0

# Same as above, put in a variable(ex. cardId4) and make it equal to the cards ID

# After, adding the new lines for a new student above. Copy the paragraph starting with "if scanner == cardId2"

# Paste this underneath the last student "if scanner == cardId3"

# Change variables like "lap2 to lap4" and vice versa for "time" and change the "print 'Marley' to the student name

cardId1 = "1b390100110010603000300833b2ddd901400000000900b5"
cardId2 = "1b390100110010603000300833b2ddd901400000001400a8"
cardId3 = "1b390100110010603000300833b2ddd901400000000700bb"
while True:
    #time = datetime.now()
buffer = ser.read(ser.inWaiting())
    if (len(buffer)>0):
        scanner = buffer.encode('hex')
        if scanner == cardId1:
            lap1 += 1
print "Philip"
print str(lap1) + " Laps"
time.sleep(1)
            time2 = time.time()
            print (time2 - time1)
            time1=time2
            print "Lap Time"
#print str(time.hour) + " Hours"
            #print str(time.minute) + " Minutes"
            #print str(time.second) + " Seconds"

if scanner == cardId2:
            lap2 += 1
print "Marley"
print str(lap2) + " Laps"
time.sleep(1)
            time4 = time.time()
            print (time4 - time3)
            time3=time4
            print "Lap Time"
#print str(time.hour) + " Hours"
            #print str(time.minute) + " Minutes"
            #print str(time.second) + " Seconds"

if scanner == cardId3:
           lap3 += 1
print "Bob"
print str(lap3) + " Laps"
time.sleep(1)
           time6 = time.time()
           print (time6 - time5)
           time5=time6
           print "Lap Time"
#print str(time.hour) + " Hours"
           #print str(time.minute) + " Minutes"
           #print str(time.second) + " Seconds"

Leave a Reply