def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) # assert default_place.name == "" # assert default_place.country == "" # assert default_place.priority == 0 # assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) # TODO: Write tests to show this initialisation works print(new_place) # TODO: Add more tests, as appropriate, for each method # test mark_visited new_place.mark_visited() print(new_place) # test mark_unvisited new_place.mark_unvisited() print(new_place) # test isimportant place new_place.isimportant()
def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) print(new_place) assert new_place.name == "Malagar" assert new_place.country == "Spain" assert new_place.priority == 1 assert not default_place.is_visited is False print("Test for making places visited") visited_test_place = Place("Townsville", "Australia", 9, False) assert visited_test_place.is_visited is False print(visited_test_place)
def run_tests() : """Test Place class.""" # Test empty place (defaults) print ("Test empty place:") default_place = Place ( ) print (default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print ("Test initial-value place:") new_place = Place ("Malagar", "Spain", 1, False) # TODO: Write tests to show this initialisation works print ("Test aleranate method for marking visited places") """This is the visited value that has changed from boolean to str; oupost should still be the same""" new_places = place ("Malagar", "spain", 1, "n") print (new_places) # TODO: Add more tests, as appropriate, for each method print (new_places) """String is representation of place""" print (new_places.check_visited ( )) """Check if place has been visited or not""" print (new_places.is_important ( )) """Important that place is added to the list"""
def run_tests(): """Test Place class.""" print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) # TODO: Write tests to show this initialisation works assert new_place.name == 'Malagar' assert new_place.country == 'Spain' assert new_place.priority == 1 assert not new_place.is_visited # TODO: Add more tests, as appropriate, for each method new_place.mark_visited() assert new_place.is_visited assert new_place.is_important() print(str(new_place)) assert str( new_place) == 'Name: Malagar, Country: Spain, Priority: 1, Visited.'
def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) # TODO: Write tests to show this initialisation works assert new_place.name == "Malagar" assert new_place.country == "Spain" assert new_place.priority == 1 assert not new_place.is_visited # TODO: Add more tests, as appropriate, for each method print("Test place mark visited") new_place.visited() assert new_place.is_visited print("Test place mark unvisited") new_place.unvisited() assert not new_place.is_visited print("Test place is important") assert new_place.is_important()
def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) print(default_place) assert default_place.name == "Malagar" assert default_place.country == "Spain" assert default_place.priority == 1 assert default_place.is_visited # TODO: Write tests to show this initialisation works default_place.visit() assert default_place.is_visited default_place.unvisited() assert not default_place.is_visited
def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) # TODO: Write tests to show this initialisation works print("marking visited place") new_place = Place("Malage", "Spain", 1, "n") print(new_place) # TODO: Add more tests, as appropriate, for each method print(new_place) print(new_place.check_visited()) "check already visited this place or not " print(new_place.is_important()) "add important place"
def plate(size, chaise): for i in range(size): if i % 2 == 0: c = Place(randrange(5000, 50000, 500)) else: c = Place(randrange(-100000, -5000, 5000)) chaise.plateau.append(c)
def make_places(): places = [] for i in range(69): places.append(Place(i)) areas = [] for i in range(5): areas.append(Place(i)) return places, areas
def set_en_passant(self, src, tgt): piece = self[src] src_x, src_y = src.coords tgt_x, tgt_y = tgt.coords if piece.id == 'p' and abs(tgt_y - src_y) == 2: for addx, addy in ((1, 0), (-1, 0)): #TODO refactor plc = Place((tgt_x + addx, tgt_y + addy)) if self.inside_at(plc) and str(self[plc]) == f'{self.enemy}p': self[plc].can_en_passant = (plc, Place((src_x, (tgt_y + src_y) // 2)), tgt) #GOTO; ATTACK
def run_tests(): """Test PlaceCollection class.""" # Test empty PlaceCollection (defaults) print("Test empty PlaceCollection:") place_collection = PlaceCollection() print(place_collection) assert not place_collection.places # an empty list is considered False # Test get_unvisited method print("Test get_unvisited method:") p = PlaceCollection() place1 = Place("Sydney", "Australia", 3, True) place2 = Place("New York", "USA", 4, False) place3 = Place("Tokyo", "Japan", 1, True) p.add_place(place1) p.add_place(place2) p.add_place(place3) print(p) print("{} total unvisited places".format(p.get_unvisited())) # Test loading places print("Test loading places:") place_collection.load_places('places.csv') print(place_collection) assert place_collection.places # assuming CSV file is non-empty, non-empty list is considered True # Test adding a new Place with values # print("Test adding new place:") # place_collection.add_place(Place("Smithfield", "Australia", 5, False)) # print(place_collection) # Test sorting places print("Test sorting - priority:") place_collection.sort_places("priority") print(place_collection) # Test sorting places print("Test sorting - name:") place_collection.sort_places("name") print(place_collection) # Test sorting places print("Test sorting - country:") place_collection.sort_places("country") print(place_collection) # Test sorting places print("Test sorting - visited:") place_collection.sort_places("is_visited") print(place_collection) # Test saving places (check CSV file manually to see results) print("Test saving") place_collection.save_places('places.csv') assert place_collection.places
def nextHand(self, board, previousMove, isBlack): if isBlack: if not board.canBlackPlace: return Place(-1, -1) else: if not board.canWhitePlace: return Place(-1, -1) if self.is_random: return self.randomNextHand(board, isBlack) return self.simpleBdSearchNextHand(board, previousMove, isBlack)
def main(): """main method""" """load the file""" filename = "places.csv" """create a places object and load a csv file""" places_obj = PlaceCollection() places_obj.load_places(filename) places = places_obj.places # print info print("Travel Tracker 1.0 - by Tong Wenlin") print("%d places loaded from places.csv" % len(places)) """run the choice option""" loop = True while loop: display_main_menu() choice = input(">>> ").upper() if choice == "L": print(places) elif choice == "A": name = input("Name: ") country = input("Country: ") priority = int(input("Priority: ")) place_obj = Place(name=name, country=country, priority=priority) places.append((place_obj.name, place_obj.country, place_obj.priority, place_obj.is_visited)) elif choice == "M": name = input("Input a place name:") for place in places: if place[0] == name: place_obj = Place(name=place[0], country=place[1], priority=place[2], is_visited=place[3]) place_obj.mark_place_visited() places.remove(place) new_place = (place_obj.name, place_obj.country, place_obj.priority, place_obj.is_visited) places.append(new_place) print("add success") break elif choice == "Q": places_obj.save_places() loop = False print("%d places saved to places.csv" % len(places)) print("Have a nice day :)") else: print("Invalid menu choice")
def load_places(self, file_name): """Load place information from csv to list, return a place list""" file = open(file_name, "r") content = file.readlines() # read the whole file for i in content: place = i.strip('\n').split(',') if place[3] == 'v': new_place = Place(place[0], place[1], place[2], True) self.places.append(new_place) elif place[3] == 'n': new_place = Place(place[0], place[1], place[2], False) self.places.append(new_place) file.close()
def run_tests(): """Test Place class.""" # Test empty place (defaults) """print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited""" # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False) print(new_place) if new_place.is_unvisited(): print("This place is unvisited") elif new_place.is_visited(): print("This place is visited") # Test if place is visited print("Test if place is visited:") another_place = Place("Malagar", "Spain", 1, "v") print(another_place) if another_place.is_unvisited(): print("This place is unvisited") else: print("This place is visited") # Test if place is not visited print("Test if place is unvisited:") another_location = Place("Malagar", "Spain", 1, "n") print(another_location) if another_location.is_unvisited(): print("This place is unvisited") else: print("This place is visited") # Test if place is important print("Test if place is important:") place = Place("Malagar", "Spain", 1, False) print(place) if place.is_important(): print("This place is important") else: print("Place is not important")
def run_tests(): """Test Place class.""" # Test empty place (defaults) print("Test empty place:") default_place = Place() print(default_place) assert default_place.name == "" assert default_place.country == "" assert default_place.priority == 0 assert not default_place.is_visited # Test initial-value place print("Test initial-value place:") new_place = Place("Malagar", "Spain", 1, False)
def price(): price = Price(request.form.get("price"), request.form.get("Currency")) incity = Place(request.form.get("incity")).name outcity = Place(request.form.get("outcity")).name date = "{}/{}/{}".format(request.form.get("day"), request.form.get("month"), request.form.get("year")) ids = cities_ids(incity, outcity, "files\\ids.txt") #coefficient = price.currency_coefficient("USD") coefficient = 0.037216 while True: try: search_id = get_search_id(ids[0], ids[1], date=date) break except: pass while True: try: get_tickets_json("files\\initial_tickets.json", search_id) dct = tickets_info(inpath="files\\initial_tickets.json", search_id=search_id, outpath="files\\final_tickets.json") break except: pass info = [] place_in = Place(incity) place_out = Place(outcity) place_in.get_coordinates() place_out.get_coordinates() get_map([place_in, place_out], "templates\\map.html", location=list(place_out.coordinates)) for num in dct.values(): info.append([ "Departure time: {}".format(num["departureTime"]), "Arrival time: {}".format(num["ar_time"]), "Number of stops: {}".format(num["stops"]), "Company: {}".format(num["companyName"]), "Price: {}".format( str(round(num["price"] / coefficient, 2))), "Transport: {}".format(num["mode"]), "Departure station: {}".format(num["stations_dep"][0]["name"]), "Arrival station: {}".format(num["stattions_ar"][0]["name"]), num["url"] ]) new_price = price.price * coefficient return render_template("price.html", new_price=new_price, info=info)
def load_places(self): open_file = open("places.csv", "r") for place in open_file.readlines(): file = place.split(",") self.places_list.append( [Place(file[0], file[1], int(file[2]), file[3].strip())]) open_file.close()
def __init__(self): pygame.init() config.screen = pygame.display.set_mode( (config.screen_width, config.screen_height)) config.screen.fill(colors.white) new_snake = Snake() config.snakes += [new_snake] place = Place() config.process = True while config.process: for i in pygame.event.get(): if i.type == pygame.QUIT: #ыыыыыыыыыыыыы exit() pressed = pygame.mouse.get_pressed() if pressed[0]: speeding = 2 else: speeding = 1 for s in config.snakes: s.move(speeding) while config.food_energy + config.snake_energy < config.max_energy: # Ну или сколько там new_food = Food() config.all_food += [new_food] config.screen.fill(colors.black) for f in config.all_food: f.draw(new_snake.coords) for s in config.snakes: s.draw() place.draw(new_snake.coords) pygame.display.update() pygame.time.delay(40)
def __setitem__(self, key, value): if type(key) is Place: self.board_list[key.idx] = value elif type(key) is tuple: self.board_list[Place(key).idx] = value else: self.board_list[key] = value
def __getitem__(self, query): if type(query) is Place: return self.board_list[query.idx] elif type(query) is tuple: return self.board_list[Place(query).idx] elif type(query) in (int, slice): return self.board_list[query]
def result_to_plcae_obj(cityid, cityname, jobname, result): business_status = None if 'business_status' in result: business_status = result['business_status'] formatted_address = None if 'formatted_address' in result: formatted_address = result['formatted_address'] name = None if 'name' in result: name = result['name'] opening_hours = None if 'opening_hours' in result: opening_hours = result['opening_hours'] plus_code = None if 'plus_code' in result: plus_code = result['plus_code'] rating = None if 'rating' in result: rating = result['rating'] types = None if 'types' in result: types = result['types'] user_ratings_total = None if 'user_ratings_total' in result: user_ratings_total = result['user_ratings_total'] p = Place(cityid, cityname, jobname, business_status, formatted_address, name, opening_hours, plus_code, rating, types, user_ratings_total) return p
def press_add(self, name, country, priority): """ Handler for pressing the add button :return: None """ if (not name) or (not country) or (not priority): self.status_text = "All fields must be completed" else: try: priority = int(priority) if priority < 1: self.status_text = "Priority must be > 0" else: # Adding widget p = Place(name=name, country=country, priority=priority, visited_status=False) temp_str = p.__str__( ) + " (visited)" if p.visited_status else p.__str__() temp_button = Button(text=temp_str) temp_button.bind(on_release=self.press_entry) temp_button.place = p temp_button.state = "down" if p.visited_status else "normal" # add the button to the "entries_box" using add_widget() self.root.ids.entries_box.add_widget(temp_button) self.clear_fields() # Adding to place collection self.pc.add_place(p) except: self.status_text = "Please enter a valid number"
def add_place(self): try: place_name = self.root.ids.title_input.text place_country = self.root.ids.artist_input.text place_priority = self.root.ids.year_input.text # Check if user missed something: if (place_name == "" or place_country == "" or place_priority == ""): self.click_status = "All fields must be completed!" return # Convert priority to INT to check: place_priority = int(place_priority) if (place_priority / 10000) >= 1: raise ValueError place_visited = "" place_to_add = Place(place_visited, place_name, place_country, place_priority) self.placelist.addPlace(place_to_add) # Print the place list to debug: print(self.placelist) self.destroy_places_view() self.add_widgets("priority") self.click_status = "New place added. Thank you!" self.update_topbar() self.clear_inputs() # When inputting an invalid place priority: except ValueError: self.click_status = "Please enter a valid number/data"
def run_tests(): """Test PlaceCollection class.""" # Test empty PlaceCollection (defaults) print("Test empty PlaceCollection:") place_collection = PlaceCollection() print(place_collection) assert not place_collection.places # an empty list is considered False # Test loading places print("Test loading places:") place_collection.load_places('places.csv') print(place_collection) assert place_collection.places # assuming CSV file is non-empty, non-empty list is considered True # Test adding a new Place with values print("Test adding new place:") place_collection.add_place(Place("Smithfield", "Australia", 5, False)) print(place_collection) # Test sorting places print("Test sorting - priority:") place_collection.sort("priority") print(place_collection) print("Test sorting - name:") place_collection.sort("name") print(place_collection)
def run_tests(): """Test PlaceCollection class.""" """Test empty PlaceCollection (defaults)""" print("Test empty PlaceCollection:") place_collection = PlaceCollection() print(place_collection) assert not place_collection.list_data # an empty list is considered False """Test loading places""" print("Test loading places:") place_collection.read_places('places.csv') print(place_collection) assert place_collection.list_data # assuming CSV file is non-empty, non-empty list is considered True """Test adding a new Place with values""" print("Test adding new place:") place_collection.add_place(Place("Smithfield", "Australia", 5, False)) print(place_collection) """Test sorting - name:""" print("Test sorting - name:") place_collection.s_places("name") print(place_collection) """Test sorting - country:""" print("Test sorting - country:") place_collection.s_places("country") print(place_collection) """Test sorting places - priority""" print("Test sorting - priority:") place_collection.s_places("priority") print(place_collection) """Test sorting places - visited_status""" print("Test sorting - visited:") place_collection.s_places("visited") print(place_collection) """Test listing places""" print("Test listing:") place_collection.list_all_places()
def press_entry(self, button): #Function that displays the 2nd message buttonID = button.id #Determine the id on the widget buttons selectedPlace = Place() for place in self.place_list.places: #Loop the Place within the Place list if buttonID == place.name: selectedPlace = place break message = "" #Mark the Place visited/unvisited if selectedPlace.is_visited == 'v': selectedPlace.mark_unvisited() if selectedPlace.is_important(): message = "You need to visited {}.Get going!".format( selectedPlace.name) else: message = "You need to visited {}.".format(selectedPlace.name) else: selectedPlace.mark_visited() if selectedPlace.is_important(): message = "You visited {}.Great travelling!".format( selectedPlace.name) else: message = "You visited {}.".format(selectedPlace.name) self.root.ids.entriesBox.clear_widgets() #Apply to Kivy GUI self.create_widgets() self.message2 = message
def add_new_place(self): """ adds new place to the place collection """ # Get the text from the text inputs new_place = self.root.ids.new_place.text new_country = self.root.ids.new_country.text new_priority = self.root.ids.new_priority.text if new_place == BLANK_STRING or new_country == BLANK_STRING or new_priority == BLANK_STRING: self.update_program_status_bar("All fields must be completed") else: try: new_priority = int(new_priority) if new_priority < 0: self.update_program_status_bar( "Please enter a number >= 0") self.update_program_status_bar( "Please enter a number <= 0") else: self.root.ids.new_place.text = BLANK_STRING self.root.ids.new_country.text = BLANK_STRING self.root.ids.new_priority.text = BLANK_STRING self.place_collections.add_place( Place(new_place, new_country, new_priority)) self.sort_places(self.root.ids.select_day.text) self.update_program_status_bar( "{} {} from {} Added".format(new_place, new_country, new_priority)) except ValueError: self.update_program_status_bar("Please enter a valid number") except TypeError: self.update_program_status_bar("Please enter a valid number")
def __init__(self, filename, places): root = FromXmlFile(filename) walker = root.createTreeWalker(root.documentElement, NodeFilter.SHOW_ELEMENT, None, 0) while 1: nodeName = walker.currentNode.nodeName attribs = walker.currentNode.attributes if nodeName == 'game': self.startingPlace = attribs['startingPlace'].value elif nodeName == 'place': placeName = attribs['name'].value desc = attribs['description'].value currentPlace = Place(placeName, desc) places[placeName] = currentPlace elif nodeName == 'object': currentPlace.addObject(attribs['name'].value) elif nodeName == 'connection': currentPlace.addConnection(attribs['place'].value) next = walker.nextNode() if next is None: break
def main(): """Run the whole process""" print("Travel Tracker 1.0 - by <Yudan Zhang>") place_collection = PlaceCollection() placs_list = place_collection.load_places('places.csv') while True: choice = read_menu() if choice == 'L': place_collection.list_places() elif choice == 'A': new_place = validate_new_places() place_collection.add_place( Place(new_place[0], new_place[1], new_place[2], new_place[3])) elif choice == 'M': mark_places(place_collection, placs_list) elif choice == 'Q': print("""{} places saved to places.csv Have a nice day :)""".format(len(place_collection.places_list))) break else: print("Invalid menu choice")