def expression_generator(self, queue): while self.expression_num > 0: [expression, operand_list, operator_list] = Arithmetic(self.domain).create_arithmetic() [answer, stage_results] = Calculate(expression).cal_expression() # 计算错误 if answer: # 如果该答案不存在字典中,则新建该键值对,否则判断重复,若重复则不添加表达式 stringify_answer = answer.to_string() if answer.to_string() in self.no_repeat_dict: if self.judge_repeat( answer.to_string(), [stage_results, operand_list, operator_list]): self.no_repeat_dict[answer.to_string()].append( [stage_results, operand_list, operator_list]) self.expression_num -= 1 res = [expression, answer, self.expression_num] queue.put(res) else: self.no_repeat_dict[answer.to_string()] = [[ stage_results, operand_list, operator_list ]] self.expression_num -= 1 res = [expression, answer, self.expression_num] queue.put(res)
def predict(self, interface: Interface, image_batch, split_char, size_string, model_type, model_site, start_time): result = interface.predict_batch(image_batch, split_char) if interface.model_charset == 'ARITHMETIC': if '=' in result or '+' in result or '-' in result or '×' in result or '÷' in result: result = result.replace("×", "*").replace("÷", "/") result = str(int(Arithmetic.calc(result))) logger.info( '[{} {}] | [{}] - Size[{}] - Type[{}] - Site[{}] - Predict[{}] - {} ms' .format(self.request.remote_ip, self.request.uri, interface.name, size_string, model_type, model_site, result, round((time.time() - start_time) * 1000))) return result
def regenTiles(self): while len(self.tiles) == 0 or self.tiles[-1].rect.bottom <= Constants.HEIGHT + Tile.SIZE: bot = Tile.SIZE if len(self.tiles) == 0 else self.tiles[-1].rect.bottom col = pygame.Color(0) col.hsva = (360.0 + self.hueShift) % 360.0, 100, 100, 100 map(self.tiles.append, [Tile(x, bot, hueShift=self.hueShift) for x in [0, Constants.WIDTH - Tile.SIZE]]) self.hueShift = (self.hueShift + self.hueStep) % 360.0 self.tilesUntilPlatform -= 1 if self.tilesUntilPlatform == 0: self.tilesUntilPlatform = randint(40, 60) threshold = Arithmetic.lerp(70, 140, (self.tilesUntilPlatform - 50.0) / 20.0) width = randint( max(20, self.lastPlatformWidth - threshold), min(self.lastPlatformWidth + threshold, 350) ) self.generatePlatform(width, col) self.lastPlatformWidth = width while self.tiles[0].rect.bottom < 0: self.tiles.pop(0)
from interface import InterfaceManager, Interface from config import Config from utils import ImageUtils, ParamUtils, Arithmetic from signature import Signature, ServerType from tornado.concurrent import run_on_executor from concurrent.futures import ThreadPoolExecutor from middleware import * from event_loop import event_loop tornado.options.define('request_count', default=dict(), type=dict) model_path = "model" system_config = Config(conf_path="config.yaml", model_path=model_path, graph_path="graph") sign = Signature(ServerType.TORNADO, system_config) arithmetic = Arithmetic() semaphore = asyncio.Semaphore(500) scheduler = BackgroundScheduler(timezone=utc) class BaseHandler(RequestHandler): def __init__(self, application, request, **kwargs): super().__init__(application, request, **kwargs) self.exception = Response(system_config.response_def_map) self.executor = ThreadPoolExecutor(workers) self.image_utils = ImageUtils(system_config) def data_received(self, chunk): pass
def tick(self): Particle.tick(self) self.alpha = Arithmetic.clamp(0.0, 255.0, self.alpha - self.fade) self.col.a = int(round(self.alpha))