def __judge_special(self, testcase, timeout_command, path, sandbox_submission, judger_path, sandbox_judge): testcase_in = str(testcase) testcase_out = str(testcase.parents[1] / 'out' / testcase.name) # make pipe to communicate with pipe() as inpp, pipe() as outp: try: additional_command = [] if self.sandbox_enabled: additional_command += timeout_command additional_command.append( str(self.cfg.getint('limit', 'time') + 1)) # start the judger first # disable Ctrl-C for subprocess judger = utils.Popen(sandbox_judge, additional_command + [judger_path, testcase_in, testcase_out], stdin=outp.r, stdout=inpp.w, stderr=subprocess.PIPE, start_new_session=True) # run submitted one starttime = time() # disable Ctrl-C for subprocess submitted = utils.Popen( sandbox_submission, additional_command + self.lang['exec'].replace('{path}', path).split(), stdin=inpp.r, stdout=outp.w, start_new_session=True) # submitted.communicate(timeout=timelimit) submitted.wait(timeout=self.cfg.getint('limit', 'time')) exectime = int((time() - starttime) * 1000) if submitted.returncode != 0: utils.kill_child_processes(judger) return ("RE", None) except subprocess.TimeoutExpired: res = ("TLE", None) if judger.poll() is not None and judger.returncode != 0: res = ("IE", None) utils.kill_child_processes(submitted) utils.kill_child_processes(judger) return res try: # wait for judger for (timelimit) secs result = judger.communicate( timeout=self.cfg.getint('limit', 'time'))[1] except subprocess.TimeoutExpired: utils.kill_child_processes(judger) return ("IE", None) # judger TLE if judger.returncode != 0: return ("IE", None) if result.startswith(b"AC"): return ("AC", exectime) return ("WA", exectime)
def main(): args = parse_args() print(args.cc) print(args.file) pipe.pipe(args.file)
def __init__(self, player): self.player = player self.platform_list = pygame.sprite.Group() self.score_list = pygame.sprite.Group() #self.score_list.add(score(0,0)) l = random.randrange(200, 300) pipe_top = pipe(150, l, "up") pipe_down = pipe(150, 400 - l, "down") self.platform_list.add(pipe_top) self.platform_list.add(pipe_down)
def add_pipe(self): l = random.randrange(200, 300) pipe_top = pipe(self.player.rect.right, l, "up") pipe_down = pipe(self.player.rect.right, 400 - l, "down") self.platform_list.add(pipe_top) self.platform_list.add(pipe_down) self.score_list.empty() scoreDigits = [int(x) for x in list(str(self.score))] for i in range(len(scoreDigits)): self.score_list.add(score(scoreDigits[i], i))
def add_pipe(self): height = randint(100, 200) gap = randint(100, 250) top_pipe = pygame.Surface((self.pipew, height)) top_pipe.fill((0, 255, 0)) bottom_pipe = pygame.Surface((self.pipew, self.surfaceH - (height + gap))) bottom_pipe.fill((0,255,0)) top = pipe(top_pipe, [self.surfaceW - 100, 0], "top", height) bottom = pipe(bottom_pipe, [self.surfaceW - 100, self.surfaceH - (height + gap)], "bottom", height) self.pipeList.append(top) self.pipeList.append(bottom)
def SpawnPipe(self): if self.player.dead == 0: self.SpawnTime += 3 if self.SpawnTime >= self.width: Pipe = pipe.pipe(self.screen, self.player, self.width, self.height) self.PipeList.append(Pipe) self.SpawnTime = 0
def pipe_update_ics(test=False): '''Update the ICS table''' if test: raise Exception('NYI') rows = test_data2 else: rows = gen_rows_ics global vals vals = [] def collect(p): for v in p: vals.append(v) yield v def cat(p): for v in p: yield v g = pipe.pipe( lambda x: rows(), compute_active_insulin, find_rescue_events, # lambda p: pipe.tee(p,prefix='x: ',stringify=lambda r: str(listify_row(r,IOB_KEYS))), cat # nonzerocarbs ) # pipe.more(g(None)) db_update(g(None), 'insulin_carb_smoothed', IOB_KEYS)
def main(): global loopCount, scoreCount, touch while True: gapSize = random.randint(5, 25) if loopCount % 90 == 0: topPos = random.randint(0, height / 2) - 400 pipes.add(pipe((width + 100, topPos + gapSize + 800))) score.add(gap((width + 100, topPos + gapSize + 800))) pipes.add(pipe((width + 100, topPos), True)) for event in pygame.event.get(): if event.type == QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: player.speed[1] = -10 player.update() pipes.update() score.update() gets_hit = pygame.sprite.spritecollide(player, pipes, False) \ or player.rect.center[1] > height point_get = pygame.sprite.spritecollide(player, score, True) screen.blit(background, [0, 0]) pipes.draw(screen) score.draw(screen) screen.blit(player.image, player.rect) pygame.display.flip() loopCount += 1 if gets_hit: lose() #print("Touch = "+str(touch)+" Point Get? = "+str(point_get)) if point_get and touch == False: scoreCount += 1 print("Score: " + str(scoreCount)) touch = True else: touch = False
def init_as_game(self, rend): if rend is not None: self.type = "game" self.background = background(rend) self.floor = floor(rend) self.pipe1_bot = pipe(rend, False) self.pipe1_top = pipe(rend, True) self.pipe2_bot = pipe(rend, False) self.pipe2_top = pipe(rend, True) self.pipe1_top.surface.x = 804 self.pipe1_bot.surface.x = 804 self.pipe2_top.surface.x = 1130 self.pipe2_bot.surface.x = 1130 self.player = bird(rend) self.score = score(rend) self.entities = [ self.background, self.pipe1_bot, self.pipe1_top, self.pipe2_bot, self.pipe2_top, self.floor, self.player, self.score ] self.index_player = self.entities.index(self.player) self.start() else: self.player.surface.x = 80 self.player.surface.y = 270 self.pipe1_top.surface.x = 800 self.pipe2_top.surface.x = 1130 self.pipe1_bot.surface.x = 800 self.pipe2_bot.surface.x = 1130 self.pipe1_top.surface.y = random.randint(pipeTopLowBound, pipeTopHighBound) self.pipe1_bot.surface.y = self.pipe1_top.surface.y + pipeOffset self.pipe2_top.surface.y = random.randint(pipeTopLowBound, pipeTopHighBound) self.pipe2_bot.surface.y = self.pipe2_top.surface.y + pipeOffset self.background.surface.x = 0 self.background.surface.y = 0 self.floor.surface.x = 0 self.score.count = 0 self.score.update_textures() pass
def pipe4(test=False): '''Write smoothed data to .csv file''' print('Not yet ready for prime time') raise Exception if test: p1 = ic_test_data1 filename = 'active_insulin_on_test_data.csv' else: p1 = gen_rows filename = 'active_insulin_on_real_data.csv' g = pipe.pipe(lambda x: p1(), lambda x: pipe.mapiter(x, coerce_row), gen_insulin_carb_vrows, gen_all_rows_basals) csv_output(g(None), filename, IOB_KEYS)
def start_convert(): file = request.files['file'] try: blur = bool(request.form['add_blur']) except: blur = False colors_num = int(request.form['colors']) max_pieces_size = int(request.form['pieces_size']) if file and allowed_file(file.filename): filename = secure_filename(file.filename) f_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(f_path) try: pipe.pipe(f_path, colors_num=colors_num, blur=blur, max_pieces_size=max_pieces_size) with open('vot-eto-da-both.svg') as f: vector = f.read() return { 'status': 'OK', 'raster': f'../{f_path}', 'vector': vector } except QuantizeError: return { 'status': 'ERROR', 'error': 'QuantizeError', 'error_msg': 'Number of colors is higher than img pixels num!' } else: return { 'status': 'ERROR', 'error': 'FormatError', 'error_msg': 'This input file format not supprted!', } return 'Error'
def pipe_write_ics2(test=False, start=None, end=None): '''Update the ICS table''' if test: raise Exception('NYI') rows = test_data2 else: rows = lambda: gen_rows_ic(start=start, end=end) def cat(p): for v in p: yield v def check_carb_code(p, label): n = 0 keys = 'rtime,carbs,carb_code,dynamic_carbs'.split(',') for row in p: n += 1 if row_get(row, 'rtime') == datetime(2017, 1, 1, 0, 35, 0) or n == 1: print(n, label, [str(row_get(row, x)) for x in keys]) if row_get(row, 'rec_nums') == '87789&87790': raise Exception('trouble!') if (row_get(row, 'carbs') > 0 and row_get(row, 'carb_code') not in [ 'before6', 'breakfast', 'lunch', 'snack', 'dinner', 'after9', 'rescue' ]): print row raise Exception('bad carb_code in {} check: {}'.format( label, row_get(row, 'carb_code'))) yield row g = pipe.pipe( lambda x: rows(), basal_amt_12, categorize_carbs, lambda x: check_carb_code(x, 'one'), compute_minutes_since, # has to be after categorize carbs, since that identifies meals compute_cgm_slopes, compute_dynamic_insulin, lambda x: check_carb_code(x, 'two'), compute_dynamic_carbs, lambda x: check_carb_code(x, 'three'), # lambda p: pipe.tee(p,prefix='x: ',stringify=lambda r: str(listify_row(r,IOB_KEYS))), cat # nonzerocarbs ) # pipe.more(g(None)) # I don't recall why I switched to insulin_carb_smoothed_2. Need to figure that out. ic_output_list(g(None), 'insulin_carb_smoothed_2', cursor_columns)
def create_virtual_rows(test=False, start=None, end=None): '''Reads from ICG and writes to ICS, inserting filler rows so that we have a row for every rtime''' if test: rows = test_data2 else: rows = lambda: gen_rows_ic_dictionaries( tablename='insulin_carb_grouped', start=start, end=end) keys_from_icg() g = pipe.pipe( lambda x: rows(), lambda p: gen_insulin_carb_vrows(rows=p), # does the actual smoothing ) # pipe.more(g(None)) ic_output_dict(g(None), 'insulin_carb_smoothed', IC_KEYS)
def pipe_create_ics(test=False): '''Compute smoothed data''' if test: rows = test_data2 else: rows = gen_rows g = pipe.pipe( lambda x: rows(), lambda p: pipe.mapiter(p, coerce_row), lambda p: gen_insulin_carb_vrows(rows=p), # does the actual smoothing lambda p: gen_all_rows_basals(rows=p), # calc basal_amt_12 ) # pipe.more(g(None)) db_output(g(None), 'insulin_carb_smoothed', ICS_KEYS)
def setup_plant(self): ## River water cooling circuit: # Water intake from river river_intake1 = self.add(river("River water intake 1")) river_intake2 = self.add(river("River water intake 2")) # River pumps river_pump1 = self.add(pump("River Pump 1", physics.large_pump_pressure_Pa, base_height_m=-4.0)) river_pump2 = self.add(pump("River Pump 2", physics.large_pump_pressure_Pa, base_height_m=-4.0)) river_pump1.in_port.connect(river_intake1.port) river_pump2.in_port.connect(river_intake2.port) # Backflow valves for pumps river_valve1 = self.add(valve("River Backflow Valve 1", height_m=-4.0)) river_valve2 = self.add(valve("River Backflow Valve 2", height_m=-4.0)) river_valve1.in_port.connect(river_pump1.out_port) river_valve2.in_port.connect(river_pump2.out_port) # Tank that combines inflows from river pumps river_in_tank = self.add(tank("River intake tank", 10.0, 2.0, 1.0)) river_in_tank.add_port("in1").connect(river_valve1.out_port) river_in_tank.add_port("in2").connect(river_valve2.out_port) river_tank_out_port = river_in_tank.add_port("out") river_in_pipe = self.add(pipe("River tank to steam condenser pipe", 30.0, area_m2=physics.large_pipe_size_m2)) river_in_pipe.in_port.connect(river_tank_out_port) # Steam condenser steam_condenser = self.add(heat_exchanger("Steam condenser")) steam_condenser.a_in.connect(river_in_pipe.out_port) # River waste-water pipe river_out = self.add(river("River cooling water outlet")) river_out_pipe = self.add(pipe("Steam condenser to river pipe", 40.0, area_m2=physics.large_pipe_size_m2)) river_out_pipe.in_port.connect(steam_condenser.a_out) river_out_pipe.out_port.connect(river_out.port)
def end_statement(): end_token() # Remove comments try: comment_index = statement.index(COMMENT_TOKEN) except ValueError: pass else: del statement[comment_index:] if statement: # TODO: make `lex` into a class to avoid hacks like [:] statement[:] = pipe(statement, on=PIPE_TOKEN) program.append(tuple(statement)) statement.clear()
def pipe_count_carbs(): carb_count = [0] def count_carbs(seq): for s in seq: if s['carbs'] > 0: carb_count[0] += 1 yield s g = pipe.pipe( lambda x: gen_rows(), lambda p: pipe.mapiter(p, coerce_row), lambda p: gen_insulin_carb_vrows(rows=p), # does the actual smoothing lambda p: gen_all_rows_basals(rows=p), # calc basal_amt_12 count_carbs) # pipe.more(g(None)) pipe.exhaust(g(None), progress=1000) print 'carb_count', carb_count
def updateScore(dt): global last_pipe global pipes # remove offscreen pipes pipes_off_screen = [index for index,value in enumerate(pipes) if value.x < (-1 * PIPE_WIDTH)] for p in pipes_off_screen: pipes[p].delete() pipes.pop(p) # add a new pipe if it is due if last_pipe % PIPE_FREQUENCY == 0: rand_height = random.randint(0, window.height - PIPE_GAP) new_pipe = pipe(window.width, rand_height, PIPE_WIDTH, PIPE_GAP, PIPE_VELOCITY, window.height, main_batch) pipes.append(new_pipe) last_pipe = 0 last_pipe += 1 # move agent agent.update() # update score scoreboard.set_score(agent.score) # check for game over if agent.y > 0: agent.set_score(agent.score + 1) else: game_over() for p in pipes: p.update() if ((agent.x + agent.size) > p.x) and (agent.x < (p.x + PIPE_WIDTH)): if ((agent.y < p.y) or ((agent.y + agent.size) > (p.y + PIPE_GAP))): game_over()
continue rc = os.fork() wait = True if '&' in args: wait = False args.remove('&') if rc < 0: os.write(2, "fork failed, exiting...".encode()) sys.exit(0) elif rc == 0: # child if '|' in args: pipe(args) continue if '<' in args: redirect(args, '<') if '>' in args: redirect(args, '>') try: os.execve(args[0], args, os.environ) except FileNotFoundError: pass for dir in re.split(":", os.environ['PATH']): # try each directory in the path program = "%s/%s" % (dir, args[0])
# import dash # import dash_html_components as html import dash_core_components as dcc from pipe import pipe df2 = pipe() data = df2.groupby('Country_ARR').count() grafica1 = [{'x': [x], 'y': [y], 'type': 'bar', 'name': name} for x, y, name in zip(range(1, data.shape[0]), data.Id, data.index)] data = df2[df2['Country_DEP']=='SPAIN'].groupby('Country_ARR').count() grafica2 = [{'x': [x], 'y': [y], 'type': 'bar', 'name': name} for x, y, name in zip(range(1, data.shape[0]), data.Id, data.index)] data = df2[df2['Country_ARR']=='SPAIN'].groupby('Country_DEP').count() grafica3 = [{'x': [x], 'y': [y], 'type': 'bar', 'name': name} for x, y, name in zip(range(1, data.shape[0]), data.Id, data.index)] df2['date_DEP_TIME'] = df2['DEP_TIME'].dt.date data = df2.groupby('date_DEP_TIME').count() grafica4 = [{'x': list(data.index), 'y': list(data.Id), 'type': 'line', 'name': list(data.index)}] g1 = grafica1 g2 = grafica2 g3 = grafica3 g4 = grafica4 # grafica 1 graphic1 = dcc.Graph( id='example-graph-1', figure={
def step(self, action): if action == 1: self.bird.jump() reward = 1 # remove offscreen pipes pipes_off_screen = [ index for index, value in enumerate(self.pipes) if value.x < (-1 * self.pipe_width) ] for p in pipes_off_screen: self.pipes[p].delete() self.pipes.pop(p) reward += 150 # add a new pipe if it is due if self.last_pipe % self.pipe_frequency == 0: rand_height = random.randint(0, self.window_y - self.pipe_gap) new_pipe = pipe(self.window_x, rand_height, self.pipe_width, self.pipe_gap, self.pipe_velocity, self.window_y, self.batch) self.pipes.append(new_pipe) self.last_pipe = 0 self.last_pipe += 1 # move agent self.bird.update() # update score if not self.batch == False: self.scoreboard.set_score(self.bird.score) # check for game over done = False if self.bird.y <= 0: done = True if self.bird.y + self.bird.size >= self.bird.max_y: done = True for p in self.pipes: p.update() if ((self.bird.x + self.bird.size) > p.x) and (self.bird.x < (p.x + self.pipe_width)): if ((self.bird.y < p.y) or ((self.bird.y + self.bird.size) > (p.y + self.pipe_gap))): done = True if not done: self.bird.set_score(self.bird.score + reward) else: reward = -100 self.reset() observation = self.observation() return (observation, reward, done, '')
def __init__(self): self.pipe = pipe()