Exemple #1
0
def qseven(request):
    if request.method == "GET":
        global starttime7
        starttime7 = my_timer()
        form = Question7Form()
    elif request.method == "POST":
        form = Question7Form(request.POST)
        global endtime7
        endtime7 = my_timer()
        timespentstr7 = '{0} seconds'.format(endtime7 - starttime7)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q7_response = (form.cleaned_data['question7'])
            a = Responses7(question7=q7_response,
                           timespent7=timespentstr7,
                           username=request.user.get_username())
            a.save()
            return redirect(
                'question1/question2/question3/question4/question5/question6/question7/question8'
            )

    else:
        form = Question7Form()

    return render(request, 'question7.html', {'form': form})
Exemple #2
0
def qeight(request):
    if request.method == "GET":
        global starttime8
        starttime8 = my_timer()
        form = Question8Form()
    elif request.method == "POST":
        form = Question8Form(request.POST)
        global endtime8
        endtime8 = my_timer()
        timespentstr8 = '{0} seconds'.format(endtime8 - starttime8)
        form.save(commit=False)
        if form.is_valid():
            q8_response = (form.cleaned_data['question8'])
            a = Responses8(question8=q8_response,
                           timespent8=timespentstr8,
                           username=request.user.get_username())
            a.save()
            return redirect(
                'question1/question2/question3/question4/question5/question6/question7/question9'
            )

    else:
        form = Question8Form()

    return render(request, 'question8.html', {'form': form})
Exemple #3
0
def qfive(request):
    if request.method == "GET":
        global starttime5
        starttime5 = my_timer()
        form = Question5Form()
    elif request.method == "POST":
        form = Question5Form(request.POST)
        global endtime5
        endtime5 = my_timer()
        timespentstr5 = '{0} seconds'.format(endtime5 - starttime5)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q5_response = (form.cleaned_data['question5'])
            a = Responses5(question5=q5_response,
                           timespent5=timespentstr5,
                           username=request.user.get_username())
            a.save()
            # form.fields['timespent5'].initial = timespentstr
            # print("hi")
            # print(timespentstr)
            # form = form.save(commit=True)
            return redirect(
                'question1/question2/question3/question4/question5/question6/')
    else:
        form = Question5Form()

    return render(request, 'question5.html', {'form': form})
Exemple #4
0
def qone(request):
    if request.method == "GET":
        global starttime1
        starttime1 = my_timer()
        form = Question1Form()
    elif request.method == "POST":
        form = Question1Form(request.POST)
        global endtime1
        endtime1 = my_timer()
        timespentstr1 = '{0} seconds'.format(endtime1 - starttime1)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q1_response = (form.cleaned_data['question1'])
            a = Responses1(question1=q1_response,
                           timespent1=timespentstr1,
                           username=request.user.get_username())
            a.save()
            # form.fields['timespent1'].initial = timespentstr
            # print("hi")
            # print(timespentstr)
            # form = form.save(commit=True)
            return redirect('question1/question2/')
    else:
        form = Question1Form()

    return render(request, 'question1.html', {'form': form})
Exemple #5
0
def qsix(request):
    if request.method == "GET":
        global starttime6
        starttime6 = my_timer()
        form = Question6Form()
    elif request.method == "POST":
        form = Question6Form(request.POST)
        global endtime6
        endtime6 = my_timer()
        timespentstr6 = '{0} seconds'.format(endtime6 - starttime6)
        form.save(commit=False)
        if form.is_valid():
            q6_response = form.cleaned_data['question6']
            a = Responses6(question6=q6_response,
                           timespent6=timespentstr6,
                           username=request.user.get_username())
            a.save()
            return redirect(
                'question1/question2/question3/question4/question5/question6/question7/'
            )

    else:
        form = Question6Form()

    return render(request, 'question6.html', {'form': form})
Exemple #6
0
def qfour(request):
    if request.method == "GET":
        global starttime4
        starttime4 = my_timer()
        form = Question4Form()
    elif request.method == "POST":
        form = Question4Form(request.POST)
        global endtime4
        endtime4 = my_timer()
        timespentstr4 = '{0} seconds'.format(endtime4 - starttime4)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q4_response = (form.cleaned_data['question4'])
            a = Responses4(question4=q4_response,
                           timespent4=timespentstr4,
                           username=request.user.get_username())
            a.save()
            # form.fields['timespent4'].initial = timespentstr
            # print("hi")
            # print(timespentstr)
            # form = form.save(commit=True)
            return redirect(
                'question1/question2/question3/question4/question5/')

    else:
        form = Question4Form()

    return render(request, 'question4.html', {'form': form})
Exemple #7
0
def qthree(request):
    if request.method == "GET":
        global starttime3
        starttime3 = my_timer()
        form = Question3Form()
    elif request.method == "POST":
        form = Question3Form(request.POST)
        global endtime3
        endtime3 = my_timer()
        timespentstr3 = '{0} seconds'.format(endtime3 - starttime3)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q3_response = (form.cleaned_data['question3'])
            a = Responses3(question3=q3_response,
                           timespent3=timespentstr3,
                           username=request.user.get_username())
            a.save()
            # form.fields['timespent3'].initial = timespentstr
            # print("hi")
            # print(timespentstr)
            # form = form.save(commit=True)
            return redirect('question1/question2/question3/question4/')

    else:
        form = Question3Form()

    return render(request, 'question3.html', {'form': form})
Exemple #8
0
def qtwo(request):
    if request.method == "GET":
        global starttime2
        starttime2 = my_timer()
        form = Question2Form()
    elif request.method == "POST":
        form = Question2Form(request.POST)
        global endtime2
        endtime2 = my_timer()
        timespentstr2 = '{0} seconds'.format(endtime2 - starttime2)
        form.save(commit=False)
        # form.cleaned_data['timespent1'] = 0
        if form.is_valid():
            q2_response = (form.cleaned_data['question2'])
            a = Responses2(question2=q2_response,
                           timespent2=timespentstr2,
                           username=request.user.get_username())
            a.save()
            # form.fields['timespent2'].initial = timespentstr
            # print("hi")
            # print(timespentstr)
            # form = form.save(commit=True)
            return redirect('question1/question2/question3/')

    else:
        form = Question2Form()

    return render(request, 'question2.html', {'form': form})
Exemple #9
0
def qnine(request):
    if request.method == "GET":
        global starttime9
        starttime9 = my_timer()
        form = Question9Form()
    elif request.method == "POST":
        form = Question9Form(request.POST)
        global endtime9
        endtime9 = my_timer()
        timespentstr9 = '{0} seconds'.format(endtime9 - starttime9)
        form.save(commit=False)
        if form.is_valid():
            q9_response = (form.cleaned_data['question9'])
            a = Responses9(question9=q9_response,
                           timespent9=timespentstr9,
                           username=request.user.get_username())
            a.save()

            return render(request, "recorded.html")

    else:
        form = Question9Form()

    return render(request, 'question9.html', {'form': form})
Exemple #10
0
# print(time.gmtime(0))
#
# # print(time.localtime())
# #
# # print(time.time())
#
# time_here = time.localtime()
# print(time_here)
# print("Year:", time_here[0], time_here.tm_year)
# print("Month:", time_here[1], time_here.tm_mon)
# print("Day:", time_here[2], time_here.tm_mday)

import time
from time import time as my_timer
import random

input("Please enter to start")

wait_time = random.randint(1, 6)
time.sleep(wait_time)
star_time = my_timer()

input("Please enter to stop")

end_time = my_timer()

print("started at: " + time.strftime("%X", time.localtime(star_time)))
print("stopped at: " + time.strftime("%X", time.localtime(end_time)))

print("Your reaction time was {} seconds".format(end_time - star_time))
Exemple #11
0
# currenttime : time.struct_time(tm_year=2019, tm_mon=11, tm_mday=17, tm_hour=11, tm_min=51, tm_sec=33, tm_wday=6, tm_yday=321, tm_isdst=0)
print(time.localtime())
print()
print(time.time())  # no of time the epoc has started : 1573971777.0138555

time_here = time.localtime()
print(time_here)
print("year : ", time_here[0], time_here.tm_year)
print("month : ", time_here[1], time_here.tm_mon)
print("day : ", time_here[2], time_here.tm_mday)

#####################################################################################################################
# Time difference between two enters
print("*" * 50)

input("press enter")
wait_tm = random.randint(1, 6)
time.sleep(wait_tm)
start_tm = my_timer()
input("Press enter again")
end_tm = my_timer()

# strftime converts a string to date
print("stsrted at : " + time.strftime("%X", time.localtime(start_tm)))
print("ended at : " + time.strftime("%X", time.localtime(end_tm)))

print("elapsed : {}".format(end_tm - start_tm))
#####################################################################################################################
s = datetime.today().second
print(s)
import time
from time import time as my_timer, perf_counter as my_perf_timer, monotonic as my_mono_timer
import random

# epoch: start time, tuple
print(time.gmtime(0))
# now: local time, tuple
print(time.localtime())
# now: epoch in ms
# OR
#  my_timer()
print(time.time())
print()

#
wait_time = random.randint(1, 6)
# wait between 1 to 6 ms
time.sleep(wait_time)
# current ms
# perf_counter most accurate
# monotonic for day light saving
start_time = my_timer()  # my_mono_timer()  # my_perf_timer()
input("Press enter to stop")
end_time = my_timer()  # my_mono_timer()  # my_perf_timer()

print("Started at "+time.strftime("%X", time.localtime(start_time)))
print("Ended at "+time.strftime("%X", time.localtime(end_time)))

print("Lapsed time was between your reaction was {}".format(end_time-start_time))
print("Reaction time : {} seconds".format(end_time - start_time))

print("=" * 10)
### Measuring the performance with performance counter and monotonic with compare to normal method
# time.time() is depending on system clock. if system clock is set in between then the actual difference will be lost
# perf_counter, monotonic calculates elapsed time rather than sync with system clock
# process_time works with the actual time that CPU uses for a process. not the time that we capture in system

from time import perf_counter as my_timer
from time import time as timer
from time import monotonic as mon_timer
from time import process_time as cpu_timer

input("Press enter to start...")
start_time = timer()
perf_start = my_timer()
mon_start = mon_timer()
cpu_start = cpu_timer()

input("Press enter again to end...")
end_time = timer()
perf_end = my_timer()
mon_end = mon_timer()
cpu_end = cpu_timer()

print("Started at : " + time.strftime("%X", time.localtime(start_time)))
print("Finished at : " + time.strftime("%X", time.localtime(end_time)))
print("Reaction time : {} seconds".format(end_time - start_time))

print("Perf Started at : " + time.strftime("%X", time.localtime(perf_start)))
print("Perf Finished at : " + time.strftime("%X", time.localtime(perf_end)))
Exemple #14
0
import time
from time import process_time as my_timer
from time import time as actual_time
import random

input("press enter to start")

start_process_time = my_timer()
start_time = actual_time()
input("press enter to stop")
result = 1
for i in range(1, 100000):
    if(i==50000):
        time.sleep(5)
    result *= i
end_process_time = my_timer()
end_time = actual_time()

print("process started at " + time.strftime("%X",time.localtime(start_process_time)))
print("actually started at " + time.strftime("%X",time.localtime(start_time)))
print("process ended at " + time.strftime("%X",time.localtime(end_process_time)))
print("actually ended at " + time.strftime("%X",time.localtime(end_time)))

print("computer process time was {} seconds".format(end_process_time - start_process_time ))
print("actual time taken was {} seconds".format(end_time - start_time ))
print('Month:', time_here[1], time_here.tm_mon)


#print standard time!

l = t.localtime()
print(l.tm_hour, l.tm_min, l.tm_sec, sep=':')


from time import perf_counter as my_timer
import random

# def game():
#     input('Press Enter to Start')
wait_time = random.randint(1,5)
start_time = my_timer()
#print(start_time)

t.sleep(wait_time)
end_time = my_timer()
#print(end_time)

print(t.localtime(start_time))
print("Started at: " + t.strftime("%X", t.localtime(start_time)))
print(t.localtime(end_time))
print("Finished at: " + t.strftime("%X", t.localtime(end_time)))

print("The interval was {:.4f} seconds".format(end_time - start_time))

from time import perf_counter
from time import monotonic
Exemple #16
0
#
# print(time.localtime(time.time()))
#
# print(time.time())   # this is the time when epoch started i.e. 1970
#
# time_here = time.localtime()
# print(time_here)
# print("Year:", time_here[0], time_here.tm_year)
# print("Month:", time_here[1], time_here.tm_mon)
# print("Day:", time_here[2], time_here.tm_mday)

# from time import time as my_timer
from time import perf_counter as my_timer    # this doesn't give the system time. This is best
# from time import monotonic as my_timer
# from time import process_time as my_timer      # this shows the CPU processing time
import random

input("Press enter to start ")

wait_time = random.randint(1, 6)
time.sleep(wait_time)
start_time = my_timer()                   # this function returns the system time at that instant
input("Press enter to stop ")

end_time = my_timer()

print("Started at " + time.strftime("%X", time.localtime(start_time)))    # strftime returns the local time
print("Ended at " + time.strftime("%X", time.localtime(end_time)))        # %X lower and upper case makes a diff

print("Your reaction time was {} seconds".format(end_time - start_time))
Exemple #17
0
import time
from time import time as my_timer
import random

input("Press enter to start : ") # Awaits user to press start


wait_time = random.randint(1, 6)  # we setup a random number between one and six using the random module.
time.sleep(wait_time) # we use the time module to tell the program to wait for the random number in line 8
start_time = my_timer()  # start time is assigned my_timer which is the time it started
input("Press enter to stop: ") # enter to stop

end_time = my_timer()  # end time is now the time when enter was pressed again

print("Started at " + time.strftime('%X', time.localtime(start_time))) # prints time enter was first pressed
print("Ended at " + time.strftime("%X", time.localtime(end_time)))  # prints time enter was pressed again

print("Your reaction time was {} seconds ".format(end_time - start_time)) #prints out reaction time
Exemple #18
0
import time
from time import process_time as my_timer  # first time is the module, second is the fucntion
import random

input('Enter to start: ')
waitRandomTime = random.randint(
    1, 6)  # will return a random number between 1 and 6

# the program will stop its execution for a PARTICUALR period of time
# and after that time, the program will resume executing
time.sleep(waitRandomTime)

startTime = my_timer()

input("Press Enter to stop")

endTime = my_timer()

print("Started at: " + time.strftime("%X", time.localtime(startTime))
      )  # %X	Locale’s appropriate time representation.
print("Ended at: " + time.strftime("%X", time.localtime(endTime)))
print("Your reaction time was {} seconds".format(endTime - startTime))
# The result has the following attributes:

# adjustable: True if the clock can be changed automatically (e.g. by a NTP daemon)
#             or manually by the system administrator, False otherwise
# implementation: The name of the underlying C function used to get the clock value.
#                  Refer to Clock ID Constants for possible values.
# monotonic: True if the clock cannot go backward, False otherwise
# resolution: The resolution of the clock in seconds (float)

from time import time as my_timer
from time import perf_counter, monotonic, process_time
import time

print('Time Clock INFORMATION\n')

print('Time : ' + time.strftime('%X', time.localtime(my_timer())) + "\n")
description = time.get_clock_info('time')
print('Adjustable : {0}\n'
      'Implementation : {1}\n'
      'Monotonic : {2}\n'
      'Resolution : {3}\n'.format(description.adjustable,
                                  description.implementation,
                                  description.monotonic,
                                  description.resolution))

print('Perf_counter Clock INFORMATION\n')

print('Time : ' + time.strftime('%X', time.localtime(perf_counter())) + "\n")
description = time.get_clock_info('perf_counter')
print('Adjustable : {0}\n'
      'Implementation : {1}\n'
import time
from time import perf_counter as my_timer
import random

# Counts the reaction time of the user

input("Press enter to start!")

wait_time = random.randint(1, 3)
time.sleep(wait_time)
start_time = my_timer()
input("Press enter to stop!")

end_time = my_timer()

print("Started at " + time.strftime("%X", time.localtime(start_time)))
print("Ended at " + time.strftime("%X", time.localtime(end_time)))

print("Your reaction time was {} seconds!".format(end_time - start_time))
Exemple #21
0
# import time
#
# print(time.gmtime())
# print(time.localtime())
# print(time.time())

import time
from time import time as my_timer
import random

input("Please enter to start")
wait_time = random.randint(1, 4)
time.sleep(wait_time)
start_time = my_timer()

input("Please enter to stop")
stop_time = my_timer()

print("Started at {}".format(time.strftime("%X", time.localtime(start_time))))
print("Ended at {}".format(time.strftime("%X", time.localtime(start_time))))
print("Your reaction time was {} seconds".format(stop_time - start_time))