<commit_before>import requests, math, heapq, time
from pprint import pprint

stepLength = 50 #cm

#-----------------------------------------------------------------------------
# initialise building name and level
# get JSON response from the url and parse to data
#-----------------------------------------------------------------------------
def initialise():
    #http://showmyway.comp.nus.edu.sg/getMapInfoGraphView.php?Building=AAA&Level=BBB
    url = "http://ShowMyWay.comp.nus.edu.sg/getMapInfo.php"
    
    buildingName = "oksure"
    level = 1337
    mapID = [buildingName, level]
    params = dict(Building = buildingName, Level = level)
    response = requests.get(url=url, params = params)
    data = response.json()
    
    
    FloorPlanDatabase = FloorPlanList()  #initialise database
    myFloorPlan = FloorPlan(mapID, data)    
    FloorPlanDatabase.addFloorPlan(myFloorPlan) #add floor plan to database
    
    return data


#-----------------------------------------------------------------------------
# startup function will play audio data when the system first starts up
#-----------------------------------------------------------------------------
def startUp():
    # to audio: 1. Welcome Message. Press star hash at anytime to repeat last message
    # to audio: 2. Please select the current map. (optional)
    # to audio: 3. Press 1 to begin navigation. Press 2 to select another map
    # to audio: 4. Please enter your current node ID
    # to audio: 5. Please enter your destination node ID
    return


#-----------------------------------------------------------------------------
# main
#-----------------------------------------------------------------------------
def main():
    data = initialise()
    pprint(data)

    nodeList = NodeList(data["map"], data["info"])
    aList = AdjList(nodeList)        #constructs adjlist from node list

    currentInstruction = int(input("Press 1 to begin navigating, 2 to select function"))
    
    if (currentInstruction == 1):
        startNode = nodeList.getNodeById(int(input("Input start node id")))
        destinationNode = nodeList.getNodeById(int(input("Input destination node id")))
        
        cost, path = shortestPath(aList.getGraph(), startNode.id, destinationNode.id)
        
        currentX = startNode.x
        currentY = startNode.y
        i = 1

        while (isReached(currentX, currentY, destinationNode.x, destinationNode.y) == False):
            
            #update currentHeading
            
            targetNode = nodeList.getNodeById(path[i])
            
            while (isReached(currentX, currentY, targetNode.x, targetNode.y) == False):
                #update currentHeading
                time.sleep(1) #assume 1 step 1 second
                currentHeading = 0#get from arduino
               
                direction, degree  = computeDirection(currentHeading, currentX, currentY, targetNode.x, targetNode.y, nodeList.north)
                
                currentX, currentY = updateCurrentLocation(currentX, currentY, currentHeading, 1)
            
            i = i + 1 
    else:
        print ("test") 


#-----------------------------------------------------------------------------
# check whether the destination is reached.
# return True if current location is within 0.5 meter radius of destination
#-----------------------------------------------------------------------------
def isReached(currentX, currentY, nextX, nextY):
    yDistance = math.fabs((nextY * 1.0 - currentY * 1.0) * 1.0)
    xDistance = math.fabs((nextX * 1.0 - currentX * 1.0) * 1.0)
    
    d = math.sqrt(yDistance ** 2 + xDistance ** 2)
    
    if (d < 50.0):
        return True
    else:
        return False
     
     
#-----------------------------------------------------------------------------<commit_msg>Updated code to work towards integration<commit_after>import requests, math, heapq, time, json
from pprint import pprint

stepLength = 50 #cm
#rPi GPIO interrupt will activate UART read on rPi's side
#flag to tell UART handler whether we are taking in currentXYheading during
#navigation or we are taking in keyad values when outside navigation
navigation = 0
#-----------------------------------------------------------------------------
#These values will be updated real-time by the arduino through UART when 
#navigation begins
currentX = 0
currentY = 0
currentHeading = 0
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
#Sample command to play Intro.txt audio
#espeak -v+f3 -s100 -f /home/pi/Vision/Intro.txt --stdout | aplay
#all audio will be put in .txt files to resolve a lag issue with audio playback
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# initialise building name and level
# get JSON response from the url and parse to data
#-----------------------------------------------------------------------------
def initialise():
    #http://showmyway.comp.nus.edu.sg/getMapInfoGraphView.php?Building=AAA&Level=BBB
    url = "http://ShowMyWay.comp.nus.edu.sg/getMapInfo.php"
    
    control = int(input("Press 1 to input new map, Press 2 to load Com1 Level 2\n"))

    if control == 1:
        buildingName = str(raw_input("Enter building name\n"))
        level = int(raw_input("Enter level\n"))
        #buildingName = "oksure"
        #level = 1337

        mapID = [buildingName, level]
        params = dict(Building = buildingName, Level = level)
        response = requests.get(url=url, params = params)
        data = response.json()

    elif control == 2:
        json_data=open('data.txt')
        data = json.load(json_data)
        json_data.close()
    
    #FloorPlanDatabase = FloorPlanList()  #initialise database
    #myFloorPlan = FloorPlan(mapID, data)    
    #FloorPlanDatabase.addFloorPlan(myFloorPlan) #add floor plan to database
    
    return data


#-----------------------------------------------------------------------------
# startup function will play audio data when the system first starts up
#-----------------------------------------------------------------------------
def startUp():
    # to audio: 1. Welcome Message. Press star hash at anytime to repeat last message
    # to audio: 2. Please select the current map. (optional)
    # to audio: 3. Press 1 to begin navigation. Press 2 to select another map
    # to audio: 4. Please enter your current node ID
    # to audio: 5. Please enter your destination node ID
    return


#-----------------------------------------------------------------------------
# main
#-----------------------------------------------------------------------------
def main():
    data = initialise()
    pprint(data)
    global currentX
    global currentY
    global currentHeading

    nodeList = NodeList(data["map"], data["info"])
    aList = AdjList(nodeList)        #constructs adjlist from node list

    currentInstruction = int(input("Press 1 to begin navigating"))
    
    if (currentInstruction == 1):
        startNode = nodeList.getNodeById(int(input("Input start node id")))
        destinationNode = nodeList.getNodeById(int(input("Input destination node id")))
        
        cost, path = shortestPath(aList.getGraph(), startNode.id, destinationNode.id)
        
        currentX = startNode.x
        currentY = startNode.y
        i = 1

        while (isReached(currentX, currentY, destinationNode.x, destinationNode.y) == False):
            
            #update currentHeading
            
            targetNode = nodeList.getNodeById(path[i])
            
            while (isReached(currentX, currentY, targetNode.x, targetNode.y) == False):
                #update currentHeading
                time.sleep(1) #assume 1 step 1 second
                currentHeading = 0#get from arduino
               
                direction, degree  = computeDirection(currentHeading, currentX, currentY, targetNode.x, targetNode.y, nodeList.north)
                print (direction, degree)

                #just for testing. to be updated through uart by arduino
                currentX = int(input("Input currentX\n"))
                currentY = int(input("Input currentY\n"))
                currentHeading = int(input("Input currentHeading\n"))
                #currentX, currentY = updateCurrentLocation(currentX, currentY, currentHeading, 1)
            

            if targetNode != destinationNode : #prevent overflow
                i = i + 1 
    else:
        print ("test") 


#-----------------------------------------------------------------------------
# check whether the destination is reached.
# return True if current location is within 0.5 meter radius of destination
#-----------------------------------------------------------------------------
def isReached(currentX, currentY, nextX, nextY):
    yDistance = math.fabs((nextY * 1.0 - currentY * 1.0) * 1.0)
    xDistance = math.fabs((nextX * 1.0 - currentX * 1.0) * 1.0)
    
    d = math.sqrt(yDistance ** 2 + xDistance ** 2)
    
    if (d < 50.0):
        return True
    else:
        return False
     
     
#-----------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.25782590051457976, 'fraction_numerical': 0.010398799313893654, 'mean_word_length': 1.4087270849470694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7113503', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2217, 'n_words': 712}