Esempio n. 1
0
    def test_sortDeliveriesOneSwap(self):
        grid = Grid(7, 4)
        startingHouses = [House(2,3), House(0,1)]
        driver = Driver(grid, startingHouses)

        driver.sortDeliveries()

        expected = [House(0,1), House(2,3)]

        self.assertEqual(driver.deliveryList, expected)
Esempio n. 2
0
    def test_sortDeliveriesXConflictSouth(self):
        grid = Grid(7, 4)
        startingHouses = [House(1,1), House(1,2)]
        driver = Driver(grid, startingHouses)

        driver.sortDeliveries()

        expected = [House(1,2), House(1,1)]

        self.assertEqual(driver.deliveryList, expected)
Esempio n. 3
0
    def test_driverCompleteDelivery(self):
        grid = Grid(7, 4)
        startingHouses = [House(1,1), House(1,2)]
        driver = Driver(grid, startingHouses)

        driver.completeDelivery(driver.deliveryList[0])

        expected = True

        self.assertEqual(driver.deliveryList[0].isDelivered, expected)
        self.assertEqual(driver.actionList[-1], "D")
Esempio n. 4
0
    def build(self, size=20, step=1):
        self.size = size

        from collections import defaultdict

        empty = House(0, self, VoidState)

        self.houses = defaultdict(lambda: empty, {
            k: House(1000, self, EmptyState)
            for k in range(1, size + 1, step)
        })
    def setUp(self):
        self.house_long = House(100)
        self.house_short = House(1)
        self.house_shortest = House(1 / 60)  # one second timeframe

        self.house_long.devices_settings['heating_lvl'] = 0
        self.house_short.devices_settings['heating_lvl'] = 0
        self.house_shortest.devices_settings['heating_lvl'] = 0

        self.house_long.devices_settings['cooling_lvl'] = 1
        self.house_short.devices_settings['cooling_lvl'] = 1
        self.house_shortest.devices_settings['cooling_lvl'] = 1
Esempio n. 6
0
    def test_northBoundaryMoveEast(self):
        grid = Grid(5, 5)
        startingHouses = [House(0,1), House(2,3)]
        driver = Driver(grid, startingHouses)

        driver.p.x = 0
        driver.p.y = 5
        driver.goNorth = True

        driver.move()

        expected = Point(1, 5)

        self.assertEqual(driver.p, expected)
Esempio n. 7
0
    def test_moveWest(self):
        grid = Grid(7, 4)
        startingHouses = [House(0,1), House(2,3)]
        driver = Driver(grid, startingHouses)

        driver.p.x = 3
        driver.p.y = 0
        driver.goNorth = False

        driver.moveWest()

        expected = Point(2, 0)

        self.assertEqual(driver.p, expected)
        self.assertEqual(driver.actionList[-1], "W")
Esempio n. 8
0
    def test_moveNorth(self):
        grid = Grid(7, 4)
        startingHouses = [House(0,1), House(2,3)]
        driver = Driver(grid, startingHouses)

        driver.p.x = 0
        driver.p.y = 1
        driver.goNorth = True

        driver.moveNorth()

        expected = Point(0, 2)

        self.assertEqual(driver.p, expected)
        self.assertEqual(driver.actionList[-1], "N")
Esempio n. 9
0
    def  test_northAndEastBoundary(self):
        grid  = Grid(6, 4)

        startingHouses = [House(0,1), House(2,3)]
        driver = Driver(grid, startingHouses)

        driver.p.x = 6
        driver.p.y = 4
        driver.goNorth = True

        driver.move()

        expected = Point(6, 4)

        self.assertEqual(driver.p, expected)
Esempio n. 10
0
    def  test_southAndEastBoundary(self):
        grid  = Grid(5, 5)

        startingHouses = [House(0,1), House(2,3)]
        driver = Driver(grid, startingHouses)

        driver.p.x = 5
        driver.p.y = 0
        driver.goNorth = False

        driver.move()

        expected = Point(5, 0)

        self.assertEqual(driver.p, expected)
Esempio n. 11
0
    def new_level(self):
        self.items = []
        if variables.LEVEL == 5:
            return
        variables.ISLAND_WIDTH = variables.LEVEL_ISLAND_SIZE[variables.LEVEL -
                                                             1]
        n = variables.LEVEL_TREES[variables.LEVEL - 1]
        sizes = np.random.multinomial(
            variables.LEVEL_TREES_RESSOURCES[variables.LEVEL - 1],
            np.ones(n) / n,
            size=1)[0]
        part1_trees = np.linspace(
            variables.ISLAND_CENTER[0] - variables.ISLAND_WIDTH // 3,
            variables.ISLAND_CENTER[0] - 50, n // 2)
        part2_trees = np.linspace(
            variables.ISLAND_CENTER[0] + 50,
            variables.ISLAND_CENTER[0] + variables.ISLAND_WIDTH // 3, n // 2)
        trees_pos = np.hstack((part1_trees, part2_trees))
        for s, x in zip(sizes, trees_pos):
            self.items.append(Tree(s, x))
        self.items.append(House())

        self.bkg = pg.image.load(self.background_image)
        self.isl = pg.image.load(self.island_image)
        variables.RAFT_MIN_SIZE = variables.LEVEL_RAFT[variables.LEVEL - 1]
Esempio n. 12
0
    def load_houses(self, filename):
        """
        Load houses from filename.
        Return a dictionary of 'id' : House objects.
        """
        # First we parse all the data we need to create the houses with.
        # All parsed lines of data are saved to houses_data.
        houses = {}
        with open(filename, 'r') as infile:
            reader = csv.reader(infile)
            # Skip first row
            next(reader)
            # Set count for houses
            id = 1
            # Iterate over every row in file
            for rows in reader:
                # Put id, x and y position, max output into house object
                x_position = int(rows[0])
                y_position = int(rows[1])
                max_output = float(rows[2])
                house = House(id, x_position, y_position, max_output)
                # Add house to dict with id as key
                houses[id] = house
                id += 1

        return houses
Esempio n. 13
0
 def _process_house_item(self, item):
     item['area'] = int(item['area'][:-1])
     item['rent'] = int(item['rent'])
     session.add(House(**item))
     session.commit()
     session.close()
     return item
Esempio n. 14
0
    def load_houses(self):
        """
        Parses through csv file and saves houses as house.House
        objects. Returns instances in dict to __init__
        """
        # find specific directory with the data
        subpath = f"Huizen&Batterijen\wijk{INPUT}_huizen.csv"
        path = str(Path.cwd()).replace("scripts", subpath)
        # open file
        with open(path, newline="") as houses_csv:

            # read data from csv
            data_houses = csv.reader(houses_csv, delimiter=",")

            # skip headers
            next(data_houses, None)
            houses = {}

            # for every house, save coordinates and output in dictionary
            # name for instance in dict is Xcoord-Ycoord
            for row in data_houses:
                x = row[0]
                y = row[1]
                id = f"{x}-{y}"

                output = row[2]
                houses[id] = House(x, y, output)

        # returns dict, goes to init (self.houses)
        return houses
Esempio n. 15
0
 def addHouse(self):
     """
     
     Add a house Object to Villager
      
     """
     self.house = House(self.x, self.y)
Esempio n. 16
0
    def load_houses(self):
        """Load houses from csv to dict objects.

        Parses through csv file and saves houses as house.House
        objects. Returns instances in dict to __init__
        """
        # open file
        INPUT_HOUSES = f"wijk{self.input}_huizen.csv"
        cwd = os.getcwd()
        path = os.path.join(*[cwd, "data", f"{INPUT_HOUSES}"])
        sys.path.append(path)

        with open(path) as houses_csv:

            # read data from csv
            data_houses = csv.reader(houses_csv, delimiter=",")

            # skip headers
            next(data_houses, None)
            houses = {}

            # for every house, save coordinates and output in dictionary
            # name for instance in dict is Xcoord-Ycoord
            for row in data_houses:
                x = row[0]
                y = row[1]
                id = f"{x}-{y}"

                output = row[2]
                houses[id] = House(x, y, output)

        # returns dict, goes to init (self.houses)
        return houses
Esempio n. 17
0
def enter():
    game_framework.reset_time()
    global map, player, house, background, avalanche, coin, snows, map_on_coins, game_over, santa, game_clear, distance, stones
    map = Map()
    player = Player()
    house = House()
    background = Background()
    avalanche = Avalanche()
    coin = Coin()
    game_over = Game_over()
    santa = Santa()
    game_clear = Game_clear()
    distance = Distance()
    map_on_coins = [Map_on_Coin() for i in range(200)]
    snows = [Snow() for i in range(20)]
    stones = [Stone() for i in range(10)]

    Player.x = 300.0
    Player.y = 300.0
    Player.unreal_x = 300.0
    Player.unreal_y = 0
    Player.jump_before_y = 0
    Map.map_move_y_minor = 0
    Avalanche.game_over = 0
    Game_clear.game_clear = 0
    Santa.game_clear = 0
Esempio n. 18
0
 def _update_houses(self, housearray):
     self.update_idx += 1
     for ha in housearray:
         # Get an iterator over all houses that have center x coordinate within 5 cm of the input value.
         # Then see if one of the houses is close enough to be considered the same. If there are, update it's
         # location
         point = ha[2:4]
         to_change = None
         for oldhouse_idx in self.xes.irange_key(point[0] - D, point[0] + D):  # in cm.
             oldhouse = self.houses[oldhouse_idx]
             if -D < oldhouse.center.coords()[1] - point[1] < D and oldhouse.color == ha[1]:
                 to_change = oldhouse_idx
                 break
         if to_change is not None:
             house = self.houses[to_change]
             house.center.update(point)
         else:
             to_change = self.next_new_house
             self.next_new_house += 1
             house = House(point, ha[1])
         self.xes[to_change] = house.center.coords()[0]
         self.houses[to_change] = house
         self.houseupdates[to_change] = self.update_idx
     # if not self.update_idx % 5:
     self.clean_houses()
     self.update_potentials()
     if self.gui.enabled:
         self.draw_houses()
         self.draw_path(self._create_path((45, 75), self.car.yxintcoords()))
Esempio n. 19
0
 def load_houses(self, filename):
     """
     Loads houses from filename, returns a list of housetype objects
     """
     with open(filename, "r") as f:
         content = f.readlines()
         # Remove whitespace characters like `\n` at the end of each line.
         f = [x.strip() for x in content]
         houses = []
         itemnr = 0
         for item in f:
             # Add each type of house to a list
             if item == "~":
                 id = f[itemnr + 1]
                 name = f[itemnr + 2]
                 length = float(f[itemnr + 3])
                 width = float(f[itemnr + 4])
                 price = float(f[itemnr + 5])
                 min_space = float(f[itemnr + 6])
                 value_increase = float(f[itemnr + 7])
                 house = House(id, name, length, width, price, min_space,
                               value_increase)
                 houses.append(house)
                 itemnr += 1
             else:
                 itemnr += 1
     return houses
Esempio n. 20
0
    def load_houses(self, filename):
        """
        Load houses from filename.
        Returns a dictionary of 'id' : House objects.
        """
        # First parse data from file
        # Save parsed lines to houses_data
        houses_data = []
        with open(filename, "r") as file:
            for line in file:
                stripped_line = line.strip('\n')
                houses_data.append(stripped_line.split(','))

        # Create house objects for each set of data just parsed.
        houses = {}
        id_nr = 0
        for house in houses_data:
            id = id_nr
            house.insert(0, id)
            x = int(house[1])
            y = int(house[2])
            max_output = float(house[3])
            id_nr += 1
            # initialize a house object and put it in a dict with id as key
            house = House(id, x, y, max_output)
            houses[id] = house

        #print(houses)
        return houses
Esempio n. 21
0
    def load_houses(self):

        # open file
        cwd = os.getcwd()
        cwd = os.path.dirname(cwd)
        path = os.path.join(*[cwd, "data", f"{INPUT_HOUSES}"])
        sys.path.append(path)

        with open(path) as houses_csv:

            # read data from csv
            data_houses = csv.reader(houses_csv, delimiter=",")

            # skip headers
            next(data_houses, None)
            houses = {}

            # for every house, save coordinates and output in dictionary
            # name for instance in dict is Xcoord-Ycoord
            for row in data_houses:
                x = row[0]
                y = row[1]
                id = f"{x}-{y}"

                output = row[2]
                houses[id] = House(x, y, output)

        # returns dict, goes to init (self.houses)
        return houses
Esempio n. 22
0
    def reset(self, world=None):
        """(Re)initializes the environment and registers the listeners.

        Should be used to start a new episode. Returns the first,
        serialized initial state.

        Returns:
            Serialized initial state of the environment
        """

        self.world = world or World()

        self.timesteps = 0
        self.temp_diff_ok_count = 0
        self.temp_diff_perfect_count = 0
        self.light_diff_ok_count = 0
        self.light_diff_perfect_count = 0

        self.house = House(self.world.time_step_in_minutes)
        self.outside_sensors = [OutsideSensor(self.house) for _ in range(1)]

        # register listeners:
        for outside_sensor in self.outside_sensors:
            self.world.register(outside_sensor)

        # transfer initial information to listeners
        self.world.update_listeners()

        return self.serialize_state(self.get_current_state())
  def __init__(self, path):
    """
    En el constructor se leen todos los archivos con extensión html que están 
    en el directorio '/casas'.

    El contenido de cada archivo html se lee en una cadena que se usa para 
    crear un objeto de tipo House. 
    """
    
    ## ==== Leer archivos html ==== ##
    #archivo = open("casas/10053.html", "r", encoding='utf-8') # encoding = 'utf-8' para windows
    
    list_file_html = [] # Declaracion de la Lista
    files = os.listdir('./'+path)
    
    for file in files:
      if '.html' in file:
        list_file_html.append(file)

    # print("Lista de archivos html:", list_file_html)
    # ['10053.html', '10264.html', '10564.html', '10567.html', '8696.html']

    self.list_houses = [] # Lista para accederla desde otra clase
    
    for file_html in list_file_html:
      archivo = open(path + file_html, "r", encoding = 'utf-8')
      self.list_houses.append(House(archivo.read(), file_html))
      #self.casa = House(archivo.read(), file_html)
    
    """
Esempio n. 24
0
    def load_houses(self):
        """
        Parses through csv file and saves houses as house.House
        objects. Returns instances in dict to __init__
        """

        # open file
        with open(house_file, newline="") as houses_csv:

            # read data from csv
            data_houses = csv.reader(houses_csv, delimiter=",")

            # skip headers
            next(data_houses, None)
            houses = {}

            # for every house, save coordinates and output in dictionary
            # name for instance in dict is Xcoord-Ycoord
            for row in data_houses:
                x = row[0]
                y = row[1]
                id = f"{x}-{y}"

                output = row[2]
                houses[id] = House(x, y, output)

        # returns dict, goes to init (self.houses)
        return houses
Esempio n. 25
0
 def test_house_set_temp_to_350_using_mock():
     kitchen_mock = mock()
     house = House(kitchen_mock, None)  # subject under test
     house.bake_cookies()
     verify(kitchen_mock).set_oven(350)
     verify(kitchen_mock).set_oven(150)
     verify(kitchen_mock).set_oven(650)
     unstub()
 def build_house(self):
     self._house = House()
     self.build_wall()
     self.install_door()
     self.install_window()
     self.lay_floor()
     self.plant_garden()
     self.excavate_pool()
    def setUp(self):
        self.house = House(1)  # one minute timeframe
        self.house.influence = 0.2
        self.house.devices_settings = {
            'energy_src': 'grid',
            'cooling_lvl': 0.5,
            'heating_lvl': 0.5,
            'light_lvl': 0.5,
            'curtains_lvl': 0.5
        }
        self.house.battery['current'] = 0.5

        self.house_empty_battery = House(1)
        self.house_empty_battery.battery['current'] = 0.2
        self.house_empty_battery.devices_settings = {
            'energy_src': 'grid',
        }
Esempio n. 28
0
    def search(self, city, params, low, high):
        reqo = Req()
        mapo = Map()

        self.g = reqo.initialSearch(city, low, high)

        nHouses = json.loads(self.g.text)['total_records']
        temp = [House(0, 0, 0) for i in range(nHouses)]

        nParams = len(params)

        paramlist = [x for x in params if x is not None]

        nParams = len(paramlist)

        for i in range(0, nHouses):
            lat = json.loads(self.g.text)['results'][i]['lat']
            lng = json.loads(self.g.text)['results'][i]['long']
            mlsid = json.loads(self.g.text)['results'][i]['mls_id']

            temp[i] = House(mlsid, lat, lng)

            if (nParams >= 1):
                temp[i].setWTime(
                    mapo.getDistanceTime((lat, lng),
                                         mapo.getGeoCode(paramlist[0])))
            if (nParams >= 2):
                temp[i].setETime(
                    mapo.getDistanceTime((lat, lng),
                                         mapo.getGeoCode(paramlist[1])))
            if (nParams >= 3):
                temp[i].set1Time(
                    mapo.getDistanceTime((lat, lng),
                                         mapo.getGeoCode(paramlist[2])))
            if (nParams >= 4):
                temp[i].set2Time(
                    mapo.getDistanceTime((lat, lng),
                                         mapo.getGeoCode(paramlist[3])))
            if (nParams >= 5):
                temp[i].set3Time(
                    mapo.getDistanceTime((lat, lng),
                                         mapo.getGeoCode(paramlist[4])))
        print("\n")

        return temp
Esempio n. 29
0
def main():

    my_house = House()

    print(my_house)

    my_house.set_windows_and_bed()
    my_house.set_floors_and_surfaces()
    my_house.set_shopping()
    my_house.set_pandemic_shopping()
Esempio n. 30
0
 def get_simulated_result(self, player1, player2: str):
     coin_toss = True if random() > 0.5 else False
     house = House(first_player_first_move=coin_toss, debug=False)
     house.simulate(player1, player2, render_every=False, pause=0.5)
     if coin_toss:
         self.black_player, self.white_player = player1, player2
     else:
         self.black_player, self.white_player = player2, player1
     self.winner = house.winner
     self.board_config = house.board.config
     self.logs = house.board.log