def add_water(self): """ Add Water() obj to values in dict. """ for coordinate in self.coordinates: if coordinate not in list(self.board.keys()): self.board[coordinate] = Water()
def tracker(): form = Waterer(request.form) if request.method=="POST": fire = form.water.data fire2= form.water2.data fire3= form.water3.data fire6= form.note1.data fire7= form.note2.data fire8 = form.pain1.data fire10= Water(fire,fire2,fire3,fire6,fire7,fire8) water_db = root.child('water') water_db.push({ 'Water': fire10.get_water(), "Water2": fire10.get_water2(), "Water3": fire10.get_water3(), "Note1": fire10.get_note1(), "Note2": fire10.get_note2(), "Pain1": fire10.get_pain1(), }) return render_template('tracker.html',form=form)
def create_water(ai_settings, screen, waters, water_number, list_number): '''创建一个外星人并将其放在当前行''' water = Water(ai_settings, screen) water_height = water.rect.height water.y = water.rect.height + 2 * water.rect.height * water_number water.rect.y = water.y water.rect.x = water.rect.width + 2 * water.rect.width * list_number waters.add(water)
def action(self): x = self.__outer.x y = self.__outer.y water_over = self.__outer.water_amount - self.__outer.water_capacity water = Water(self.__outer._ecosystem, x, y, water_over ) self.__outer._ecosystem.water_map[x][y] = water self.__outer._ecosystem.plant_map[x][y] = None self.__outer._ecosystem.flower_map[x][y].clear() self._status = bt.Status.FAIL
def create_waters(ai_settings, screen, waters): '''创建外星人群''' #创建第一行外星人 water = Water(ai_settings, screen) number_waters_x = get_number_waters_x(ai_settings, water.rect.width) number_waters_y = get_number_waters_y(ai_settings, water.rect.height) for number_list in range(number_waters_x): for water_number in range(number_waters_y): create_water(ai_settings, screen, waters, water_number, number_list)
def update_wiki(id): form=Waterer(request.form) if request.method=='POST': general=form.water2.data symptoms=form.water.data surgery=form.water3.data types=form.note1.data longtermeffect=form.pain1.data stay=form.note2.data wikiupdate=Water(symptoms,general,surgery,types,stay,longtermeffect) wikiupdate_db= root.child('water/'+id) wikiupdate_db.set({ "Water2":wikiupdate.get_water2(), "Water":wikiupdate.get_water(), "Water3":wikiupdate.get_water3(), "Note1":wikiupdate.get_note1(), "Pain1":wikiupdate.get_pain1(), 'Note2':wikiupdate.get_note2(), }) flash('Magazine Updated Sucessfully.', 'success') return redirect(url_for('diabetes')) else: url = 'water/'+id wikidata=root.child(url).get() if wikidata['Water'] != " ": wikiadmin= Water(wikidata['Water'],wikidata['Water2'],wikidata['Water3'],wikidata['Note1'],wikidata['Note2'],wikidata['Pain1']) wikiadmin.set_pubid((id)) form.water2.data=wikiadmin.get_water2() form.water.data=wikiadmin.get_water() form.water3.data=wikiadmin.get_water3() form.note1.data=wikiadmin.get_note1() form.pain1.data=wikiadmin.get_pain1() form.note2.data=wikiadmin.get_note2() return render_template('updatewiki.html',form=form)
def __init__(self): self._my_exchange_table = \ [[0 for col in range(self._NUMBER_OF_RSC + 1)] for row in range(self._NUMBER_OF_RSC + 1)] self._other_exchange_table = \ [[0 for col in range(self._NUMBER_OF_RSC + 1)] for row in range(self._NUMBER_OF_RSC + 1)] self._rsc_enum = {'food': 0, 'water': 1} # Information of Civilization self._total_population = 0 self._total_tools = 0 # Initialize it self._init_rsc_table(self._my_exchange_table, -1) self._init_rsc_table(self._other_exchange_table, -1) self._degree_of_civilized = 0 # Resource Object List self._food = Food(0) self._water = Water(0) # Person Object Lists # 여기 수정중 self._food_maker = FoodMaker(has_tool=0, _food=self._food, _water=self._water, _population=0) self._water_maker = WaterMaker(has_tool=0, _food=self._food, _water=self._water, _population=0) # Communication Data(Dictionary) self._civil1_info_dic = { 'Civil1_NumPeople': self._total_population, 'Civil1_Food': self._food.getquantity(), 'Civil1_Water': self._water.getquantity(), 'Civil1_DegOfCivilized': self._degree_of_civilized, } self._civil2_info_dic = { 'Civil2_NumPeople': 0, 'Civil2_Food': 0, 'Civil2_Water': 0, 'Civil2_DegOfCivilized': 0, } self._db_manager = DBManager.DBManager( civil_dic1=self._civil1_info_dic, civil_dic2=self._civil2_info_dic)
def calc_wettable_squares_from_file(filename): ground = create_ground_slice(filename) wx = ground.well_coordinate[0] wy = ground.well_coordinate[1] + 1 water = Water(wx, wy, ground, None) squares_to_check = [(wx, wy)] while squares_to_check: # print(f'{len(squares_to_check)} squares to check') new_squares_to_check = ground.check_square(squares_to_check.pop()) squares_to_check.extend(new_squares_to_check) print(f'total wet squares: {ground.wet_squares}') print(f'wet squares in range: {ground.wet_squares_in_range}') return ground.wet_squares_in_range
def diabetes(): water = root.child('water').get() list = [] for pubid in water: admindata=water[pubid] if admindata['Note1'] != " ": admindatapage=Water(admindata['Water'],admindata['Water2'],admindata['Water3'],admindata['Note1'],admindata['Pain1'],admindata['Note2']) admindatapage.set_pubid(pubid) print(admindatapage.get_pubid()) list.append(admindatapage) return render_template('diabetesedit.html', water=list)
def init_game(): for y, row in enumerate(settings.field): for x, column in enumerate(row): if column == 1: settings.grass.append( Grass(settings.main_surf, settings.field_size, settings.cells_size, (x, y))) elif column == 2: settings.armor.append( Armor(settings.main_surf, settings.field_size, settings.cells_size, (x, y))) elif type(column) is list: for add_nums in column: if add_nums[0] == 0: if add_nums[1] % 2 == 0: ind = 0 else: ind = 3 else: if add_nums[1] % 2 == 0: ind = 2 else: ind = 1 settings.bricks.append( Brick(settings.main_surf, settings.field_size, settings.cells_size, (50 + settings.cells_size * x + add_nums[0] * settings.cells_size // 2, 50 + settings.cells_size * y + add_nums[1] * settings.cells_size // 4), ind)) elif column == 4: settings.fin.append( Fin(settings.main_surf, settings.field_size, settings.cells_size, (x, y))) settings.fin_pos.append([x, y]) elif column == 5: settings.spawns.append([x, y]) elif column == 6: settings.bots_spawn.append([x, y]) elif column == 7: settings.water.append( Water(settings.main_surf, settings.field_size, settings.cells_size, (x, y)))
def __init__(self, initial_generator): self.seed() self.viewer = None self.world = Box2D.b2World() self.ship = None self.lander = None self.particles = [] self.water = Water([0, 1], force_const_volume=True) self.prev_reward = None self.origin = (W / 2, H / 20) # dummy initial variables, will be set in update_initials self.initial_pos_x = self.origin[0] self.initial_pos_y = self.origin[1] + H / 2 self.initial_vel = 0 self.initial_dir = 0 self.initial_vdir = 0 self.ship_width = 100 # non constant hyperparameters self.initial_generator = initial_generator self.difficulty = 0.1 self.steps = 0 high = np.array( [np.inf] * 8) # useful range is -1 .. +1, but spikes can be higher self.observation_space = spaces.Box(-high, high) if self.continuous: # Action is two floats [main engine, left-right engines]. # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power. # Left-right: -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off self.action_space = spaces.Box(-1, +1, (2, )) else: # Nop, fire left engine, main engine, right engine self.action_space = spaces.Discrete(4) self.reset()
def __init__(self, *args, **kwargs): self.power = "" # get data and merge on 'tds' if "Electricity" in args: self.power = "Electricity" self.data = Electricity().get_data(**kwargs) else: self.power = "Water" self.data = Water().get_data(**kwargs) self.coords = Coords().get_all_data() # cleanup the data self.merge_coords() self.add_year_column() self.set_dtypes() # compute df of mean consumption by (tds x year) self.tds_by_year = None self.get_by_year_data() # add other pre-computed dataframes here # ... self.tds_sum_year = None self.get_aggregate_data()
def initialize_forest(self): """Adds initial organisms to the map.""" directions = list(Direction) # Water map for pool_size in WATER_POOLS: rand_x = random.randint(0, self.width - 1) rand_y = random.randint(0, self.height - 1) while self.water_map[rand_x][rand_y]: rand_x = random.randint(0, self.width - 1) rand_y = random.randint(0, self.height - 1) water_pools_added = 0 positions = [(rand_x, rand_y)] WATER_POOLS_POSITIONS.append((rand_x, rand_y)) while water_pools_added < pool_size and positions: # Breadth first add water pools around x, y = positions.pop(0) if not self.water_map[x][y]: water = Water(self, x, y) self.water_map[x][y] = water water_pools_added += 1 # Insert all neighbors random.shuffle( directions) # shuffle for a bit random shapes for dir in directions: new_x = x + dir.value[0] new_y = y + dir.value[1] # Check if out of bounds if new_x < 0 or new_x >= self.width or new_y < 0 or new_y >= self.height: continue if self.water_map[new_x][new_y]: continue positions.append((new_x, new_y)) # Plant map for x in range(self.width): for y in range(self.height): # check if water if self.water_map[x][y]: continue if random.random() <= TREE_PERCENTAGE: tree = Tree(self, x, y) self.plant_map[x][y] = tree if random.random() <= HIVES_PER_TREE: hive = Hive(self, x, y) self.animal_map[x][y].append(hive) bee_amount = random.randint(HIVE_BEE_MIN_AMOUNT, HIVE_BEE_MAX_AMOUNT) bee = Bee(self, x, y, hive=hive, scout=True, age=random.randint(0, 24 * 150)) hive.bees.append(bee) self.animal_map[x][y].append(bee) for _ in range(bee_amount): bee = Bee(self, x, y, hive=hive, scout=False, age=random.randint(0, 24 * 150)) self.animal_map[x][y].append(bee) hive.bees.append(bee) elif random.random() <= GRASS_INIT_PERCENTAGE: grass = Grass(self, x, y, random.randint(-80, 100), None, self.get_initial_water_level(x, y)) self.plant_map[x][y] = grass else: earth = Earth(self, x, y, self.get_initial_water_level(x, y)) self.plant_map[x][y] = earth # Flower map from organisms import Type for x in range(self.width): for y in range(self.height): if self.water_map[x][y]: continue if random.random() <= FLOWER_PERCENTAGE: if self.plant_map[x][y] and self.plant_map[x][ y].type == Type.TREE: continue for _ in range(random.randint(1, 4)): flower = Flower(self, x, y, random.randint(-50, 100), nectar=random.randint(0, 100), has_seed=random.choice([True, False])) self.flower_map[x][y].append(flower) # Animal map import numpy as np # Rabbits for _ in range(BURROW_AMOUNT): x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) while self.water_map[x][y]: x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) burrow = Burrow(self, x, y) self.animal_map[x][y].append(burrow) rabbit_amount = random.randint(BURROW_RABBIT_MIN_AMOUNT, BURROW_RABBIT_MAX_AMOUNT) for _ in range(rabbit_amount): dx = random.randint(-3, 3) dy = random.randint(-3, 3) if x + dx < 0 or x + dx >= self.width or y + dy < 0 or y + dy >= self.height: continue if self.water_map[x + dx][y + dy]: continue rabbit = Rabbit(self, x + dx, y + dy, random.choice([True, False]), adult=True, burrow=burrow, age=random.randint(24 * 30, 24 * 30 * 3), reproduction_timer=random.randint(0, 24 * 6), genetics_factor=np.random.normal(1, 0.1)) self.animal_map[x + dx][y + dy].append(rabbit) # Foxes for _ in range(FOX_AMOUNT): x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) while self.water_map[x][y]: x = random.randint(0, self.width - 1) y = random.randint(0, self.height - 1) fox = Fox(self, x, y, random.choice([True, False]), adult=True, age=random.randint(24 * 30 * 2, 24 * 30 * 6), genetics_factor=np.random.normal(1, 0.1)) self.animal_map[x][y].append(fox)
def create_water_s(x, y, n=2): wall_list = [] for i in range(n): wall = Water(x, y+60*i) wall_list.append(wall) return wall_list
def create_water_h(x, y, n=2): water_list = [] for i in range(n): water = Water(x+60*i, y) water_list.append(water) return water_list
# Boat boat_img = pygame.image.load('cargo_ship_1.png') boat_X = 355 boat_Y = 505 boat_X_change = 0 boat_Y_change = 0 def boat_move(boat_X): screen.blit(boat_img, (boat_X, boat_Y)) # Water Section /*/*/*/ # defining water class w1 = Water() # Movement of water.. def moving_water(): for i in range(w1.wave_len): for j in range(w1.wave_wid): screen.blit(w1.W_wave_img[i][j], (w1.W_wave_X[i][j], w1.W_wave_Y[i][j])) w1.wave_move() # pygame.display.update() # Object Section /*/*/*/ # Objects making
import threading from water import Water from communication import Communication from db import Connection from sensoren import Sensoren import time from apiMain import start #com = Communication("RPI", "192.168.2.156 com = Communication("RPI", "0.0.0.0") sensoren = Sensoren(pinRain=22, pinVent1=17, pinVent2=27) water = Water(com, sensoren) db = Connection(host="localhost", user="******", password="******", database="sensor_data") t_com = threading.Thread(target=com.server) t_sensoren = threading.Thread(target=sensoren.update_data) t_water = threading.Thread(target=water.main) t_api = threading.Thread(target=start) if __name__ == '__main__': print("Starting") t_com.start() t_sensoren.start() t_water.start() t_api.start()
def main(): global SCREEN_FULLSCREEN pygame.init() util.load_config() if len(sys.argv) > 1: for arg in sys.argv: if arg == "-np": Variables.particles = False elif arg == "-na": Variables.alpha = False elif arg == "-nm": Variables.music = False elif arg == "-ns": Variables.sound = False elif arg == "-f": SCREEN_FULLSCREEN = True scr_options = 0 if SCREEN_FULLSCREEN: scr_options += FULLSCREEN screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT),scr_options ,32) pygame.display.set_icon(util.load_image("kuvake")) pygame.display.set_caption("Trip on the Funny Boat") init() joy = None if pygame.joystick.get_count() > 0: joy = pygame.joystick.Joystick(0) joy.init() try: util.load_music("JDruid-Trip_on_the_Funny_Boat") if Variables.music: pygame.mixer.music.play(-1) except: # It's not a critical problem if there's no music pass pygame.time.set_timer(NEXTFRAME, 1000 / FPS) # 30 fps Water.global_water = Water() main_selection = 0 while True: main_selection = Menu(screen, ("New Game", "High Scores", "Options", "Quit"), main_selection).run() if main_selection == 0: # New Game selection = Menu(screen, ("Story Mode", "Endless Mode")).run() if selection == 0: # Story score = Game(screen).run() Highscores(screen, score).run() elif selection == 1: # Endless score = Game(screen, True).run() Highscores(screen, score, True).run() elif main_selection == 1: # High Scores selection = 0 while True: selection = Menu(screen, ("Story Mode", "Endless Mode", "Endless Online"), selection).run() if selection == 0: # Story Highscores(screen).run() elif selection == 1: # Endless Highscores(screen, endless = True).run() elif selection == 2: # Online Highscores(screen, endless = True, online = True).run() else: break elif main_selection == 2: # Options selection = Options(screen).run() else: #if main_selection == 3: # Quit return
def main(): pygame.init() noparticles = False usealpha = True if len(sys.argv) > 1: for arg in sys.argv: if arg == "-np": noparticles = True elif arg == "-na": usealpha = False screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_icon(util.load_image("kuvake")) pygame.display.set_caption("Trip on the Funny Boat") init() joy = None if pygame.joystick.get_count() > 0: joy = pygame.joystick.Joystick(0) joy.init() try: util.load_music("JDruid-Trip_on_the_Funny_Boat") pygame.mixer.music.play(-1) except: pass pygame.time.set_timer(NEXTFRAME, 1000 / FPS) # 30 fps Water.global_water = Water(usealpha) while True: selection = Menu(screen).run() if selection == Menu.NEWGAME: #print "New game!" selection = Menu(screen, gametype_select=True).run() if selection == Menu.STORY: score = Game(screen, usealpha, noparticles).run() #print "Final score: " + str(score) Highscores(screen, score).run() elif selection == Menu.ENDLESS: score = Game(screen, usealpha, noparticles, True).run() #print "Final score: " + str(score) Highscores(screen, score, True).run() elif selection == Menu.HIGHSCORES: #print "High scores!" selection = Menu(screen, gametype_select=True).run() if selection == Menu.STORY: Highscores(screen).run() elif selection == Menu.ENDLESS: Highscores(screen, endless=True).run() #elif selection == Menu.OPTIONS: #print "Options!" #elif selection == Menu.QUIT: else: #print "Quit! :-(" return