def insert_route_data(route_number, route_data): route = Route(routeNumber=route_number) route.put() for record in route_data: road_name = record[0] #check if road exist if not create one road = Road.get_or_insert(road_name, name=road_name) #store the location location = Location(node=record[2], lat=float(record[3]), lng=float(record[4]), placeId=record[5]) location.put() #map location to the route route_location = RouteLocation(nodeIndex=int(record[1]), route=route.key, road=road.key, node=location.key) route_location.put() return route.key
def get_all_routes(countries, airports): json = _json_response(ALL_ROUTES_URL, ALL_ROUTES_PARAMS) for outbound_airport in json['airports']: for route in outbound_airport['routes']: if _is_airport_route(route): if outbound_airport['iataCode'] in airports: _outbound_airport = airports[outbound_airport['iataCode']] _outbound_airport.latitude = outbound_airport['coordinates']['latitude'] _outbound_airport.longitude = outbound_airport['coordinates']['longitude'] else: # Add country to countries if outbound_airport['countryCode'].upper() not in countries: _country = Country(outbound_airport['countryCode'].upper()) countries[_country.countryCode] = _country # Add airport to airports + Add airport in corresponding country _country = countries[outbound_airport['countryCode'].upper()] _outbound_airport = Airport(_country, outbound_airport['iataCode'].upper(), outbound_airport['name']) _country.add_airport(_outbound_airport) if _extract_iataCode_from_route(route) in airports: _inbound_airport = airports[_extract_iataCode_from_route(route)] _outbound_airport.add_route(Route(_outbound_airport, _inbound_airport)) return countries, airports
def on_key_press(self, key): if key == arcade.key.DOWN: if self.selecting_choice < 3: self.selecting_choice += 1 else: self.selecting_choice = 1 elif key == arcade.key.UP: if self.selecting_choice > 1: self.selecting_choice -= 1 else: self.selecting_choice = 3 elif key == arcade.key.ENTER: self.router.change_route(Route(self.selecting_choice))
def init_routes(self): """ Adds the deposit and a first linehaul node to each route :return: """ for i in range(0, int(self._instance.routes_count)): route = Route() route.set_index(i) route.add_node(self._instance.nodes_list[0]) route.max_linehaul_capacity = self._vehicle_capacity route.max_backhaul_capacity = self._vehicle_capacity for x in self._instance.rnd_nodes_ids: node = self._instance.get_node_by_index(x) if len(self._instance.linehaul_ids) > 0: if node.get_type == 'linehaul' and node.get_index in self._instance.linehaul_ids and node.get_capacity <= self._vehicle_capacity: route.add_node(node) self._instance.linehaul_ids.pop(self._instance.linehaul_ids.index(x)) self._routes.append(route) break else: pass else: pass
def build_map_from_list(self, lista): listo = [] listi = [] routes_map = [] for i in range(0, len(lista)): listo.append(lista[i]) if i != len(lista) - 1: if lista[i].get_index == 0 and lista[i + 1].get_index == 0: listi.append(listo) listo = [] if lista[i].get_index == 0 and i == len(lista) - 1: listi.append(listo) listo = [] c = 0 for rn in listi: route = Route() for n in rn: route.add_node(n) if not route.is_route_valid(): return False assert isinstance(route, Route) route.update_cost() route.set_index(c) routes_map.append(route) c += 1 if len(routes_map) != len(self.random_map.get_routes): return False cost = 0 for route in routes_map: cost += route.get_cost cost = round(cost, 2) rm = RandomMap() rm.set_routes(routes_map) rm.set_cost(cost) rm.file_name = self.file_name self.cost_map[cost] = rm return True
def put_new_route(): content = g.data session = get_session() locale = get_post_locale(session) places = [] for index, place_info in enumerate(content['places']): if session.query(Place).get(place_info['id']) is None: session.close() abort(400, "Place with id = %s not found" % (place_info['id'])) return route_place_info = RoutePlaceInfo( place_id=place_info['id'], order=index, ) if 'description' in place_info: description_id = str(uuid4()) locale_string = LocaleString( id=description_id, locale=locale, text=place_info['description'] ) route_place_info.description_id = description_id route_place_info.description.set(locale_string) if 'audioguide_link' in place_info: audioguide_link_id = str(uuid4()) locale_link = LocaleLink( id=audioguide_link_id, locale=locale, path=place_info['audioguide_link'] ) route_place_info.audioguide_link_id = audioguide_link_id route_place_info.audioguide_link.set(locale_link) places.append(route_place_info) route = Route( places=places, city_id=content['city_id'] ) name_id = str(uuid4()) locale_string = LocaleString( id=name_id, locale=locale, text=content['name'] ) route.name_id = name_id route.name.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString( id=description_id, locale=locale, text=content['description'] ) route.description_id = description_id route.description.set(locale_string) session.add(route) session.commit() session.close() return 'ok'
u2 = User('Поручникова', 'Юлия', 'Владимировна', 'г. Санкт-Петербург, ул. Маркса, д 24, кв 30', '9057525924', '2') u3 = User('Жирнов', 'Евгений', 'Борисович', 'г. Томск, ул. Октябрьская, д 7, кв 17', '9169284356', '3') jsonP.appendItem('User', u1) jsonP.appendItem('User', u2) jsonP.appendItem('User', u3) h1 = Hotel('Сокол', 6300, 'Россия, Крым', '4') h2 = Hotel('Саванна', 7000, 'США, Джорджия', '5') h3 = Hotel('Джунгли', 5600, 'Индия, Нью-Дели', '6') jsonP.appendItem('Hotel', h1) jsonP.appendItem('Hotel', h2) jsonP.appendItem('Hotel', h3) r1 = Route('Жаркий Крым', 2, 'Умеренно-континентальный', h1, '7') r2 = Route('Дикая Саванна', 4, 'Субэкваториальный', h2, '8') r3 = Route('Индийские джунгли', 1, 'Субтропический', h3, '9') r4 = Route('Русское Чёрное море', 4, 'Умеренно-континентальный', h1, '10') jsonP.appendItem('Route', r1) jsonP.appendItem('Route', r2) jsonP.appendItem('Route', r3) jsonP.appendItem('Route', r4) w1 = Waybill(r4, u1, '20.06.2019', 3, '11') w2 = Waybill(r2, u3, '03.10.2019', 1, '12') w3 = Waybill(r3, u3, '10.04.2019', 2, '13') jsonP.appendItem('Waybill', w1) jsonP.appendItem('Waybill', w2) jsonP.appendItem('Waybill', w3)
def handle_incomming_message(message): #in einzelne funktionen auslagern if "LR" in message: # print("handle detected LR message: " + message) buffer_list.pop(0) # print("Buffer after LR pop: " ) # print(buffer_list) message = message.replace('\r', '') message = message.replace('\n', '') real_src = message[3:7] message = message[11:] flag = message[:2] dest = message[2:6] src = message[6:10] ttl = int(message[10:12]) seq = int(message[12:14]) payload = message[14:] # print(flag + " " + dest + " " + src + " " + str(ttl) + " " + str(seq) + " " + payload) if flag == '00': print("incomming chat message") temp_message = Message(dest, src, ttl, seq, payload) message_box.append(temp_message) print(message_box) if dest == lora_config['freq']: print(f"Got my message: {temp_message}") if src in routing_table: send_acknowledgement(src) # ToDo: add ack else: print("can't send ack sry") else: if dest in routing_table and ttl > 1: forward_chat_message(dest, src, ttl - 1, seq + 1, payload) else: print("Can't forward message!") elif flag == '01': #print("incomming self_propagation message") change = False if src not in routing_table: new_route = Route(src, 1, real_src) routing_table[src] = new_route change = True if src in routing_table: # updating timestamp and hopcount route = routing_table[src] if route.hop_count > 1: routing_table[src] = Route(src, 1, real_src) else: route.set_timestamp() routing_table[src] = route if change: routing_table_propagation() # print("propagiere routing tabelle platzhalter") #print("printing routingtable :") #print(routing_table) elif flag == '02': #print('incomming routing_table_propagation') change = False for i in range(0, len(payload), 6): addr = payload[i:i + 4] hop = int(payload[i + 4:i + 6]) #print(f"{addr} : {hop}") if addr not in routing_table: if lora_config['freq'] != addr: new_route = Route(addr, hop + 1, real_src) routing_table[addr] = new_route #print(routing_table) change = True elif addr in routing_table: if addr == real_src and routing_table[addr].hop_count != 1: new_route = Route(addr, 1, real_src) routing_table[addr] = new_route #print(routing_table) elif int(hop) + 1 < routing_table[addr].hop_count: new_route = Route(addr, hop + 1, real_src) routing_table[addr] = new_route #print(routing_table) if change: routing_table_propagation() elif flag == '05': # ToDo: test #print('incomming acknowlagement message') if dest == lora_config['freq']: # print(f"Got ack: {message}") klo = 0 else: if dest in routing_table and ttl > 1: forward_acknowledgement(dest, src, ttl - 1, seq + 1) else: print("Can't forward ack! Adress not found") else: print('wrong message') elif "AT," in message: # Do nothing here xyz = 1 else: #print("Wrong message popping : " + message) #print(buffer_list) buffer_list.pop(0)
from models.Route import Route route1 = Route("0014", 1, "0014") route3 = Route("0014", 1, "0014") route2 = Route("0016", 2, "0014") print(route1) print(route2) route2.hop_count += 1 print(route2) print(route2 == route1) print(route1 == route3)