def get_ingredient_calories(ingredient): response_json = __api_request(ingredient) new_values = __parse_values(__extract_values(response_json)) dictionary = {} for value in new_values: brand_name = value[1] calories = value[0] if brand_name in dictionary: pair = dictionary[brand_name] new_calories = pair[0] + calories new_num = pair[1] + 1 dictionary[brand_name] = (new_calories, new_num) else: pair = (calories, 1) dictionary[brand_name] = pair max_elem = 0 max_calories = 0 for item in dictionary: if dictionary[item][1] > max_elem: max_elem = dictionary[item][1] max_calories = dictionary[item][0] log.debug(max_calories / max_elem) return max_calories / max_elem
def upload(self, app_path): export_type = self.export_type if export_type == 'export': return self._upload_export(app_path) elif export_type == 'pgy': return self._upload_pgy(app_path) elif export_type == 'appStore': return self._upload_app_store(app_path) else: log.debug('不支持的导出类型') return None
def __extract_tags(response_json): if 'results' in response_json: ingredients = [] main_dish = [] tags = response_json['results'][0]['tags'] for tag in tags: log.debug(str(tag['confidence']) + " " + tag['tag']) if tag['confidence'] > MAIN_DISH_CONFIDENCE: main_dish.append(tag['tag']) if tag['confidence'] > AI_CONFIDENCE: ingredients.append(tag['tag']) return __filter_results(ingredients, main_dish) return []
def _upload_export(app_path): if not os.path.exists(Paths.outputs_dir): os.makedirs(Paths.outputs_dir) app_dir = os.path.dirname(app_path) export_dir = os.path.join(Paths.outputs_dir, os.path.basename(app_dir)) if os.path.exists(export_dir): shutil.rmtree(export_dir) shutil.copytree(app_dir, export_dir) export_path = os.path.join(export_dir, os.path.basename(app_path)) if os.path.exists(export_path): log.debug('已成功导出到:%s' % export_path) else: log.debug('导出失败,请稍后重试')
def connect(user, password, database, host, port): """ Returns a DB connection and a metadata object. :param user: DB user. :param password: DB password. :param database: DB database. :param host: DB host. :param port: DB port. """ # Follow the structure: `postgresql://user:password@host:port/db`. url_string = 'postgresql://{}:{}@{}:{}/{}' url = url_string.format(user, password, host, port, database) log.debug('DB URL: ' + url_string.format(user, 'REDACTED', host, port, database)) # Create the connection object. _engine = create_engine(url, client_encoding='utf8') # Bind connection to create metadata object. _meta = MetaData(bind=_engine, reflect=True) return _engine, _meta
def upload(self, app_path): log.debug('正在上传到AppStore……') result = self._validate_app(app_path) if result == 0: result = self._upload_app(app_path) if result == 0: log.debug('上传成功') else: log.debug('上传失败')
def shutdown_session(exception=None): log.debug('Session removed: {}'.format(exception)) sqlalchemy.db_session.remove()
def shutdown_session(exception=None): log.debug('Session removed: {}'.format(exception))
def _upload_app_store(self, app_path): build_type = IOSBuildConfig.build_type if build_type.lower() == 'release': self.__publisher.upload(app_path) else: log.debug('%s方式不支持上传到AppStore' % build_type)
def upload(self, app_path): log.debug('上传到应用市场功能暂不支持Android %s' % app_path)