def phraseTwo(): global phraseTwoPath print "phase two begin" global returnPath, phaseTwoPath returnPath.append(startPosition) print "RETURN PATH: "+str(returnPath) setRunningPhrase(2) utility.startTimer() pathTwo = phaseTwoPath #pathTwo=[] print "===========" print pathTwo if(pathTwo==[]): print "no optimal path find so go back on the same path as phase one" pathTwo=returnPath while True: time.sleep(0.01) if(len(pathTwo)!=0): print "aaaaaaaaaaaa" moveFromCurrentPositionTo(pathTwo[0]) pathTwo.pop(0) elif(currentPosition==startPosition): sendMessages("Reached StartPosition, total running time: "+str(utility.getTime())+" seconds",3) break startingCheck()
def phraseTwo(): #global phraseTwoPath print "phase two begin" global returnPath, phaseTwoPath returnPath.append(startPosition) print "RETURN PATH: "+str(returnPath) setRunningPhrase(2) utility.startTimer() pathTwo = phaseTwoPath print "===========" print pathTwo if(pathTwo==[]): print "no optimal path find so go back on the same path as phase one" pathTwo=returnPath while True: time.sleep(0.01) if(len(pathTwo)!=0): print "aaaaaaaaaaaa" moveFromCurrentPositionTo(pathTwo[0]) pathTwo.pop(0) elif(currentPosition==startPosition): sendMessages("Reached StartPosition, total running time: "+str(utility.getTime())+" seconds",3) break
def phraseOne(): setRunningPhrase(1) threading.Thread(target=utility.startTimer).start() path = [] goBack=False getPath=True #getPath = True #turn 90 at very first while True: #to return on the same path used isPath=True time.sleep(1) if(endPosition==currentPosition): sendMessages("Reached EndPosition in "+str(utility.getTime())+" seconds",3) #print "=========================>>>>> reach endpoint" #phraseOneCheckIfAtGoal() break try: if(currentPosition==path[0]): path.pop(0) except: pass #if getPath is true, get optimal path (90degrees) if(getPath or len(path)==0): getPath = False sendMessages("currentAngle "+str(currentAngle),3) sendMessages("currentPosition "+str(currentPosition[0])+" "+str(currentPosition[1]),3) sendMessages("phraseOneFindOptimalPath",1) pathInString = comms.getMsg() pathInString = pathInString.translate(string.maketrans('', ''), '[] ') pathInString = pathInString.split(',')
def findLongestSessions(sc, rddCheckins, mininum_distance, max_count, outfile): """ task 7 """ mininum_distance -= 0.0001 # to do greater than filtering pointsOfInterest = [row[0] for row in \ rddCheckins \ .map(lambda x: (x[2], Point(x[5], x[6], 0))) \ .reduceByKey(calculateHaversinePoints) \ .filter(lambda x: x[1].distance > mininum_distance) \ .takeOrdered(max_count, lambda x: -x[1].distance)] checkins = sc.broadcast(set(pointsOfInterest)) # Map: output data as csv data = rddCheckins.filter(lambda x: x[2] in checkins.value) \ .map(lambda x: (';'.join(x[:3]) + ";" + getTime(x[3], x[4]) + ';' + ';'.join(x[5:]))) \ .coalesce(1) # should I map these to cities? assignment text doesn't mention it. # it's trivial since we have only ~2000 entries, but cartodb can read lat/longitude data.saveAsTextFile(outfile) header = "checkin_id\\;user_id\\;session_id\\;date\\;lat\\;lon\\;category\\;subcategory" system("(echo " + header + " && cat " + outfile + "/part-00000 ) >> " + outfile + "/out.csv") return data
import utility import threading import time threading.Thread(target=utility.startTimer).start() time.sleep(2) print utility.getTime() time.sleep(1) print utility.getTime() utility.startTimer() time.sleep(1) print utility.getTime() time.sleep(1) print utility.getTime()
wt = buf_wts[_i: (_i + 1)] if 'LR' in algo: feed_dict = {model.x_id: x_id, model.wt: wt} pred = model.prediction.eval(feed_dict=feed_dict)[0][0] preds.append(pred) labels.extend(buf_labels) return np.array(labels), np.array(preds) if __name__ == '__main__': src = "vlion" camp = "231" algo = "LR" tag = src + "_" + camp + "_" + algo + "_" + utility.getTime() if src == "ipinyou": data_path = config.ipinyouPath camp_info = config.get_camp_info(camp, src) elif src == 'vlion': data_path = config.vlionPath camp_info = config.get_camp_info(camp, src) elif src == "yoyi": data_path = config.yoyiPath camp_info = config.get_camp_info(camp, src) train_path = data_path + camp + "/urp-train/train.yzx.shuf.txt" test_path = data_path + camp + "/urp-train/test.yzx.shuf.txt" eval_path = data_path + camp + "/urp-train/test.yzx.eval.txt" # mode options: train, test, write prediction
def phraseOne(): setRunningPhrase(1) threading.Thread(target=utility.startTimer).start() path = [] goBack=False getPath=True #getPath = True #turn 90 at very first while True: #to return on the same path used isPath=True time.sleep(1) if(endPosition==currentPosition): sendMessages("Reached EndPosition in "+str(utility.getTime())+" seconds",3) #print "=========================>>>>> reach endpoint" #phraseOneCheckIfAtGoal() break try: if(currentPosition==path[0]): path.pop(0) except: pass #print "dddd" #if getPath is true, get optimal path (90degrees) if(getPath or len(path)==0): getPath = False sendMessages("currentAngle "+str(currentAngle),3) sendMessages("currentPosition "+str(currentPosition[0])+" "+str(currentPosition[1]),3) sendMessages("phraseOneFindOptimalPath",1) returnMsgInString = comms.getMsg() #print "aaaaaa" #print returnMsgInString returnMsgInString = returnMsgInString.split(';') pathInString = returnMsgInString[0] pathInString = pathInString.translate(string.maketrans('', ''), '[] ') pathInString = pathInString.split(',') changeSafetyDistance = utility.parseBoolString(returnMsgInString[1]); #print "bbbb" #print changeSafetyDistance #print pathInString ''' if (pathInString=='[]'): goBack=True continue ''' path=[] i=0 #print "======== "+str(pathInString) while i<len(pathInString): path.append([int(pathInString[i]),int(pathInString[i+1])]) i=i+2 print "get new path:::" print path #base on path, get direction to face directionToFace = utility.getAngle(currentPosition, path[0], currentAngle) distanceToNextPoint = utility.getDistance(currentPosition, path[0], cmPerBox) #print ("direction "+str(directionToFace)) #print ("distance "+str(distanceToNextPoint)) print "currentPosition = "+str(currentPosition) if(directionToFace!=0): if(currentPosition==startPosition): isPath=False elif(len(returnPath)>0): if(returnPath[0]==currentPosition): isPath=False if(isPath): newPoint=[0,0] newPoint[0]=currentPosition[0] newPoint[1]=currentPosition[1] returnPath.insert(0,newPoint) turn(directionToFace) while arduino.getRobotMotorMovingStatus(): pass #print (WHITE+"current position "+str(currentPosition)) #print (WHITE+"current angle "+str(currentAngle)) #print (WHITE+"disatnce to next point"+str(distanceToNextPoint)) #check left and right sensor for obs sensorValues = arduino.getSensorStatus() #print WHITE+"sensor values" #print WHITE+sensorValues sensorValues = sensorValues.split() isLeftObstacle=utility.parseBoolString(sensorValues[4]) isRightObstacle=utility.parseBoolString(sensorValues[6]) print "sensor values:::::" print sensorValues if (currentPosition[0]>=34 and currentPosition[1]>=24 and (isRightObstacle or isLeftObstacle)): sendMessages("Reached EndPosition in "+str(utility.getTime())+" seconds",3) print "not very accurate, but regard as reached" #print "=========================>>>>> reach endpoint" #phraseOneCheckIfAtGoal() break if(isRightObstacle):#if right sensor is true #print ("current "+str(currentPosition)) #print "currentPosition = "+str(currentPosition) #print "left obstacle" setObstacle("right",10) obsTrueCoords = comms.getMsg() sendMessages("map setObstacle "+obsTrueCoords,2) getPath=True #bottom sensor is for front left if(isLeftObstacle):#if bottom sensor is true, front obs within 10cm #print ("current "+str(currentPosition)) #print "currentPosition = "+str(currentPosition) #print "right obstacle" setObstacle("left",10) obsTrueCoords = comms.getMsg() sendMessages("map setObstacle "+obsTrueCoords,2) getPath=True if ((not getPath) or changeSafetyDistance): move(10) changeSafetyDistance=False else: continue while arduino.getRobotMotorMovingStatus(): pass continue endingCheck()
def phraseOne(): setRunningPhrase(1) threading.Thread(target=utility.startTimer).start() path = [] goBack = False getPath = True #getPath = True #turn 90 at very first while True: #to return on the same path used isPath = True time.sleep(1) if (endPosition == currentPosition): sendMessages( "Reached EndPosition in " + str(utility.getTime()) + " seconds", 3) #print "=========================>>>>> reach endpoint" #phraseOneCheckIfAtGoal() break try: if (currentPosition == path[0]): path.pop(0) except: pass #print "dddd" #if getPath is true, get optimal path (90degrees) if (getPath or len(path) == 0): getPath = False sendMessages("currentAngle " + str(currentAngle), 3) sendMessages( "currentPosition " + str(currentPosition[0]) + " " + str(currentPosition[1]), 3) sendMessages("phraseOneFindOptimalPath", 1) returnMsgInString = comms.getMsg() #print "aaaaaa" #print returnMsgInString returnMsgInString = returnMsgInString.split(';') pathInString = returnMsgInString[0] pathInString = pathInString.translate(string.maketrans('', ''), '[] ') pathInString = pathInString.split(',') changeSafetyDistance = utility.parseBoolString( returnMsgInString[1]) #print "bbbb" #print changeSafetyDistance #print pathInString ''' if (pathInString=='[]'): goBack=True continue ''' path = [] i = 0 #print "======== "+str(pathInString) while i < len(pathInString): path.append([int(pathInString[i]), int(pathInString[i + 1])]) i = i + 2 print "get new path:::" print path #base on path, get direction to face directionToFace = utility.getAngle(currentPosition, path[0], currentAngle) distanceToNextPoint = utility.getDistance(currentPosition, path[0], cmPerBox) #print ("direction "+str(directionToFace)) #print ("distance "+str(distanceToNextPoint)) print "currentPosition = " + str(currentPosition) if (directionToFace != 0): if (currentPosition == startPosition): isPath = False elif (len(returnPath) > 0): if (returnPath[0] == currentPosition): isPath = False if (isPath): newPoint = [0, 0] newPoint[0] = currentPosition[0] newPoint[1] = currentPosition[1] returnPath.insert(0, newPoint) turn(directionToFace) while arduino.getRobotMotorMovingStatus(): pass #print (WHITE+"current position "+str(currentPosition)) #print (WHITE+"current angle "+str(currentAngle)) #print (WHITE+"disatnce to next point"+str(distanceToNextPoint)) #check left and right sensor for obs sensorValues = arduino.getSensorStatus() #print WHITE+"sensor values" #print WHITE+sensorValues sensorValues = sensorValues.split() isLeftObstacle = utility.parseBoolString(sensorValues[4]) isRightObstacle = utility.parseBoolString(sensorValues[6]) print "sensor values:::::" print sensorValues if (currentPosition[0] >= 34 and currentPosition[1] >= 24 and (isRightObstacle or isLeftObstacle)): sendMessages( "Reached EndPosition in " + str(utility.getTime()) + " seconds", 3) print "not very accurate, but regard as reached" #print "=========================>>>>> reach endpoint" #phraseOneCheckIfAtGoal() break if (isRightObstacle): #if right sensor is true #print ("current "+str(currentPosition)) #print "currentPosition = "+str(currentPosition) #print "left obstacle" setObstacle("right", 10) obsTrueCoords = comms.getMsg() sendMessages("map setObstacle " + obsTrueCoords, 2) getPath = True #bottom sensor is for front left if (isLeftObstacle): #if bottom sensor is true, front obs within 10cm #print ("current "+str(currentPosition)) #print "currentPosition = "+str(currentPosition) #print "right obstacle" setObstacle("left", 10) obsTrueCoords = comms.getMsg() sendMessages("map setObstacle " + obsTrueCoords, 2) getPath = True if ((not getPath) or changeSafetyDistance): move(10) changeSafetyDistance = False else: continue while arduino.getRobotMotorMovingStatus(): pass continue endingCheck()
def calculateLocalTime(rddCheckins, indexOfUtcTime1, indexOfOffsett, outfile): """ Task 2 """ rddLocalTime = rddCheckins \ .map(lambda row: getTime(row[indexOfUtcTime1], row[indexOfOffsett])) rddLocalTime.saveAsTextFile(outfile) return rddLocalTime
x_id = buf_x_ids[_i:(_i + 1)] wt = buf_wts[_i:(_i + 1)] if 'LR' in algo: feed_dict = {model.x_id: x_id, model.wt: wt} pred = model.prediction.eval(feed_dict=feed_dict)[0][0] preds.append(pred) labels.extend(buf_labels) return np.array(labels), np.array(preds) if __name__ == '__main__': src = "vlion" camp = "231" algo = "LR" tag = src + "_" + camp + "_" + algo + "_" + utility.getTime() if src == "ipinyou": data_path = config.ipinyouPath camp_info = config.get_camp_info(camp, src) elif src == 'vlion': data_path = config.vlionPath camp_info = config.get_camp_info(camp, src) elif src == "yoyi": data_path = config.yoyiPath camp_info = config.get_camp_info(camp, src) train_path = data_path + camp + "/urp-train/train.yzx.shuf.txt" test_path = data_path + camp + "/urp-train/test.yzx.shuf.txt" eval_path = data_path + camp + "/urp-train/test.yzx.eval.txt" # mode options: train, test, write prediction