def __init__(self, system, clusterID, nUnits, Ti, Tn, NBin_nEntries, SB_sizeCluster, cbClusterDoneReading, cbClusterDone): # cluster things self.system = system self.cbClusterDoneReading = cbClusterDoneReading self.VERBOSE = op.verboseCluster self.clusterID = clusterID self.busy = False self.windowID = 0 #The units self.SB_sizeCluster = SB_sizeCluster self.units = [] self.nUnits = nUnits self.Tn = Tn self.Ti = Ti self.NBin_nEntries = NBin_nEntries self.unitLastPosInWindow = np.zeros((nUnits, 2)) #it records the last position of the actual window that was sent to each unit (nWindow, pos) self.subWindowDataFlat = {} self.unitsReadingWindow = {} self.filtersToUnits = {} self.unitToWindow = {} self.filterIDs = [] self.unitFilterCnt = [0]*nUnits self.unitsFinishedThisGroup = {} for i in range(nUnits): self.units.append(unit.Unit(system, clusterID, i, NBin_nEntries, Ti, Tn, SB_sizeCluster/nUnits, self.cbInputRead, self.cbDataAvailable))
def crossvaltest(self, sd, ed): unit1 = unit.Unit(self.symb, sd, ed, self.predlen) testx = unit1.preprocessRF() xx = testx[:, :-1] yy = testx[:, -1] print xx.shape print yy.shape if self.cat == 'RF': clf = sklearn.ensemble.RandomForestClassifier(n_estimators=25) elif self.cat == 'KNN': clf = sklearn.neighbors.KNeighborsClassifier() elif self.cat == 'SVM': clf = sklearn.svm.SVC() elif self.cat == 'NN': clf = sklearn.neural_network.MLPClassifier() accu = cross_val_score(clf, xx, yy, cv=3) #precision = cross_val_score(clf, xx, yy, cv=10, scoring='precision') #recall = cross_val_score(clf,xx,yy,cv=10,scoring='recall') print accu #print precision #print recall print 'mean:' print 'accu: ' + str(np.mean(accu))
def deviation( dvx1: object, dvy1: object, dvx2: object, dvy2: object, dist, plot: object = False ) -> object: #simulation of first half of the orbit if plot: arrX.clear() arrY.clear() global dt unitmass = 1.0 ut = unit.Unit(np.array([1.0, 0.0, 0.0]), np.array([0.0 + dvx1, 1.0 + dvy1, 0.0]), unitmass) sp = space.Space() planetmass = 1.0 / G pl = planet.Planet(planetmass) sp.planet = pl sp.unit = ut pos = ut.pos angle = 0 E0 = ut.getEnergy(planetmass) A0 = ut.vectorLenc(planetmass) flag = False while True: #Condition for the whole orbit if (ut.pos[1] < ut.vel[1] * dt) and (ut.pos[0] < 0) and not flag: flag = True ut.vel[0] += dvx2 ut.vel[1] += dvy2 elif flag and (ut.pos[0] > 0) and (ut.pos[1] > 0): #pos_next = ut.pos[1] + ut.vel[1] * dt #vel_next = ut.vel + pl.acceleration(ut.pos) * dt #ut.vel = (ut.vel * abs(pos_next) + vel_next * abs(ut.pos[1])) / (abs(ut.pos[1]) + abs(pos_next)) break angle += math.degrees(0.001 / 57) sp.step_rot(dt, dist, angle) if plot: arrX.append(ut.pos[0]) arrY.append(ut.pos[1]) E = ut.getEnergy(planetmass) A = ut.vectorLenc(planetmass) glob_vel = ut.vel glob_pos = ut.pos delta = ((E - E0)**2) + vectors.squarelength(A - A0) return delta
def findExplorerUnit(self): units = BoScript.allPlayerUnits(self.mPlayer) for u in units: if BoScript.isUnitMobile(u): if BoScript.canUnitMineMinerals(u) or BoScript.canUnitMineOil( u): continue pos = BoScript.unitPosition(u) if pos[0] != -1: return unit.Unit(self.mPlayer, u) return 0
def load_units(self, unit_type): """Load units into link_units and comment_units Creates units from data found in UNIT_PATH """ units = [] for unit_data in db.get_units(unit_type): units.append(unit.Unit(unit_data)) print ":: loaded %d %s units" % (len(units), unit_type) return units
def __init__(self, m): self.model = m self.units = [unit.Unit(self.model, x, y) for x, y in self.model.conf.units] self.all_effects = pygame.sprite.Group() self.individual_effects = defaultdict(pygame.sprite.Group) self.all_walkers = pygame.sprite.Group() self.renderer = render.Renderer() self.renderer.draw(self.model) self.clock = pygame.time.Clock() # Win conditions self.win_duration_sec = self.model.conf.game["duration"] self.win_duration_frames = self.model.conf.game["duration"] * FRAMES_PER_SECOND self.win_living_min_threshold = self.model.conf.game["living_min_threshold"] self.font = bont.Tiny() self.news_font = data.load_font(*NEWS_FONT) self.over_font = data.load_font(*OVER_FONT) self.selection = None self.last_selection = None self.need_destination = False self.pending_cmd = None self.buttons = buttons.ButtonRegistry() self.buttons.add_sprite_button("Cleanse", self.send_reap, 150, 160) self.buttons.add_sprite_button("Burn", self.send_burn, 150, 180) self.buttons.add_sprite_button("Block", self.send_block, 205, 160) self.buttons.add_sprite_button("Cancel", self.cancel_selection, 205, 180) self.advisor_face = data.load_image("faces/6p.png") self.frame = 0 self.newsflash = None # don't fire a newsflash right away self.next_newsflash = 5 * FRAMES_PER_SECOND self.hover_info = hover_info.HoverInfo() self.over = None self.paused = False self.final_click = False self.voice_chan = None self.select_voice_iter = itertools.cycle(self.select_voices) music.enqueue("minor1")
def __init__(self, other=None): self.Teams = [[None, None, None, None], [None, None, None, None]] self.FirstMove = 0 if (other is None): self.Teams = [[None, None, None, None], [None, None, None, None]] for j in range(4): for i in range(2): self.Teams[i][j] = unit.Unit(j) #random.randint(0,4)) self.Teams[i][j].assign_name(TeamNames[i] + " " + str(j) + " the " + self.Teams[i][j].job) else: self.copy(other)
def __init__(self, port): self.tx = PWM(port[0], freq=38000, duty=0, timer=1) self.rx = Pin(port[1], Pin.IN) self.rx.init(Pin.IN) self.rx.irq(handler=self._irq_cb, trigger=Pin.IRQ_FALLING) self.rx_value = 0 self.times = 0 self.status = 0 self.tx_en = 0 self.duty = 0 self.time_num = peripheral.get_timer() if self.time_num == None: raise unit.Unit('ir application time fail') self.timer = Timer(self.time_num) self.timer.init(period=50, mode=self.timer.PERIODIC, callback=self._update)
def create_home(self, pos_m_x, pos_m_y, home_name): home_environment = environment.Environment(name='home', matrix_width=16, matrix_height=16, _dictionary=self.dictionary) home_environment.units.append(unit.Unit('HomeDoor', self.dictionary)) home_environment.units[-1].pos_pixel_x = 220 home_environment.units[-1].pos_pixel_y = 140 home_environment.units[-1].data['pos'] = (pos_m_x, pos_m_y) key = str(pos_m_x) + ',' + str(pos_m_y) self.home_index_dict[key] = len(self.homes) self.homes.append(home_environment) if home_name == 'HomeS': home_environment.init_home('S') elif home_name == 'HomeM': home_environment.init_home('M') elif home_name == 'HomeL': home_environment.init_home('L')
def querysingleday(self, date): sd = '2017-1-1' ed = date testunit = unit.Unit(self.symb, sd, ed, self.predlen) testx = testunit.preprocessRF(mode=2) predy = self.learner.query(testx) res = predy[-1] #need modification if res > 0.3: return 'buy' elif res < -0.3: return 'sell' else: return 'watch'
def querydates(self, sd, ed): sd = util.minusdate(sd) testunit = unit.Unit(self.symb, sd, ed, self.predlen) testx = testunit.preprocessRF(mode=2) predy = self.learner.query(testx) res = testunit.convert2(predy) res.dropna() print res for i in range(len(res)): if res.ix[i, 0] > 0.3: res.ix[i, 0] = 'buy' elif res.ix[i, 0] < -0.3: res.ix[i, 0] = 'sell' else: res.ix[i, 0] = 'watch' return res
def __init__(self, info=b"14U24U34U44U15U25U35U45U41u31u21u11u40u30u20u10u"): self.state = info.decode() self.units = [ unit.Unit(1, 4, Geister.colorIndex[self.state[2]], "A"), unit.Unit(2, 4, Geister.colorIndex[self.state[5]], "B"), unit.Unit(3, 4, Geister.colorIndex[self.state[8]], "C"), unit.Unit(4, 4, Geister.colorIndex[self.state[11]], "D"), unit.Unit(1, 5, Geister.colorIndex[self.state[14]], "E"), unit.Unit(2, 5, Geister.colorIndex[self.state[17]], "F"), unit.Unit(3, 5, Geister.colorIndex[self.state[20]], "G"), unit.Unit(4, 5, Geister.colorIndex[self.state[23]], "H"), unit.OpUnit(4, 1, Geister.colorIndex[self.state[26]], "a"), unit.OpUnit(3, 1, Geister.colorIndex[self.state[29]], "b"), unit.OpUnit(2, 1, Geister.colorIndex[self.state[32]], "c"), unit.OpUnit(1, 1, Geister.colorIndex[self.state[35]], "d"), unit.OpUnit(4, 0, Geister.colorIndex[self.state[38]], "e"), unit.OpUnit(3, 0, Geister.colorIndex[self.state[41]], "f"), unit.OpUnit(2, 0, Geister.colorIndex[self.state[44]], "g"), unit.OpUnit(1, 0, Geister.colorIndex[self.state[47]], "h") ] self.history = []
def deviation(dvx, dvy, dist): #simulation of first half of the orbit global glob_pos #some global names to store variables global glob_vel unitmass = 1.0 ut = unit.Unit(np.array([1.0, 0.0, 0.0]), np.array([0.0 + dvx, 1.1 + dvy, 0.0]), unitmass) sp = space.Space() count = 0 planetmass = 1.0 / G pl = planet.Planet(planetmass) sp.planet = pl sp.unit = ut pos = ut.pos dt = 0.001 #simulation step E0 = ut.getEnergy(planetmass) A0 = ut.vectorLenc(planetmass) M0 = ut.getMomentum() while ((ut.pos[1] > ut.vel[1] * dt) or (ut.pos[0] > 0)): #Condition for one half of the orbit #while (ut.movetime(dt) < math.pi): #while (count < math.pi/dt): sp.step(dt, dist) count += 1 arrX.append(ut.pos[0]) arrY.append(ut.pos[1]) E = ut.getEnergy(planetmass) A = ut.vectorLenc(planetmass) M = ut.getMomentum() glob_vel = ut.vel glob_pos = ut.pos #delta = ((E - E0)**2) + vectors.squarelength(M - M0) + vectors.squarelength(A - A0) delta = ((E - E0)**2) + vectors.squarelength(A - A0) #print ('unit position: ',ut.pos) return delta
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests tests = [ unit.Unit(name="auth_login.php", host=host, url="/api/endpoint/auth/auth_login.php", request_method=unit.Unit.METHOD_POST, preexec=lambda: {}, postexec=f_session_store, data_request={ 'username': '******', 'password': '******', 'who': 'LibreSignage-Utests', 'permanent': False }, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ "session": RespDict({ "who": RespStr('LibreSignage-Utests'), "from": RespStr(None), "created": RespInt(None), "max_age": RespInt(None), "permanent": RespBool(False), "token": RespStr(None) }), "error": RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Set-Cookie': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }) ]
def deviation2(dvx, dvy, dist): # simulation of the second half sp = space.Space() count = 0 planetmass = 1.0 / G pl = planet.Planet(planetmass) sp.planet = pl unitmass = 1.0 pos = glob_pos vel = glob_vel dv = np.array([dvx, dvy, 0]) ut = unit.Unit(pos, (vel + dv), unitmass) sp.unit = ut #print ('start velocity', ut.vel) dt = 0.001 E0 = ut.getEnergy(planetmass) A0 = ut.vectorLenc(planetmass) M0 = ut.getMomentum() #while (ut.pos[1] < ut.vel[1] * dt) or (ut.pos[0] < 0 ): #Condition for second half of the orbit #while (ut.pos[1] <= 0): while (count < math.pi / dt): sp.step(dt, dist) count += 1 arrX.append(ut.pos[0]) arrY.append(ut.pos[1]) E = ut.getEnergy(planetmass) A = ut.vectorLenc(planetmass) M = ut.getMomentum() #delta = ((E - E0)**2) + vectors.squarelength(M - M0) + vectors.squarelength(A - A0) delta = ((E - E0)**2) + vectors.squarelength(A - A0) #print ('unit position: ', ut.pos , 'unit velocity: ', ut.vel) return delta
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests tests = [ unit.Unit(name="auth_logout.php", host=host, url="/api/endpoint/auth/auth_logout.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={"error": RespInt(0)}, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }) ]
def update(self): self.update_units() self.update_clock() self.update_continuous_events() # 更新img index if self.frames % 8 == 0: self.player.stay_img_index = (self.player.stay_img_index + 1) % 8 if self.frames % 4 == 0 and self.player.state == 'W': self.player.run_img_index = (self.player.run_img_index + 1) % 8 if self.frames % 2 == 0 and self.player.state == 'R': self.player.run_img_index = (self.player.run_img_index + 1) % 8 # 玩家饥饿 if self.frames % 90 == 29: self.player.sub_sp(1) # 昼夜交替 if self.frames % 2000 == 1999: self.night = ~self.night # 夜晚刷新怪物 if self.night and self.frames % 300 == 299: self.environment.units.append( unit.Unit('MushroomMonster', self.dictionary)) self.environment.units[ -1].pos_pixel_x = self.player.pos_pixel_x + random.choice( [-1, 1]) * random.randint(400, 1200) self.environment.units[ -1].pos_pixel_y = self.player.pos_pixel_y + random.choice( [-1, 1]) * random.randint(300, 900) self.environment.units[-1].data['attack_cd'] = False self.environment.units[-1].data['attack'] = 5 self.environment.units[-1].data['speed'] = 5 self.environment.units[-1].data['hp'] = 20 self.environment.units[-1].data['movement'] = (0, 0) self.environment.units[-1].data['alert_distance'] = 1000 self.environment.units[-1].data['drop_thing'] = 'RedMushroom' self.environment.units[-1].data['face'] = 0 self.environment.units[-1].data['action'] = 1
import display import character import unit import attack import random units = [] attacks = [] envWidth, envHeight = 40, 30 # environment numRocks = 30 for n in range(numRocks): x = random.randint(1, envWidth - 2) y = random.randint(1, envHeight - 2) rock = unit.Unit(x, y, 'rock', 'o', False) units.append(rock) numEnemies = 5 enemies = [] for n in range(numEnemies): x = random.randint(1, envWidth - 2) y = random.randint(1, envHeight - 2) enemy = character.Character(x, y, 'Enemy', '>', 2, units, attacks) enemies.append(enemy) units.append(enemy) x = random.randint(1, envWidth - 2) y = random.randint(1, envHeight - 2) hero = character.Character(x, y, 'Leo', 'S', 2, units, attacks) units.append(hero)
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests; tests = [ unit.Unit( name = "slide_data_query.php", host = host, url = "/api/endpoint/slide/slide_data_query.php", request_method = unit.Unit.METHOD_GET, preexec = f_session_use, postexec = lambda a, b: None, data_request = { 'id': 1, }, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'data': RespDict(None), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = "slide_save.php", host = host, url = "/api/endpoint/slide/slide_save.php", request_method = unit.Unit.METHOD_POST, preexec = f_session_use, postexec = lambda a, b: None, data_request = { 'id': None, 'name': 'LS-Utest-Slide', 'index': 0, 'time': 5000, 'markup': 'Unit testing...', 'enabled': True, 'sched': False, 'sched_t_s': 0, 'sched_t_e': 0, 'animation': 1, 'queue_name': 'default', 'collaborators': [] }, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'id': RespRe('.*'), 'name': RespStr('LS-Utest-Slide'), 'index': RespInt(0), 'time': RespInt(5000), 'markup': RespRe('Unit testing...'), 'enabled': RespBool(True), 'sched': RespBool(False), 'sched_t_s': RespInt(0), 'sched_t_e': RespInt(0), 'animation': RespInt(1), 'owner': RespStr('admin'), 'queue_name': RespStr('default'), 'collaborators': RespList([]), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = "slide_rm.php", host = host, url = "/api/endpoint/slide/slide_rm.php", request_method = unit.Unit.METHOD_POST, preexec = f_session_use, postexec = lambda a, b: None, data_request = { 'id': '0x3' }, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = "slide_get.php", host = host, url = "/api/endpoint/slide/slide_get.php", request_method = unit.Unit.METHOD_GET, preexec = f_session_use, postexec = lambda a, b: None, data_request = { 'id': '0x1', }, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'slide': RespDict({ 'id': RespRe('0x1'), 'name': RespRe('.*'), 'index': RespInt(None), 'time': RespInt(None), 'markup': RespRe('.*'), 'owner': RespRe('.*'), 'enabled': RespBool(None), 'sched': RespBool(None), 'sched_t_s': RespInt(None), 'sched_t_e': RespInt(None), 'animation': RespInt(None), 'queue_name': RespStr('default'), 'collaborators': RespList([]) }), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = "slide_dup.php", host = host, url = "/api/endpoint/slide/slide_dup.php", request_method = unit.Unit.METHOD_POST, preexec = f_session_use, postexec = lambda a, b: None, data_request = { 'id': '0x1', }, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'slide': RespDict({ 'id': RespRe('.*'), 'name': RespRe('.*'), 'index': RespInt(None), 'time': RespInt(None), 'markup': RespRe('.*'), 'owner': RespRe('.*'), 'enabled': RespBool(None), 'sched': RespBool(None), 'sched_t_s': RespInt(None), 'sched_t_e': RespInt(None), 'animation': RespInt(None), 'queue_name': RespStr('default'), 'collaborators': RespList([]) }), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = "slide_list.php", host = host, url = "/api/endpoint/slide/slide_list.php", request_method = unit.Unit.METHOD_GET, preexec = f_session_use, postexec = lambda a, b: None, data_request = {}, headers_request = {}, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'slides': RespDict(None), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), ];
def _available(self): if self.i2c.is_ready(self.addr) or self.i2c.is_ready(self.addr): pass else: raise unit.Unit("DAC unit maybe not connect")
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests; tests = [ unit.Unit( name = 'auth_get_sessions.php', host = host, url = '/api/endpoint/auth/auth_get_sessions.php', request_method = unit.Unit.METHOD_GET, preexec = f_session_use, postexec = lambda a, b: None, data_request = {}, headers_request = {}, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'sessions': RespDict(None), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = 'auth_session_renew.php', host = host, url = '/api/endpoint/auth/auth_session_renew.php', request_method = unit.Unit.METHOD_POST, preexec = f_session_use, postexec = f_session_store, data_request = {}, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'session': RespDict({ 'who': RespStr( 'LibreSignage-Utests' ), 'from': RespRe('.*'), 'created': RespInt(None), 'max_age': RespInt(None), 'permanent': RespBool(False), 'token': RespRe('.*') }), 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Set-Cookie': RespRe('.*'), 'Content-Type': RespRe( 'application/json.*' ) } ), unit.Unit( name = 'auth_logout_other.php', host = host, url = '/api/endpoint/auth/auth_logout_other.php', request_method = unit.Unit.METHOD_POST, preexec = f_session_use, postexec = lambda a, b: None, data_request = {}, headers_request = { 'Content-Type': 'application/json' }, cookies_request = None, data_expect_strict = True, headers_expect_strict = False, status_expect = 200, data_expect = { 'error': RespInt(0) }, headers_expect = { 'Access-Control-Allow-Origin': RespRe( '.*' ), 'Content-Type': RespRe( 'application/json.*' ) } ) ];
def _available(self): if self.i2c.available() or self.i2c.available(): pass else: raise unit.Unit("Pb.hub unit maybe not connect")
def _available(self): if self.i2c.is_ready(92) or self.i2c.is_ready(92): pass else: raise unit.Unit("ENV unit maybe not connect")
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests tests = [ unit.Unit(name="queue_create.php", host=host, url="/api/endpoint/queue/queue_create.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={'name': 'utest-queue'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={'error': RespInt(0)}, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="queue_list.php", host=host, url="/api/endpoint/queue/queue_list.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'queues': RespList(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="queue_get.php", host=host, url="/api/endpoint/queue/queue_get.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={'name': 'utest-queue'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'owner': RespStr('admin'), 'slides': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="queue_remove.php", host=host, url="/api/endpoint/queue/queue_remove.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={'name': 'utest-queue'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={'error': RespInt(0)}, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }) ]
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests tests = [ unit.Unit(name="user_get_current.php", host=host, url="/api/endpoint/user/user_get_current.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'user': RespDict({ 'user': RespStr('admin'), 'groups': RespList(['admin', 'editor', 'display']) }), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="users_get_all.php", host=host, url="/api/endpoint/user/users_get_all.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'users': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="user_get_quota.php", host=host, url="/api/endpoint/user/user_get_quota.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={'user': '******'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'quota': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="user_create.php", host=host, url="/api/endpoint/user/user_create.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={ 'user': '******', 'groups': ['editor', 'display'] }, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'user': RespDict({ 'name': RespStr('utestuser'), 'groups': RespList(['editor', 'display']), 'pass': RespRe('.*'), }), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="user_save.php", host=host, url="/api/endpoint/user/user_save.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={ 'user': '******', 'pass': None, 'groups': ['editor'] }, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'user': RespDict({ 'name': RespStr('utestuser'), 'groups': RespList(['editor']) }), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="user_get.php", host=host, url="/api/endpoint/user/user_get.php", request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={'user': '******'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'user': RespDict({ 'user': RespStr('utestuser'), 'groups': RespList(['editor']), }), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name="user_remove.php", host=host, url="/api/endpoint/user/user_remove.php", request_method=unit.Unit.METHOD_POST, preexec=f_session_use, postexec=lambda a, b: None, data_request={'user': '******'}, headers_request={'Content-Type': 'application/json'}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={'error': RespInt(0)}, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }) ]
def setup(host: str, f_session_use: Callable[[], Dict[str, Any]], f_session_store: Callable[[bool, Response], None]) -> None: global tests tests = [ unit.Unit(name='api_err_codes.php', host=host, url='/api/endpoint/general/api_err_codes.php', request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'codes': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name='api_err_msgs.php', host=host, url='/api/endpoint/general/api_err_msgs.php', request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'messages': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }), unit.Unit(name='library_licenses.php', host=host, url='/api/endpoint/general/library_licenses.php', request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=False, headers_expect_strict=False, status_expect=200, data_expect=RespRe('.*'), headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('text/plain.*') }), unit.Unit(name='libresignage_license.php', host=host, url='/api/endpoint/general/libresignage_license.php', request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=False, headers_expect_strict=False, status_expect=200, data_expect=RespRe('.*'), headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('text/plain.*') }), unit.Unit(name='server_limits.php', host=host, url='/api/endpoint/general/server_limits.php', request_method=unit.Unit.METHOD_GET, preexec=f_session_use, postexec=lambda a, b: None, data_request={}, headers_request={}, cookies_request=None, data_expect_strict=True, headers_expect_strict=False, status_expect=200, data_expect={ 'limits': RespDict(None), 'error': RespInt(0) }, headers_expect={ 'Access-Control-Allow-Origin': RespRe('.*'), 'Content-Type': RespRe('application/json.*') }) ]
prey_list = [] predator_list = [] util.populate_prey(prey_list, config) util.populate_predator(predator_list, config) pygame.init() screen = pygame.display.set_mode(config["size"]) pygame.display.set_caption("The Birds") screen.fill(color.THECOLORS['lightslategray']) clock = pygame.time.Clock() prey_sprites = pygame.sprite.RenderPlain() for b in prey_list: new_sprite = unit.Unit(b, 'prey') prey_sprites.add(new_sprite) predator_sprites = pygame.sprite.RenderPlain() for p in predator_list: new_sprite = unit.Unit(p, 'predator') predator_sprites.add(new_sprite) done = False while not done: dt = clock.tick(config["FPS"]) screen.fill(color.THECOLORS['lightslategray']) prey_sprites.update() prey_sprites.draw(screen)
def setUp(self): self.pos = (100, 100) self.dimensions = (100, 100) self.unit = unit.Unit(self.pos, self.dimensions)
def deviation(dvx,dvy, dist): sp = space.Space() count = 0 planetmass = 1.0 / G pl = planet.Planet(planetmass) sp.planet = pl unitmass = 1.0 ut = unit.Unit(np.array([0.9,0.0,0.0]),np.array([0.0+dvx,1.0+dvy,0.0]), unitmass) sp.unit = ut t = 0 angle = 0 dt = 0.01 # simulation step pos0 = np.array([1,0.0,0.0]) pos = ut.pos E0 = ut.getEnergy(planetmass) A0 = ut.vectorLenc(planetmass) U0 = ut.getPotentialEnergy(planetmass) KO = ut.getKinectEnergy() #----------------Arrays of physical quantities ---------------- arrE = [] arrt = [] arrT = [] arrX = [] arrY = [] arrU = [] arrK = [] arrA = [] arrM = [] arrM_full = [] arrMx = [] arrMy = [] arrMz = [] arrAx = [] arrAy = [] arrAz = [] arrAngle = [] arrA_full = [] #------------------Simulation cycle----------------------------- n = 10 # number of circles while (t<(2*math.pi)*n): #one circle sp.step_rot(dt, dist, angle) count +=1 t+=dt angle+= math.degrees(0.001/57) E = ut.getEnergy(planetmass) U = ut.getPotentialEnergy(planetmass) K = ut.getKinectEnergy() A = ut.vectorLenc(planetmass) M = ut.getMomentum() Angle = math.atan2(ut.vectorLenc(planetmass)[0],ut.vectorLenc(planetmass)[1]) T = t / (2 * math.pi) # number of orbits done #-----------------Filling the arrays---------------------------- arrK.append(K) arrE.append(E) arrU.append(U) arrt.append(t) arrT.append(T) arrX.append(ut.pos[0]) arrY.append(ut.pos[1]) arrA.append(A) arrAx.append(A[0]) arrAy.append(A[1]) arrAz.append(A[2]) arrA_full.append(A[0]+A[1]+A[2]) arrMx.append(M[0]) arrMy.append(M[1]) arrMz.append(M[2]) arrM_full.append(M[0]+M[1]+M[2]) arrAngle.append(Angle) #-------------------------------------------------------------- #plt.plot(lnh, lnE) #------------------ graph plotting----------------------------- plt.figure(1) plt.xlabel('Number of circles') plt.ylabel('Potential Energy') plt.title('Potential Energy of the spacecraft') plt.axis([0, n, 0, 2]) plt.grid(True) plt.plot(arrT,arrU) #plt.plot(arrX,arrY) plt.figure(2) plt.xlabel('Number of circles') plt.ylabel('Angle') plt.grid(True) plt.plot(arrT, arrAngle) plt.figure(3) plt.xlabel('Number of circles') plt.ylabel('E') plt.title('Total Energy of the spacecraft') plt.axis([0, n, -0.7, -0.3]) plt.grid(True) plt.plot(arrT, arrE) plt.figure(4) plt.xlabel('x') plt.ylabel('y') plt.title('Orbit of the spacecraft') plt.axis([-1.5, 1.5, -1.5, 1.5]) plt.grid(True) plt.plot(arrX, arrY) plt.figure(5) plt.axis([0, n, -1, 2]) plt.grid(True) plt.plot(arrT, arrA_full) plt.xlabel('Number of circles') plt.ylabel('A') plt.title('Laplace–Runge–Lenz vector state ') plt.figure(6) plt.axis([0, n, -1, 2]) plt.grid(True) fig, ax = plt.subplots() ax.plot(arrT, arrAx, label ='x_component') ax.plot(arrT, arrAy, label ='y_component') ax.plot(arrT, arrAz, label ='z_component') plt.xlabel('Number of circles') plt.ylabel('A') plt.title('Laplace–Runge–Lenz vector components state ') legend = ax.legend(loc='upper right', shadow=True) frame = legend.get_frame() frame.set_facecolor('0.90') plt.figure(7) plt.axis([0, n, -1, 2]) plt.grid(True) fig, ay = plt.subplots() ay.plot(arrT, arrMx, label='x_component') ay.plot(arrT, arrMy, label='y_component') ay.plot(arrT, arrMz, label='z_component') plt.xlabel('Number of circles') plt.ylabel('A') plt.title('Angular momentum state ') legend = ay.legend(loc='upper right', shadow=True) frame = legend.get_frame() frame.set_facecolor('0.90') # Set the fontsize for label in legend.get_texts(): label.set_fontsize('large') for label in legend.get_lines(): label.set_linewidth(1.5) # the legend line width plt.show() #-------------------------------------------------------------- M = ut.getMomentum() #delta = ((E - E0)**2) + vectors.squarelength(M - M0) + vectors.squarelength(A - A0) delta = ((E - E0) ** 2) + vectors.squarelength(A - A0) return delta
def train(self, trainsd='2016-6-4', trained='2017-1-10'): trainunit = unit.Unit(self.symb, trainsd, trained, self.predlen) trainxy = trainunit.preprocessRF() trainx = trainxy[:, :-1] trainy = trainxy[:, -1] self.learner.train(trainx, trainy)