def stack(bid): if bid % 100 == 0: print 'bundle', bid+1 presents = np.load('data/w300/bundle%04d.npz' % (bid+1))['presents'] ysort = np.argsort(presents[:, 2])[::-1] presents = presents[ysort] sleigh = Sleigh(bid, len(presents)) x, y, z = 1, 1, 1 skip = list() znext = 0 i = 0 while i < len(presents) - 1: shelf = Shelf(sleigh, presents[i, 2], x, y, z) i, skip = shelf.fill(presents[i:], i, skip) if shelf.zmax > znext: znext = shelf.zmax if i >= len(presents) - 1: break if y + shelf.height - 1 > 1000: print 'new layer' z = znext y = 1 else: y += shelf.height return sleigh
def stack(bid): if bid % 100 == 0: print 'bundle', bid + 1 presents = np.load('data/w300/bundle%04d.npz' % (bid + 1))['presents'] ysort = np.argsort(presents[:, 2])[::-1] presents = presents[ysort] sleigh = Sleigh(bid, len(presents)) x, y, z = 1, 1, 1 skip = list() znext = 0 i = 0 while i < len(presents) - 1: shelf = Shelf(sleigh, presents[i, 2], x, y, z) i, skip = shelf.fill(presents[i:], i, skip) if shelf.zmax > znext: znext = shelf.zmax if i >= len(presents) - 1: break if y + shelf.height - 1 > 1000: print 'new layer' z = znext y = 1 else: y += shelf.height return sleigh
def read_warehouse_data(): global max_x, max_y with open(warehouse_items_path) as csvfile: reader = csv.reader(csvfile) for i, rows in enumerate(reader): if len(rows) == 3: item_id = rows[0] x = int(float(rows[1])) * 2 + 1 y = int(float(rows[2])) * 2 + 1 point = Point(x, y) item = Item(rows[0], x, y) new_shelf = Shelf(x, y) if shelves.get(point) is not None: shelf = shelves.get(point) shelf.put(item) database[item_id] = shelf else: new_shelf.put(item) shelves[point] = new_shelf database[item_id] = new_shelf x_coord.append(x) y_coord.append(y) if (x > max_x): max_x = x if (y > max_y): max_y = y
def positive_tests(self): # test add_order new_order = self.generate_order() shelf1 = Shelf(new_order.temperature) order_added = shelf1.add_order(new_order) self.assertTrue(order_added) # test pickup_order pickup_order = shelf1.pickup_order(new_order.id) self.assertEqual(new_order, pickup_order) # test has_capacity has_capacity = shelf1.has_capacity() self.assertTrue(has_capacity) # test dispose random order shelf1.add_order(new_order) waste_order = shelf1.dispose_random_order() self.assertEqual(new_order, waste_order) self.assertEqual(0, len(shelf1.orders)) # test clean up order OrderTestCase.add_orders_to_capacity(shelf1) self.assertEqual(CAPACITY, len(shelf1.orders)) list(shelf1.orders.values())[0].order_state = ORDER_PICKEDUP removed = shelf1.cleanup_orders() self.assertEqual(True, removed) self.assertEqual(CAPACITY - 1, len(shelf1.orders)) list(shelf1.orders.values())[0].order_time -= 1000 removed = shelf1.cleanup_orders() self.assertEqual(True, removed) self.assertEqual(CAPACITY - 2, len(shelf1.orders))
def __create_shelves(self): for temp in SUPPORTED_TEMPERATURES: self.shelves[temp] = Shelf(temp) assert OVERFLOW_SHELF_NAME not in self.shelves, \ "{} already exists in supported shelves {}"\ .format(OVERFLOW_SHELF_NAME, SUPPORTED_TEMPERATURES) self.shelves[OVERFLOW_SHELF_NAME] = Shelf(OVERFLOW_SHELF_NAME, True)
class Basketball: def __init__(self, radius=40, image_file="bb.jpg"): self.radius = radius self.image_file = image_file label = "Basketball\n----------\n- Rotation via X, Y, Z axes\n- Scaling\n- On/Off Texture" self.shelf = Shelf(label = label) self.scale = 1 self.texture_status = True self.load_textures() # rotational values self.xrot = self.yrot = self.zrot = True self.rot = 0.0 def load_textures(self): texture_file = os.getcwd() + os.path.join('/images', self.image_file) texture_surface= image.load(texture_file) texture = texture_surface.image_data.create_texture(image.Texture) glBindTexture(GL_TEXTURE_2D, texture.id) # glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) # glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) self.texture = texture def draw(self): # draw the shelf glPushMatrix() glRotatef(90, 1, 0, 0) self.shelf.draw() glPopMatrix() # Enable/Disabling texture if self.texture_status: glBindTexture(GL_TEXTURE_2D, self.texture.id) else: glDisable(GL_TEXTURE_2D) # draw the bird glPushMatrix() glScalef(self.scale, self.scale, self.scale) glTranslatef(0, 2 * self.radius, 0) glRotatef(self.rot, int(self.xrot), int(self.yrot), int(self.zrot)) quad = gluNewQuadric() gluQuadricTexture(quad, GL_TRUE) gluSphere(quad, self.radius, 100, 100) glPopMatrix() # resetting texture status for drawing other objects glEnable(GL_TEXTURE_2D) def update(self): # a bit of a hack, I guess .. weird if(self.xrot == False and self.yrot == False and self.zrot == False): self.rot += 0.0 else: self.rot += 0.5 self.shelf.update()
class Teapot: def __init__(self, size=40, image_file='silverware.jpg'): self.size = size self.scale = 1 self.texture_status = True self.image_file = image_file self.load_textures() label = "Teapot\n----------\n- Rotation via X, Y, Z axes\n- Scaling\n- On/Off Texture" self.shelf = Shelf(label = label) # rotational values self.xrot = self.yrot = self.zrot = True self.rot = 0.0 def load_textures(self): texture_file = os.getcwd() + os.path.join('/images', self.image_file) texture_surface = image.load(texture_file) texture = texture_surface.image_data.create_texture(image.Texture) glBindTexture(GL_TEXTURE_2D, texture.id) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) self.texture = texture def draw(self): # draw the shelf glPushMatrix() glRotatef(90, 1, 0, 0) self.shelf.draw() glPopMatrix() if self.texture_status: glBindTexture(GL_TEXTURE_2D, self.texture.id) else: glDisable(GL_TEXTURE_2D) glColor3f(0, 0, 0) # draw the teapot glPushMatrix() glScalef(self.scale, self.scale, self.scale) glTranslatef(0, 2 * self.size, 0) glRotatef(self.rot, int(self.xrot), int(self.yrot), int(self.zrot)) glutSolidTeapot(self.size) glPopMatrix() glColor3f(1, 1, 1) # resetting texture glEnable(GL_TEXTURE_2D) def update(self): # a bit of a hack, I guess .. weird if(self.xrot == False and self.yrot == False and self.zrot == False): self.rot += 0.0 else: self.rot += 0.5 self.shelf.update()
def main(): print 'starting up' shelf = Shelf() listener = ShelfListener() shelf.addEventListener(listener) shelf.startGovernor() #st = ShelfState() shelf_id = requests.get("http://iot.vpolevoy.com/api/register/").json()["board_id"] service = threading.Thread(target = service_thread, args = [None]) service.start() service.join()
def shelf(): log('启动挂出繁育定时任务') shelf = Shelf(cookie) try: # shelf.shelf_all(100, 0) # shelf.shelf_all(100, 1) # shelf.shelf_all(100, 2) rare_degree_price_dic = {0: 100, 1: 100, 2: 100, 3: 1000, 4: 100000, 5: 1000000} shelf.shelf_all_once(rare_degree_price_dic) except: traceback.print_exc() log('挂出繁育定时任务执行完成')
def shelf(): logger.info('启动挂出繁育定时任务') shelf = Shelf(cookie) try: # rare_num_price_dic = {0: 100, 1: 100, 2: 100, 3: 100, 4: 500, 5: 10000} rare_num_price_dic = {0: 100, 1: 100, 2: 100, 3: 100, 4: 500} # 按稀有属性数量批次挂出繁育,时间上会成倍增加,如不需按稀有数量批次上架请使用shelf_by_rare_num_once # shelf.shelf_by_rare_nums(rare_num_price_dic) # 按稀有属性数量一次性挂出繁育所有的狗 shelf.shelf_by_rare_nums_once(rare_num_price_dic) except: traceback.print_exc() logger.info('挂出繁育定时任务执行完成')
def __create_shelves(self): self.shelves.append( Shelf(0, (0.02, 0.1, 0.33, 0.15), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(1, (0.02, 0.25, 0.33, 0.3), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(2, (0.02, 0.4, 0.33, 0.45), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(3, (0.02, 0.55, 0.33, 0.6), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(4, (0.37, 0.1, 0.65, 0.15), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(5, (0.37, 0.25, 0.65, 0.3), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(6, (0.37, 0.4, 0.65, 0.45), self.screen.get_size()[0], self.screen.get_size()[1])) self.shelves.append( Shelf(7, (0.37, 0.55, 0.65, 0.6), self.screen.get_size()[0], self.screen.get_size()[1])) self.set_shelves()
def get_modulefile_path(package_name): """Generate the modulefile path from module name""" s = Shelf() if package_name not in s.installed_packages: raise Exception('Package {} not installed'.format(package_name)) package = s.find_package(package_name) name = package.name version = package.version return os.path.join(settings.module_dir, name, version)
def negative_tests(self): shelf1 = Shelf(SUPPORTED_TEMPERATURES[0]) # over capacity OrderTestCase.add_orders_to_capacity(shelf1) extra_order_added = shelf1.add_order(self.generate_order()) self.assertFalse(extra_order_added) # pickup order (non exist) pickup_order = shelf1.pickup_order(str(uuid4())) self.assertEqual(None, pickup_order) # test has_capacity has_capacity = shelf1.has_capacity() self.assertFalse(has_capacity)
def install_package(package_name): """Given a package name, determine package dependencies, install if necessary and then install the package.""" print 'Installing {0}'.format(package_name) # Generate build environment build_env = BuildEnvironment() current_shelf = Shelf() setup_own_gcc(current_shelf, build_env) package_blueprint = load_blueprint_by_name(package_name) dependencies = package_blueprint.direct_dependencies missing_dependencies = set(dependencies) - set( current_shelf.installed_packages) for dependency in missing_dependencies: install_package(dependency) for dependency in dependencies: package = current_shelf.find_package(dependency) package.update_env_manager(build_env) yaml_builder = builder_by_name_yaml(package_name, load_dependencies=False) try: extra_CPPFLAGS = yaml_builder.env_manager.extra_CPPFLAGS except AttributeError: extra_CPPFLAGS = '' build_env.extra_CPPFLAGS = extra_CPPFLAGS yaml_builder.env_manager = build_env yaml_builder.env_manager.update_CPPFLAGS() yaml_builder.env_manager.update_LDFLAGS() yaml_builder.process_all_stages() yaml_builder.yaml_rep['environment_flags'] = build_env.my_env yaml_rep = yaml.dump(yaml_builder.yaml_rep, default_flow_style=False) receipt_path = os.path.join(yaml_builder.shelf_dir, settings.receipt_file) with open(receipt_path, 'w') as f: f.write(yaml_rep)
def generate_modulefile_text(package_name): """Given an installed package, generate the modulefile text necessary to activate that package.""" s = Shelf() if package_name not in s.installed_packages: raise Exception('Package {} not installed'.format(package_name)) tloader = FileSystemLoader(settings.template_dir) tenv = Environment(loader=tloader) t = tenv.get_template(settings.module_template) package = s.find_package(package_name) return t.render(package=package)
def __init__(self, body_radius=50 ): self.body_radius = body_radius self.scale = 1 label = "Snowman\n----------\n - Lethal\n- Scaling" self.shelf = Shelf(label=label) # rotational values self.xrot = self.yrot = self.zrot = False self.rot = 0.0
def setUp(self): database = Database() shelf = Shelf() self.interp = Interpreter() self.cont = InterpreterController(self.interp, database, shelf) self.interp.attach(self.cont) if path.exists("output"): rmtree("output")
def list_installed_packages(args): s = Shelf() package_names = s.installed_packages.keys() package_names.sort() #print '\t'.join(package_names) pretty_columnular_output(package_names)
def load_templated_yaml_rep(name, all_packages=None): name = name.lower() tloader = FileSystemLoader(settings.yaml_dir) tenv = Environment(loader=tloader) blueprint_name = name + settings.yaml_ext t = tenv.get_template(blueprint_name) s = Shelf() if all_packages is None: all_packages = s.installed_packages loaded_packages = {name: s.find_package(name) for name in all_packages} t_rendered = t.render(packages=loaded_packages) return yaml.load(t_rendered)
def __init__(self, radius=40, image_file="bb.jpg"): self.radius = radius self.image_file = image_file label = "Basketball\n----------\n- Rotation via X, Y, Z axes\n- Scaling\n- On/Off Texture" self.shelf = Shelf(label = label) self.scale = 1 self.texture_status = True self.load_textures() # rotational values self.xrot = self.yrot = self.zrot = True self.rot = 0.0
def __init__(self, size=40, image_file='silverware.jpg'): self.size = size self.scale = 1 self.texture_status = True self.image_file = image_file self.load_textures() label = "Teapot\n----------\n- Rotation via X, Y, Z axes\n- Scaling\n- On/Off Texture" self.shelf = Shelf(label = label) # rotational values self.xrot = self.yrot = self.zrot = True self.rot = 0.0
def main(): filename = 'orders.json' json_data = get_json_data(read_json_file(filename)) shelf_type_to_capacity_dict = { "hot": 10, "cold": 10, "frozen": 10, "overflow": 10 } shelf = Shelf(shelf_type_to_capacity_dict=shelf_type_to_capacity_dict) kitchen = Kitchen(shelf=shelf) emit_every_time_interval(json_data, 2, kitchen) return
class Stack(object): def __init__(self, shelf=None): self.env_manager = EnvManager() self.included_components = {} if shelf == None: self.shelf = Shelf() def add_by_name(self, name, add_dependencies=False): """Add a component from a (string) name.""" if name in self.included_components: return package = self.shelf.find_package(name) self.included_components[name] = package package.update_stack(self) if add_dependencies: for dependency in package.direct_dependencies: self.add_by_name(dependency) def add_component(self, component): if component.name in self.included_components: return self.included_components[component.name] = component component.update_stack(self) for dependency in component.direct_dependencies: c_dep = load_component_by_name(dependency) self.add_component(c_dep) def shell(self): self.env_manager.shell() def __repr__(self): return "<Stack: {}>".format(','.join(self.included_components))
def main(): #creating the global store the_store = Store() print("Store created") #creating some people persons = [] persons.append(Employed("Andrea", "Baesso", "admin", "admin")) persons.append(Employed("Admino", "Nimda", "admino", "admino")) persons.append(Client("Tizio", "Uno", "tizio1", "tizio1")) persons.append(Client("Tizio", "Due", "tizio2", "tizio2")) #creating some shelves the_store.create_shelf(Shelf(the_store.shelves_id, Product.GROCERIES, 50)) the_store.create_shelf( Shelf(the_store.shelves_id, Product.FRUITS_AND_VEGETABLES, 50)) the_store.create_shelf(Shelf(the_store.shelves_id, Product.FISH, 10)) the_store.create_shelf(Shelf(the_store.shelves_id, Product.PASTA, 100)) the_store.create_shelf(Shelf(the_store.shelves_id, Product.BEVERAGE, 200)) the_store.create_shelf(Shelf(the_store.shelves_id, Product.HOME, 50)) the_store.create_shelf(Shelf(the_store.shelves_id, Product.OTHERS, 50)) #creating some products for each shelf the_store.insert_products( 0, Product(the_store.new_product_code(), "Bread type 0", Product.GROCERIES, 0.50), 20) the_store.insert_products( 0, Product(the_store.new_product_code(), "Bread type 1", Product.GROCERIES, 0.40), 20) the_store.insert_products( 0, Product(the_store.new_product_code(), "Bread type 2", Product.GROCERIES, 0.30), 20) the_store.insert_products( 0, Product(the_store.new_product_code(), "Bread type 3", Product.GROCERIES, 0.20), 20) # get_products for shelf in the_store.get_shelves(): shelf.get_products()
def __init__(self): ## CONSTANTS self.all_item_dict = { 1: 'red_block', 2: 'green_block', 3: 'blue_block', 4: 'shuangwaiwai', 5: 'yangleduo', 6: 'wahaha', 7: 'beer', 8: 'red_bull', 9: 'le_hu', 10: 'tennis_ball' 11: 'magic_cube' 12: 'deluxe_milk' } self.car = car.Car() self.shelves = dict() for key in ['A', 'B', 'C', 'D']: slef.shelves[key] = Shelf()
class ShelfUnitTests(TestCase): """Unittests for Shelf""" def setUp(self): self.shelf = Shelf() self.shelf.shelf_name = "test_shelve" def tearDown(self): if os.path.exists("test_shelve.dat"): os.remove('test_shelve.dat') os.remove('test_shelve.bak') os.remove('test_shelve.dir') def test_write_shelf(self): # Act self.shelf.write_shelf("tests/test_class_2.py") with shelve.open(self.shelf.shelf_name) as shelf: actual = bool(shelf) # Assert self.assertTrue(actual) def test_write_shelf_if_shelf_name_none(self): # Act actual = self.shelf.write_shelf("tests/test_class_2.py") # Assert self.assertIsNone(actual) def test_read_shelf(self): # Arrange self.shelf.write_shelf("tests/test_class_5.py") expected = "KEY: TEST_CLASS_5\n" expected += "Class Name: Plant\n" expected += "Attribute: plant_height\n" expected += "Function: __init__\n" expected += "Function: grow_plant\n" expected += "-"*20 + "\n" expected += "Class Name: Sunflower\n" expected += "Function: drop_seed\n" expected += "Parent: Plant\n" expected += "-"*20 + "\n" expected += "Class Name: Orchid\n" expected += "Parent: Plant\n" expected += "-"*20 + "\n" # Act actual = self.shelf.read_shelf() # Assert self.assertMultiLineEqual(expected, actual) def test_read_shelf_two_dict(self): self.shelf.write_shelf("./tests/test_class_1.py") self.shelf.write_shelf("tests/test_class_5.py") expected = "KEY: TEST_CLASS_1\n" expected += "Class Name: DemoClass\n" expected += "-" * 20 + "\n" expected += "KEY: TEST_CLASS_5\n" expected += "Class Name: Plant\n" expected += "Attribute: plant_height\n" expected += "Function: __init__\n" expected += "Function: grow_plant\n" expected += "-" * 20 + "\n" expected += "Class Name: Sunflower\n" expected += "Function: drop_seed\n" expected += "Parent: Plant\n" expected += "-" * 20 + "\n" expected += "Class Name: Orchid\n" expected += "Parent: Plant\n" expected += "-" * 20 + "\n" # Act actual = self.shelf.read_shelf() # Assert self.assertEqual(expected, actual) def test_read_shelf_exception_thrown(self): self.shelf.shelf_name = None with self.assertRaises(Exception): self.shelf.read_shelf() def test_clear_shelf(self): # Arrange self.shelf.clear_shelf() expected = [] # Act with shelve.open(self.shelf.shelf_name, 'r') as test_file: actual = list(test_file.keys()) # Assert self.assertListEqual(expected, actual)
def __init__(self, shelf=None): self.env_manager = EnvManager() self.included_components = {} if shelf == None: self.shelf = Shelf()
costText = buttonFont.render(str((currentUnlock + 2) * 20), True, YELLOW, None) buyButton.image.blit(costText, (235, 75)) shelfContents = [[0, "Apple", 20, 25, False], [1, "Banana", 2, 15, False], [2, "Bread", 3, 10, False], [3, "Water", 10, 100, False], [4, "Orange", 10, 15, False], [5, "Orange", 8, 15, True], [6, "Orange", 8, 15, True], [7, "Orange", 8, 15, True], [8, "Orange", 8, 15, True], [9, "Orange", 8, 15, True], [10, "Orange", 8, 15, True], [11, "Orange", 8, 15, True], [12, "Orange", 8, 15, True], [13, "Orange", 8, 15, True], [14, "Orange", 8, 15, True], [15, "Orange", 8, 15, True]] shelves = pygame.sprite.Group() for i in range(len(shelfContents)): shelves.add( Shelf(shelfContents[i][0], GREY, BLACK, shelfContents[i][1], shelfContents[i][2], shelfContents[i][3], shelfContents[i][4])) current = shelves.sprites()[-1] current.rect.x = 35 + ((i % 4) * 185) current.rect.y = 125 + ((i // 4) * 155) while carryOn: for event in pygame.event.get(): if event.type == pygame.QUIT: carryOn = False if event.type == pygame.MOUSEBUTTONDOWN: mousex, mousey = pygame.mouse.get_pos() if gameState == "play": for shelf in shelves: if shelf.isClicked(mousex, mousey): if shelf.quantity > 0 and not shelf.locked: money = shelf.buy(money)
from controller import InterpreterController from database import Database from shelf import Shelf from interpreter import Interpreter if __name__ == '__main__': database = Database() shelf = Shelf() interpreter = Interpreter() controller = InterpreterController(interpreter, database, shelf) interpreter.attach(controller) controller.start()
count += 1 dataFrame.pack(fill=tk.X) def sel(): sel = var.get() if sel is 1: add_book = tk.Tk() elif sel is 2: print(sel) elif sel is 3: print(sel) # Building data s = Shelf() s.add_book(12093840, "Linux Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(32984579, "Windows Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(10938457, "Python", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(10983530, "Pi Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(32984579, "Windows Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(12093840, "Linux Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(12093840, "Linux Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(12938743, "Linux PRO", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(12093840, "Linux Admin", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(12938743, "Linux PRO", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) s.add_book(86598056, "Linux dig", "English", "India", ["Rebello Williams"], "0.1a", 3050.00) # Shelf().search_isbn(12093840) # Shelf().get_books() build_ui(root)
class Snowman: def __init__(self, body_radius=50 ): self.body_radius = body_radius self.scale = 1 label = "Snowman\n----------\n - Lethal\n- Scaling" self.shelf = Shelf(label=label) # rotational values self.xrot = self.yrot = self.zrot = False self.rot = 0.0 def draw(self): # draw the shelf glPushMatrix() glRotatef(90, 1, 0, 0) self.shelf.draw() glPopMatrix() glDisable(GL_TEXTURE_2D) # draw the snowman glPushMatrix() glTranslatef(0, (self.body_radius * self.scale)+20, 0) quad = gluNewQuadric() gluQuadricNormals(quad, GLU_SMOOTH) # Main body glPushMatrix() glColor3f(1, 1, 1) gluSphere(quad, self.body_radius * self.scale, 100, 100) glTranslatef(0, self.body_radius * 1.5 * self.scale, 0) gluSphere(quad, self.body_radius * 0.75 * self.scale, 100, 100) glTranslatef(0, self.body_radius * self.scale, 0) gluSphere(quad, self.body_radius * 0.5 * self.scale, 100, 100) # Nose glColor3f(1, 0, 0) glTranslatef(0, 0, self.body_radius*0.5 * self.scale) gluCylinder(quad, self.body_radius * 0.1 * self.scale, 0.0, 20 * self.scale, 100, 100) # Two Eyes glColor3f(0, 0, 0) glTranslatef(-10 * self.scale, 10 * self.scale, 0) gluSphere(quad, self.body_radius * 0.03 * self.scale, 100, 100) glTranslatef(20 * self.scale, 0, 0) gluSphere(quad, self.body_radius * 0.03 * self.scale, 100, 100) glColor3f(1,1, 1) glPopMatrix() # Hat glPushMatrix() glColor3f(0, 0, 0) glTranslatef(0, self.body_radius * 2.85 * self.scale, 0) glRotatef(-90, 1, 0, 0) gluCylinder(quad, self.body_radius * 0.4 * self.scale, self.body_radius * 0.4 * self.scale, 45 * self.scale, 100, 100) # Hat brim glColor3f(0,0,0) gluDisk(quad, 17 * self.scale, 38 * self.scale, 100, 100) glPopMatrix() glPopMatrix() glColor3f(1, 1, 1) glEnable(GL_TEXTURE_2D) def update(self): self.shelf.update()
app.config['SECURITY_PASSWORD_SALT'] = 'mysalt'#"hash_123678*", app.config['SECURITY_SEND_REGISTER_EMAIL'] = False app.config['APP_ROOT'] = os.path.dirname(os.path.abspath(__file__)) app.config['APP_STATIC'] = os.path.join(app.config['APP_ROOT'], 'static') app.config['MEDIA_ROOT'] = os.path.join(app.config['APP_STATIC'], 'media') app.config['MEDIA_URL'] = '/static/media/' try: os.makedirs(app.config['MEDIA_ROOT']) except OSError: pass with app.app_context(): db.init_app(app) db.app = app shlf = Shelf(app) shlf.init_db(db) shlf.init_admin() shlf.init_security(User, Role) shlf.load_plugins(( "shelf.plugins.wysiwyg", "shelf.plugins.workflow", "shelf.plugins.library" )) shlf.admin.add_view(admin.PostModelView(model.Post, db.session)) shlf.admin.add_view(FileAdmin(name="Media")) shlf.setup_plugins() app.run('0.0.0.0')
def setUp(self): self.shelf = Shelf() self.shelf.shelf_name = "test_shelve"
def prepare_parents(self, father_rare_num, father_price, mother_rare_num): while True: try: father, mother = self.get_parents(father_rare_num, mother_rare_num) if not father or not mother: logger.warn('无满足条件的繁育双亲, 一分钟后重试') time.sleep(60) continue # 未上架繁育,将其上架 if father['shelfStatus'] == 0: logger.info('父亲狗狗{0}处于未上架繁育状态,将其上架'.format(father['petId'])) shelf = Shelf(self.cookie) shelf.shelf(father['petId'], father_price) # 等待3分钟避免错误:专属分享,3分钟后可购买 time.sleep(3 * 60) # 出售中,将其下架然后上架繁育 elif father['shelfStatus'] == 1: logger.info('父亲狗狗{0}处于售卖中, 将其下架, 三分钟后再挂出繁育'.format(father['petId'])) sale = Sale(self.cookie) sale.unsale(father['petId']) # 3分钟后再挂出繁育,避免上下架过频繁 time.sleep(3 * 60) logger.info('挂出繁育父亲狗狗{0}'.format(father['petId'])) shelf = Shelf(self.cookie) shelf.shelf(father['petId'], father_price) # 出售中,将其下架 if mother['shelfStatus'] == 1: logger.info('母亲狗狗{0}处于出售状态,将其下架然'.format(mother['petId'])) sale = Sale(self.cookie) sale.unsale(mother['petId']) # 挂出繁育中,将其下架 elif mother['shelfStatus'] == 2: logger.info('母亲狗狗{0}处于挂出繁育状态,将其下架'.format(mother['petId'])) shelf = Shelf(self.cookie) shelf.off_shelf(mother['petId']) # 再次获取狗狗双亲信息,保证信息是最新的 father = self.get_pet_info_on_market(father['petId']) mother = self.get_pet_info_on_market(mother['petId']) return (father, mother) except: traceback.print_exc()
def create_app(): app = Flask(__name__) app.debug = True app.testing = False import config app.config.from_object(config) app.config['SHELF_PAGES'] = { "index": (IndexPage, IndexPageModelView), "contact": (ContactPage, ContactPageModelView), } with app.app_context(): db.init_app(app) db.create_all() babel = Babel(app) shlf = Shelf(app) shlf.init_db(db) dview = DashboardView() shlf.init_admin(index_view=dview) shlf.init_security(User, Role) shlf.load_plugins(( "shelf.plugins.dashboard", "shelf.plugins.i18n", "shelf.plugins.library", "shelf.plugins.page", "shelf.plugins.preview", "shelf.plugins.workflow", "shelf.plugins.wysiwyg", "shelf.plugins.ecommerce", )) init_admin(shlf.admin, db.session) shlf.setup_plugins() page = shlf.get_plugin_by_class(PagePlugin) page.register_pages(app, shlf.db) init_views(app) init_filters(app) return app
from flask import Flask from shelf import LazyConfigured from shelf import Shelf from shelf.base import db from shelf.security.models import User, Role from shelf.admin.view import SQLAModelView from sqlalchemy_defaults import Column app = Flask(__name__) app.debug = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///simplest.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['SECRET_KEY'] = 'notasecret' class Post(LazyConfigured): id = Column(db.Integer, primary_key=True) title = Column(db.Unicode(150)) content = Column(db.UnicodeText) with app.app_context(): db.init_app(app) shlf = Shelf(app) shlf.init_db(db) shlf.init_admin() shlf.init_security(User, Role) shlf.admin.add_view(SQLAModelView(Post, db.session)) app.run('0.0.0.0')
def __create_shelves(self, shelves): for temp in SUPPORTED_TEMPERATURES: shelves[temp] = Shelf(temp) shelves[OVERFLOW_SHELF_NAME] = Shelf(OVERFLOW_SHELF_NAME, True)