def read_single_station(self, row): ''' Create a DivvyStation object based on a line from the stations CSV file ''' if len(row) < 7: print("Error in parsing line: " + ",".join(row)) return None try: station_id = int(row[0]) name = row[1] latitude = float(row[2]) longitude = float(row[3]) coords = coordinates.Coordinates(latitude, longitude) dpcapacity = int(row[4]) landmark = int(row[5]) date = time.strptime(row[6], "%m/%d/%Y") except Exception as e: print("Error in parsing data: " + str(e)) return None return divvy_station.DivvyStation(station_id, name, coords, dpcapacity, landmark, date)
def __init__(self, radius=50, level=1): self.x = [] self.y = [] self.current = 0 self.failedPositions = [[0, 0]] self.operations = [0, 0, 0, 0] #left right up down self.COORDINATES = Coords.Coordinates(radius, level) self.fillCoordinates() self.GC = guiControl.guiControl(self.MOUSE_SPEED)
class Tabs: COORDINATES = c.Coordinates() CORD_LAST_UPDATE = time.time() CORD_UPDATE_THRESHOLD = 60 TABS = [] def __init__(self, name): self.name = name def get_cords(self): if time.time() - self.CORD_LAST_UPDATE > Tabs.CORD_UPDATE_THRESHOLD: self.update_cords() return self.COORDINATES def update_cords(self): Tabs.COORDINATES.find_game_window() print( f"{self.name} last update was {time.time() - self.CORD_LAST_UPDATE} ago" ) print( f"{self.name} called for a cord update at {helpers.time_format()}") Tabs.CORD_LAST_UPDATE = time.time() def go_to_tab(self): if time.time() - self.CORD_LAST_UPDATE > Tabs.CORD_UPDATE_THRESHOLD: self.update_cords() for tab in self.TABS: pg.click(tab) pg.moveTo(self.COORDINATES.safe_spot) def add_or_remove_clones(self, images, zone_x_width=500, zone_y_height=60, click_image=None): coordinates = self.COORDINATES for image in images: zone = self.check_if_cached(image) if zone == -1: zone = helpers.get_active_zone(image, zone_x_width, zone_y_height, coordinates) if zone == -1: return self.cache_image(image, zone) helpers.click_image_in_zone(click_image, zone=zone) pg.moveTo(coordinates.safe_spot) def check_if_cached(self, image): if image in self.COORDINATES.IMAGE_CACHE: return self.COORDINATES.IMAGE_CACHE[image] return -1 def cache_image(self, image, value): self.COORDINATES.IMAGE_CACHE[image] = value
def process(picture, colors): # original = picture.copy() blurred = blur(picture) #border = addborder(blurred, 6, [0,0,0]) hsv = converttohsv(blurred) cfilter = filterbycolor(hsv, colors) masked = cv2.bitwise_and(blurred, blurred, mask=cfilter) contours = findinnercontours(masked) rectcont = findmaxrectangle(contours) inv = cv2.bitwise_not(blurred, blurred, mask=cfilter) if rectcont is not None: cX = findcenter(rectcont) diff = finddiff(rectcont) # print(str(diff)) coords = getcoords(cX, diff) return directtorect(inv, cX), coords, cX else: return inv, coordinates.Coordinates(), -1
def pre_processing(): print( "Starting Direct Flight Builder! Built by Kenneth Shinn and Stacey Chen" ) print() new_file() #create the airport set global organized_set print("initializing dictionary of airport coordinates") organized_set = airport_set.Airport_Set() coordinates_dict = coordinates.Coordinates() coordinates_dict = coordinates_dict.get_dictionary() print("number of total airports in dictionary: " + str(len(coordinates_dict))) print() iata_seen = set() #start with the earliest flight data - parse through it for i in range(1990, 2019): print('reading flight data from ' + str(i)) name_d = str(i) + "_D" name_i = str(i) + "_I" with open('flight_data/' + name_d + '.csv', encoding='latin-1') as dom_data: with open('flight_data/' + name_i + '.csv', encoding='latin-1') as int_data: csv_reader_d = csv.DictReader(dom_data, delimiter=',') csv_reader_i = csv.DictReader(int_data, delimiter=',') for row in csv_reader_d: airport_iata = str(row['ORIGIN']) iata_seen.add(airport_iata) city = str(row['ORIGIN_CITY_NAME']) date = int(str(i) + row['MONTH']) dest = str(row['DEST']) ap = organized_set.locate_airport(airport_iata) #check if a given airport has been seen if not ap is None: ap.set_flight(date, dest) else: flights = {} new_ap = airport.Airport(airport_iata, flights, city, coordinates_dict) new_ap.set_flight(date, dest) organized_set.place_airport(new_ap) for row in csv_reader_i: airport_iata = str(row['ORIGIN']) iata_seen.add(airport_iata) city = str(row['ORIGIN_CITY_NAME']) date = int(str(i) + row['MONTH']) dest = str(row['DEST']) ap = organized_set.locate_airport(airport_iata) #check if a given airport has been seen if not ap is None: ap.set_flight(date, dest) else: flights = {} new_ap = airport.Airport(airport_iata, flights, city, coordinates_dict) new_ap.set_flight(date, dest) organized_set.place_airport(new_ap)
def test_6(): cRegenstein = coordinates.Coordinates(41.79218, -87.599934) cRyerson = coordinates.Coordinates(41.7902836, -87.5991959) helper(cRegenstein, cRyerson, 219.569166)
def test_11(): cSnitchock = coordinates.Coordinates(41.791218, -87.601026) cHarper = coordinates.Coordinates(41.787965, -87.599642) helper(cSnitchock, cHarper, 379.480114)
import aStar import graph import coordinates import random import math numberOfStations = 3500 numberOfConnections = 15000 maxX = 1000. maxY = 1000. stationGraph = graph.Graph() for i in xrange(numberOfStations): xCoordinate = random.uniform(1., maxX) yCoordinate = random.uniform(1., maxY) nodeCoordinate = coordinates.Coordinates(xCoordinate, yCoordinate) node = graph.GraphNode(i + 1, nodeCoordinate) stationGraph.add_node(node) for i in xrange(numberOfConnections): parent = random.randint(1, numberOfStations) while True: child = random.randint(1, numberOfStations) if child != parent: added = stationGraph.add_edge(parent, child) if added: break while True: stationSpecificationIdentifier = '0'
class ActionClass(Tabs): COORDINATES = c.Coordinates() print( f"{Fore.CYAN}ActionClass called c.Coordinates() at {helpers.time_format()}" ) CORD_LAST_UPDATE = time.time() START_BUTTON = None REWARD_BUTTON = None FALL_BACK_POS = [] ALL_ACTION_CLASSES = {} CAMPAIGNS = {} DUNGEONS = {} TABS = [] def __init__(self, name): super().__init__(name) self.timer = TimerClass(self.name, -1) self.is_active = False self.action_region = -1 self.action_region_relative = -1 self.current_duration = None self.camp_index = -1 self.active_name = self.name + "_active" ActionClass.ALL_ACTION_CLASSES[self.name] = self def check_if_active(self): coordinates = self.get_cords() self.go_to_tab() try: pos = helpers.return_position_of_image_on_screen( IMAGE_DICTIONARY[self.active_name]) except KeyError as exception: pos = (self.FALL_BACK_POS[0], self.FALL_BACK_POS[1] + 45 * self.camp_index) print(exception) if pos[0] == -1: pos = (self.FALL_BACK_POS[0], self.FALL_BACK_POS[1] + 45 * self.camp_index) x = round(pos[0]) y = round(pos[1]) - 25 self.action_region_relative = (x - coordinates.X_PAD, y - coordinates.Y_PAD, x + 350 - coordinates.X_PAD, y + 50 - coordinates.Y_PAD) pg.moveTo(pos[0] + 50, pos[1]) tooltip_image = helpers.get_image_from_zone(coordinates.tooltip_region) time.sleep(0.1) time_left = get_hours_left(tooltip_image) if time_left == -1: print(f"{Fore.RED}{self.name} is not active") self.is_active = False return False elif time_left == 0: print( f"{Fore.GREEN}{self.name} is finished... Collecting Reward (self.collect_reward())" ) self.collect_reward() self.is_active = False return False self.timer.set_end_time(time_left + 5) self.timer.reset_timer() self.is_active = True print( f"{Fore.GREEN}{self.name} is active with {self.timer.time_remaining():.0f} remaining" ) return True def start_action(self): """ This part can be run for both campaign and dungeons. """ if self.is_active and self.timer.time_remaining() > 0: print( f"{self.name} is active with {self.timer.time_remaining():.0f} remaining" ) return coordinates = self.get_cords() self.go_to_tab() pos = helpers.return_position_of_image_on_screen( IMAGE_DICTIONARY[self.name], coordinates) # coordinates x = round(pos[0]) y = round(pos[1]) - 25 self.action_region = (x, y, x + 350, y + 50) self.action_region_relative = (x - coordinates.X_PAD, y - coordinates.Y_PAD, x + 350 - coordinates.X_PAD, y + 50 - coordinates.Y_PAD) pg.moveTo(coordinates.safe_spot) helpers.click_image_in_zone(IMAGE_DICTIONARY[self.START_BUTTON], zone=self.action_region) pg.moveTo(coordinates.safe_spot) duration = self.current_duration + 20 if self.timer == -1: self.timer = TimerClass(self.name, duration) else: self.timer.set_end_time(duration) self.timer.reset_timer() TIMER_TRACKER[self.timer.name] = self.timer print( f"{self.name} has {self.timer.time_remaining()} seconds remaining") def collect_reward(self): coordinates = self.get_cords() self.go_to_tab() pos = self.action_region_relative if pos[0] == -1: pos = (self.FALL_BACK_POS[0], self.FALL_BACK_POS[1] + 45 * self.camp_index) x = round(pos[0]) y = round(pos[1]) - 15 zone = (x + coordinates.X_PAD, y + coordinates.Y_PAD, x + 400 + coordinates.X_PAD, y + 65 + coordinates.Y_PAD) print(self.REWARD_BUTTON) helpers.click_image_in_zone(IMAGE_DICTIONARY[self.REWARD_BUTTON], zone=zone) pg.moveTo(coordinates.safe_spot) time.sleep(2) helpers.click_image_on_screen(IMAGE_DICTIONARY["close_button"]) time.sleep(0.1) self.is_active = False
nextStep = Hist() #next step nextElbow = Hist() #(lat long) of next turning-point here = Hist() #Current location (lat, long) if wEn: walk = Walk() #walking object cam = walk.getcam() #(1) Get destination #end = readDest() end = "220 Yonge St, Toronto, ON M5B2H1" #(2) Get start location, i.e. current location port = 5007 print "Listening for coordinates app at {}:{}".format(ipaddr, port) coord = coord.Coordinates(ipaddr=ipaddr, port=port) start = coord.getCoord() #start = "40 St George St, Toronto, ON, M5S2E4" print "Start is {}".format(start) #(3) Get directions directions = Directions(start, end) steps = directions.getsteps() print "Steps to {} are {}".format(end, steps) #90 -> N #180-> E #270-> S #0 | 360-> W port = 5005
def __init__(self, coords, V, mu, Theta_deg): self.coords = coordinates.Coordinates(coords) self.V, self.mu, self.Theta = V, mu, np.deg2rad(Theta_deg)
def test_1(): cChicago = coordinates.Coordinates(41.8337329, -87.7321555) cNewYork = coordinates.Coordinates(40.7056308, -73.9780035) helper(cChicago, cNewYork, 1155076.772338)
def getcoords(cX, diff): coords = coordinates.Coordinates() coords.angle = measureangle(cX) coords.distance = measuredistance(diff) coords.latest = time.time() return coords
def test_5(): cChicago = coordinates.Coordinates(41.8337329, -87.7321555) cNairobi = coordinates.Coordinates(-1.3048036, 36.8473969) helper(cChicago, cNairobi, 12895627.486686)
def test_4(): cChicago = coordinates.Coordinates(41.8337329, -87.7321555) cSydney = coordinates.Coordinates(-33.856898, 151.215281) helper(cChicago, cSydney, 14865550.217648)
def test_3(): cChicago = coordinates.Coordinates(41.8337329, -87.7321555) cBuenosAires = coordinates.Coordinates(-34.6158527, -58.4332985) helper(cChicago, cBuenosAires, 9010486.474634)
def test_2(): cChicago = coordinates.Coordinates(41.8337329, -87.7321555) cLondon = coordinates.Coordinates(51.5286416, -0.1015987) helper(cChicago, cLondon, 6363076.446747)
def test_7(): cRegenstein = coordinates.Coordinates(41.79218, -87.599934) cSnitchock = coordinates.Coordinates(41.791218, -87.601026) helper(cRegenstein, cSnitchock, 140.136890)
def test_8(): cRegenstein = coordinates.Coordinates(41.79218, -87.599934) cHarper = coordinates.Coordinates(41.787965, -87.599642) helper(cRegenstein, cHarper, 469.311408)
import coordinates if __name__ == "__main__": # We create two Coordinates objects, one representing the # location of Chicago, and one representing the location # of New York cChicago = coordinates.Coordinates( 41.8337329, -87.7321555) cNewYork = coordinates.Coordinates( 40.7056308, -73.9780035) # We print out the coordinates print("The coordinates of Chicago are " + str(cChicago)) print("The coordinates of New York are " + str(cNewYork)) # We compute the distance between them distance = cChicago.distance_to(cNewYork) # Note that we could have also done the following: # # distance = cNewYork.distance_to(cChicago) # We print the distance s = "The distance between Chicago and New York is {:.2f}km" print(s.format(distance/1000.0))
def test_9(): cRyerson = coordinates.Coordinates(41.7902836, -87.5991959) cSnitchock = coordinates.Coordinates(41.791218, -87.601026) helper(cRyerson, cSnitchock, 183.890430)
import airport import airport_set import csv import coordinates import formulas #create the global variable organized_set = airport_set.Airport_Set() iata_seen = set() coordinates_dict = coordinates.Coordinates().get_dictionary() def new_file(): #write the header with open('outputs/flights.csv', 'w', newline="\n", encoding='utf-8-sig') as out_file: csv_writer = csv.writer(out_file, delimiter=',') header = [ "location a name", "location b name", "location a radius", "location b radius", "location a airports", "location b airports", "flights", "location a coordinates", "location b coordinates" ] for year in range(1990, 2019): for month in range(1, 13): date = int(str(year) + str(month)) #data ends in August, 2018 if date > 20188: break header.append(str(date))
def test_10(): cRyerson = coordinates.Coordinates(41.7902836, -87.5991959) cHarper = coordinates.Coordinates(41.787965, -87.599642) helper(cRyerson, cHarper, 260.455871)
#END SHAPE F****r #dynamic variables lower_yellow = np.array([20, 100, 60]) upper_yellow = np.array([50, 230, 200]) #lower_yellow = np.array([30,40,0]) #upper_yellow = np.array([100,100,100]) camera_width = 320 camera_fov = 60 cube_width = 42 #centimeters cube_height = 69 #changethese #derived variables camera_middle = camera_width / 2 camera_single = camera_width / camera_fov coordinates = coordinates.Coordinates() #functions def process2(picture): blurred = blur(picture) cv2.imshow("blurred", blurred) hsv = converttohsv(blurred) cfilter = filterbycolor(hsv) cv2.imshow("mask", cfilter) masked = cv2.bitwise_and(blurred, blurred, mask=cfilter) cv2.imshow("masked", masked) smallest, biggest, cX, cY, area = filterbyshape(masked) coordinates = getcoords2(smallest, biggest, cX, cY, area) cv2.waitKey(27) & 0xFF == ord('q') return coordinates
import aStar import file_manager import city import graph import coordinates import math file_library = file_manager.CityFileLibrary('cities.txt') city_data = file_library.get_city_data() number_of_cities = len(city_data) city_graph = graph.Graph() for i in xrange(number_of_cities): node_coordinates = coordinates.Coordinates(city_data[i].x, city_data[i].y) node = graph.GraphNode(i, node_coordinates) city_graph.add_node(node) for parent in xrange(number_of_cities-1): for child in xrange(number_of_cities): city_graph.add_edge(parent, child) aStarLibrary = aStar.AStarLibrary(city_graph) shortestPath, cost = aStarLibrary.find_shortest_path() print 'Shortest cycle' print shortestPath print '' print 'Cycle cost' print cost