def get_cards(status=""): """ Arguments: - status (optional): Name of a Trello List <str> Returns: <List(Item)> """ lists = get_lists() trello_cards = [] for _list in lists: list_name = str(status).strip().title() list_info = {"id": _list["id"], "name": list_name} if list_name.lower() == _list["name"].lower(): constructed_url = TRELLO_BASE_URL + "/lists/" + list_info[ "id"] + "/cards" response = requests.get(constructed_url, params=params).json() for card in response: trello_cards.append( Item(card["id"], card["name"], list_info["name"], card["desc"], card["badges"]["due"])) return trello_cards else: constructed_url = TRELLO_BASE_URL + "boards/" + TRELLO_BOARD_ID + "/cards" response = requests.get(constructed_url, params=params).json() for card in response: trello_cards.append( Item(card["id"], card["name"], get_list_name(card["idList"]), card["desc"], card["badges"]["due"])) return trello_cards
def read_hits(directory="scenesHits/run2/", hit_file_regex="hit*.txt"): items_map = {} all_items = [] hit_files = glob.glob(directory + hit_file_regex) for hit_file in hit_files: hit_name = hit_file.split('/')[-1] hit_num = int(hit_name[3:-4]) hit_items = read_hit(hit_file) cnt = 1 for url in hit_items: item_obj = Item() item_obj.url = extract_from_url(url) idx = -1 if item_obj in all_items: idx = all_items.index(item_obj) if idx == -1: item_obj.ground_truth_label = url.split('/')[-2] item_obj.hitID_array.append(hit_num) all_items.append(item_obj) items_map[(hit_num, cnt)] = item_obj else: all_items[idx].hitID_array.append(hit_num) items_map[(hit_num, cnt)] = all_items[idx] cnt += 1 return (len(hit_files), items_map, all_items)
def main(): cycles = 36 # 3 years N = 50 # sampling 50 lines # Save 10k per month into certificate deposite (Assuming APR = 1.115%) saving_item = Item(0.0, ConstantGrowthF(1.000915), ConstantGrowthF(10000.0)) # Buy 10k tsmc per month. tsmc_growthf = LoadNormalGrowthFFromPath("data/tsmc.p") tsmc_item = Item(0.0, tsmc_growthf, ConstantGrowthF(10000.0)) composite = Composite([saving_item, tsmc_item]) array_of_sum_amounts = [] for i in xrange(N): array_of_sum_amounts.append(composite.Run(cycles)) # Composite t = np.arange(0, len(array_of_sum_amounts[0]), 1) # Show Matplot for i in xrange(N): plt.plot(t, array_of_sum_amounts[i]) plt.ylim((0, 1200000)) plt.title("10k CD + 10k TSMC stock per month") plt.show()
def create_items(): return [ Item("Sword", 5, 0, 10), Item("Shield", 0, 5, 10), Item("Bow", 4, 2, 10), Item("Helmet", 0, 6, 10), Item("Dagger", 3, 3, 10) ]
def _process(image, annotations, detector, reid_model): result = detector.get_bboxes(img_filename) bboxes, crops = [], [] for row in range(len(result)): if result[row][4] < 0.3: continue x1, y1, x2, y2 = map(int, result[row][:4]) bbox = Bbox(x1=x1, y1=y1, x2=x2, y2=y2) bbox.clip(max_w=image.shape[1], max_h=image.shape[0]) bboxes.append(bbox) crops.append(image[bbox.y1:bbox.y2, bbox.x1:bbox.x2, :]) embeddings = reid_model.get_embeddings(crops) shelves_per_images: Dict[str, List[Shelve]] = {} for filename, shelves in annotations.items(): shelves_per_images[filename] = [] for shelve_idx, shelve in tqdm.tqdm(enumerate(shelves), total=len(shelves)): shelve_name, shelve_points = shelve shelve = Shelve(name='shelve_{}'.format(shelve_idx), points=[Point(x, y) for x, y in shelve_points]) shelves_per_images[filename].append(shelve) crops = [] for bbox, embedding in zip(bboxes, embeddings): area = bbox.intersection_area(shelve.points) if area <= 0: continue intersection_area = area / bbox.area if intersection_area <= threshold: continue item = Item(bbox, embedding=embedding) shelve.items.add(item) x1 = bbox.x1 y1 = bbox.y1 x2 = bbox.x2 y2 = bbox.y2 crops.append(image[y1:y2, x1:x2, :]) for filename, shelves in shelves_per_images.items(): for shelve in shelves: embeddings = np.array([item.embedding for item in shelve.items]) if len(embeddings) == 0: continue clustering = DBSCAN(eps=0.2, min_samples=2, metric='cosine').fit(embeddings) for item, label in zip(shelve.items, clustering.labels_): item.label = label return shelves_per_images
def test_inv_append(items, inv, *args, **kwargs): """ Test for inventory append functionality """ itemcount = len(items) for i in range(inv.MAX_ITEM_COUNT - itemcount): assert inv.append(Item(2)) is None assert inv.append(Item(1)) == "No room in inventory" assert len(inv) == inv.MAX_ITEM_COUNT #Separate tests for stackable items assert inv.append(Item(0)) is None assert inv.items[inv.items.index(Item(0))]._count == 2
def test_inv_append(items, inv, *args, **kwargs): """ Test for inventory append functionality """ itemcount = len(items) for i in range(inv.max_capacity - itemcount): assert inv.append(Item(2)) == f"{Item(2).name} added to inventory" assert inv.append(Item(1)) == "No room in inventory" assert len(inv) == inv.max_capacity #Separate tests for stackable items assert inv.append(Item(0)) == f"2 {Item(0).name} in container" assert inv.items[inv.items.index(Item(0))]._count == 2
def test_inv_equip_unequip(items, inv, *args, **kwargs): """ Test for inventory item equip/unequip functionality """ # Equipping items assert inv.equip(Item(1)) == f"You equip {Item(1).name}" assert inv.equip(Item(2)) == "You can't equip that" # Unequipping items assert inv.unequip('weapon') == f"You unequip {Item(1).name}" assert inv.unequip('off-hand') == "That slot is empty" assert inv.gear['head'] is None assert inv.gear['weapon'] is None
def giveItems(data): data.bag.medicine.append(Item('Healing','Potion', 5)) data.bag.medicine.append(Item('Healing','Super Potion', 5)) data.bag.medicine.append(Item('Healing','Hyper Potion', 5)) data.bag.medicine.append(Item('Healing','Max Potion', 5)) data.bag.medicine.append(Item('Healing','Full Restore', 5)) data.bag.balls.append(Item('Ball','PokeBall', 5)) data.bag.balls.append(Item('Ball','Great Ball', 5)) data.bag.balls.append(Item('Ball','Ultra Ball', 5)) data.bag.balls.append(Item('Ball','Master Ball', 5))
def update_shoppinglist(listid): """ Update the Shopping List """ user = get_user() current_list = get_shopping_list(user, listid) items = [item.name for item in current_list.items] if request.method == 'POST': name = request.form.get('listname') items = request.form.get('listitems') items = items.split('\n') current_list.update_list(name) itemid = 1 new_items = list() for item in items: new_item = Item(itemid, item) itemid += 1 new_items.append(new_item) current_list.items = new_items return redirect(url_for('shopping_list')) return render_template('addshoppinglist.html', shoplist=current_list, items=items, edit=True)
def add_shopping_list(): """ Add shopping lists """ user = get_user() if request.method == "POST": name = request.form["listname"] items = request.form["listitems"] items = items.split('\n') if len(user.shopping_lists) == 0: listid = 1 else: listid = len(user.shopping_lists) + 1 today = datetime.date.today() shoplist = ShoppingList(listid, name, today) for item in items: if len(shoplist.items) == 0: itemid = 1 else: itemid = shoplist.count_items() + 1 if item: new_item = Item(itemid, item) shoplist.add_item(new_item) user.add_list(shoplist) return redirect(url_for('shopping_list')) return render_template('addshoppinglist.html')
class MyTest(unittest.TestCase): item = Item() def test_add(self): abc = Operations() actual_result = abc.add(5, 6) expected_result = 11 self.assertEqual(expected_result, actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(6) # expected_result = True # self.assertEqual(expected_result, actual_result) self.assertTrue(actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(5) self.assertFalse(actual_result) def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result)
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view1(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view2(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view3(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_update_item(self): result = self.item.update_item(4, "khana", "non-veg", 220) self.assertTrue(result) def test_update_item1(self): result=self.item.update_item(4, "khana", "veg", 200) self.assertFalse(result) def test_delete_item(self): result=self.item.delete_item(4) self.assertFalse(result) def test_add_order(self): result=self.order.add_order(4[]) self.assertTrue(result)
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view_1(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view_2(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_update_item(self): result = self.item.update_item(5, "Masu", "veg", 600) self.assertTrue(result) def test_delete_item(self): result = self.item.delete_item(5) self.assertTrue(result) def test_delete_item_1(self): result = self.item.delete_item("aa") self.assertFalse(result) def test_add_order(self): result = self.order.add_order(5, ("burger", "chicken", "150")) self.assertTrue(result)
def test_inv_remove(items, inv, *args, **kwargs): """ Test for inventory item removal """ inv.items[inv.items.index(Item(0))]._count += 2 # Non-stackable items assert inv.remove(Item(1)) is None assert inv.items.count(Item(1)) == 0 # Stackable items assert inv.remove(Item(0)) is None assert inv.items.count(Item(0)) == 1 assert inv.remove(Item(0), count=3) == "You don't have that many" assert inv.remove(Item(0), count=2) is None assert inv.items.count(Item(0)) == 0
def test_inv_remove(items, inv, *args, **kwargs): """ Test for inventory item removal """ inv.items[inv.items.index(Item(0))]._count += 2 # Non-stackable items assert inv.remove(Item(1)) == f"{Item(1).name} was successfully removed" assert inv.items.count(Item(1)) == 0 # Stackable items assert inv.remove( Item(0) ) == f"1/{inv.items[inv.items.index(Item(0))]._count+1} {Item(0).name} removed" assert inv.items.count(Item(0)) == 1 assert inv.remove(Item(0), count=3) == "You don't have that many" assert inv.remove(Item(0), count=2) == f"{Item(0).name} was successfully removed" assert inv.items.count(Item(0)) == 0
# Initialization window and graphic library window = pygame.display.set_mode((450, 450)) background = pygame.image.load('graphics/background.png').convert() wall = pygame.image.load('graphics/wall.png').convert() win = pygame.image.load('graphics/win.png').convert() lose = pygame.image.load('graphics/lose.png').convert() # Initialization of the player, grid and exit player = Player() exit = Exit() grid = generate_grid(player, exit) # Item creation and insertion in grid # Item no.1 needle = Item("Needle", 'graphics/item1.png') needle.set_coord(generate_random_coordinates()) grid = put_item_in_grid(grid, needle, player, exit) # Item no.2 ether = Item("Ether", 'graphics/item2.png') ether.set_coord(generate_random_coordinates()) grid = put_item_in_grid(grid, ether, player, exit) # Item no.3 tube = Item("Tube", 'graphics/item3.png') tube.set_coord(generate_random_coordinates()) grid = put_item_in_grid(grid, tube, player, exit) # Display of the grid display_grid(grid, window, wall, background, exit, player)
community_center: [elevator], gym: [elevator] } # crystal_location = { # josh_room: [liz_office, kitchen, elevator, roof, community_center, gym], # liz_office: [josh_room, kitchen, elevator, roof, community_center, gym, # kitchen: [liz_office, josh_room, elevator, roof, community_center, gym], # elevator: [liz_office, josh_room, kitchen, roof, community_center, gym], # roof: [liz_office, josh_room, kitchen, community_center, gym, elevator], # community_center: [liz_office, josh_room, kitchen, roof, community_center, gym], # gym: [liz_office, kitchen, elevator, roof, community_center, josh_room] # } # Items Instantiation # Josh's Room monitor = Item("monitor", josh_room, "pass", False, 40) jacket = Item("jacket", josh_room, "shirt", False, -25) bag_of_chips = Item("bag of chips", josh_room, "pass", "pass", 35) items_josh_room = [monitor, jacket, bag_of_chips] # Liz's Room tshirt = Item("t-shirt", liz_office, "shirt", False, -20) # input code in book and if you can solve unlocks ryan phone number and he distracts security guard for you book = Item("book", liz_office, "pass", "pass") keyboard = Item("keyboard", liz_office, "pass", "pass", 20) items_liz_office = [tshirt, book, keyboard] # # Elevator key_card = Item("Dropped Key Card", elevator, "pass", "pass") trash_can = Item("Trash Can", elevator, "pass", "pass", 0, -10) items_elevator = [key_card, trash_can]
def afterDead(self, bot=None, user=None): body = Item(protoId=101, locationId=self.locationId) if bot and user: user.addExp(bot, 400)
# CLEAR BROWSER CACHE EVERY TIME OR ELSE THINGS WON'T UPDATE PROPERLY # Settings > Additional Settings > Privacy & Security > Clear browsing data > Only select "Cached images and files" my_ical = "https://eastsideprep.instructure.com/feeds/calendars/user_MPUy1VMR3ETeTWnqhcr7AwY5ni2jUfM4UgHu14T9.ics" # If `entrypoint` is not defined in app.yaml, App Engine will look for an app # called `app` in `main.py`. app = Flask(__name__) #TESTING VARS username = "******" fname = "Everest" lname = "Oreizy" test_items = [ Item(0, "CW Tener Mas", "n", False, datetime.date(2020, 10, 11), datetime.date(2020, 10, 15)), Item(1, "Contemplation Day 13", "n", False, datetime.date(2020, 10, 11), datetime.date(2020, 10, 12)), Item(2, "Rational Roots", "nx", False, datetime.date(2020, 10, 11), datetime.date(2020, 10, 13)), Item(3, "Mixed Nomenclature", "nx", False, datetime.date(2020, 10, 12), datetime.date(2020, 10, 15)), Item(4, "Lab 4", "lab4", True, datetime.date(2020, 10, 11), datetime.date(2020, 10, 12)), Item("string", "SM3DAS", "sm3d", False, datetime.date(2020, 10, 15), datetime.date(2020, 10, 16)) ] @app.route('/', methods=['GET']) def hello():
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add(self): abc = Operations() actual_result = abc.add(5, 6) expected_result = 11 self.assertEqual(expected_result, actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(6) # expected_result = True # self.assertEqual(expected_result, actual_result) self.assertTrue(actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(5) self.assertFalse(actual_result) def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order(5, listdata) self.assertTrue(data) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order("five", listdata) self.assertFalse(data) def test_order_items(self): listdata = [("", "")] data = self.order.add_order(5, listdata) self.assertFalse(data) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order("", listdata) self.assertFalse(data) def test_ordershow_items(self): data = self.order.show_orders_by_order_id(3) actual_result = len(data) expected_result = 3 self.assertEqual(expected_result, actual_result) def test_showallorder(self): data = self.order.show_all_orders() actual_result = len(data) expected_result = 44 self.assertEqual(expected_result, actual_result) def test_showallorder(self): data = self.order.show_all_orders() actual_result = len(data) expected_result = 42 self.assertNotEqual(expected_result, actual_result)
def mutate(population, elite): for i in range(elite, len(population)): r1 = random.uniform(0, 1) if r1 < mutation_probability: r2 = random.randint(0, len(population[i].packed)-1) population[i].packed[r2] = not population[i].packed[r2] pop_size = 25 mutation_probability = 0.75 elite = int(pop_size * 0.2) max_iter = 100 threshold = 165 items = [Item(92, 23), Item(57, 31), Item(49, 29), Item(68, 44), Item(60, 53), Item(43, 38), Item(67, 63), Item(84, 85), Item(87, 89), Item(72, 82)] pop = init_pop(pop_size, items) eval_pop(pop, threshold) progress = [pop[0].fitness] for i in range(max_iter): pop = crossover(pop, elite) mutate(pop, elite) eval_pop(pop, threshold) progress.append(pop[0].fitness) print("Solution: " + str(pop[0])) print("Value of the best solution: " + str(pop[0].fitness))
def extract_single_line_items_from_column(page_data, column_box=None, bullets=[]): # extract all the words in the page words = list(extract_word_list(page_data)) + bullets # excluding any that aren't in the column, if box was provided if column_box: words = [word for word in words if word.bounding_box in column_box] # build up a list of the clusters as we find them clusters = [] # sort words by leftmost X value, so that we seed the initial clusters with vertical diversity words = sorted(words, key=lambda word: word.bounding_box.x1) # loop over the words and add them one by one to the best cluster, or create a new cluster for word in words: # keep track of the most overlapping cluster, ignoring any with < 0.1 overlap cluster_i = None cluster_overlap = 0.2 # loop over the existing clusters to find the one with the most overlap for i, cluster in enumerate(clusters): overlap = word.bounding_box.overlap(cluster["box"], axis="y") if overlap > cluster_overlap: cluster_overlap = overlap cluster_i = i if cluster_i is None: # if no overlapping cluster was found, create a new one clusters.append({"box": word.bounding_box, "words": [word]}) else: # if we found the cluster with the largest overlap, add to that # bullets should only be the starts of clusters, so toss false positives if word.text in ["•", "-"]: continue cluster = clusters[cluster_i] cluster["box"] = cluster["box"] | word.bounding_box cluster["words"].append(word) # sort the clusters (lines) by top Y value to put them in sequential order clusters = sorted(clusters, key=lambda cluster: cluster["box"].y1) # remove duplicate bullets for cluster in clusters: if len(cluster["words"]) < 2: continue w1, w2 = cluster["words"][:2] if ( w1.bounding_box.overlap(w2.bounding_box) > 0.05 and w1.text.strip() == w2.text.strip() ): cluster["words"].pop(1) items = ItemList([]) for cluster in clusters: # if not cluster["words"]: line = Line(words=cluster["words"]) bullet = line.extract_bullet_by_pattern() items.append(Item(lines=[line], bullet=bullet)) column_box = items.get_box(include_bullet=True).expanded(0.02) for item in items: item.lines[0].column_box = column_box remove_empty_lines_and_items(items) return items
from classes import Room, Person, Item, GameState, Enemy from types import MethodType #Define some items potatoes = Item('Bag of potatoes',['potatoes', 'taters', 'potats', 'spuds']) backpack = Item('Backpack',['bag', 'backpack', 'rucksack']) def updateMaxItems(self, person): person.maxItems = 5 backpack.takeFunction = MethodType(updateMaxItems, backpack) def dropEverything(self, person): for item in person.items: person.removeItem(item) person.room.addItem(item) backpack.dropFunction = MethodType(dropEverything, backpack) food = Item('Some food',['food', 'foods']) water = Item('A bottle of water',['water', 'bottle', 'waters']) boots = Item('Walking boots',['boots', 'walking boots', 'shoes']) stick = Item('Stick',['stick', 'twig', 'branch']) #Define some enemies cow = Enemy('Cow') #Construct some rooms startRoom = Room()
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler from telegram import InlineKeyboardButton, InlineKeyboardMarkup, InputMediaPhoto from classes import Item from datetime import datetime from db_manager import dbManager import sqlite3 from sqlite3 import Error import os db_file_path = os.path.join(os.getcwd(), "db\pythonsqlite.db") NAME, DESC, PRICE, PICTURE, DONE = range(5) i = Item() dibsKeyboard = InlineKeyboardMarkup([[InlineKeyboardButton("Dibs", callback_data='dibs')]]) def newitem(update, context): update.message.reply_text("It seems you want to add a new item, great! Let's get started. First, give me the name of the item you want to give away. Type \"Quit\" at any point to stop quit the process.") return NAME def name(update, context): update.message.reply_text("Next please me the description of the item(s).") i.name(update.message.text) return DESC def description(update, context): update.message.reply_text("Now tell me the price of the item. If it's free, simple send the 'free'") i.desc(update.message.text) return PRICE
class OrderView: def __init__(self): self.window = Tk() self.window.title('Orders') self.window.geometry('503x500+0+0') self.item = Item() self.order = Order() self.all_items = self.item.show_item() self.ordered_item_list = [] self.label_item = Label(self.window, text='Item') self.label_item.grid(row=0, column=0) self.combo_item = ttk.Combobox(self.window, state='readonly', width=27) self.combo_item.grid(row=0, column=1) # self.combo_item['values'] = self.all_items self.label_qty = Label(self.window, text='Qty') self.label_qty.grid(row=1, column=0) self.entry_qty = Entry(self.window, width=30) self.entry_qty.grid(row=1, column=1) self.btn_add_item = Button(self.window, text='Add >>', command=self.on_add_item) self.btn_add_item.grid(row=2, column=0) self.label_tbl = Label(self.window, text='Table No.') self.label_tbl.grid(row=3, column=0) self.entry_tbl = Entry(self.window, width=30) self.entry_tbl.grid(row=3, column=1) self.btn_add_order = Button(self.window, text='Submit Order', command=self.on_submit_order) self.btn_add_order.grid(row=4, column=0) self.btn_reset = Button(self.window, text='Reset', command=self.on_reset) self.btn_reset.grid(row=4, column=1) self.combo_order = ttk.Combobox(self.window) self.combo_order.grid(row=5, column=0) self.btn_show_order = Button(self.window, text='Show Order', command=self.show_orders_in_tree) self.btn_show_order.grid(row=5, column=1) self.order_tree = ttk.Treeview(self.window, column=('tbl', 'name', 'type', 'price', 'qty')) self.order_tree.grid(row=6, column=0, columnspan=2) self.order_tree['show'] = 'headings' self.order_tree.column('tbl', width=100, anchor='center') self.order_tree.column('name', width=100, anchor='center') self.order_tree.column('type', width=100, anchor='center') self.order_tree.column('price', width=100, anchor='center') self.order_tree.column('qty', width=100, anchor='center') self.order_tree.heading('tbl', text='Table No.') self.order_tree.heading('name', text='Name') self.order_tree.heading('type', text='Type') self.order_tree.heading('price', text='Price') self.order_tree.heading('qty', text='Qty') self.btn_bill = Button(self.window, text='Generate Bill', command=self.generate_bill) self.btn_bill.grid(row=7, column=0) self.show_items_in_combo() self.show_orders_in_combo() self.window.mainloop() def show_items_in_combo(self): show_items = [] for i in self.all_items: show_items.append((i[1], i[2])) self.combo_item['values'] = show_items def on_add_item(self): # item_id = self.combo_item.get()[0] item_index = self.combo_item.current() # item_id = self.all_items[item_index][0] item = self.all_items[item_index] qty = self.entry_qty.get() self.ordered_item_list.append((item[0], qty)) self.order_tree.insert('', 'end', text='', value=('', item[1], item[2], item[3], qty)) def on_submit_order(self): if self.combo_order.get() == '': tbl = self.entry_tbl.get() if self.order.add_order(tbl, self.ordered_item_list): messagebox.showinfo('Order', 'Order added') self.show_orders_in_combo() else: messagebox.showerror('Error', 'Order can not added') else: order_id = self.combo_order.get() if self.order.add_order_to_prev_customer(self.ordered_item_list, order_id): messagebox.showinfo('Order', 'Order added') self.show_orders_in_combo() else: messagebox.showerror('Error', 'Order can not added') self.ordered_item_list.clear() def show_orders_in_combo(self): self.combo_order['values'] = self.order.show_all_orders() def show_orders_in_tree(self): order_id = self.combo_order.get() if order_id == '': messagebox.showerror('Error', 'Select Order number First') else: orders = self.order.show_orders_by_order_id(order_id) self.order_tree.delete(*self.order_tree.get_children()) for i in orders: self.order_tree.insert('', 'end', text='', value=i) def on_reset(self): self.combo_order.set('') self.entry_qty.delete(0, END) self.entry_tbl.delete(0, END) self.order_tree.delete(*self.order_tree.get_children()) self.ordered_item_list.clear() def generate_bill(self): if self.combo_order.get() == '': messagebox.showerror('Error', 'Select Order number First') else: orders = self.order_tree.get_children() if len(orders) == 0: messagebox.showerror('Error', 'Show order first') else: total = 0 bill_list = [] tbl_no = self.order_tree.item(orders[0], 'values')[0] for i in orders: order = self.order_tree.item(i, 'values') amt = float(order[3]) * float(order[4]) total += amt bill_list.append( (order[1], order[2], order[3], order[4], amt)) # tbl_no = order[0] BillView(bill_list, total, tbl_no)
def inner(*args, **kwargs): items = [Item(i) for i in range(kwargs.get("itemcount", 3))] inv = Inventory(items=deepcopy(items), **kwargs) return testcase(items, inv, *args, **kwargs)
from classes import Room, Item, Weapon, Food, Creature, Player import random #-----------ITEMS---------------------------- echo = Item("echo", "an amazon echo, it seems to still be working.", True, [examine, break, take, drop, get]) echo_dot = Item("echo dot", "an amazon echo dot. It seems to still be working.", True, [examine, break, take, drop, get]) button = Item("button", "a button, it can be pressed.", True, [use, examine, break, take, drop, get]) paper = Item("paper", "a piece of paper, ot seems to have something on it.", False, [break, examine, cut, take, drop, read, get]) kindle = Item("kindle", "an amazon kindle paperwhite model 5.", True, [take, drop, break, examine, read, get]) computer = Item("computer", "a large white apple iMac.", True, [break, examine]) torch = Item("torch", "a flashlight.", True, [break, drop, examine, take, get]) tree = Item("tree", "an enormous tree, which looks like it may be climbable.", False, [climb]) gloves = Item("gloves", "a medium sized pair of gloves, they are slightly worn out", False, [drop, examine, take, get]) climbing_shoes = Item("climbing shoes", "a large pair of climbing shoes, this could be helpful on slopes", False, [climb, drop, examine, take, get]) body = Item("body", "a perfectly preserved corpse with a slightly surprised expression on its face", False, [examine, eat]) rock = Item("rock", "a large rock, it looks slightly lodged", False, [examine, move, search]) car = Item("car", "a rusty old car, it hasn't run in years", False, [examine, search]) backpack = Item("backpack", "a dark blue backpack with something in it", False, [drop, examine, open, take, get]) macbook = Item("macbook", "an old macbook from before the linux uprising", True [break, drop, examine, take, get]) hollowed_tree = Item("hollowed tree", "a hollowed out tree, there could be something inside", False, [climb, examine, search]) #----------WEAPONS---------------------------- sword = Weapon("sword", "a beautiful and ancient-looking sword of fearsome proportions.", False, [take, get, drop], 5) knife = Weapon("knife", "a short and deadly knife, it has a look of brutality.", False, [take, get, drop], 3) machete = Weapon("machete", "a long curved machete, it looks pretty sharp.", False, [take, get, drop], 4) pistol = Weapon("pistol", "a lovingly maintained Glock, ready to fire.", False, [take, get, drop], 7) rifle = Weapon("rifle", "a semi-automatic rifle with a pretty hardcore military vibe.", False, [take, get, drop], 10)
def __init__(self): self.window = Tk() self.window.title('Orders') self.window.geometry('503x500+0+0') self.item = Item() self.order = Order() self.all_items = self.item.show_item() self.ordered_item_list = [] self.label_item = Label(self.window, text='Item') self.label_item.grid(row=0, column=0) self.combo_item = ttk.Combobox(self.window, state='readonly', width=27) self.combo_item.grid(row=0, column=1) # self.combo_item['values'] = self.all_items self.label_qty = Label(self.window, text='Qty') self.label_qty.grid(row=1, column=0) self.entry_qty = Entry(self.window, width=30) self.entry_qty.grid(row=1, column=1) self.btn_add_item = Button(self.window, text='Add >>', command=self.on_add_item) self.btn_add_item.grid(row=2, column=0) self.label_tbl = Label(self.window, text='Table No.') self.label_tbl.grid(row=3, column=0) self.entry_tbl = Entry(self.window, width=30) self.entry_tbl.grid(row=3, column=1) self.btn_add_order = Button(self.window, text='Submit Order', command=self.on_submit_order) self.btn_add_order.grid(row=4, column=0) self.btn_reset = Button(self.window, text='Reset', command=self.on_reset) self.btn_reset.grid(row=4, column=1) self.combo_order = ttk.Combobox(self.window) self.combo_order.grid(row=5, column=0) self.btn_show_order = Button(self.window, text='Show Order', command=self.show_orders_in_tree) self.btn_show_order.grid(row=5, column=1) self.order_tree = ttk.Treeview(self.window, column=('tbl', 'name', 'type', 'price', 'qty')) self.order_tree.grid(row=6, column=0, columnspan=2) self.order_tree['show'] = 'headings' self.order_tree.column('tbl', width=100, anchor='center') self.order_tree.column('name', width=100, anchor='center') self.order_tree.column('type', width=100, anchor='center') self.order_tree.column('price', width=100, anchor='center') self.order_tree.column('qty', width=100, anchor='center') self.order_tree.heading('tbl', text='Table No.') self.order_tree.heading('name', text='Name') self.order_tree.heading('type', text='Type') self.order_tree.heading('price', text='Price') self.order_tree.heading('qty', text='Qty') self.btn_bill = Button(self.window, text='Generate Bill', command=self.generate_bill) self.btn_bill.grid(row=7, column=0) self.show_items_in_combo() self.show_orders_in_combo() self.window.mainloop()
def processRow(website, row, profession, lang): columns = row.find_all('td') if len(columns) == 0: return None try: plvl = columns[0].string.strip() except: plvl = -1 try: name = columns[2].a.string.strip() except: name = -1 try: commission = htmlToCopper(columns[3].contents) except: commission = -1 try: profeciency = columns[4].string.strip() except: profeciency = -1 try: focus = columns[5].string.strip() except: focus = -1 try: quantity = columns[7].div.contents[0].string.replace('x', '').strip() except: quantity = -1 try: morale = columns[8].string.strip() except: morale = -1 try: time = columns[9].string.strip() except: time = -1 if focus != -1: try: focusMin = int(focus.split('-')[0].strip()) except ValueError: focusMin = 0 try: focusMax = int(focus.split('-')[1].strip()) except ValueError: focusMax = 0 else: focusMin = -1 focusMax = -1 item_ref = columns[7].a['href'] infos = processItemPage(website + item_ref) item = Item.Item(name, lang, infos[0], infos[1], infos[2], infos[3], infos[4], quantity, plvl, profession, commission, morale, time, focusMin, focusMax, profeciency) if len(columns[6].contents) > 2: for i in range((len(columns[6].contents) - 1) / 3): q = columns[6].contents[3 * int(i)].replace('x', '').replace( ',', '').strip() n = columns[6].contents[3 * int(i) + 1]['title'] item.addMaterial(q, n) return item
from classes import Room, Item, Weapon, Food, Creature, Player import random #-----------ITEMS---------------------------- echo = Item("echo", "an amazon echo, it se") echo_dot = Item("echo dot", "an amazon echo") echo_show = Item() button = Item() paper = Item() kindle = Item() computer = Item() torch = Item() tree = Item() gloves = Item() climbing_shoes = Item() body = Item() rock = Item() car = Item() backpack = Item() macbook = Item() hollowed_tree = Item() #----------WEAPONS---------------------------- sword = Weapon() knife = Weapon() machete = Weapon() pistol = Weapon() rifle = Weapon() #---------FOOD-------------------------------- chocolate = Food()