Exemple #1
0
    def upload_all_targets(client, target_json, sys_db, out):
        cur = db.cursor()  #allows execution of all SQL queries
        cur.execute("SELECT * FROM targets")

        #Fetches every row of the table;
        #Columns are as follows:
        #1st - target_id, 2 - type, 3 - latitude, 4 - longitude, 5 - orientation, 6 - shape, 7 - background-color, 8 - alphanumeric, 9 - alphanumeric_color
        # 10 - image path
        #note: target_id is a long/int, and latitude and longitude are floats/doubles
        for row in cur.fetchall():
            target = interop.Target(
                type=row[
                    1],  #indexing starts from 0, data doesn't include target_id
                latitude=row[2],
                longitude=row[3],
                orientation=row[4],
                shape=row[5],
                background_color=row[6],
                alphanumeric=row[7],
                alphanumeric_color=row[8])

            target = client.post_target(target)  #send target values to server

            #open corresponding image file.  Assumes the naming convention goes "1_lettercolor_letter_shapecolor_shape.png".  Ex. "2_white_B_green_square.png"
            with open(imagedir + "/" + row[10] + '.png', 'rb') as f:
                #the 'rb' option reads the file in binary, as opposed to as a text file
                image_data = f.read()
                client.put_target_image(target.id, image_data)
def postimage(num):
	SubmissionText = os.path.join(ImageLoc,str(num),'.txt')
	SubmissionImage = os.path.join(ImageLoc,str(num),'.jpg')

	with open(ImageInfoLoc,"r") as file: 
		alpha = file.readline()
		alphaColor = file.readline()
		shape = file.readline()
		backColor = file.readline()
		targetType = file.readline()
		lat = float(file.readline())
		lng = float(file.readline())
		deg = float(file.readline())

	if (deg > 180):
		deg = deg-360
	elif(deg < -180):
		deg = deg+360

	if (deg > 157.5):
		orient = 's'
	elif(deg <= 157.5 and deg > 112.5):
		orient = 'sw'
	elif(deg <= 112.5 and deg > 67.5):
		orient = 'w'
	elif(deg <= 67.5 and deg > 22.5):
		orient = 'nw'
	elif(deg <= 22.5 and deg > -22.5):
		orient = 'n'
	elif(deg <= -22.5 and deg > -67.5):
		orient = 'ne'
	elif(deg <= -67.5 and deg > -112.5):
		orient = 'e'
	elif(deg <= -112.5 and deg > -157):
		orient = 'se'
	else:
		orient = 's'


	target = interop.Target(type=targetType,
		latitude=lat,
		longitude=lng,
		orientation=orient,
		shape=shape,
		background_color=backColor,
		alphanumeric=alpha,
		alphanumeric_color=alphaColor)

	target = client.post_target(target)

	with open(SubmissionImage, 'rb') as f:
   		image_data = f.read()
   		client.put_target_image(target.id, image_data)
Exemple #3
0
    def view_current_targets(sys_db, out):
        cur = db.cursor()  #allows execution of all SQL queries
        cur.execute("SELECT * FROM targets")

        for row in cur.fetchall():
            target = interop.Target(
                type=row[
                    1],  #indexing starts from 0, data doesn't include target_id
                latitude=row[2],
                longitude=row[3],
                orientation=row[4],
                shape=row[5],
                background_color=row[6],
                alphanumeric=row[7],
                alphanumeric_color=row[8])

            out.insert(END, target)
            out.insert(END, "\n")
            out.see(END)
Exemple #4
0
    def upload2Interop(self):
        s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = None
        s1 = self.text1.get()
        s2 = self.entry2.get()
        s3 = self.entry3.get()
        s4 = self.text4.get()
        s5 = self.text5.get()
        s6 = self.text6.get()
        s7 = self.entry7.get()
        s8 = self.text8.get()
        s9 = self.entry9.get()
        if s9 == "":
            s9 = None

        s2 = eval(s2)
        s3 = eval(s3)
        target_response = OrderedDict([("id", 1), (
            "user",
            1,
        ), ("type", s1), ("latitude", s2), ("longitude", s3),
                                       ("orientation", s4), ("shape", s5),
                                       ("background_color", s6),
                                       ("alphanumeric", s7),
                                       ("alphanumeric_color", s8),
                                       ("description", s9),
                                       ("autonomous", False)])

        # print target_response
        json_str = json.dumps(target_response)
        print(json_str)

        x = self.gps()
        print("Latitude and Longitude : ")
        print(x)

        with open(str(self.index2) + ".json", 'w') as outfile:
            json.dump(target_response, outfile)
        a = str(self.index2) + ".json"
        b = "cp " + a + " mydata/" + a
        os.system(b)

        client = interop.Client(url='http://127.0.0.1:8000',
                                username='******',
                                password='******')

        target = interop.Target(type=s1,
                                latitude=s2,
                                longitude=s3,
                                orientation=s4,
                                shape=s5,
                                background_color=s6,
                                alphanumeric=s7,
                                alphanumeric_color=s8)
        target = client.post_target(target)

        print(str(self.index2) + ".jpg")

        with open(str(self.index2) + ".jpg", 'rb') as f:
            image_data = f.read()
            client.put_target_image(target.id, image_data)
        self.index2 += 1
Exemple #5
0
#Connect to the mySQL database
db = MySQLdb.connect(host = "localhost", user="******", passwd = "abolishmacaroni", db ="testdb")
#Use own credentials for actual database

cur = db.cursor() #allows execution of all SQL queries
cur.execute("SELECT * FROM targets")

#Fetches every row of the table; 
#Columns are as follows:
#1st - target_id, 2 - type, 3 - latitude, 4 - longitude, 5 - orientation, 6 - shape, 7 - background-color, 8 - alphanumeric, 9 - alphanumeric_color
#note: target_id is a long/int, and latitude and longitude are floats/doubles
for row in cur.fetchall():
	target = interop.Target(type = row[1], #indexing starts from 0, data doesn't include target_id
				latitude = row[2],
				longitude = row[3],
				orientation = row[4],
				shape = row[5],
				background_color = row[6],
				alphanumeric = row[7],
				alphanumeric_color = row[8])

	target = client.post_target(target) #send target values to server
	
	#open corresponding image file.  Assumes the naming convention goes "1_lettercolor_letter_shapecolor_shape.png".  Ex. "2_white_B_green_square.png"
	with open(imagedir + "/" + str(row[0]) + '_' + row[8] + '_' + row[7] + '_' + row[6] + '_' + row[5] + '.png', 'rb') as f:
	#the 'rb' option reads the file in binary, as opposed to as a text file
		image_data = f.read()
    		client.put_target_image(target.id, image_data)

	#Example:
	#with open('/home/brian/interop/client/interop/testdata/A.jpg', 'rb') as f: