# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda root]
#     language: python
#     name: conda-root-py
# ---

# +
import time
import datetime
import pandas
import json
import keyboard
import random
from subprocess import Popen
# %cd G:/JupyterNotebooks/School Projects
    
def collect_info():
    categories = ["Name","Age","Gamer Status","Gamer Categories"]
    responses = []
    responses.append(input("Please enter your name: "))
    responses.append(input("Please enter your age in years: "))
    gamer_question = input("Are you a Gamer? Y or N: ")
    responses.append(gamer_question)
    
    if gamer_question == "Y":
        gamer_categories = {1:"Action",2:"RPG",3:"Mobile Games"}
        print("What type of games do you play? \n 1. Action (eg: God of War, Call of Duty, Fortnite) \n 2. RPG \n 3. Mobile Games")
        gamer_type = input("Please enter the relevant number: ")
        responses.append(gamer_categories[int(gamer_type)])
    else:
        responses.append["None"]
    
    #packaging user info into a dictionary
    data = dict(zip(categories,responses))
    
    
    # return dictionary
    return(data)

def record_times(round_limit=10):
    print("Thanks! Now we're going to test your reaction times!")
    i = 0
    round_limit = round_limit
    your_list = []
    while i < round_limit:
        print(str(round_limit-i),"rounds to go.")
        print("Get ready to hit the space bar!")
        time.sleep(random.uniform(2.0,6.0))
        print("Now!")
        ph = Popen('{path} "./Just Do It_1.mp4" -autoexit -fs'.format(path=path))

        #start timer
        time_start = time.time() 

        #print("starting timer: ",time_start)
        #set up trigger
        while True:
            if keyboard.is_pressed("space"):
                print("You stopped the timer")
                break

        # stop timer 
        time_end = time.time() 
        #print("Timer stopped at ",time_end)

        #calculate duration
        duration = round(time_end - time_start,3)
        #print("Duration: ",duration)
        print("Your time:",str(duration))
        your_list.append(duration)

        ph.wait()
        # increase i
        i += 1
    return(your_list)

def write_to_file(data):
    for each_time in range(len(data["Times"])):
        with open('names.csv','a',newline='') as csvfile:
            fieldnames = ["Name","Age","Gamer Status","Gamer Categories","Times"]
            writer = csv.DictWriter(csvfile,fieldnames=fieldnames)
                #writer.writeheader()
            writer.writerow({"Name":data["Name"],"Age":data["Age"],"Gamer Status":data["Gamer Status"],"Gamer Categories":data["Gamer Categories"],"Times":data["Times"][each_time]})
    


def record_data():
    data = collect_info()
    data["Times"] = record_times()
    write_to_file(data)
    
    
# -

record_data()

StarcoderdataJupyterScriptsDedupFiltered