def populate(self, *args, **kwargs): """ """ for key in [ 'city_entities', 'blocked_areas', 'tilesets', '__class__', 'unlocked_areas' ]: kwargs.pop(key, None) buildings = kwargs.pop('entities') # Buildings for raw_building in buildings: if raw_building['type'] in ['production', 'residential', 'goods']: building = self.session.query(Building).get(raw_building['id']) if not building: building = Building(city=self) building.update(**raw_building) return super(City, self).populate(*args, **kwargs)
def test_accept(self): vertices = [Point(0, 0, 0), Point(0, 1, 0), Point(1, 0, 0)] building = Building(Point(0, 0, 0), vertices) generator_mock = mock.Mock() calls = [mock.call.start_building(building), mock.call.end_building(building)] building.accept(generator_mock) generator_mock.assert_has_calls(calls)
def setUp(self): self.dojo = Building(office_names, living_space_names, input_file) self.allocated_offices, self.office_unallocated \ = self.dojo.allocate_room(self.dojo.all_employees, self.dojo.offices) self.allocated_living_spaces, self.ls_unallocated \ = self.dojo.allocate_room(self.dojo.fellows, self.dojo.living_spaces) self.dojo.print_office_allocation() self.dojo.print_living_space_allocation()
def test_can_access_employees_from_input(self): """ Tests if employee details in input file are accessed and objects created """ self.assertIsNotNone(self.dojo.all_employees) self.assertIsInstance(self.dojo.all_employees[0], Person) self.assertEquals('<type \'str\'>', str(type(self.dojo.all_employees[0].name))) self.assertEquals( '<type \'bool\'>', str(type(self.dojo.all_employees[0].is_allocated_office))) self.dojo = Building(office_names, living_space_names, empty_file) self.assertEquals(False, self.dojo.access_employees()[0])
def __build_model_objs(self, course) -> set(): """Use building-related fields to construct a Building Object""" room_capacity = course['maximumEnrollment'] school_name = 'Northeastern University' for elem in course['meetingsFaculty']: meeting_time = elem['meetingTime'] # Skip any course slots that are for Final Exams if meeting_time[ 'meetingTypeDescription'] == 'Final Exam' or not meeting_time[ 'beginTime']: continue # Buildings can just be created and added to the set building = Building(name=meeting_time['buildingDescription'], slug=meeting_time['building'], school_name=school_name, school_id=1) self.buildings.add(building) # same for Classrooms classroom = Classroom(room_number=meeting_time['room'], building_name=meeting_time['building'], school_name=school_name, school_id=1, capacity=room_capacity) self.classrooms.add(classroom) # CourseSlots are based on both time of day and day of week # i.e. a `meeting_time` object can have multiple CourseSlots in it # Helper method to create the individual slots self.__create_course_slots(meeting_time) return self.__convert_to_csvs()
def get(self): buildings = Building.query().fetch() # print buildings buildings_template = jinja_env.get_template('templates/index.html') self.response.write(buildings_template.render({ 'buildings': buildings }))
def bu_cr(): if not session["logged_in"] or not session.get("person")["admin"]: return redirect(url_for("bu_page")) db = Database() data = request.form building = Building(data["name"], data["code"], data["campus"]) db.add_building(building) return redirect(url_for("bu_page"))
def test_can_access_employees_from_input(self): """ Tests if employee details in input file are accessed and objects created """ self.assertIsNotNone(self.dojo.all_employees) self.assertIsInstance(self.dojo.all_employees[0], Person) self.assertEquals('<type \'str\'>', str(type(self.dojo.all_employees[0].name))) self.assertEquals('<type \'bool\'>', str(type(self.dojo.all_employees[0].is_allocated_office))) self.dojo = Building(office_names, living_space_names, empty_file) self.assertEquals(False, self.dojo.access_employees()[0])
def get(self): # print 'hello world' building_street_number = self.request.get('building') building = Building.query(Building.street_number == int(building_street_number)).get() floors = [] for floor in building.floors: floors.append(floor.get()) # '/directions?building=%s&floor=%s'%(floor['building'], floor['name']) floors_template = jinja_env.get_template('templates/floors.html') self.response.write(floors_template.render({ 'building': building, 'floors': floors }))
def crawl_building(self): """ Building class를 생성할 data crawling """ driver = self.client.driver # Building Class의 속성 building_name = driver.find_elements_by_class_name("heading")[7].text deal_count = driver.find_elements_by_class_name("txt_price")[0].text tnant_count = driver.find_elements_by_class_name("txt_price")[1].text rent_count = driver.find_elements_by_class_name("txt_price")[2].text land_address = driver.find_element_by_class_name( "p_address_place._addr").text road_address = driver.find_element_by_class_name( "p_address_road._road_addr").text[8:] category = driver.find_element_by_class_name( "label_detail.label_detail--positive").text[:-3] if category == "아파트": category = "APT" elif category == "오피스텔": category = "OPT" try: # 최근에 매매된 기록이 있는지 판단 (class name이 data인 배열에 '최근 거래가'요소 추가로 인덱스 밀림) whether_deal_recently = driver.find_element_by_class_name("date") # 최근에 매매된 기록이 있을 때 household_info = driver.find_elements_by_class_name("data")[3].text built_year = driver.find_elements_by_class_name("data")[6].text except: # 최근에 매매된 기록이 없을 때 household_info = driver.find_elements_by_class_name("data")[2].text built_year = driver.find_elements_by_class_name("data")[5].text # 크롤링 된 내용 가공 total_dong, total_household = self.split_household_info(household_info) building = Building( name=building_name, category=category, deal_count=deal_count, tnant_count=tnant_count, rent_count=rent_count, built_year=built_year, total_dong=total_dong, total_household=total_household, land_address=land_address, road_address=road_address, ) return building
class Play: """This class is used to run the elevator's simulator.""" def __init__(self, floors, elevators, requests): self.floors = floors self.elevators = elevators self.requests = requests self.building = Building(self.floors, self.elevators) def generate_requests(self): from_floor, to_floor = random.sample(range(self.floors), 2) request = Requests_Elevators(from_floor, to_floor) print(request.__str__()) self.building.requests.append(request) def run(self): """This method is used to start. """ print(self.building.__repr__()) print(self.building.__str__()) self.building.move_passengers() while True: self.generate_requests() sleep(5)
def _create_buildings(self, city, size): blocks_count = size - 1 building_spacing = 18 for x in range(blocks_count): for y in range(blocks_count): for block_x in range(3): for block_y in range(3): pos = Point( x * self.multiplier + block_x * 30 + building_spacing, y * self.multiplier + block_y * 30 + building_spacing, 0) if abs(pos.y - pos.x) > building_spacing and \ abs(pos.y + pos.x - self.multiplier * blocks_count) > building_spacing: building = Building.square(pos, 20, 40) city.add_building(building)
def main(): current_page = args.page_number try: print("Processing page {}...".format(current_page)) result = make_request(args, current_page) if 'error' in result: exit() res = result['response']['search']['offers']['entities'] # res = list(filter(lambda r: r['building'].get('buildingId'), res)) for e in convert(res): session.merge(Author(*e['author'])) if e['site']: session.merge(Site(*e['site'])) if e['building']: session.merge(Building(*e['building'])) nbid = None else: nb = session.merge(NewBuilding(*e['new_building'])) session.commit( ) # todo it's working now only for new buildings autoinc IDs nbid = nb.id o = (nbid, ) + e['offer'] session.merge(Offer(*o)) # session.merge(Photo(*e['photo'])) # for ent in res: # session.merge(Offer( # ent['offerId'], # ent['active'], # ent['area']['value'], # ent['building'].get('houseId') # )) session.commit() current_page += 1 print("Waiting {0} seconds".format(args.delay)) time.sleep(args.delay) except Exception as e: print(e) print("Unknown exception, waiting 60 seconds.") time.sleep(60) except KeyboardInterrupt: print("Finishing...") exit() print("Done")
def _create_buildings(self, city): ''' Iterate the ways to find the buildings data and create model buildings with it. ''' for key, value in self.osm_ways.iteritems(): tags = value['tags'] if 'building' in tags: vertices = [] for ref in value['refs']: ref_lat = self.osm_coords[ref]['lat'] ref_lon = self.osm_coords[ref]['lon'] ref_pair = LatLon(ref_lat, ref_lon) vertex = self._translate_coords(ref_pair) vertices.append(vertex) if 'height' in value: height = value['height'] else: height = 20 building = Building(Point(0, 0, 0), vertices, height=height) city.add_building(building)
def get(self): # print , 'aoisdnaisndiasndi' building_street_number = self.request.get('building') floor_name = self.request.get('floor') building = Building.query( Building.street_number == int(building_street_number)).get() floor = {} bins = [] hotspots = [] for _floor in building.floors: _floor = _floor.get() if _floor.name == floor_name: floor = _floor if floor.bins != None: for _bin in floor.bins: _bin = _bin.get().to_dict() directions = [] for direction in _bin['directions']: _direction = direction.get() directions.append(_direction) _bin['directions'] = directions bins.append(_bin) if floor.hotspots != None: for hotspot in floor.hotspots: hotspots.append(hotspot.get()) direction_template = jinja_env.get_template('templates/direction.html') self.response.write( direction_template.render({ 'building': building, 'floor': floor, 'bins': bins, 'hotspots': hotspots, 'http_host': os.environ['HTTP_HOST'] }))
def __init__(self, floors, elevators, requests): self.floors = floors self.elevators = elevators self.requests = requests self.building = Building(self.floors, self.elevators)
def setUp(self): self.building = Building(5, 3)
def get_building(self, location): building_data = self.db.get_building(location) if not building_data: return None return Building(**building_data)
def test_bounding_box_with_pentagonal_base_building(self): building = Building(Point(10, 20), [Point(-10, -20), Point(10, -30), Point(20, 10), Point(-5, 30), Point(-20, 5)]) self.assertEqual(building.bounding_box(), BoundingBox(Point(-10, -10), Point(30, 50) + Point(0, 0, 10)))
def test_bounding_box_with_one_point_building_not_centered_at_0_0(self): origin = Point(34, 68) building = Building.square(origin, 0, 14) self.assertEqual(building.bounding_box(), BoundingBox(origin, origin + Point(0, 0, 14)))
def create_building(self, location): building = Building(location=location) return self.db.put_building(building)
# description :Allocates persons to rooms in a building # author :Stanley Ndagi # email :[email protected] # date :20160108 # version :0.0.1 # python_version :2.7.10 # ===================================================================== import os import sys from models.building import Building living_space_names = ['Rm1', 'Rm2', 'Rm3', 'Rm4', 'Rm5', 'Rm6', 'Rm7', 'Rm8', 'Rm9', 'Rm10'] office_names = ['Hogwarts', 'Valhalla', 'Oculus', 'Krypton', 'Shire', 'Narnia', 'Camelot', 'Mordor', 'Round Table', 'Midgar'] if len(sys.argv) > 1: file_name = sys.argv[1] else: file_name = "files/employees.txt" if __name__ == '__main__': dojo = Building(office_names, living_space_names, file_name) dojo.print_office_allocation() dojo.print_living_space_allocation() dojo.print_unallocated_employees() dojo.print_allocation_for_one_room('Shire') dojo.print_allocation_for_one_room('Rm1')
class Test(unittest.TestCase): """Setup before the Test""" def setUp(self): self.dojo = Building(office_names, living_space_names, input_file) self.allocated_offices, self.office_unallocated \ = self.dojo.allocate_room(self.dojo.all_employees, self.dojo.offices) self.allocated_living_spaces, self.ls_unallocated \ = self.dojo.allocate_room(self.dojo.fellows, self.dojo.living_spaces) self.dojo.print_office_allocation() self.dojo.print_living_space_allocation() def test_can_pre_populate(self): """ Test if offices and living space can be prepopulated """ self.assertIsInstance(self.dojo.offices[4], Room) self.assertEquals('Shire', self.dojo.offices[4].name) self.assertEquals(len(self.dojo.offices), 10) self.assertEquals('Rm1', self.dojo.living_spaces[0].name) self.assertEquals(len(self.dojo.living_spaces), 10) self.assertEquals('<type \'bool\'>', str(type(self.dojo.living_spaces[0].is_full()))) self.assertIsNotNone(self.dojo.offices[6].get_occupants()) def test_can_access_employees_from_input(self): """ Tests if employee details in input file are accessed and objects created """ self.assertIsNotNone(self.dojo.all_employees) self.assertIsInstance(self.dojo.all_employees[0], Person) self.assertEquals('<type \'str\'>', str(type(self.dojo.all_employees[0].name))) self.assertEquals( '<type \'bool\'>', str(type(self.dojo.all_employees[0].is_allocated_office))) self.dojo = Building(office_names, living_space_names, empty_file) self.assertEquals(False, self.dojo.access_employees()[0]) def test_employees_entities_are_valid(self): """ Tests if the types of employees are correct the Y or N are taken in for fellow """ self.assertIsInstance(self.dojo.fellows[0], Fellow) self.assertEquals('Y', self.dojo.fellows[0].is_interested) def test_allocate_room(self): """ Tests if the allocation of room works receiving randomized room and randomized person """ self.assertIsNotNone( self.dojo.allocate_room(self.dojo.all_employees, self.dojo.offices)[0].keys()) self.assertIsNotNone( self.dojo.allocate_room(self.dojo.fellows, self.dojo.living_spaces)[0].keys()) self.assertIsInstance(self.dojo.offices[0], Office) self.assertIsInstance(self.dojo.living_spaces[0], LivingSpace) def test_get_list_of_office_allocations(self): """ Tests if the allocation of Office is okay """ self.assertIsNotNone(self.dojo.get_list_of_office_allocations()) def test_get_list_of_living_space_allocations(self): """ Tests if the allocation of Living Space is okay """ self.assertIsNotNone(self.dojo.get_list_of_living_space_allocations()) def test_print_room_allocation(self): """ Tests if the allocation of room is presented in the stipulated format """ self.assertEquals('<type \'list\'>', str(type(self.allocated_offices.keys()[:]))) self.assertEquals('<type \'str\'>', str(type(self.allocated_offices.keys()[0]))) self.assertEquals('<type \'list\'>', str(type(self.allocated_living_spaces.keys()[:]))) self.assertEquals('<type \'str\'>', str(type(self.allocated_living_spaces.keys()[0]))) print self.allocated_living_spaces self.assertIsInstance( self.dojo.print_allocation(self.allocated_living_spaces)[0], Fellow) self.assertIsInstance( self.dojo.print_allocation(self.allocated_offices)[0], Person) def test_print_unallocated_employees(self): """ Tests if the unallocated employees are appended """ self.assertEquals('<type \'list\'>', str(type(self.office_unallocated))) self.assertEquals(self.office_unallocated, []) self.assertIsInstance(self.ls_unallocated[0], Fellow) self.assertIsNone(self.dojo.print_unallocated_employees()) def test_allocation_of_one_room(self): """ Tests if Printing Occupants of one room can be accessed to be printed """ self.assertIsInstance(self.allocated_offices["Shire"][0], Person) self.assertIsInstance(self.allocated_living_spaces["Rm1"][0], Fellow) self.assertEquals('Invalid', self.dojo.print_allocation_for_one_room('abcd')) self.assertEquals('Office allocated', self.dojo.print_allocation_for_one_room('Hogwarts')) self.assertEquals('LS allocated', self.dojo.print_allocation_for_one_room('Rm1'))
class Test(unittest.TestCase): """Setup before the Test""" def setUp(self): self.dojo = Building(office_names, living_space_names, input_file) self.allocated_offices, self.office_unallocated \ = self.dojo.allocate_room(self.dojo.all_employees, self.dojo.offices) self.allocated_living_spaces, self.ls_unallocated \ = self.dojo.allocate_room(self.dojo.fellows, self.dojo.living_spaces) self.dojo.print_office_allocation() self.dojo.print_living_space_allocation() def test_can_pre_populate(self): """ Test if offices and living space can be prepopulated """ self.assertIsInstance(self.dojo.offices[4], Room) self.assertEquals('Shire', self.dojo.offices[4].name) self.assertEquals(len(self.dojo.offices), 10) self.assertEquals('Rm1', self.dojo.living_spaces[0].name) self.assertEquals(len(self.dojo.living_spaces), 10) self.assertEquals('<type \'bool\'>', str(type(self.dojo.living_spaces[0].is_full()))) self.assertIsNotNone(self.dojo.offices[6].get_occupants()) def test_can_access_employees_from_input(self): """ Tests if employee details in input file are accessed and objects created """ self.assertIsNotNone(self.dojo.all_employees) self.assertIsInstance(self.dojo.all_employees[0], Person) self.assertEquals('<type \'str\'>', str(type(self.dojo.all_employees[0].name))) self.assertEquals('<type \'bool\'>', str(type(self.dojo.all_employees[0].is_allocated_office))) self.dojo = Building(office_names, living_space_names, empty_file) self.assertEquals(False, self.dojo.access_employees()[0]) def test_employees_entities_are_valid(self): """ Tests if the types of employees are correct the Y or N are taken in for fellow """ self.assertIsInstance(self.dojo.fellows[0], Fellow) self.assertEquals('Y', self.dojo.fellows[0].is_interested) def test_allocate_room(self): """ Tests if the allocation of room works receiving randomized room and randomized person """ self.assertIsNotNone(self.dojo.allocate_room(self.dojo.all_employees, self.dojo.offices)[0].keys()) self.assertIsNotNone(self.dojo.allocate_room(self.dojo.fellows, self.dojo.living_spaces)[0].keys()) self.assertIsInstance(self.dojo.offices[0], Office) self.assertIsInstance(self.dojo.living_spaces[0], LivingSpace) def test_get_list_of_office_allocations(self): """ Tests if the allocation of Office is okay """ self.assertIsNotNone(self.dojo.get_list_of_office_allocations()) def test_get_list_of_living_space_allocations(self): """ Tests if the allocation of Living Space is okay """ self.assertIsNotNone(self.dojo.get_list_of_living_space_allocations()) def test_print_room_allocation(self): """ Tests if the allocation of room is presented in the stipulated format """ self.assertEquals('<type \'list\'>', str(type(self.allocated_offices.keys()[:]))) self.assertEquals('<type \'str\'>', str(type(self.allocated_offices.keys()[0]))) self.assertEquals('<type \'list\'>', str(type(self.allocated_living_spaces.keys()[:]))) self.assertEquals('<type \'str\'>', str(type(self.allocated_living_spaces.keys()[0]))) print self.allocated_living_spaces self.assertIsInstance(self.dojo.print_allocation( self.allocated_living_spaces)[0], Fellow) self.assertIsInstance(self.dojo.print_allocation( self.allocated_offices)[0], Person) def test_print_unallocated_employees(self): """ Tests if the unallocated employees are appended """ self.assertEquals('<type \'list\'>', str(type(self.office_unallocated))) self.assertEquals(self.office_unallocated, []) self.assertIsInstance(self.ls_unallocated[0], Fellow) self.assertIsNone(self.dojo.print_unallocated_employees()) def test_allocation_of_one_room(self): """ Tests if Printing Occupants of one room can be accessed to be printed """ self.assertIsInstance(self.allocated_offices["Shire"][0], Person) self.assertIsInstance(self.allocated_living_spaces["Rm1"][0], Fellow) self.assertEquals('Invalid', self.dojo.print_allocation_for_one_room('abcd')) self.assertEquals('Office allocated', self.dojo.print_allocation_for_one_room('Hogwarts')) self.assertEquals('LS allocated', self.dojo.print_allocation_for_one_room('Rm1'))
def test_bounding_box_with_not_convex_base_building(self): building = Building(Point(0, 0), [Point(-15, 0), Point(10, -40), Point(0, 0), Point(15, 30)]) self.assertEqual(building.bounding_box(), BoundingBox(Point(-15, -40), Point(15, 30, 10)))
def test_bounding_box(self): building = Building(Point(10, 20), [Point(15, 30), Point(15, -5), Point(40, 30), Point(40, -5)], 15) self.assertEqual(building.bounding_box(), BoundingBox(Point(25, 15), Point(50, 50, 15)))
class BuildingTestCase(unittest.TestCase): building = None def setUp(self): self.building = Building(5, 3) def test_get_elevator(self): direction = 1 self.assertIsInstance( self.building.get_elevator(self.building.elevators, direction), Elevator) direction = -1 self.assertIsInstance( self.building.get_elevator(self.building.elevators, direction), Elevator) def test_call_elevator(self): from_floor = 3 direction = 1 # Nearest elevator arrives to floor 'from_floor" self.assertIsInstance( self.building.call_elevator(from_floor, direction), Elevator) def test_move_elevator(self): to_floor = 5 elevator = self.building.elevators[0] self.building.move_elevator(elevator, to_floor) self.assertEqual(to_floor, elevator.floor) to_floor = 6 self.assertNotEqual(to_floor, elevator.floor) def test_validate_floor_elevator_direction(self): to_floor = 3 elevator = self.building.elevators[0] elevator.floor = 4 elevator.direction = 1 self.assertRaises(ValueError, self.building.validate_floor_elevator_direction, elevator, to_floor) to_floor = 5 self.assertEqual( None, self.building.validate_floor_elevator_direction( elevator, to_floor)) def test_validate_direction(self): from_floor = 0 direction = -1 self.assertRaises(ValueError, self.building.validate_direction, from_floor, direction) direction = 1 self.assertEqual( None, self.building.validate_direction(from_floor, direction)) from_floor = 5 self.assertRaises(ValueError, self.building.validate_direction, from_floor, direction) direction = -1 self.assertEqual( None, self.building.validate_direction(from_floor, direction)) def test_add_request_elevators(self): from_floor = 4 to_floor = 5 self.building.add_request(from_floor, to_floor) self.assertEqual(1, len(self.building.requests)) from_floor = 4 to_floor = 1 self.building.add_request(from_floor, to_floor) self.assertEqual(2, len(self.building.requests)) from_floor = 3 to_floor = 4 self.building.add_request(from_floor, to_floor) self.assertEqual(3, len(self.building.requests)) def test_move_passengers(self): for _ in range(6): from_floor, to_floor = random.sample( range(len(self.building.floors)), 2) request = Requests_Elevators(from_floor, to_floor) print(request.__str__()) self.building.requests.append(request) self.building.move_passengers() self.assertEqual(0, len(self.building.requests)) def test_move_passenger_demo(self): from_floor = 0 to_floor = 4 self.building.add_request(from_floor, to_floor) from_floor = 0 to_floor = 4 self.building.add_request(from_floor, to_floor) from_floor = 0 to_floor = 4 self.building.add_request(from_floor, to_floor) from_floor = 0 to_floor = 3 self.building.add_request(from_floor, to_floor) from_floor = 4 to_floor = 0 self.building.add_request(from_floor, to_floor) from_floor = 2 to_floor = 3 self.building.add_request(from_floor, to_floor) from_floor = 2 to_floor = 3 self.building.add_request(from_floor, to_floor) self.building.move_passengers() self.assertEqual(0, len(self.building.requests)) def tearDown(self): self.building = None