def _load_saved_state(self): """Read and reproduce the state of the cluster from this instance's varstore.""" depot_list = self.var.get_depot_list() for depot_spec in depot_list: depot = Depot(self, depot_spec['uuid']) self._depot_map[depot_spec['uuid']] = depot depot._load_saved_state()
def get_depots(self) -> dict: depots = {} for depot in self.data['depots']: new_depot = Depot() new_depot.point_id = depot.get('point_id') new_depot.location_x = depot.get('location_x') new_depot.location_y = depot.get('location_y') depots[new_depot.point_id] = new_depot return depots
def test_set_depot_uuid(self): service = TcdsService(Utils(Resolv()), self.var) uuidstr = self.depot_uuid depot = Depot(service, uuidstr) self.var.add_depot(depot, uuidstr, 30, depot.CONSTANTS['STATE_OFFLINE']) self.assertEquals(self.var.get_depot_state(depot), depot.CONSTANTS['STATE_OFFLINE']) uuidstr2 = self.depot_uuid2 self.var.set_depot_uuid(depot, uuidstr2) self.assertRaises(KeyError, self.var.get_depot_state, depot) depot.uuid = uuidstr2 self.assertEquals(self.var.get_depot_state(depot), depot.CONSTANTS['STATE_OFFLINE']) self.var.del_depot(depot)
def create_depot(self, depot_id, replication_factor): """Creates a new depot @type depot_id string @param depot_id the newly created depot will have this uuid @type replication_factor int @param replication_factor the replication of the new depot @rtype Depot instance @return the newly created depot """ depot = Depot(self, depot_id) self.var.add_depot(depot, depot_id, replication_factor, depot.CONSTANTS['STATE_OFFLINE']) depot.setup() self._depot_map[depot_id] = depot return depot
def __init__ (self, var, local_depot, dep, sub_depot): """Return an HTTP `Depot` object.""" # This is better, but doesn't work for classic classes: # super (http, self).__init__ (dep) # So, we're forced to hardcode the superclass for now: Depot.__init__ (self, dep) if type (dep) == types.InstanceType: self.var = dep.var else: self.var = var # full URL path where packages are to be found pkg_path = None if type (dep) == types.InstanceType: self.pkg_url = urljoin (dep.pkg_url, sub_depot) elif var is not None: # path to "root" of package directory pkg_path = var['dist'] if pkg_path: self.pkg_url = urljoin (self.pkg_url, pkg_path) if not local_depot: return # make local depot mirror the directory structure of the # remote depot. This is to make it possible to specify the # path of the local depot as a depot to future sessions. if type (dep) == types.InstanceType: self.local_path = os.path.join (dep.local_path, sub_depot) else: if pkg_path: self.local_path = os.path.join (local_depot, pkg_path) else: self.local_path = local_depot if not os.path.exists (self.local_path): os.makedirs (self.local_path)
def __init__ (self, var, dep, sub_depot): # This is better, but doesn't work for classic classes: # super (file, self).__init__ (dep) # So, we're forced to hardcode the superclass for now: Depot.__init__ (self, dep) if type (dep) == types.InstanceType: url = dep.url self.var = dep.var else: url = dep self.var = var self.local_path = urlparse (url).path # add to existing depot path if type (dep) == types.InstanceType: self.local_path = os.path.join (dep.local_path, sub_depot) self.pkg_url = urljoin (dep.pkg_url, sub_depot) else: if var and var['dist'] and os.path.exists (os.path.join (self.local_path, var['dist'])): self.local_path = os.path.join (self.local_path, var['dist']) self.pkg_url = urljoin (self.pkg_url, var['dist'])
def test_min_req_check(self): self.assertEquals(Depot._get_meets_min_requirements(3, 3, 2, 3), True) self.assertEquals(Depot._get_meets_min_requirements(3, 3, 2, 2), False) self.assertEquals(Depot._get_meets_min_requirements(3, 3, 1, 3), False) self.assertEquals(Depot._get_meets_min_requirements(2, 2, 3, 3), False) self.assertEquals(Depot._get_meets_min_requirements(3, 3, 2, 4), True) self.assertEquals(Depot._get_meets_min_requirements(3, **{'num_osd': 3, 'num_mon':4, 'num_mds': 1}), False) self.assertRaises(ValueError, Depot._get_meets_min_requirements, 0, 3, 2, 3) self.assertRaises(ValueError, Depot._get_meets_min_requirements, 3, -1, 2, 3) self.assertRaises(TypeError, Depot._get_meets_min_requirements, 3.5, 3, 2, 3) self.assertRaises(TypeError, Depot._get_meets_min_requirements, '3', 3, 2, 3)
def __init__(self): self.verbosity = 0 ############################################## #field_width=230*in_*3 #field_height=133*in_*3 self.field_width = 54 * ft_ self.field_height = 27 * ft_ self.hab_line_x = 94.3 * in_ # Call this function so the Pygame library can initialize itself pygame.init() pygame.joystick.init() self.joysticks = [ pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count()) ] for joystick in self.joysticks: joystick.init() # Create an 800x600 sized screen #screen_size=[800,600] screen_size = [self.field_width, int(self.field_height * 1.20)] self.screen = pygame.display.set_mode(screen_size, pygame.RESIZABLE) # Set the title of the window pygame.display.set_caption('Test') max_x = self.field_width max_y = self.field_height min_x = 0 min_y = 0 mid_x = max_x / 2.0 mid_y = max_y / 2.0 wall_thickness = 1 * in_ wall_1 = Wall(min_x, min_y, width=self.field_width, height=wall_thickness, color=BLACK) wall_2 = Wall(min_x, max_y, width=self.field_width, height=wall_thickness, color=BLACK) wall_3 = Wall(min_x, min_y, width=wall_thickness, height=self.field_height, color=BLACK) wall_4 = Wall(max_x, min_y, width=wall_thickness, height=self.field_height, color=BLACK) cargo_ship_xo = mid_x cargo_ship_yo = mid_y cargo_ship_1 = Cargo_ship(cargo_ship_xo, cargo_ship_yo) rocket_1_xo = 229 * in_ rocket_1_yo = min_y rocket_2_xo = rocket_1_xo rocket_2_yo = max_y rocket_3_xo = max_x - rocket_1_xo rocket_3_yo = rocket_1_yo rocket_4_xo = rocket_3_xo rocket_4_yo = rocket_2_yo rocket_1 = Rocket(rocket_1_xo, rocket_1_yo, BLUE) rocket_2 = Rocket(rocket_2_xo, rocket_2_yo, BLUE, flip_y=True) rocket_3 = Rocket(rocket_3_xo, rocket_3_yo, RED) rocket_4 = Rocket(rocket_4_xo, rocket_4_yo, RED, flip_y=True) x = min_x y = mid_y blue_hab_platform_level_3 = Hab_platform_level_3(x, y, BLUE_HAB3, flip_x=False) x = min_x y = blue_hab_platform_level_3.rect.bottom blue_hab_platform_level_2b = Hab_platform_level_2(x, y, BLUE_HAB2, flip_x=False, flip_y=False) x = min_x y = blue_hab_platform_level_3.rect.top blue_hab_platform_level_2a = Hab_platform_level_2(x, y, BLUE_HAB2, flip_x=False, flip_y=True) x = blue_hab_platform_level_3.rect.right y = mid_y blue_hab_platform_level_1 = Hab_platform_level_1(x, y, BLUE_HAB1, flip_x=False) x = blue_hab_platform_level_3.rect.right y = mid_y blue_hab_platform_level_0 = Hab_platform_level_0(x, y, BLUE_HAB0, flip_x=False) x = min_x y = blue_hab_platform_level_2b.rect.bottom blue_depot_a = Depot(x, y, ORANGE, flip_x=False, flip_y=False) x = min_x y = blue_hab_platform_level_2a.rect.top blue_depot_b = Depot(x, y, ORANGE, flip_x=False, flip_y=True) dy_loading_station = 27 * in_ x = min_x y = min_y + dy_loading_station blue_loading_station_a = LoadingStation(x, y, ORANGE, flip_x=False, flip_y=False) x = min_x y = max_y - dy_loading_station blue_loading_station_b = LoadingStation(x, y, ORANGE, flip_x=False, flip_y=True) x = max_x y = mid_y red_hab_platform_level_3 = Hab_platform_level_3(x, y, RED_HAB3, flip_x=True) x = max_x y = red_hab_platform_level_3.rect.bottom red_hab_platform_level_2b = Hab_platform_level_2(x, y, RED_HAB2, flip_x=True, flip_y=False) x = max_x y = red_hab_platform_level_3.rect.top red_hab_platform_level_2a = Hab_platform_level_2(x, y, RED_HAB2, flip_x=True, flip_y=True) x = red_hab_platform_level_3.rect.left y = mid_y red_hab_platform_level_1 = Hab_platform_level_1(x, y, RED_HAB1, flip_x=True) x = red_hab_platform_level_3.rect.left y = mid_y red_hab_platform_level_0 = Hab_platform_level_0(x, y, RED_HAB0, flip_x=True) x = max_x y = red_hab_platform_level_2b.rect.bottom red_depot_a = Depot(x, y, ORANGE, flip_x=True, flip_y=False) x = max_x y = red_hab_platform_level_2a.rect.top red_depot_b = Depot(x, y, ORANGE, flip_x=True, flip_y=True) dy_loading_station = 27 * in_ x = max_x y = min_y + dy_loading_station red_loading_station_a = LoadingStation(x, y, ORANGE, flip_x=True, flip_y=False) x = max_x y = max_y - dy_loading_station red_loading_station_b = LoadingStation(x, y, ORANGE, flip_x=True, flip_y=True) ############################################ # Robot starting points # blue_x = blue_hab_platform_level_1.rect.centerx blue_y1 = blue_hab_platform_level_1.rect.centery blue_y2 = blue_y1 + blue_hab_platform_level_1.rect.height / 3 blue_y3 = blue_y1 - blue_hab_platform_level_1.rect.height / 3 red_x = red_hab_platform_level_1.rect.centerx red_y1 = red_hab_platform_level_1.rect.centery red_y2 = red_y1 + red_hab_platform_level_1.rect.height / 3 red_y3 = red_y1 - red_hab_platform_level_1.rect.height / 3 # Create the robot object # # # self.robot1 = Robot(x=blue_x, y=blue_y1, color=BLUE1, angle=270, keymap=key_map_1, joystick=joystick_1, is_mecanum=True, mecanum_control_is_in_field_frame=True, team_name=5115, width=27 * in_, length=45 * in_) self.robot2 = Robot(x=blue_x, y=blue_y2, color=BLUE2, angle=270, keymap=key_map_2, joystick=joystick_2, is_mecanum=True, mecanum_control_is_in_field_frame=False, team_name=493, width=27 * in_, length=55 * in_) self.robot3 = Robot(x=blue_x, y=blue_y3, color=BLUE3, angle=270, keymap=key_map_3, joystick=joystick_3, is_mecanum=False, team_name=503, width=45 * in_, length=45 * in_) self.robot4 = Robot(x=red_x, y=red_y1, color=RED1, angle=90, keymap=key_map_4, joystick=joystick_4, is_mecanum=True, mecanum_control_is_in_field_frame=False, team_name=3361, width=27 * in_, length=45 * in_) self.robot5 = Robot(x=red_x, y=red_y2, color=RED2, angle=90, keymap=key_map_5, joystick=joystick_5, is_mecanum=False, team_name=3258, width=27 * in_, length=45 * in_) self.robot6 = Robot(x=red_x, y=red_y3, color=RED3, angle=90, keymap=key_map_6, joystick=joystick_6, is_mecanum=False, team_name=2106, width=27 * in_, length=45 * in_) # self.all_sprites_list = pygame.sprite.Group() self.all_sprites_list = pygame.sprite.OrderedUpdates() self.all_sprites_list.add(wall_1) self.all_sprites_list.add(wall_2) self.all_sprites_list.add(wall_3) self.all_sprites_list.add(wall_4) self.all_sprites_list.add(cargo_ship_1) self.all_sprites_list.add(rocket_1) self.all_sprites_list.add(rocket_2) self.all_sprites_list.add(rocket_3) self.all_sprites_list.add(rocket_4) self.all_sprites_list.add(blue_hab_platform_level_0) self.all_sprites_list.add(blue_hab_platform_level_1) self.all_sprites_list.add(blue_hab_platform_level_2a) self.all_sprites_list.add(blue_hab_platform_level_2b) self.all_sprites_list.add(blue_hab_platform_level_3) self.all_sprites_list.add(blue_depot_a) self.all_sprites_list.add(blue_depot_b) self.all_sprites_list.add(blue_loading_station_a) self.all_sprites_list.add(blue_loading_station_b) self.all_sprites_list.add(red_hab_platform_level_0) self.all_sprites_list.add(red_hab_platform_level_1) self.all_sprites_list.add(red_hab_platform_level_2a) self.all_sprites_list.add(red_hab_platform_level_2b) self.all_sprites_list.add(red_hab_platform_level_3) self.all_sprites_list.add(red_depot_a) self.all_sprites_list.add(red_depot_b) self.all_sprites_list.add(red_loading_station_a) self.all_sprites_list.add(red_loading_station_b) self.all_sprites_list.add(self.robot1) self.all_sprites_list.add(self.robot2) self.all_sprites_list.add(self.robot3) self.all_sprites_list.add(self.robot4) self.all_sprites_list.add(self.robot5) self.all_sprites_list.add(self.robot6) self.solid_sprites_list = pygame.sprite.Group() self.solid_sprites_list.add(wall_1) self.solid_sprites_list.add(wall_2) self.solid_sprites_list.add(wall_3) self.solid_sprites_list.add(wall_4) self.solid_sprites_list.add(cargo_ship_1) self.solid_sprites_list.add(rocket_1) self.solid_sprites_list.add(rocket_2) self.solid_sprites_list.add(rocket_3) self.solid_sprites_list.add(rocket_4) # self.solid_sprites_list.add(blue_hab_platform_level_1) self.solid_sprites_list.add(blue_hab_platform_level_2a) self.solid_sprites_list.add(blue_hab_platform_level_2b) self.solid_sprites_list.add(blue_hab_platform_level_3) self.solid_sprites_list.add(blue_depot_a) self.solid_sprites_list.add(blue_depot_b) # self.solid_sprites_list.add(red_hab_platform_level_1) self.solid_sprites_list.add(red_hab_platform_level_2a) self.solid_sprites_list.add(red_hab_platform_level_2b) self.solid_sprites_list.add(red_hab_platform_level_3) self.solid_sprites_list.add(red_depot_a) self.solid_sprites_list.add(red_depot_b) self.solid_sprites_list.add(self.robot1) self.solid_sprites_list.add(self.robot2) self.solid_sprites_list.add(self.robot3) self.solid_sprites_list.add(self.robot4) self.solid_sprites_list.add(self.robot5) self.solid_sprites_list.add(self.robot6) self.robots_list = pygame.sprite.Group() self.robots_list.add(self.robot1) self.robots_list.add(self.robot2) self.robots_list.add(self.robot3) self.robots_list.add(self.robot4) self.robots_list.add(self.robot5) self.robots_list.add(self.robot6) self.clock = pygame.time.Clock()
def __init__(self): ############################################## #field_width=230*in_*3 #field_height=133*in_*3 self.field_width = 54 * ft_ self.field_height = 27 * ft_ self.hab_line_x = 94.3 * in_ # Call this function so the Pygame library can initialize itself pygame.init() # Create an 800x600 sized screen #screen_size=[800,600] screen_size = [self.field_width, int(self.field_height * 1.20)] self.screen = pygame.display.set_mode(screen_size, pygame.RESIZABLE) # Set the title of the window pygame.display.set_caption('Test') max_x = self.field_width max_y = self.field_height min_x = 0 min_y = 0 mid_x = max_x / 2.0 mid_y = max_y / 2.0 wall_thickness = 1 * in_ wall_1 = Wall(min_x, min_y, width=self.field_width, height=wall_thickness, color=BLACK) wall_2 = Wall(min_x, max_y, width=self.field_width, height=wall_thickness, color=BLACK) wall_3 = Wall(min_x, min_y, width=wall_thickness, height=self.field_height, color=BLACK) wall_4 = Wall(max_x, min_y, width=wall_thickness, height=self.field_height, color=BLACK) cargo_ship_xo = mid_x cargo_ship_yo = mid_y cargo_ship_1 = Cargo_ship(cargo_ship_xo, cargo_ship_yo) rocket_1_xo = 229 * in_ rocket_1_yo = min_y rocket_2_xo = rocket_1_xo rocket_2_yo = max_y rocket_3_xo = max_x - rocket_1_xo rocket_3_yo = rocket_1_yo rocket_4_xo = rocket_3_xo rocket_4_yo = rocket_2_yo rocket_1 = Rocket(rocket_1_xo, rocket_1_yo, BLUE) rocket_2 = Rocket(rocket_2_xo, rocket_2_yo, BLUE, flip_y=True) rocket_3 = Rocket(rocket_3_xo, rocket_3_yo, RED) rocket_4 = Rocket(rocket_4_xo, rocket_4_yo, RED, flip_y=True) x = min_x y = mid_y blue_hab_platform_level_3 = Hab_platform_level_3(x, y, BLUE_HAB3, flip_x=False) x = min_x y = blue_hab_platform_level_3.rect.bottom blue_hab_platform_level_2b = Hab_platform_level_2(x, y, BLUE_HAB2, flip_x=False, flip_y=False) x = min_x y = blue_hab_platform_level_3.rect.top blue_hab_platform_level_2a = Hab_platform_level_2(x, y, BLUE_HAB2, flip_x=False, flip_y=True) x = blue_hab_platform_level_3.rect.right y = mid_y blue_hab_platform_level_1 = Hab_platform_level_1(x, y, BLUE_HAB1, flip_x=False) x = blue_hab_platform_level_3.rect.right y = mid_y blue_hab_platform_level_0 = Hab_platform_level_0(x, y, BLUE_HAB0, flip_x=False) x = min_x y = blue_hab_platform_level_2b.rect.bottom blue_depot_a = Depot(x, y, ORANGE, flip_x=False, flip_y=False) x = min_x y = blue_hab_platform_level_2a.rect.top blue_depot_b = Depot(x, y, ORANGE, flip_x=False, flip_y=True) dy_loading_station = 27 * in_ x = min_x y = min_y + dy_loading_station blue_loading_station_a = LoadingStation(x, y, ORANGE, flip_x=False, flip_y=False) x = min_x y = max_y - dy_loading_station blue_loading_station_b = LoadingStation(x, y, ORANGE, flip_x=False, flip_y=True) x = max_x y = mid_y red_hab_platform_level_3 = Hab_platform_level_3(x, y, RED_HAB3, flip_x=True) x = max_x y = red_hab_platform_level_3.rect.bottom red_hab_platform_level_2b = Hab_platform_level_2(x, y, RED_HAB2, flip_x=True, flip_y=False) x = max_x y = red_hab_platform_level_3.rect.top red_hab_platform_level_2a = Hab_platform_level_2(x, y, RED_HAB2, flip_x=True, flip_y=True) x = red_hab_platform_level_3.rect.left y = mid_y red_hab_platform_level_1 = Hab_platform_level_1(x, y, RED_HAB1, flip_x=True) x = red_hab_platform_level_3.rect.left y = mid_y red_hab_platform_level_0 = Hab_platform_level_0(x, y, RED_HAB0, flip_x=True) x = max_x y = red_hab_platform_level_2b.rect.bottom red_depot_a = Depot(x, y, ORANGE, flip_x=True, flip_y=False) x = max_x y = red_hab_platform_level_2a.rect.top red_depot_b = Depot(x, y, ORANGE, flip_x=True, flip_y=True) dy_loading_station = 27 * in_ x = max_x y = min_y + dy_loading_station red_loading_station_a = LoadingStation(x, y, ORANGE, flip_x=True, flip_y=False) x = max_x y = max_y - dy_loading_station red_loading_station_b = LoadingStation(x, y, ORANGE, flip_x=True, flip_y=True) ############################################ # Robot starts # blue_x = blue_hab_platform_level_1.rect.centerx blue_y1 = blue_hab_platform_level_1.rect.centery blue_y2 = blue_y1 + blue_hab_platform_level_1.rect.height / 3 blue_y3 = blue_y1 - blue_hab_platform_level_1.rect.height / 3 red_x = red_hab_platform_level_1.rect.centerx red_y1 = red_hab_platform_level_1.rect.centery red_y2 = red_y1 + red_hab_platform_level_1.rect.height / 3 red_y3 = red_y1 - red_hab_platform_level_1.rect.height / 3 key_map_1 = { pygame.K_w: "forward", pygame.K_s: "backward", pygame.K_a: "strafe_left", pygame.K_d: "strafe_right", pygame.K_e: "rotate_right", pygame.K_q: "rotate_left" } key_map_2 = { pygame.K_t: "forward", pygame.K_g: "backward", pygame.K_f: "strafe_left", pygame.K_h: "strafe_right", pygame.K_r: "rotate_right", pygame.K_y: "rotate_left" } key_map_3 = { pygame.K_i: "forward", pygame.K_k: "backward", pygame.K_j: "strafe_left", pygame.K_l: "strafe_right", pygame.K_u: "rotate_right", pygame.K_o: "rotate_left" } key_map_4 = { pygame.K_UP: "forward", pygame.K_DOWN: "backward", pygame.K_LEFT: "strafe_left", pygame.K_RIGHT: "strafe_right", pygame.K_PAGEUP: "rotate_right", pygame.K_PAGEDOWN: "rotate_left" } key_map_5 = { pygame.K_KP0: "forward", pygame.K_KP1: "backward", pygame.K_KP2: "strafe_left", pygame.K_KP3: "strafe_right", pygame.K_KP4: "rotate_right", pygame.K_KP5: "rotate_left" } key_map_6 = { pygame.K_0: "forward", pygame.K_1: "backward", pygame.K_2: "strafe_left", pygame.K_3: "strafe_right", pygame.K_4: "rotate_right", pygame.K_5: "rotate_left" } # Create the robot object self.robot1 = Robot(blue_x, blue_y1, BLUE1, angle=270, keymap=key_map_1, is_mecanum=True, team_name=5115, width=10 * in_, length=45 * in_) self.robot2 = Robot(blue_x, blue_y2, BLUE2, angle=270, keymap=key_map_2, is_mecanum=False, team_name=493) self.robot3 = Robot(blue_x, blue_y3, BLUE3, angle=270, keymap=key_map_3, is_mecanum=False, team_name=503) self.robot4 = Robot(red_x, red_y1, RED1, angle=90, keymap=key_map_4, is_mecanum=True, team_name=3361) self.robot5 = Robot(red_x, red_y2, RED2, angle=90, keymap=key_map_5, is_mecanum=False, team_name=3258) self.robot6 = Robot(red_x, red_y3, RED3, angle=90, keymap=key_map_6, is_mecanum=False, team_name=2106) # self.all_sprites_list = pygame.sprite.Group() self.all_sprites_list = pygame.sprite.OrderedUpdates() self.all_sprites_list.add(wall_1) self.all_sprites_list.add(wall_2) self.all_sprites_list.add(wall_3) self.all_sprites_list.add(wall_4) self.all_sprites_list.add(cargo_ship_1) self.all_sprites_list.add(rocket_1) self.all_sprites_list.add(rocket_2) self.all_sprites_list.add(rocket_3) self.all_sprites_list.add(rocket_4) self.all_sprites_list.add(blue_hab_platform_level_0) self.all_sprites_list.add(blue_hab_platform_level_1) self.all_sprites_list.add(blue_hab_platform_level_2a) self.all_sprites_list.add(blue_hab_platform_level_2b) self.all_sprites_list.add(blue_hab_platform_level_3) self.all_sprites_list.add(blue_depot_a) self.all_sprites_list.add(blue_depot_b) self.all_sprites_list.add(blue_loading_station_a) self.all_sprites_list.add(blue_loading_station_b) self.all_sprites_list.add(red_hab_platform_level_0) self.all_sprites_list.add(red_hab_platform_level_1) self.all_sprites_list.add(red_hab_platform_level_2a) self.all_sprites_list.add(red_hab_platform_level_2b) self.all_sprites_list.add(red_hab_platform_level_3) self.all_sprites_list.add(red_depot_a) self.all_sprites_list.add(red_depot_b) self.all_sprites_list.add(red_loading_station_a) self.all_sprites_list.add(red_loading_station_b) self.all_sprites_list.add(self.robot1) self.all_sprites_list.add(self.robot2) self.all_sprites_list.add(self.robot3) self.all_sprites_list.add(self.robot4) self.all_sprites_list.add(self.robot5) self.all_sprites_list.add(self.robot6) self.solid_sprites_list = pygame.sprite.Group() self.solid_sprites_list.add(wall_1) self.solid_sprites_list.add(wall_2) self.solid_sprites_list.add(wall_3) self.solid_sprites_list.add(wall_4) self.solid_sprites_list.add(cargo_ship_1) self.solid_sprites_list.add(rocket_1) self.solid_sprites_list.add(rocket_2) self.solid_sprites_list.add(rocket_3) self.solid_sprites_list.add(rocket_4) # self.solid_sprites_list.add(blue_hab_platform_level_1) self.solid_sprites_list.add(blue_hab_platform_level_2a) self.solid_sprites_list.add(blue_hab_platform_level_2b) self.solid_sprites_list.add(blue_hab_platform_level_3) self.solid_sprites_list.add(blue_depot_a) self.solid_sprites_list.add(blue_depot_b) # self.solid_sprites_list.add(red_hab_platform_level_1) self.solid_sprites_list.add(red_hab_platform_level_2a) self.solid_sprites_list.add(red_hab_platform_level_2b) self.solid_sprites_list.add(red_hab_platform_level_3) self.solid_sprites_list.add(red_depot_a) self.solid_sprites_list.add(red_depot_b) self.solid_sprites_list.add(self.robot1) self.solid_sprites_list.add(self.robot2) self.solid_sprites_list.add(self.robot3) self.solid_sprites_list.add(self.robot4) self.solid_sprites_list.add(self.robot5) self.solid_sprites_list.add(self.robot6) self.robots_list = pygame.sprite.Group() self.robots_list.add(self.robot1) self.robots_list.add(self.robot2) self.robots_list.add(self.robot3) self.robots_list.add(self.robot4) self.robots_list.add(self.robot5) self.robots_list.add(self.robot6) self.clock = pygame.time.Clock()
strategyResult, "{:=+11.2%}".format(change).replace('%', " %"))) strategy200Result = 0.0 strategy200lateResult = 0.0 buyAndHoldResult = 0.0 schulererResult = 0.0 for stock in starting_conf["stocks"]: tb = TableManager(stock) tempDate = getFirstValidDate() print("Simulating %s starting at %s" % (stock, tempDate)) dpt = Depot(tb.symbol, tb) strategy200(tb, dpt, tempDate) strategy200Result += dpt.getMoney() plot(tb, dpt, "Normal") dpt = Depot(tb.symbol, tb) strategy200(tb, dpt, tempDate, percent=3) strategy200lateResult += dpt.getMoney() plot(tb, dpt, "Plus3Percent") dpt = Depot(tb.symbol, tb) buyAndHold(tb, dpt, tempDate) buyAndHoldResult += dpt.getMoney() plot(tb, dpt, "BuyAndHold") dpt = Depot(tb.symbol, tb)
def new_depot(name, packages): depot = Depot(name) for c in packages: depot.add_cargo(c) return depot
mycar2 = Car('兰博基尼2', '红色', '22222', '小型车', '红色', '辽A22222') mycar3 = Car('兰博基尼3', '红色', '33333', '小型车', '黑色', '辽A33333') mycar4 = Car('兰博基尼4', '红色', '44444', '小型车', '白色', '辽A44444') mycar5 = Car('兰博基尼5', '红色', '55555', '小型车', '黄色', '辽A55555') mycars = [mycar1, mycar4] driver1 = Driver('小明', 18, mycars, '123414', '12345123436') driver2 = Driver('小红', 18, mycars, '123415', '12345123437') drivers = [driver1, driver2] # 0代表空闲 stopposition1 = Stopposition('1', 0.5, '0') stopposition2 = Stopposition('2', 0.5, '0') stopposition3 = Stopposition('3', 0.5, '0') stoppositions = [stopposition1, stopposition2, stopposition3] depot1 = Depot(stoppositions, '浑河新区世纪新城', '新城停车场', 3, '小型车', 3) depot2 = Depot(stoppositions, '浑河新区世纪新城1', '新城停车场1', 3, '小型车', 3) index = random.randint(0, 1) driver = drivers[index] driver.drive_car() driver.come_in_depot(depot2) stop_order = Stop_record('1', driver.cars[0].car_id, time.time()) # depot2.produce_record() # stop_order.set_come_time = time.time() driver.stop_on_position(stopposition1, time.time(), stop_order) # depot2.update_record() # stop_order.set_stop_time(time.time())
def addDepots(rd): ldepot = [] Depots._numberDepots = rd.get_numberDepots() #Depots._loadVehicle = rd.get_load() #Depots._durationRoute = rd.get_durationRoute() for i in range(Depots._numberDepots): dataDepot = rd.get_dataDepots()[i].split() dpt = Depot() dpt.set_id(int(dataDepot[0])) dpt.set_xy_coord(float(dataDepot[1]), float(dataDepot[2])) dpt.set_durationRoute(rd.get_durationRoute()) dpt.set_numberVehicles(rd.get_numberVehicles()) dpt.set_loadVehicle(rd.get_load()) dpt.set_loadTotal(rd.get_load() * rd.get_numberVehicles()) ldepot.append((dataDepot[0], dpt)) Depots._depotsList = dict(ldepot)
LOG_PATH = BASE_PATH + "data/log/" LOG_DEBUG_FILENAME = LOG_PATH + "tour_de_source.debug.log" LOG_CRITICAL_FILENAME = LOG_PATH + "tour_de_source.critical.log" # now make blank logging files open(LOG_DEBUG_FILENAME, 'a').close() open(LOG_CRITICAL_FILENAME, 'a').close() e1 = "*****@*****.**" p1 = "cro0thiezlutrl" to = "*****@*****.**" l = util.prepareLogging(e1, p1, to, BASE_PATH, LOG_DEBUG_FILENAME, LOG_CRITICAL_FILENAME, thisCloneName) d = Depot(l, BASE_PATH) # test scanner or quickly send finished email # s = [LocalTestSourcer("copycat_test_sourcer", e1, p1, l, bp=BASE_PATH)] # t = Tourist(d, e1, p1, to, PythonRegexScanner(l), s, l, "LocalTestSourcer tour ended with status: ", LOG_CRITICAL_FILENAME) # test github interactions # s = [GithubPythonSourcer("mock", e1, p1, l)] # t = LookiLoo(d, e1, p1, to, PythonRegexScanner(l), s, l, "Lookilo finished with status: ", LOG_CRITICAL_FILENAME) # test normal operation or run normally # 15249309 will be a small, fast repo, 15249311 is two repos later s = [GithubPythonSourcer("20Commits", e1, p1, l, credentials, first, stop)] t = Tourist(d, e1, p1, to, PythonRegexScanner(l), s, l, endingMessage, LOG_CRITICAL_FILENAME) t.tour()