code
stringlengths
22
1.05M
apis
listlengths
1
3.31k
extract_api
stringlengths
75
3.25M
from pathlib import Path def read(filename='in'): file_path = Path(__file__).parent / filename with file_path.open('r') as file: return read_lines(file.readlines()) def read_lines(lines): cells = {} for y in range(len(lines)): line = lines[y].strip() for x in range(len(line)): cells[(x, y)] = line[x] return cells
[ "pathlib.Path" ]
[((68, 82), 'pathlib.Path', 'Path', (['__file__'], {}), '(__file__)\n', (72, 82), False, 'from pathlib import Path\n')]
## Copyright 2014 Cognitect. All Rights Reserved. ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS-IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. import itertools from transit.pyversion import imap, izip def mapcat(f, i): return itertools.chain.from_iterable(imap(f, i)) def pairs(i): return izip(*[iter(i)] * 2) cycle = itertools.cycle def take(n, i): return itertools.islice(i, 0, n)
[ "itertools.islice", "transit.pyversion.imap" ]
[((844, 869), 'itertools.islice', 'itertools.islice', (['i', '(0)', 'n'], {}), '(i, 0, n)\n', (860, 869), False, 'import itertools\n'), ((729, 739), 'transit.pyversion.imap', 'imap', (['f', 'i'], {}), '(f, i)\n', (733, 739), False, 'from transit.pyversion import imap, izip\n')]
import pandas as pd import matplotlib.pyplot as plt #한글 폰트 오류 제거 from matplotlib import font_manager,rc font_path ="D:/5674-833_4th/part4/malgun.ttf" font_name = font_manager.FontProperties(fname=font_path).get_name() rc('font',family = font_name) df = pd.read_excel('D:/5674-833_4th/part4/시도별 전출입 인구수.xlsx',engine = 'openpyxl',header =0) df = df.fillna(method='ffill') #누락값을 앞 데이터로 채움 #서울에서 다른 지역으로 이동한 데이터만 추출하여 정리 mask = (df['전출지별'] == '서울특별시') & (df['전입지별'] != '서울특별시') df_seoul = df[mask] df_seoul = df_seoul.drop(['전출지별'],axis= 1) #전출지별 column 삭제 df_seoul.rename({'전입지별':'전입지'},axis=1,inplace=True) #전입지별 column을 전입지로 바꿔줌 df_seoul.set_index('전입지',inplace = True) print(df_seoul) #서울에서 충청남도 , 경상북도 ,강원도 로 이동한 인구 데이터 값 선택 col_years = list(map(str,range(1970,2018))) df_3 = df_seoul.loc[['충청남도','경상북도','강원도'],col_years] #스타일 지정 plt.style.use('ggplot') #그래프 객체 생성(figure에 1개의 서브 플롯생성) fig = plt.figure(figsize=(20,5)) ax =fig.add_subplot(1,1,1) #axe 객체에 plot 함수로 그래프 출력 ax.plot(col_years,df_3.loc['충청남도',:],marker = 'o',markerfacecolor = 'green', markersize = 10,color = 'olive',linewidth = 2, label = '서울 -> 충남') ax.plot(col_years,df_3.loc['경상북도',:],marker = 'o',markerfacecolor = 'blue', markersize = 10, color = 'skyblue', linewidth = 2 , label = '서울 -> 경북') ax.plot(col_years,df_3.loc['강원도',:],marker = 'o',markerfacecolor = 'red', markersize =10, color = 'magenta',linewidth = 2, label = '서울 -> 강원') #범례표시 ax.legend(loc = 'best') #차트 제목 추가 ax.set_title('서울 -> 충남, 경북 , 강원 인구 이동',size = 20 ) #축 이름 추가 ax.set_xlabel('기간',size =12) ax.set_ylabel('이동 인구수',size =12) #축 눈금 라벨 지정 및 90 도 회전 ax.set_xticklabels(col_years,rotation = 90) #축 눈금 라벨 크기 ax.tick_params(axis = "x", labelsize =10) ax.tick_params(axis = "y", labelsize= 10) plt.show()
[ "matplotlib.font_manager.FontProperties", "matplotlib.pyplot.style.use", "matplotlib.pyplot.figure", "matplotlib.rc", "pandas.read_excel", "matplotlib.pyplot.show" ]
[((218, 246), 'matplotlib.rc', 'rc', (['"""font"""'], {'family': 'font_name'}), "('font', family=font_name)\n", (220, 246), False, 'from matplotlib import font_manager, rc\n'), ((254, 342), 'pandas.read_excel', 'pd.read_excel', (['"""D:/5674-833_4th/part4/시도별 전출입 인구수.xlsx"""'], {'engine': '"""openpyxl"""', 'header': '(0)'}), "('D:/5674-833_4th/part4/시도별 전출입 인구수.xlsx', engine='openpyxl',\n header=0)\n", (267, 342), True, 'import pandas as pd\n'), ((835, 858), 'matplotlib.pyplot.style.use', 'plt.style.use', (['"""ggplot"""'], {}), "('ggplot')\n", (848, 858), True, 'import matplotlib.pyplot as plt\n'), ((898, 925), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(20, 5)'}), '(figsize=(20, 5))\n', (908, 925), True, 'import matplotlib.pyplot as plt\n'), ((1769, 1779), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (1777, 1779), True, 'import matplotlib.pyplot as plt\n'), ((162, 206), 'matplotlib.font_manager.FontProperties', 'font_manager.FontProperties', ([], {'fname': 'font_path'}), '(fname=font_path)\n', (189, 206), False, 'from matplotlib import font_manager, rc\n')]
import os import time import pyautogui # from voiceassmain import play_voice_assistant_speech from vacore import VACore # based on EnjiRouz realization https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/app.py # функция на старте def start(core: VACore): manifest = { "name": "Википедия (поиск)", "version": "1.0", "require_online": True, "commands": { "википедия|вики": run_wiki, }, } return manifest def run_wiki(core: VACore, phrase: str): # if core != None: # core.play_voice_assistant_speech("Ищу на вики {}".format(phrase)) import wikipediaapi wiki = wikipediaapi.Wikipedia("ru") # поиск страницы по запросу, чтение summary, открытие ссылки на страницу для получения подробной информации wiki_page = wiki.page(phrase) try: if wiki_page.exists(): core.play_voice_assistant_speech( "Вот что я нашла для {} в википедии".format(phrase) ) # webbrowser.get().open(wiki_page.fullurl) # чтение ассистентом первых двух предложений summary со страницы Wikipedia # (могут быть проблемы с мультиязычностью) core.play_voice_assistant_speech(wiki_page.summary.split(".")[:2]) else: # открытие ссылки на поисковик в браузере в случае, если на Wikipedia не удалось найти ничего по запросу # play_voice_assistant_speech(translator.get( # "Can't find {} on Wikipedia. But here is what I found on google").format(search_term)) # url = "https://google.com/search?q=" + search_term # webbrowser.get().open(url) core.play_voice_assistant_speech("Не нашла {} в википедии".format(phrase)) # поскольку все ошибки предсказать сложно, то будет произведен отлов с последующим выводом без остановки программы except: import traceback core.play_voice_assistant_speech("Проблемы с поиском в Википедии") traceback.print_exc() return
[ "traceback.print_exc", "wikipediaapi.Wikipedia" ]
[((658, 686), 'wikipediaapi.Wikipedia', 'wikipediaapi.Wikipedia', (['"""ru"""'], {}), "('ru')\n", (680, 686), False, 'import wikipediaapi\n'), ((2009, 2030), 'traceback.print_exc', 'traceback.print_exc', ([], {}), '()\n', (2028, 2030), False, 'import traceback\n')]
# Django from django.urls import include, path # Django REST Framework from rest_framework.routers import DefaultRouter # Views from .views import tasks as task_views router = DefaultRouter() router.register(r'tasks', task_views.TaskViewSet, basename='task') urlpatterns = [ path('', include(router.urls)) ]
[ "rest_framework.routers.DefaultRouter", "django.urls.include" ]
[((179, 194), 'rest_framework.routers.DefaultRouter', 'DefaultRouter', ([], {}), '()\n', (192, 194), False, 'from rest_framework.routers import DefaultRouter\n'), ((292, 312), 'django.urls.include', 'include', (['router.urls'], {}), '(router.urls)\n', (299, 312), False, 'from django.urls import include, path\n')]
import importlib.metadata import logging import os import shutil from typing import Dict, Any, List import click from sqlalchemy import text from dbd.log.dbd_exception import DbdException from dbd.config.dbd_profile import DbdProfile from dbd.config.dbd_project import DbdProject from dbd.executors.model_executor import ModelExecutor, InvalidModelException from dbd.log.dbd_logger import setup_logging log = logging.getLogger(__name__) this_script_dir = os.path.dirname(__file__) class Dbd(object): """ Top level CLI object """ def __init__(self, debug: bool = False, logfile: str = 'dbd.log', profile: str = 'dbd.profile', project: str = 'dbd.project'): """ Constructor :param bool debug: debug flag :param str logfile: log file :param str profile: profile file :param str project: project file """ self.__debug = debug self.__logfile = logfile self.__profile = profile self.__project = project def debug(self) -> bool: """ Debug flag getter :return: debug flag :rtype: bool """ return self.__debug def logfile(self) -> str: """ Logfile getter :return: logfile :rtype: str """ return self.__logfile def profile(self) -> str: """ Profile getter :return: profile :rtype: str """ return self.__profile def project(self) -> str: """ Project getter :return: project :rtype: str """ return self.__project def print_version(): """ Prints DBD version """ click.echo(f"You're using DBD version {importlib.metadata.version('dbd')}.") @click.group(invoke_without_command=True) @click.option('--debug/--no-debug', envvar='DBD_DEBUG', default=False, help='Sets debugging on/off') @click.option('--version', help="Print the DBD version and exit.", is_flag=True, is_eager=True) @click.option('--logfile', envvar='DBD_LOG_FILE', default='dbd.log', help='Log file location') @click.option('--profile', envvar='DBD_PROFILE', default='dbd.profile', help='Profile configuration file') @click.option('--project', envvar='DBD_PROJECT', default='dbd.project', help='Project configuration file') @click.pass_context def cli(ctx, debug, logfile, version, profile, project): if debug: click.echo(f"Logging DEBUG info to '{logfile}'") setup_logging(logging.DEBUG, logfile) if version: print_version() ctx.exit(0) ctx.obj = Dbd(debug, logfile, profile, project) # noinspection PyUnusedLocal @cli.command(help='Initializes a new DBD project.') @click.argument('dest', required=False, default='my_new_dbd_project') @click.pass_obj def init(dbd, dest): try: src = os.path.join(this_script_dir, '..', 'resources', 'template') if os.path.exists(dest): log.error(f"Can't overwrite directory '{dest}'") raise DbdException(f"Can't overwrite directory '{dest}'") shutil.copytree(src, dest) click.echo(f"New project {dest} generated. Do cd {dest}; dbd run .") except DbdException as d: click.echo(f"ERROR: '{d}'") @cli.command(help='Executes project.') @click.option('--only', envvar='DBD_ONLY', default=None, help='Comma separated list of fully qualified table names ' '(<schema>.<table-name-no suffix>) to execute.') @click.option('--deps/--no-deps', envvar='DBD_DEPS', default=True, help='Ignores dependencies for the --only list.') @click.argument('dest', required=False, default='.') @click.pass_obj def run(dbd, only, deps, dest): try: log.debug("Loading configuration.") prf = DbdProfile.load(os.path.join('.', dbd.profile())) prj = DbdProject.load(prf, os.path.join(dest, dbd.project())) log.debug("Creating model.") model = ModelExecutor(prj) log.debug("Connecting database.") engine = prj.alchemy_engine_from_project() # engine.execution_options(supports_statement_cache=False) log.debug("Executing model.") if not deps and only is None: log.error("You must specify --only list for --no-deps.") raise DbdException("You must specify --only list for --no-deps.") if only is not None: only_list = only.split(',') try: model.execute(engine, only_list, deps) except InvalidModelException as e: log.error(f"Can't run {only_list}: {e}") raise DbdException(f"Can't run {only_list}: {e}") else: model.execute(engine) log.debug("Finished.") click.echo("All tasks finished!") except DbdException as d: click.echo(f"ERROR: '{d}'") @cli.command(help='Validates project.') @click.argument('dest', required=False, default='.') @click.pass_obj def validate(dbd, dest): try: prf = DbdProfile.load(os.path.join('.', dbd.profile())) prj = DbdProject.load(prf, os.path.join(dest, dbd.project())) model = ModelExecutor(prj) engine = prj.alchemy_engine_from_project() # noinspection PyBroadException try: engine.execute(text("SELECT 1")) except Exception: click.echo( f"Can't connect to the target database. Check profile configuration in " f"'{os.path.normpath(os.path.join(dest, dbd.profile()))}'.") validation_result, validation_errors = model.validate() if validation_result: click.echo("No errors found. Model is valid.") else: click.echo("Model isn't valid. Please fix the following errors:") __echo_validation_errors(validation_errors) except DbdException as d: click.echo(f"ERROR: '{d}'") def __echo_validation_errors(validation_errors: Dict[str, Any]): """ Top level function for printing validation errors :param validation_errors: :return: """ __echo_validation_level(validation_errors) class InvalidValidationErrorStructure(DbdException): pass def __echo_validation_level(level_validation_errors: Dict[str, Any], indent: int = 0): """ Echo validation error line (called recursively on all Dict values) :param level_validation_errors: Dict with validation result :param indent: indentation level """ for (k, v) in level_validation_errors.items(): if isinstance(v, str): msg = f"{k}:{v}" click.echo(msg.rjust(indent * 2 + len(msg), ' ')) elif isinstance(v, Dict): msg = f"{k}:" click.echo(msg.rjust(indent * 2 + len(msg), ' ')) __echo_validation_level(v, indent + 1) elif isinstance(v, List): msg = f"{k}:{str(v)}" click.echo(msg.rjust(indent * 2 + len(msg), ' ')) else: raise InvalidValidationErrorStructure(f"Invalid validation result: '{v}' isn't supported type.")
[ "logging.getLogger", "dbd.log.dbd_logger.setup_logging", "click.argument", "os.path.exists", "sqlalchemy.text", "click.group", "click.option", "os.path.join", "dbd.executors.model_executor.ModelExecutor", "shutil.copytree", "os.path.dirname", "click.echo", "dbd.log.dbd_exception.DbdException...
[((412, 439), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (429, 439), False, 'import logging\n'), ((459, 484), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (474, 484), False, 'import os\n'), ((1787, 1827), 'click.group', 'click.group', ([], {'invoke_without_command': '(True)'}), '(invoke_without_command=True)\n', (1798, 1827), False, 'import click\n'), ((1829, 1933), 'click.option', 'click.option', (['"""--debug/--no-debug"""'], {'envvar': '"""DBD_DEBUG"""', 'default': '(False)', 'help': '"""Sets debugging on/off"""'}), "('--debug/--no-debug', envvar='DBD_DEBUG', default=False, help=\n 'Sets debugging on/off')\n", (1841, 1933), False, 'import click\n'), ((1930, 2029), 'click.option', 'click.option', (['"""--version"""'], {'help': '"""Print the DBD version and exit."""', 'is_flag': '(True)', 'is_eager': '(True)'}), "('--version', help='Print the DBD version and exit.', is_flag=\n True, is_eager=True)\n", (1942, 2029), False, 'import click\n'), ((2026, 2124), 'click.option', 'click.option', (['"""--logfile"""'], {'envvar': '"""DBD_LOG_FILE"""', 'default': '"""dbd.log"""', 'help': '"""Log file location"""'}), "('--logfile', envvar='DBD_LOG_FILE', default='dbd.log', help=\n 'Log file location')\n", (2038, 2124), False, 'import click\n'), ((2121, 2231), 'click.option', 'click.option', (['"""--profile"""'], {'envvar': '"""DBD_PROFILE"""', 'default': '"""dbd.profile"""', 'help': '"""Profile configuration file"""'}), "('--profile', envvar='DBD_PROFILE', default='dbd.profile', help\n ='Profile configuration file')\n", (2133, 2231), False, 'import click\n'), ((2228, 2338), 'click.option', 'click.option', (['"""--project"""'], {'envvar': '"""DBD_PROJECT"""', 'default': '"""dbd.project"""', 'help': '"""Project configuration file"""'}), "('--project', envvar='DBD_PROJECT', default='dbd.project', help\n ='Project configuration file')\n", (2240, 2338), False, 'import click\n'), ((2724, 2792), 'click.argument', 'click.argument', (['"""dest"""'], {'required': '(False)', 'default': '"""my_new_dbd_project"""'}), "('dest', required=False, default='my_new_dbd_project')\n", (2738, 2792), False, 'import click\n'), ((3298, 3469), 'click.option', 'click.option', (['"""--only"""'], {'envvar': '"""DBD_ONLY"""', 'default': 'None', 'help': '"""Comma separated list of fully qualified table names (<schema>.<table-name-no suffix>) to execute."""'}), "('--only', envvar='DBD_ONLY', default=None, help=\n 'Comma separated list of fully qualified table names (<schema>.<table-name-no suffix>) to execute.'\n )\n", (3310, 3469), False, 'import click\n'), ((3526, 3646), 'click.option', 'click.option', (['"""--deps/--no-deps"""'], {'envvar': '"""DBD_DEPS"""', 'default': '(True)', 'help': '"""Ignores dependencies for the --only list."""'}), "('--deps/--no-deps', envvar='DBD_DEPS', default=True, help=\n 'Ignores dependencies for the --only list.')\n", (3538, 3646), False, 'import click\n'), ((3643, 3694), 'click.argument', 'click.argument', (['"""dest"""'], {'required': '(False)', 'default': '"""."""'}), "('dest', required=False, default='.')\n", (3657, 3694), False, 'import click\n'), ((4924, 4975), 'click.argument', 'click.argument', (['"""dest"""'], {'required': '(False)', 'default': '"""."""'}), "('dest', required=False, default='.')\n", (4938, 4975), False, 'import click\n'), ((2433, 2481), 'click.echo', 'click.echo', (['f"""Logging DEBUG info to \'{logfile}\'"""'], {}), '(f"Logging DEBUG info to \'{logfile}\'")\n', (2443, 2481), False, 'import click\n'), ((2490, 2527), 'dbd.log.dbd_logger.setup_logging', 'setup_logging', (['logging.DEBUG', 'logfile'], {}), '(logging.DEBUG, logfile)\n', (2503, 2527), False, 'from dbd.log.dbd_logger import setup_logging\n'), ((2853, 2913), 'os.path.join', 'os.path.join', (['this_script_dir', '""".."""', '"""resources"""', '"""template"""'], {}), "(this_script_dir, '..', 'resources', 'template')\n", (2865, 2913), False, 'import os\n'), ((2925, 2945), 'os.path.exists', 'os.path.exists', (['dest'], {}), '(dest)\n', (2939, 2945), False, 'import os\n'), ((3086, 3112), 'shutil.copytree', 'shutil.copytree', (['src', 'dest'], {}), '(src, dest)\n', (3101, 3112), False, 'import shutil\n'), ((3121, 3189), 'click.echo', 'click.echo', (['f"""New project {dest} generated. Do cd {dest}; dbd run ."""'], {}), "(f'New project {dest} generated. Do cd {dest}; dbd run .')\n", (3131, 3189), False, 'import click\n'), ((3983, 4001), 'dbd.executors.model_executor.ModelExecutor', 'ModelExecutor', (['prj'], {}), '(prj)\n', (3996, 4001), False, 'from dbd.executors.model_executor import ModelExecutor, InvalidModelException\n'), ((4781, 4814), 'click.echo', 'click.echo', (['"""All tasks finished!"""'], {}), "('All tasks finished!')\n", (4791, 4814), False, 'import click\n'), ((5176, 5194), 'dbd.executors.model_executor.ModelExecutor', 'ModelExecutor', (['prj'], {}), '(prj)\n', (5189, 5194), False, 'from dbd.executors.model_executor import ModelExecutor, InvalidModelException\n'), ((3026, 3077), 'dbd.log.dbd_exception.DbdException', 'DbdException', (['f"""Can\'t overwrite directory \'{dest}\'"""'], {}), '(f"Can\'t overwrite directory \'{dest}\'")\n', (3038, 3077), False, 'from dbd.log.dbd_exception import DbdException\n'), ((3228, 3255), 'click.echo', 'click.echo', (['f"""ERROR: \'{d}\'"""'], {}), '(f"ERROR: \'{d}\'")\n', (3238, 3255), False, 'import click\n'), ((4323, 4382), 'dbd.log.dbd_exception.DbdException', 'DbdException', (['"""You must specify --only list for --no-deps."""'], {}), "('You must specify --only list for --no-deps.')\n", (4335, 4382), False, 'from dbd.log.dbd_exception import DbdException\n'), ((4853, 4880), 'click.echo', 'click.echo', (['f"""ERROR: \'{d}\'"""'], {}), '(f"ERROR: \'{d}\'")\n', (4863, 4880), False, 'import click\n'), ((5666, 5712), 'click.echo', 'click.echo', (['"""No errors found. Model is valid."""'], {}), "('No errors found. Model is valid.')\n", (5676, 5712), False, 'import click\n'), ((5739, 5804), 'click.echo', 'click.echo', (['"""Model isn\'t valid. Please fix the following errors:"""'], {}), '("Model isn\'t valid. Please fix the following errors:")\n', (5749, 5804), False, 'import click\n'), ((5899, 5926), 'click.echo', 'click.echo', (['f"""ERROR: \'{d}\'"""'], {}), '(f"ERROR: \'{d}\'")\n', (5909, 5926), False, 'import click\n'), ((5326, 5342), 'sqlalchemy.text', 'text', (['"""SELECT 1"""'], {}), "('SELECT 1')\n", (5330, 5342), False, 'from sqlalchemy import text\n'), ((4650, 4693), 'dbd.log.dbd_exception.DbdException', 'DbdException', (['f"""Can\'t run {only_list}: {e}"""'], {}), '(f"Can\'t run {only_list}: {e}")\n', (4662, 4693), False, 'from dbd.log.dbd_exception import DbdException\n')]
#!/usr/bin/env python # -*- coding:utf-8 -*- import os import logging ENV_VAR_ROOT = "IG_SERVICE" CONFIG_FILE_NAME = "trading_ig_config.py" logger = logging.getLogger(__name__) class ConfigEnvVar(object): def __init__(self, env_var_base): self.ENV_VAR_BASE = env_var_base def _env_var(self, key): return(self.ENV_VAR_BASE + "_" + key.upper()) def get(self, key, default_value=None): env_var = self._env_var(key) return(os.environ.get(env_var, default_value)) def __getattr__(self, key): env_var = self._env_var(key) try: return(os.environ[env_var]) except KeyError: raise Exception("Environment variable '%s' doesn't exist" % env_var) try: from trading_ig_config import config logger.info("import config from %s" % CONFIG_FILE_NAME) except Exception: logger.warning("can't import config from config file") try: config = ConfigEnvVar(ENV_VAR_ROOT) logger.info("import config from environment variables '%s_...'" % ENV_VAR_ROOT) except Exception: logger.warning("can't import config from environment variables") raise("""Can't import config - you might create a '%s' filename or use environment variables such as '%s_...'""" % (CONFIG_FILE_NAME, ENV_VAR_ROOT))
[ "logging.getLogger", "os.environ.get" ]
[((152, 179), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (169, 179), False, 'import logging\n'), ((470, 508), 'os.environ.get', 'os.environ.get', (['env_var', 'default_value'], {}), '(env_var, default_value)\n', (484, 508), False, 'import os\n')]
#!/usr/bin/env python # -*- coding: utf-8 -*- """ episode, season, disc, episode_count, season_count and episode_details properties """ import copy from collections import defaultdict from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch from rebulk.match import Match from rebulk.remodule import re from rebulk.utils import is_iterable from .title import TitleFromPosition from ..common import dash, alt_dash, seps, seps_no_fs from ..common.formatters import strip from ..common.numeral import numeral, parse_numeral from ..common.pattern import is_disabled from ..common.validators import compose, seps_surround, seps_before, int_coercable from ...reutils import build_or_pattern def episodes(config): """ Builder for rebulk object. :param config: rule configuration :type config: dict :return: Created Rebulk object :rtype: Rebulk """ # pylint: disable=too-many-branches,too-many-statements,too-many-locals def is_season_episode_disabled(context): """Whether season and episode rules should be enabled.""" return is_disabled(context, 'episode') or is_disabled(context, 'season') rebulk = Rebulk().regex_defaults(flags=re.IGNORECASE).string_defaults(ignore_case=True) rebulk.defaults(private_names=['episodeSeparator', 'seasonSeparator', 'episodeMarker', 'seasonMarker']) episode_max_range = config['episode_max_range'] season_max_range = config['season_max_range'] def episodes_season_chain_breaker(matches): """ Break chains if there's more than 100 offset between two neighbor values. :param matches: :type matches: :return: :rtype: """ eps = matches.named('episode') if len(eps) > 1 and abs(eps[-1].value - eps[-2].value) > episode_max_range: return True seasons = matches.named('season') if len(seasons) > 1 and abs(seasons[-1].value - seasons[-2].value) > season_max_range: return True return False rebulk.chain_defaults(chain_breaker=episodes_season_chain_breaker) def season_episode_conflict_solver(match, other): """ Conflict solver for episode/season patterns :param match: :param other: :return: """ if match.name != other.name: if match.name == 'episode' and other.name == 'year': return match if match.name in ('season', 'episode'): if other.name in ('video_codec', 'audio_codec', 'container', 'date'): return match if (other.name == 'audio_channels' and 'weak-audio_channels' not in other.tags and not match.initiator.children.named(match.name + 'Marker')) or ( other.name == 'screen_size' and not int_coercable(other.raw)): return match if other.name in ('season', 'episode') and match.initiator != other.initiator: if (match.initiator.name in ('weak_episode', 'weak_duplicate') and other.initiator.name in ('weak_episode', 'weak_duplicate')): return '__default__' for current in (match, other): if 'weak-episode' in current.tags or 'x' in current.initiator.raw.lower(): return current return '__default__' season_words = config['season_words'] episode_words = config['episode_words'] of_words = config['of_words'] all_words = config['all_words'] season_markers = config['season_markers'] season_ep_markers = config['season_ep_markers'] disc_markers = config['disc_markers'] episode_markers = config['episode_markers'] range_separators = config['range_separators'] weak_discrete_separators = list(sep for sep in seps_no_fs if sep not in range_separators) strong_discrete_separators = config['discrete_separators'] discrete_separators = strong_discrete_separators + weak_discrete_separators max_range_gap = config['max_range_gap'] def ordering_validator(match): """ Validator for season list. They should be in natural order to be validated. episode/season separated by a weak discrete separator should be consecutive, unless a strong discrete separator or a range separator is present in the chain (1.3&5 is valid, but 1.3-5 is not valid and 1.3.5 is not valid) """ values = match.children.to_dict() if 'season' in values and is_iterable(values['season']): # Season numbers must be in natural order to be validated. if not list(sorted(values['season'])) == values['season']: return False if 'episode' in values and is_iterable(values['episode']): # Season numbers must be in natural order to be validated. if not list(sorted(values['episode'])) == values['episode']: return False def is_consecutive(property_name): """ Check if the property season or episode has valid consecutive values. :param property_name: :type property_name: :return: :rtype: """ previous_match = None valid = True for current_match in match.children.named(property_name): if previous_match: match.children.previous(current_match, lambda m: m.name == property_name + 'Separator') separator = match.children.previous(current_match, lambda m: m.name == property_name + 'Separator', 0) if separator.raw not in range_separators and separator.raw in weak_discrete_separators: if not 0 < current_match.value - previous_match.value <= max_range_gap + 1: valid = False if separator.raw in strong_discrete_separators: valid = True break previous_match = current_match return valid return is_consecutive('episode') and is_consecutive('season') # S01E02, 01x02, S01S02S03 rebulk.chain(formatter={'season': int, 'episode': int}, tags=['SxxExx'], abbreviations=[alt_dash], children=True, private_parent=True, validate_all=True, validator={'__parent__': ordering_validator}, conflict_solver=season_episode_conflict_solver, disabled=is_season_episode_disabled) \ .regex(build_or_pattern(season_markers, name='seasonMarker') + r'(?P<season>\d+)@?' + build_or_pattern(episode_markers + disc_markers, name='episodeMarker') + r'@?(?P<episode>\d+)', validate_all=True, validator={'__parent__': seps_before}).repeater('+') \ .regex(build_or_pattern(episode_markers + disc_markers + discrete_separators + range_separators, name='episodeSeparator', escape=True) + r'(?P<episode>\d+)').repeater('*') \ .chain() \ .regex(r'(?P<season>\d+)@?' + build_or_pattern(season_ep_markers, name='episodeMarker') + r'@?(?P<episode>\d+)', validate_all=True, validator={'__parent__': seps_before}) \ .chain() \ .regex(r'(?P<season>\d+)@?' + build_or_pattern(season_ep_markers, name='episodeMarker') + r'@?(?P<episode>\d+)', validate_all=True, validator={'__parent__': seps_before}) \ .regex(build_or_pattern(season_ep_markers + discrete_separators + range_separators, name='episodeSeparator', escape=True) + r'(?P<episode>\d+)').repeater('*') \ .chain() \ .regex(build_or_pattern(season_markers, name='seasonMarker') + r'(?P<season>\d+)', validate_all=True, validator={'__parent__': seps_before}) \ .regex(build_or_pattern(season_markers + discrete_separators + range_separators, name='seasonSeparator', escape=True) + r'(?P<season>\d+)').repeater('*') # episode_details property for episode_detail in ('Special', 'Pilot', 'Unaired', 'Final'): rebulk.string(episode_detail, value=episode_detail, name='episode_details', disabled=lambda context: is_disabled(context, 'episode_details')) def validate_roman(match): """ Validate a roman match if surrounded by separators :param match: :type match: :return: :rtype: """ if int_coercable(match.raw): return True return seps_surround(match) rebulk.defaults(private_names=['episodeSeparator', 'seasonSeparator', 'episodeMarker', 'seasonMarker'], validate_all=True, validator={'__parent__': seps_surround}, children=True, private_parent=True, conflict_solver=season_episode_conflict_solver) rebulk.chain(abbreviations=[alt_dash], formatter={'season': parse_numeral, 'count': parse_numeral}, validator={'__parent__': compose(seps_surround, ordering_validator), 'season': validate_roman, 'count': validate_roman}, disabled=lambda context: context.get('type') == 'movie' or is_disabled(context, 'season')) \ .defaults(validator=None) \ .regex(build_or_pattern(season_words, name='seasonMarker') + '@?(?P<season>' + numeral + ')') \ .regex(r'' + build_or_pattern(of_words) + '@?(?P<count>' + numeral + ')').repeater('?') \ .regex(r'@?' + build_or_pattern(range_separators + discrete_separators + ['@'], name='seasonSeparator', escape=True) + r'@?(?P<season>\d+)').repeater('*') rebulk.regex(build_or_pattern(episode_words, name='episodeMarker') + r'-?(?P<episode>\d+)' + r'(?:v(?P<version>\d+))?' + r'(?:-?' + build_or_pattern(of_words) + r'-?(?P<count>\d+))?', # Episode 4 abbreviations=[dash], formatter={'episode': int, 'version': int, 'count': int}, disabled=lambda context: context.get('type') == 'episode' or is_disabled(context, 'episode')) rebulk.regex(build_or_pattern(episode_words, name='episodeMarker') + r'-?(?P<episode>' + numeral + ')' + r'(?:v(?P<version>\d+))?' + r'(?:-?' + build_or_pattern(of_words) + r'-?(?P<count>\d+))?', # Episode 4 abbreviations=[dash], validator={'episode': validate_roman}, formatter={'episode': parse_numeral, 'version': int, 'count': int}, disabled=lambda context: context.get('type') != 'episode' or is_disabled(context, 'episode')) rebulk.regex(r'S?(?P<season>\d+)-?(?:xE|Ex|E|x)-?(?P<other>' + build_or_pattern(all_words) + ')', tags=['SxxExx'], abbreviations=[dash], validator=None, formatter={'season': int, 'other': lambda match: 'Complete'}, disabled=lambda context: is_disabled(context, 'season')) # 12, 13 rebulk.chain(tags=['weak-episode'], formatter={'episode': int, 'version': int}, disabled=lambda context: context.get('type') == 'movie' or is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'(?P<episode>\d{2})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>[x-])(?P<episode>\d{2})').repeater('*') # 012, 013 rebulk.chain(tags=['weak-episode'], formatter={'episode': int, 'version': int}, disabled=lambda context: context.get('type') == 'movie' or is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'0(?P<episode>\d{1,2})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>[x-])0(?P<episode>\d{1,2})').repeater('*') # 112, 113 rebulk.chain(tags=['weak-episode'], formatter={'episode': int, 'version': int}, name='weak_episode', disabled=lambda context: context.get('type') == 'movie' or is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'(?P<episode>\d{3,4})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>[x-])(?P<episode>\d{3,4})').repeater('*') # 1, 2, 3 rebulk.chain(tags=['weak-episode'], formatter={'episode': int, 'version': int}, disabled=lambda context: context.get('type') != 'episode' or is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'(?P<episode>\d)') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>[x-])(?P<episode>\d{1,2})').repeater('*') # e112, e113, 1e18, 3e19 # TODO: Enhance rebulk for validator to be used globally (season_episode_validator) rebulk.chain(formatter={'season': int, 'episode': int, 'version': int}, disabled=lambda context: is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'(?P<season>\d{1,2})?(?P<episodeMarker>e)(?P<episode>\d{1,4})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>e|x|-)(?P<episode>\d{1,4})').repeater('*') # ep 112, ep113, ep112, ep113 rebulk.chain(abbreviations=[dash], formatter={'episode': int, 'version': int}, disabled=lambda context: is_disabled(context, 'episode')) \ .defaults(validator=None) \ .regex(r'ep-?(?P<episode>\d{1,4})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>ep|e|x|-)(?P<episode>\d{1,4})').repeater('*') # cap 112, cap 112_114 rebulk.chain(abbreviations=[dash], tags=['see-pattern'], formatter={'season': int, 'episode': int}, disabled=is_season_episode_disabled) \ .defaults(validator=None) \ .regex(r'(?P<seasonMarker>cap)-?(?P<season>\d{1,2})(?P<episode>\d{2})') \ .regex(r'(?P<episodeSeparator>-)(?P<season>\d{1,2})(?P<episode>\d{2})').repeater('?') # 102, 0102 rebulk.chain(tags=['weak-episode', 'weak-duplicate'], formatter={'season': int, 'episode': int, 'version': int}, name='weak_duplicate', conflict_solver=season_episode_conflict_solver, disabled=lambda context: (context.get('episode_prefer_number', False) or context.get('type') == 'movie') or is_season_episode_disabled(context)) \ .defaults(validator=None) \ .regex(r'(?P<season>\d{1,2})(?P<episode>\d{2})') \ .regex(r'v(?P<version>\d+)').repeater('?') \ .regex(r'(?P<episodeSeparator>x|-)(?P<episode>\d{2})').repeater('*') rebulk.regex(r'v(?P<version>\d+)', children=True, private_parent=True, formatter=int, disabled=lambda context: is_disabled(context, 'version')) rebulk.defaults(private_names=['episodeSeparator', 'seasonSeparator']) # TODO: List of words # detached of X count (season/episode) rebulk.regex(r'(?P<episode>\d+)-?' + build_or_pattern(of_words) + r'-?(?P<count>\d+)-?' + build_or_pattern(episode_words) + '?', abbreviations=[dash], children=True, private_parent=True, formatter=int, disabled=lambda context: is_disabled(context, 'episode')) rebulk.regex(r'Minisodes?', name='episode_format', value="Minisode", disabled=lambda context: is_disabled(context, 'episode_format')) rebulk.rules(WeakConflictSolver, RemoveInvalidSeason, RemoveInvalidEpisode, SeePatternRange(range_separators + ['_']), EpisodeNumberSeparatorRange(range_separators), SeasonSeparatorRange(range_separators), RemoveWeakIfMovie, RemoveWeakIfSxxExx, RemoveWeakDuplicate, EpisodeDetailValidator, RemoveDetachedEpisodeNumber, VersionValidator, RemoveWeak, RenameToAbsoluteEpisode, CountValidator, EpisodeSingleDigitValidator, RenameToDiscMatch) return rebulk class WeakConflictSolver(Rule): """ Rule to decide whether weak-episode or weak-duplicate matches should be kept. If an anime is detected: - weak-duplicate matches should be removed - weak-episode matches should be tagged as anime Otherwise: - weak-episode matches are removed unless they're part of an episode range match. """ priority = 128 consequence = [RemoveMatch, AppendMatch] def enabled(self, context): return context.get('type') != 'movie' @classmethod def is_anime(cls, matches): """Return True if it seems to be an anime. Anime characteristics: - version, crc32 matches - screen_size inside brackets - release_group at start and inside brackets """ if matches.named('version') or matches.named('crc32'): return True for group in matches.markers.named('group'): if matches.range(group.start, group.end, predicate=lambda m: m.name == 'screen_size'): return True if matches.markers.starting(group.start, predicate=lambda m: m.name == 'path'): hole = matches.holes(group.start, group.end, index=0) if hole and hole.raw == group.raw: return True return False def when(self, matches, context): to_remove = [] to_append = [] anime_detected = self.is_anime(matches) for filepart in matches.markers.named('path'): weak_matches = matches.range(filepart.start, filepart.end, predicate=( lambda m: m.initiator.name == 'weak_episode')) weak_dup_matches = matches.range(filepart.start, filepart.end, predicate=( lambda m: m.initiator.name == 'weak_duplicate')) if anime_detected: if weak_matches: to_remove.extend(weak_dup_matches) for match in matches.range(filepart.start, filepart.end, predicate=( lambda m: m.name == 'episode' and m.initiator.name != 'weak_duplicate')): episode = copy.copy(match) episode.tags = episode.tags + ['anime'] to_append.append(episode) to_remove.append(match) elif weak_dup_matches: episodes_in_range = matches.range(filepart.start, filepart.end, predicate=( lambda m: m.name == 'episode' and m.initiator.name == 'weak_episode' and m.initiator.children.named('episodeSeparator') )) if not episodes_in_range and not matches.range(filepart.start, filepart.end, predicate=lambda m: 'SxxExx' in m.tags): to_remove.extend(weak_matches) else: for match in episodes_in_range: episode = copy.copy(match) episode.tags = [] to_append.append(episode) to_remove.append(match) if to_append: to_remove.extend(weak_dup_matches) return to_remove, to_append class CountValidator(Rule): """ Validate count property and rename it """ priority = 64 consequence = [RemoveMatch, RenameMatch('episode_count'), RenameMatch('season_count')] properties = {'episode_count': [None], 'season_count': [None]} def when(self, matches, context): to_remove = [] episode_count = [] season_count = [] for count in matches.named('count'): previous = matches.previous(count, lambda match: match.name in ['episode', 'season'], 0) if previous: if previous.name == 'episode': episode_count.append(count) elif previous.name == 'season': season_count.append(count) else: to_remove.append(count) return to_remove, episode_count, season_count class SeePatternRange(Rule): """ Create matches for episode range for SEE pattern. E.g.: Cap.102_104 """ priority = 128 consequence = [RemoveMatch, AppendMatch] def __init__(self, range_separators): super(SeePatternRange, self).__init__() self.range_separators = range_separators def when(self, matches, context): to_remove = [] to_append = [] for separator in matches.tagged('see-pattern', lambda m: m.name == 'episodeSeparator'): previous_match = matches.previous(separator, lambda m: m.name == 'episode' and 'see-pattern' in m.tags, 0) next_match = matches.next(separator, lambda m: m.name == 'season' and 'see-pattern' in m.tags, 0) if not next_match: continue next_match = matches.next(next_match, lambda m: m.name == 'episode' and 'see-pattern' in m.tags, 0) if previous_match and next_match and separator.value in self.range_separators: to_remove.append(next_match) for episode_number in range(previous_match.value + 1, next_match.value + 1): match = copy.copy(next_match) match.value = episode_number to_append.append(match) to_remove.append(separator) return to_remove, to_append class AbstractSeparatorRange(Rule): """ Remove separator matches and create matches for season range. """ priority = 128 consequence = [RemoveMatch, AppendMatch] def __init__(self, range_separators, property_name): super(AbstractSeparatorRange, self).__init__() self.range_separators = range_separators self.property_name = property_name def when(self, matches, context): to_remove = [] to_append = [] for separator in matches.named(self.property_name + 'Separator'): previous_match = matches.previous(separator, lambda m: m.name == self.property_name, 0) next_match = matches.next(separator, lambda m: m.name == self.property_name, 0) initiator = separator.initiator if previous_match and next_match and separator.value in self.range_separators: to_remove.append(next_match) for episode_number in range(previous_match.value + 1, next_match.value): match = copy.copy(next_match) match.value = episode_number initiator.children.append(match) to_append.append(match) to_append.append(next_match) to_remove.append(separator) previous_match = None for next_match in matches.named(self.property_name): if previous_match: separator = matches.input_string[previous_match.initiator.end:next_match.initiator.start] if separator not in self.range_separators: separator = strip(separator) if separator in self.range_separators: initiator = previous_match.initiator for episode_number in range(previous_match.value + 1, next_match.value): match = copy.copy(next_match) match.value = episode_number initiator.children.append(match) to_append.append(match) to_append.append(Match(previous_match.end, next_match.start - 1, name=self.property_name + 'Separator', private=True, input_string=matches.input_string)) to_remove.append(next_match) # Remove and append match to support proper ordering to_append.append(next_match) previous_match = next_match return to_remove, to_append class RenameToAbsoluteEpisode(Rule): """ Rename episode to absolute_episodes. Absolute episodes are only used if two groups of episodes are detected: S02E04-06 25-27 25-27 S02E04-06 2x04-06 25-27 28. Anime Name S02E05 The matches in the group with higher episode values are renamed to absolute_episode. """ consequence = RenameMatch('absolute_episode') def when(self, matches, context): # pylint:disable=inconsistent-return-statements initiators = {match.initiator for match in matches.named('episode') if len(match.initiator.children.named('episode')) > 1} if len(initiators) != 2: ret = [] for filepart in matches.markers.named('path'): if matches.range(filepart.start + 1, filepart.end, predicate=lambda m: m.name == 'episode'): ret.extend( matches.starting(filepart.start, predicate=lambda m: m.initiator.name == 'weak_episode')) return ret initiators = sorted(initiators, key=lambda item: item.end) if not matches.holes(initiators[0].end, initiators[1].start, predicate=lambda m: m.raw.strip(seps)): first_range = matches.named('episode', predicate=lambda m: m.initiator == initiators[0]) second_range = matches.named('episode', predicate=lambda m: m.initiator == initiators[1]) if len(first_range) == len(second_range): if second_range[0].value > first_range[0].value: return second_range if first_range[0].value > second_range[0].value: return first_range class EpisodeNumberSeparatorRange(AbstractSeparatorRange): """ Remove separator matches and create matches for episoderNumber range. """ def __init__(self, range_separators): super(EpisodeNumberSeparatorRange, self).__init__(range_separators, "episode") class SeasonSeparatorRange(AbstractSeparatorRange): """ Remove separator matches and create matches for season range. """ def __init__(self, range_separators): super(SeasonSeparatorRange, self).__init__(range_separators, "season") class RemoveWeakIfMovie(Rule): """ Remove weak-episode tagged matches if it seems to be a movie. """ priority = 64 consequence = RemoveMatch def enabled(self, context): return context.get('type') != 'episode' def when(self, matches, context): to_remove = [] to_ignore = set() remove = False for filepart in matches.markers.named('path'): year = matches.range(filepart.start, filepart.end, predicate=lambda m: m.name == 'year', index=0) if year: remove = True next_match = matches.range(year.end, filepart.end, predicate=lambda m: m.private, index=0) if (next_match and not matches.holes(year.end, next_match.start, predicate=lambda m: m.raw.strip(seps)) and not matches.at_match(next_match, predicate=lambda m: m.name == 'year')): to_ignore.add(next_match.initiator) to_ignore.update(matches.range(filepart.start, filepart.end, predicate=lambda m: len(m.children.named('episode')) > 1)) to_remove.extend(matches.conflicting(year)) if remove: to_remove.extend(matches.tagged('weak-episode', predicate=( lambda m: m.initiator not in to_ignore and 'anime' not in m.tags))) return to_remove class RemoveWeak(Rule): """ Remove weak-episode matches which appears after video, source, and audio matches. """ priority = 16 consequence = RemoveMatch def when(self, matches, context): to_remove = [] for filepart in matches.markers.named('path'): weaks = matches.range(filepart.start, filepart.end, predicate=lambda m: 'weak-episode' in m.tags) if weaks: previous = matches.previous(weaks[0], predicate=lambda m: m.name in ( 'audio_codec', 'screen_size', 'streaming_service', 'source', 'video_profile', 'audio_channels', 'audio_profile'), index=0) if previous and not matches.holes( previous.end, weaks[0].start, predicate=lambda m: m.raw.strip(seps)): to_remove.extend(weaks) return to_remove class RemoveWeakIfSxxExx(Rule): """ Remove weak-episode tagged matches if SxxExx pattern is matched. Weak episodes at beginning of filepart are kept. """ priority = 64 consequence = RemoveMatch def when(self, matches, context): to_remove = [] for filepart in matches.markers.named('path'): if matches.range(filepart.start, filepart.end, predicate=lambda m: not m.private and 'SxxExx' in m.tags): for match in matches.range(filepart.start, filepart.end, predicate=lambda m: 'weak-episode' in m.tags): if match.start != filepart.start or match.initiator.name != 'weak_episode': to_remove.append(match) return to_remove class RemoveInvalidSeason(Rule): """ Remove invalid season matches. """ priority = 64 consequence = RemoveMatch def when(self, matches, context): to_remove = [] for filepart in matches.markers.named('path'): strong_season = matches.range(filepart.start, filepart.end, index=0, predicate=lambda m: m.name == 'season' and not m.private and 'SxxExx' in m.tags) if strong_season: if strong_season.initiator.children.named('episode'): for season in matches.range(strong_season.end, filepart.end, predicate=lambda m: m.name == 'season' and not m.private): # remove weak season or seasons without episode matches if 'SxxExx' not in season.tags or not season.initiator.children.named('episode'): if season.initiator: to_remove.append(season.initiator) to_remove.extend(season.initiator.children) else: to_remove.append(season) return to_remove class RemoveInvalidEpisode(Rule): """ Remove invalid episode matches. """ priority = 64 consequence = RemoveMatch def when(self, matches, context): to_remove = [] for filepart in matches.markers.named('path'): strong_episode = matches.range(filepart.start, filepart.end, index=0, predicate=lambda m: m.name == 'episode' and not m.private and 'SxxExx' in m.tags) if strong_episode: strong_ep_marker = RemoveInvalidEpisode.get_episode_prefix(matches, strong_episode) for episode in matches.range(strong_episode.end, filepart.end, predicate=lambda m: m.name == 'episode' and not m.private): ep_marker = RemoveInvalidEpisode.get_episode_prefix(matches, episode) if strong_ep_marker and ep_marker and strong_ep_marker.value.lower() != ep_marker.value.lower(): if episode.initiator: to_remove.append(episode.initiator) to_remove.extend(episode.initiator.children) else: to_remove.append(ep_marker) to_remove.append(episode) return to_remove @staticmethod def get_episode_prefix(matches, episode): """ Return episode prefix: episodeMarker or episodeSeparator """ return matches.previous(episode, index=0, predicate=lambda m: m.name in ('episodeMarker', 'episodeSeparator')) class RemoveWeakDuplicate(Rule): """ Remove weak-duplicate tagged matches if duplicate patterns, for example The 100.109 """ priority = 64 consequence = RemoveMatch def when(self, matches, context): to_remove = [] for filepart in matches.markers.named('path'): patterns = defaultdict(list) for match in reversed(matches.range(filepart.start, filepart.end, predicate=lambda m: 'weak-duplicate' in m.tags)): if match.pattern in patterns[match.name]: to_remove.append(match) else: patterns[match.name].append(match.pattern) return to_remove class EpisodeDetailValidator(Rule): """ Validate episode_details if they are detached or next to season or episode. """ priority = 64 consequence = RemoveMatch def when(self, matches, context): ret = [] for detail in matches.named('episode_details'): if not seps_surround(detail) \ and not matches.previous(detail, lambda match: match.name in ['season', 'episode']) \ and not matches.next(detail, lambda match: match.name in ['season', 'episode']): ret.append(detail) return ret class RemoveDetachedEpisodeNumber(Rule): """ If multiple episode are found, remove those that are not detached from a range and less than 10. Fairy Tail 2 - 16-20, 2 should be removed. """ priority = 64 consequence = RemoveMatch dependency = [RemoveWeakIfSxxExx, RemoveWeakDuplicate] def when(self, matches, context): ret = [] episode_numbers = [] episode_values = set() for match in matches.named('episode', lambda m: not m.private and 'weak-episode' in m.tags): if match.value not in episode_values: episode_numbers.append(match) episode_values.add(match.value) episode_numbers = list(sorted(episode_numbers, key=lambda m: m.value)) if len(episode_numbers) > 1 and \ episode_numbers[0].value < 10 and \ episode_numbers[1].value - episode_numbers[0].value != 1: parent = episode_numbers[0] while parent: # TODO: Add a feature in rebulk to avoid this ... ret.append(parent) parent = parent.parent return ret class VersionValidator(Rule): """ Validate version if previous match is episode or if surrounded by separators. """ priority = 64 dependency = [RemoveWeakIfMovie, RemoveWeakIfSxxExx] consequence = RemoveMatch def when(self, matches, context): ret = [] for version in matches.named('version'): episode_number = matches.previous(version, lambda match: match.name == 'episode', 0) if not episode_number and not seps_surround(version.initiator): ret.append(version) return ret class EpisodeSingleDigitValidator(Rule): """ Remove single digit episode when inside a group that doesn't own title. """ dependency = [TitleFromPosition] consequence = RemoveMatch def when(self, matches, context): ret = [] for episode in matches.named('episode', lambda match: len(match.initiator) == 1): group = matches.markers.at_match(episode, lambda marker: marker.name == 'group', index=0) if group: if not matches.range(*group.span, predicate=lambda match: match.name == 'title'): ret.append(episode) return ret class RenameToDiscMatch(Rule): """ Rename episodes detected with `d` episodeMarkers to `disc`. """ consequence = [RenameMatch('disc'), RenameMatch('discMarker'), RemoveMatch] def when(self, matches, context): discs = [] markers = [] to_remove = [] disc_disabled = is_disabled(context, 'disc') for marker in matches.named('episodeMarker', predicate=lambda m: m.value.lower() == 'd'): if disc_disabled: to_remove.append(marker) to_remove.extend(marker.initiator.children) continue markers.append(marker) discs.extend(sorted(marker.initiator.children.named('episode'), key=lambda m: m.value)) return discs, markers, to_remove
[ "rebulk.Rebulk", "rebulk.utils.is_iterable", "rebulk.RenameMatch", "collections.defaultdict", "copy.copy", "rebulk.match.Match" ]
[((25216, 25247), 'rebulk.RenameMatch', 'RenameMatch', (['"""absolute_episode"""'], {}), "('absolute_episode')\n", (25227, 25247), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((20193, 20221), 'rebulk.RenameMatch', 'RenameMatch', (['"""episode_count"""'], {}), "('episode_count')\n", (20204, 20221), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((20223, 20250), 'rebulk.RenameMatch', 'RenameMatch', (['"""season_count"""'], {}), "('season_count')\n", (20234, 20250), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((36881, 36900), 'rebulk.RenameMatch', 'RenameMatch', (['"""disc"""'], {}), "('disc')\n", (36892, 36900), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((36902, 36927), 'rebulk.RenameMatch', 'RenameMatch', (['"""discMarker"""'], {}), "('discMarker')\n", (36913, 36927), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((4577, 4606), 'rebulk.utils.is_iterable', 'is_iterable', (["values['season']"], {}), "(values['season'])\n", (4588, 4606), False, 'from rebulk.utils import is_iterable\n'), ((4814, 4844), 'rebulk.utils.is_iterable', 'is_iterable', (["values['episode']"], {}), "(values['episode'])\n", (4825, 4844), False, 'from rebulk.utils import is_iterable\n'), ((33411, 33428), 'collections.defaultdict', 'defaultdict', (['list'], {}), '(list)\n', (33422, 33428), False, 'from collections import defaultdict\n'), ((1170, 1178), 'rebulk.Rebulk', 'Rebulk', ([], {}), '()\n', (1176, 1178), False, 'from rebulk import Rebulk, RemoveMatch, Rule, AppendMatch, RenameMatch\n'), ((22070, 22091), 'copy.copy', 'copy.copy', (['next_match'], {}), '(next_match)\n', (22079, 22091), False, 'import copy\n'), ((23302, 23323), 'copy.copy', 'copy.copy', (['next_match'], {}), '(next_match)\n', (23311, 23323), False, 'import copy\n'), ((18914, 18930), 'copy.copy', 'copy.copy', (['match'], {}), '(match)\n', (18923, 18930), False, 'import copy\n'), ((24129, 24150), 'copy.copy', 'copy.copy', (['next_match'], {}), '(next_match)\n', (24138, 24150), False, 'import copy\n'), ((24346, 24485), 'rebulk.match.Match', 'Match', (['previous_match.end', '(next_match.start - 1)'], {'name': "(self.property_name + 'Separator')", 'private': '(True)', 'input_string': 'matches.input_string'}), "(previous_match.end, next_match.start - 1, name=self.property_name +\n 'Separator', private=True, input_string=matches.input_string)\n", (24351, 24485), False, 'from rebulk.match import Match\n'), ((19775, 19791), 'copy.copy', 'copy.copy', (['match'], {}), '(match)\n', (19784, 19791), False, 'import copy\n')]
import flask import functools import bs4 import urllib.parse from .. import auth from .. import themes from .. import settings INVALID_PERMISSIONS_FLASH_MESSAGE = "Sorry, you don't have permission to view that page." def checkForSession(): if "uid" in flask.session: session = auth.validateSession(flask.session["uid"]) if session is not None: return session return None def redirectAndSave(path): flask.session["donePage"] = urllib.parse.urlparse(flask.request.url).path return flask.redirect(path) def canRecoverFromRedirect(): if "donePage" in flask.session: return flask.session["donePage"] return None #Decorator which checks if a user logged in and capable of using the specified permissions. #If redirectPage is equal to none, #the target funciton MUST have the arguments authed and authMessage defined. def checkUserPermissions(redirectPage=None, saveRedirect=True, redirectMessage=INVALID_PERMISSIONS_FLASH_MESSAGE, requiredPermissions=None): def decorator(function): def decorated(*args, **kwargs): session = checkForSession() if session is not None: username = session.user.username result = True #If we don't have any permissions necessary, a login is enough. #Otherwise, we're going to check to make sure that all necessary permissions are in place. if requiredPermissions is not None: if type(requiredPermissions) == str: result = auth.userHasPermission(username, requiredPermissions) else: for permission in requiredPermissions: if not auth.userHasPermission(username, permission): result = False #If all permissions is valid, redirect as needed. if result: if redirectPage is not None: return function(*args, **kwargs) else: return function(authed=True, authMessage=redirectMessage, *args, **kwargs) else: #We don't want to flash on thigns like ajax routes, so we use redirectPage is not None willFlash = redirectPage is not None return _permissionRedirect(redirectPage, saveRedirect, redirectMessage, willFlash, function, *args, **kwargs) else: return _permissionRedirect(redirectPage, saveRedirect, redirectMessage, False, function, *args, **kwargs) return functools.update_wrapper(decorated, function) return decorator def _permissionRedirect(redirectPage, saveRedirect, redirectMessage, flash, function, *args, **kwargs): if flash: flask.flash(redirectMessage) if redirectPage is not None: if not saveRedirect: return flask.redirect(redirectPage) else: return redirectAndSave(redirectPage) else: return function(authed=False, authMessage=redirectMessage, *args, **kwargs) #Will return all information that is needed to render a post. #Prevents fragmentation in various post display methods def getPostsParameters(): title = settings.getSettingValue("title") subtitle = settings.getSettingValue("subtitle") displayName = settings.getSettingValue("display_name") return { "blogTitle": title, "blogSubtitle": subtitle, "displayName": displayName, } #Renders the theme's template if the theme contains one #Otherwise, it renders the default template def renderPosts(defaultPath, pageTitle, pageNumber, pageCount, nextPageExists, basePageUrl="", *args, **kwargs): theme = themes.getCurrentTheme() template = theme["template"] postParams = getPostsParameters() #Merge postParams and kwargs #Anything in kwargs will overwrite postParams (which is why we use these two lines) postParams.update(kwargs) kwargs = postParams if template is None: templateFile = open(defaultPath, "r") template = templateFile.read() templateFile.close() return flask.render_template_string(template, pageTitle=pageTitle, pageNumber=pageNumber, pageCount=pageCount, nextPageExists=nextPageExists, basePageUrl=basePageUrl, *args, **kwargs) def xssFilter(postBody): whitelistedTags = ["div", "span", "b", "i", "u", "a", "p", "img", "code", "ul", "li", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "br"] #src and href must be checked seperately whitelistedAttributes = ["id", "class", "style"] soupedBody = bs4.BeautifulSoup(postBody, "html.parser") blockedTags = soupedBody.findAll(lambda tag: tag.name not in whitelistedTags) #Check if element has any attriutes that are not allowed, but only if #they are not already in blockedTags. Those will be escaped, anyway. blockedAttrs = soupedBody.findAll(lambda tag: len(set(tag.attrs.keys()) - set(whitelistedAttributes)) != 0 and tag.name in whitelistedTags) for tag in blockedTags: #Beautiful soup will escape HTML strings tag.replace_with(str(tag)) for tag in blockedAttrs: allowedAttrs = {} for attr in tag.attrs: if attr in whitelistedAttributes: allowedAttrs[attr] = tag.attrs[attr] elif attr == "src" or attr == "href": scheme = urllib.parse.urlparse(tag.attrs[attr]).scheme if scheme != "data" and scheme != "javascript": allowedAttrs[attr] = tag.attrs[attr] tag.attrs = allowedAttrs return str(soupedBody)
[ "flask.flash", "flask.redirect", "flask.render_template_string", "bs4.BeautifulSoup", "functools.update_wrapper" ]
[((526, 546), 'flask.redirect', 'flask.redirect', (['path'], {}), '(path)\n', (540, 546), False, 'import flask\n'), ((4194, 4379), 'flask.render_template_string', 'flask.render_template_string', (['template', '*args'], {'pageTitle': 'pageTitle', 'pageNumber': 'pageNumber', 'pageCount': 'pageCount', 'nextPageExists': 'nextPageExists', 'basePageUrl': 'basePageUrl'}), '(template, *args, pageTitle=pageTitle,\n pageNumber=pageNumber, pageCount=pageCount, nextPageExists=\n nextPageExists, basePageUrl=basePageUrl, **kwargs)\n', (4222, 4379), False, 'import flask\n'), ((4723, 4765), 'bs4.BeautifulSoup', 'bs4.BeautifulSoup', (['postBody', '"""html.parser"""'], {}), "(postBody, 'html.parser')\n", (4740, 4765), False, 'import bs4\n'), ((2636, 2681), 'functools.update_wrapper', 'functools.update_wrapper', (['decorated', 'function'], {}), '(decorated, function)\n', (2660, 2681), False, 'import functools\n'), ((2830, 2858), 'flask.flash', 'flask.flash', (['redirectMessage'], {}), '(redirectMessage)\n', (2841, 2858), False, 'import flask\n'), ((2940, 2968), 'flask.redirect', 'flask.redirect', (['redirectPage'], {}), '(redirectPage)\n', (2954, 2968), False, 'import flask\n')]
#!/usr/bin/env python3 # This is bot coded by <NAME> and used for educational purposes only # https://github.com/AbhijithNT # Copyright <NAME> # Thank you https://github.com/pyrogram/pyrogram from pyrogram.types import ( InlineKeyboardMarkup, InlineKeyboardButton ) def server_select(): upload_selection = [ [ InlineKeyboardButton( "transfer.sh", callback_data="transfersh" ), InlineKeyboardButton( "File.io", callback_data="File.io" ) ], [ InlineKeyboardButton( "gofile.io", callback_data="gofileio" ), InlineKeyboardButton( "anonymfiles.com", callback_data="anonymfiles" ) ], [ InlineKeyboardButton( "aparat", callback_data="aparat" ), InlineKeyboardButton( "splus", callback_data="splus" ) ] ] return InlineKeyboardMarkup(upload_selection) def completedKeyboard(dl): replayMarkup = InlineKeyboardMarkup( [[ InlineKeyboardButton( "DOWNLOAD URL", url=f"{dl}" ) ], [ InlineKeyboardButton( "🗂 SOURCE", url="https://github.com/AbhijithNT/" ) ]]) return replayMarkup
[ "pyrogram.types.InlineKeyboardButton", "pyrogram.types.InlineKeyboardMarkup" ]
[((1111, 1149), 'pyrogram.types.InlineKeyboardMarkup', 'InlineKeyboardMarkup', (['upload_selection'], {}), '(upload_selection)\n', (1131, 1149), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((345, 408), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""transfer.sh"""'], {'callback_data': '"""transfersh"""'}), "('transfer.sh', callback_data='transfersh')\n", (365, 408), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((468, 524), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""File.io"""'], {'callback_data': '"""File.io"""'}), "('File.io', callback_data='File.io')\n", (488, 524), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((604, 663), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""gofile.io"""'], {'callback_data': '"""gofileio"""'}), "('gofile.io', callback_data='gofileio')\n", (624, 663), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((723, 791), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""anonymfiles.com"""'], {'callback_data': '"""anonymfiles"""'}), "('anonymfiles.com', callback_data='anonymfiles')\n", (743, 791), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((871, 925), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""aparat"""'], {'callback_data': '"""aparat"""'}), "('aparat', callback_data='aparat')\n", (891, 925), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((985, 1037), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""splus"""'], {'callback_data': '"""splus"""'}), "('splus', callback_data='splus')\n", (1005, 1037), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((1243, 1292), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""DOWNLOAD URL"""'], {'url': 'f"""{dl}"""'}), "('DOWNLOAD URL', url=f'{dl}')\n", (1263, 1292), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n'), ((1376, 1446), 'pyrogram.types.InlineKeyboardButton', 'InlineKeyboardButton', (['"""🗂 SOURCE"""'], {'url': '"""https://github.com/AbhijithNT/"""'}), "('🗂 SOURCE', url='https://github.com/AbhijithNT/')\n", (1396, 1446), False, 'from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton\n')]
import pickle from collections import OrderedDict from datetime import datetime from .chunk import Chunk from .review import Review from .tokenizer import LineTokenizer from .utils import norm_path from .database.snippet import maybe_init, Snippet as DataSnippet class Snippet(object): def __init__(self, snippet_id, merged, chunks, source, target): self.snippet_id = snippet_id self.merged = merged self._chunks = chunks self._chunk_ids = [] self.start = chunks[0].start self.length = self.total_len(chunks[0].start, chunks[-1].end) self.source_file = norm_path(str(source)) self.target_file = norm_path(str(target)) self._target_lines = [] self._source_lines = [] self._target_tokens = [] self._source_tokens = [] def __str__(self): return '\n-------------------------\n'.join(self.to_text()) def to_json(self): snippet = OrderedDict() snippet['snippet_id'] = self.snippet_id reviews = Review.load(self.pr_number(self.snippet_id), self.repo_id(self.snippet_id)) snippet['reviews'] = [review.to_json() for review in reviews] snippet['chunk_ids'] = self.chunk_ids return snippet @property def chunks(self): return self._chunks @property def chunk_ids(self): if not self._chunk_ids: self._chunk_ids = [c.chunk_id for c in self._chunks] return self._chunk_ids @staticmethod def repo_id(snippet_id): return snippet_id.split('-')[3] @staticmethod def pr_number(snippet_id): return snippet_id.split('-')[2] @classmethod def make_id(cls, hunk_no, file_no, pr_number, repo_id): return '-'.join([str(hunk_no), str(file_no), str(pr_number), str(repo_id)]) @staticmethod def total_len(start, end): length = end - start + 1 return length def to_tokens(self): chunks = [] for chunk in self._chunks: chunks.append(chunk.as_tokens()) return chunks def to_text(self): chunks = [] for chunk in self._chunks: chunks.append(chunk.as_text(pretty=True)) return chunks @classmethod def as_tokens(cls, code): if not isinstance(code, list): code = [code] tokens = LineTokenizer(code).tokens lines = [] for line in tokens: lines += line return lines @classmethod def as_elements(cls, code): if not isinstance(code, list): code = [code] tokens = LineTokenizer(code).elements lines = [] for line in tokens: lines += line return lines @classmethod def load(cls, snippet_id, path=None): repo_id = cls.repo_id(snippet_id) maybe_init(repo_id, path=path) db_snippet = DataSnippet.get_or_none(snippet_id=snippet_id) if db_snippet: chunks = [] chunk_ids = pickle.loads(db_snippet.chunk_ids) for chunk_id in chunk_ids: chunks.append(Chunk.load(chunk_id)) merged = db_snippet.merged source = db_snippet.source target = db_snippet.target snippet = cls(snippet_id, merged, chunks, source, target) return snippet @classmethod def load_all(cls, repo_id, merged_only=False, path=None): maybe_init(repo_id, path=path) query = DataSnippet.select( DataSnippet.snippet_id, DataSnippet.chunk_ids, DataSnippet.source, DataSnippet.target) if merged_only: query = query.where(DataSnippet.merged == 1) query = query.order_by(DataSnippet.last_mod.desc()) for db_snippet in query: snippet_id = db_snippet.snippet_id chunks = [] chunk_ids = pickle.loads(db_snippet.chunk_ids) for chunk_id in chunk_ids: chunks.append(Chunk.load(chunk_id)) merged = db_snippet.merged source = db_snippet.source target = db_snippet.target snippet = cls(snippet_id, merged, chunks, source, target) print('Finished loading snippet with ID: {0}'.format(snippet_id)) yield snippet def _serialize_ids(self): return pickle.dumps(self.chunk_ids, pickle.HIGHEST_PROTOCOL) def exists(self): repo_id = self.repo_id(self.snippet_id) maybe_init(repo_id) snippet = DataSnippet.get_or_none(snippet_id=self.snippet_id) return bool(snippet) def save(self): repo_id = self.repo_id(self.snippet_id) maybe_init(repo_id) snippet = DataSnippet.get_or_none(snippet_id=self.snippet_id) if snippet: (DataSnippet .update(snippet_id=self.snippet_id, merged=self.merged, last_mod=datetime.now(), start=self.start, length=self.length, source=self.source_file, target=self.target_file, chunk_ids=self._serialize_ids()) .where(DataSnippet.snippet_id == self.snippet_id) .execute()) else: (DataSnippet .create(snippet_id=self.snippet_id, merged=self.merged, last_mod=datetime.now(), start=self.start, length=self.length, source=self.source_file, target=self.target_file, chunk_ids=self._serialize_ids()))
[ "pickle.dumps", "pickle.loads", "collections.OrderedDict", "datetime.datetime.now" ]
[((955, 968), 'collections.OrderedDict', 'OrderedDict', ([], {}), '()\n', (966, 968), False, 'from collections import OrderedDict\n'), ((4455, 4508), 'pickle.dumps', 'pickle.dumps', (['self.chunk_ids', 'pickle.HIGHEST_PROTOCOL'], {}), '(self.chunk_ids, pickle.HIGHEST_PROTOCOL)\n', (4467, 4508), False, 'import pickle\n'), ((3084, 3118), 'pickle.loads', 'pickle.loads', (['db_snippet.chunk_ids'], {}), '(db_snippet.chunk_ids)\n', (3096, 3118), False, 'import pickle\n'), ((3990, 4024), 'pickle.loads', 'pickle.loads', (['db_snippet.chunk_ids'], {}), '(db_snippet.chunk_ids)\n', (4002, 4024), False, 'import pickle\n'), ((5530, 5544), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (5542, 5544), False, 'from datetime import datetime\n'), ((5041, 5055), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (5053, 5055), False, 'from datetime import datetime\n')]
# Copyright (c) 2015 Presslabs SRL # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from rest_framework.pagination import PageNumberPagination from rest_framework.response import Response from rest_framework.settings import api_settings from rest_framework.utils.urls import replace_query_param, remove_query_param class LinkHeaderPagination(PageNumberPagination): page_size = api_settings.PAGE_SIZE or 30 page_size_query_param = 'page_size' max_page_size = 100 def get_last_link(self): url = self.request.build_absolute_uri() page_number = self.page.paginator.num_pages return replace_query_param(url, self.page_query_param, page_number) def get_first_link(self, display_page_query_param=True): url = self.request.build_absolute_uri() if display_page_query_param: page_number = self.page.paginator.validate_number(1) return replace_query_param(url, self.page_query_param, page_number) else: return remove_query_param(url, self.page_query_param) def get_paginated_response(self, data): next_url = self.get_next_link() previous_url = self.get_previous_link() first_url = self.get_first_link() last_url = self.get_last_link() if next_url is not None and previous_url is not None: link = '<{next_url}>; rel="next", <{previous_url}>; rel="prev"' elif next_url is not None: link = '<{next_url}>; rel="next"' elif previous_url is not None: link = '<{previous_url}>; rel="prev"' else: link = '' if link: link += ', ' link += '<{first_url}>; rel="first", <{last_url}> rel="last"' link = link.format(next_url=next_url, previous_url=previous_url, first_url=first_url, last_url=last_url) headers = {'Link': link} if link else {} return Response(data, headers=headers)
[ "rest_framework.utils.urls.replace_query_param", "rest_framework.utils.urls.remove_query_param", "rest_framework.response.Response" ]
[((1158, 1218), 'rest_framework.utils.urls.replace_query_param', 'replace_query_param', (['url', 'self.page_query_param', 'page_number'], {}), '(url, self.page_query_param, page_number)\n', (1177, 1218), False, 'from rest_framework.utils.urls import replace_query_param, remove_query_param\n'), ((2471, 2502), 'rest_framework.response.Response', 'Response', (['data'], {'headers': 'headers'}), '(data, headers=headers)\n', (2479, 2502), False, 'from rest_framework.response import Response\n'), ((1450, 1510), 'rest_framework.utils.urls.replace_query_param', 'replace_query_param', (['url', 'self.page_query_param', 'page_number'], {}), '(url, self.page_query_param, page_number)\n', (1469, 1510), False, 'from rest_framework.utils.urls import replace_query_param, remove_query_param\n'), ((1544, 1590), 'rest_framework.utils.urls.remove_query_param', 'remove_query_param', (['url', 'self.page_query_param'], {}), '(url, self.page_query_param)\n', (1562, 1590), False, 'from rest_framework.utils.urls import replace_query_param, remove_query_param\n')]
import os import fecfile import json import csv import sys from settings import RAW_ELECTRONIC_DIR, MASTER_HEADER_ROW, HEADER_DUMP_FILE START_YEAR = 2019 ERROR_HEADERS = ['path', 'error', ] def readfile(filepath, writer): filename = os.path.basename(filepath) filename = filename.replace(".fec", "") file_number = int(filename) file = open(filepath, encoding = "ISO-8859-1") #file = open(filepath) firstline = file.readline() secondline = file.readline() firstline = firstline.replace("\n", "") raw_results = fecfile.parse_header(firstline) results = raw_results[0] results["filing_number"] = file_number version = raw_results[1] lines = None if len(raw_results)==3: lines = raw_results[1] original_report = results.get('report_id', None) report_number = results.get('report_number', None) if original_report: original_report = original_report.replace("FEC-", "") original_report_number = int(original_report) results["amends"] = original_report_number #print("Found amended filing %s amends %s # %s" % (file_number, original_report_number, report_number)) secondlineparsed = fecfile.parse_line(secondline, version) #print(secondlineparsed) results["form_type"] = secondlineparsed.get('form_type', '') results["filer_committee_id_number"] = secondlineparsed.get('filer_committee_id_number', '') results["committee_name"] = secondlineparsed.get('committee_name', '') results["date_signed"] = secondlineparsed.get('date_signed', '') results["coverage_from_date"] = secondlineparsed.get('coverage_from_date', '') results["coverage_through_date"] = secondlineparsed.get('coverage_through_date', '') writer.writerow(results) if __name__ == '__main__': outfile = open(HEADER_DUMP_FILE, 'w') dw = csv.DictWriter(outfile, fieldnames=MASTER_HEADER_ROW, extrasaction='ignore') dw.writeheader() print("Writing output to %s" % HEADER_DUMP_FILE) errorfile = open("header_read_errors.csv", 'w') error_writer = csv.DictWriter(errorfile, fieldnames=ERROR_HEADERS, extrasaction='ignore') error_writer.writeheader() for dirName, subdirList, fileList in os.walk(RAW_ELECTRONIC_DIR, topdown=False): try: directory_year = int(dirName.split("/")[-1][0:4]) if directory_year < START_YEAR: print("Ignoring directory %s" % dirName) continue except ValueError: continue for fname in fileList: if fname.endswith(".fec"): full_path = os.path.join(dirName, fname) #readfile(full_path, dw) #print("Found file %s" % full_path) try: readfile(full_path, dw) except Exception as e: print("error reading %s: %s" % (full_path, e)) error_writer.writerow({ 'path':full_path, 'error':e })
[ "csv.DictWriter", "fecfile.parse_line", "fecfile.parse_header", "os.path.join", "os.path.basename", "os.walk" ]
[((244, 270), 'os.path.basename', 'os.path.basename', (['filepath'], {}), '(filepath)\n', (260, 270), False, 'import os\n'), ((555, 586), 'fecfile.parse_header', 'fecfile.parse_header', (['firstline'], {}), '(firstline)\n', (575, 586), False, 'import fecfile\n'), ((1200, 1239), 'fecfile.parse_line', 'fecfile.parse_line', (['secondline', 'version'], {}), '(secondline, version)\n', (1218, 1239), False, 'import fecfile\n'), ((1859, 1935), 'csv.DictWriter', 'csv.DictWriter', (['outfile'], {'fieldnames': 'MASTER_HEADER_ROW', 'extrasaction': '"""ignore"""'}), "(outfile, fieldnames=MASTER_HEADER_ROW, extrasaction='ignore')\n", (1873, 1935), False, 'import csv\n'), ((2082, 2156), 'csv.DictWriter', 'csv.DictWriter', (['errorfile'], {'fieldnames': 'ERROR_HEADERS', 'extrasaction': '"""ignore"""'}), "(errorfile, fieldnames=ERROR_HEADERS, extrasaction='ignore')\n", (2096, 2156), False, 'import csv\n'), ((2230, 2272), 'os.walk', 'os.walk', (['RAW_ELECTRONIC_DIR'], {'topdown': '(False)'}), '(RAW_ELECTRONIC_DIR, topdown=False)\n', (2237, 2272), False, 'import os\n'), ((2632, 2660), 'os.path.join', 'os.path.join', (['dirName', 'fname'], {}), '(dirName, fname)\n', (2644, 2660), False, 'import os\n')]
# -*- coding: utf-8 -*- from django.conf.urls.defaults import patterns, url urlpatterns = patterns('collector.views', url(r'^blob404/$', 'blob404'), url(r'^deleted/$', 'deleted'), url(r'^$', 'create'), url(r'^(?P<uid>\w+)/$', 'delete'), ) # Local Variables: # indent-tabs-mode: nil # End: # vim: ai et sw=4 ts=4
[ "django.conf.urls.defaults.url" ]
[((124, 152), 'django.conf.urls.defaults.url', 'url', (['"""^blob404/$"""', '"""blob404"""'], {}), "('^blob404/$', 'blob404')\n", (127, 152), False, 'from django.conf.urls.defaults import patterns, url\n'), ((159, 187), 'django.conf.urls.defaults.url', 'url', (['"""^deleted/$"""', '"""deleted"""'], {}), "('^deleted/$', 'deleted')\n", (162, 187), False, 'from django.conf.urls.defaults import patterns, url\n'), ((194, 213), 'django.conf.urls.defaults.url', 'url', (['"""^$"""', '"""create"""'], {}), "('^$', 'create')\n", (197, 213), False, 'from django.conf.urls.defaults import patterns, url\n'), ((220, 253), 'django.conf.urls.defaults.url', 'url', (['"""^(?P<uid>\\\\w+)/$"""', '"""delete"""'], {}), "('^(?P<uid>\\\\w+)/$', 'delete')\n", (223, 253), False, 'from django.conf.urls.defaults import patterns, url\n')]
""" categories: Modules,array description: Array deletion not implemented cause: Unknown workaround: Unknown """ import array a = array.array('b', (1, 2, 3)) del a[1] print(a)
[ "array.array" ]
[((130, 157), 'array.array', 'array.array', (['"""b"""', '(1, 2, 3)'], {}), "('b', (1, 2, 3))\n", (141, 157), False, 'import array\n')]
# !/usr/bin/env python3 # -*- coding: utf-8 -*- """ @Time : 2019/9/17 15:07 @Author : <NAME> @FileName: models.py @GitHub : https://github.com/cRiii """ from datetime import datetime from werkzeug.security import generate_password_hash, check_password_hash from jaysblog.extensions import db from flask_login import UserMixin class BaseModel(object): # 模型基类 为所有模型添加创建和更新的时间 create_time = db.Column(db.DateTime, default=datetime.utcnow) update_time = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) class User(BaseModel, db.Model, UserMixin): """ UserMixin表示通过认证的用户 is_authenticated 表示用户已通过认证 返回True 否则False is_active 表示允许用户登陆 返回True 否则False is_anonymous 表示如果当前未用户登陆(匿名用户) 返回True 否则False get_id() 以unicode形式返回用户唯一标识 """ __tablename__ = 'b_users' id = db.Column(db.Integer, primary_key=True) # 用户id nick_name = db.Column(db.String(32), nullable=False) # 用户名 password_hash = db.Column(db.String(128), nullable=False) # 用户密码 mobile = db.Column(db.String(11), unique=True) # 手机号码 email = db.Column(db.String(64), unique=True, nullable=True) # 邮箱 desc = db.Column(db.Text) # 个人简介 location = db.Column(db.String(128)) # 地址 avatar_url = db.Column(db.String(256)) # 用户头像路径 is_admin = db.Column(db.Boolean, default=False) # 是否为管理员 last_login_time = db.Column(db.DateTime, default=datetime.utcnow) # 最后一次登陆时间 is_delete = db.Column(db.Integer, default=1) # 用户是否被删除 1正常 0被删除 gender = db.Column( db.Enum( 'MAN', # 男 'WOMAN' # 女 ), default='MAN' ) @property def password(self): raise AttributeError(u'该属性不可读') @password.setter def password(self, value): """ generate_password_hash(password,method='pbkdf2:sha256',salt_length=8) method指定计算散列值的方法 salt_length 指定盐长度 """ self.password_hash = generate_password_hash(value) def check_password(self, password): """ 接收散列值 和 密码作比较 返回布尔类型 check_password_hash(<PASSWORD>,password) """ return check_password_hash(self.password_hash, password) def to_dict(self): res_dict = { "id": self.id, "nick_name": self.nick_name, "email": self.email, "desc": self.desc, "avatar_url": self.avatar_url, "gender": self.gender, "is_admin": self.is_admin, } return res_dict class Post(BaseModel, db.Model): __tablename__ = 'b_posts' id = db.Column(db.Integer, primary_key=True) # 文章编号 post_title = db.Column(db.String(256), nullable=False) # 文章标题 post_user_id = db.Column(db.Integer, nullable=False) # 创建文章用户 post_digest = db.Column(db.String(512), nullable=True) # 文章简介 post_content = db.Column(db.Text, nullable=False) # 文章内容 post_clicks = db.Column(db.Integer, default=0) # 点击量 post_like_num = db.Column(db.Integer, default=0) # 点赞数量 post_index_image_url = db.Column(db.String(256)) # 主页面列表图片地址 post_status = db.Column(db.Integer, default=1) # 文章状态 post_can_comment = db.Column(db.Integer, default=1) # 当前文章是否可以被评论 post_comments = db.relationship('Comment', backref='comment_post') # 当前文章的评论 post_category = db.relationship('Category', back_populates='cg_posts') post_category_id = db.Column(db.Integer, db.ForeignKey('b_category.id'), nullable=False) # 文章类型 def get_comment_length(self): comments = [] if self.post_comments is not []: for comment in self.post_comments: if comment.comment_status == 1: comments.append(comment) return len(comments) def to_dict(self): res_dict = { "id": self.id, "post_title": self.post_title, "post_user_id": self.post_user_id, "post_digest": self.post_digest if self.post_digest else "", "post_clicks": self.post_clicks, "post_like_num": self.post_like_num, "post_index_image_url": self.post_index_image_url if self.post_index_image_url else "", "post_category": self.post_category.to_dict() if self.post_category else None, "post_comments_count": self.get_comment_length(), "post_create_time": self.create_time, "post_update_time": self.update_time, } return res_dict def to_dict_details(self): res_dict = { "id": self.id, "post_title": self.post_title, "post_user_id": self.post_user_id, "post_content": self.post_content, "post_clicks": self.post_clicks, "post_like_num": self.post_like_num, "post_can_comment": self.post_can_comment, "post_create_time": self.create_time, "post_category": self.post_category.to_dict() if self.post_category else None, "post_comments_count": self.get_comment_length(), } return res_dict class Category(BaseModel, db.Model): __tablename__ = 'b_category' id = db.Column(db.Integer, primary_key=True) # 分类编号 cg_name = db.Column(db.String(64), nullable=False, unique=True) # 分类名称 cg_posts = db.relationship('Post', back_populates='post_category') # 分类下的文章 def to_dict(self): res_dict = { "id": self.id, "cg_name": self.cg_name, "cg_posts_count": len(self.cg_posts) if self.cg_posts else 0 } return res_dict class Comment(BaseModel, db.Model): __tablename__ = 'b_comments' id = db.Column(db.Integer, primary_key=True) # 评论编号 comment_user_id = db.Column(db.Integer, nullable=False) # 评论用户ID comment_content = db.Column(db.Text, nullable=False) # 评论内容 comment_from_admin = db.Column(db.Integer, default=0) # 是否为管理员评论 comment_status = db.Column(db.Integer, default=0) # 评论是否通过审核 -1不可用 0:审核中 1:审核通过 comment_post_id = db.Column(db.Integer, db.ForeignKey('b_posts.id'), nullable=False) # 当前评论属于的文章id comment_reply = db.relationship('Reply', backref='reply_comment') # 当前评论下的回复 def to_dict(self): comment_replies = [] if self.comment_reply is not []: for reply in self.comment_reply: if reply.reply_status == 1: comment_replies.append(reply.to_dict()) user = User.query.filter_by(id=self.comment_user_id).first() res_dict = { "id": self.id, "comment_user_name": user.nick_name, "comment_user_avatar_url": user.avatar_url, "comment_content": self.comment_content, "comment_from_admin": user.is_admin, "comment_post_id": self.comment_post_id, "comment_replies": comment_replies, "comment_create_time": self.create_time, "comment_update_time": self.update_time, } return res_dict class Reply(BaseModel, db.Model): __tablename__ = 'b_reply' id = db.Column(db.Integer, primary_key=True) # 回复的id reply_from_user = db.Column(db.String(32), nullable=False) # 谁回复的 reply_to_user = db.Column(db.String(32), nullable=False) # 回复给谁的 reply_content = db.Column(db.Text, nullable=False) # 回复的内容 reply_status = db.Column(db.Integer, default=0) # 回复是否通过审核 -1不可用 0:审核中 1:审核通过 reply_comment_id = db.Column(db.Integer, db.ForeignKey('b_comments.id'), nullable=False) # 当前回复属于的评论id def to_dict(self): user = User.query.filter_by(nick_name=self.reply_from_user).first() res_dict = { "id": self.id, "reply_from_user": self.reply_from_user, "reply_to_user": self.reply_to_user, "reply_content": self.reply_content, "reply_comment_id": self.reply_comment_id, "reply_create_time": self.create_time, "reply_update_time": self.update_time, "reply_user_is_admin": user.is_admin, "reply_user_avatar_url": user.avatar_url, } return res_dict class Journey(BaseModel, db.Model): __tablename__ = 'b_journey' id = db.Column(db.Integer, primary_key=True) # 历程id journey_title = db.Column(db.String(32), nullable=False) # 历程标题 journey_desc = db.Column(db.Text, nullable=False) # 历程详情 journey_time = db.Column(db.DateTime, default=datetime.utcnow) # 历程时间 def to_dict(self): res_dict = { "id": self.id, "journey_title": self.journey_title, "journey_desc": self.journey_desc, "journey_time": self.journey_time } return res_dict class MessageBoard(BaseModel, db.Model): __tablename__ = 'b_board' id = db.Column(db.Integer, primary_key=True) # 留言板id board_user = db.Column(db.String(32), nullable=False) # 留言用户 board_desc = db.Column(db.Text, nullable=False) # 留言内容 board_status = db.Column(db.Integer, nullable=False, default=0) # 留言状态 -1不可用 0:审核中 1:审核通过 board_email = db.Column(db.String(50), nullable=False) # 留言回复邮箱 def to_dict(self): res_dict = { "id": self.id, "board_user": self.board_user, "board_desc": self.board_desc, "board_status": self.board_status, "board_create_time": self.create_time, "board_update_time": self.update_time, "board_email": self.board_email, } return res_dict class UsersLikePosts(BaseModel, db.Model): __tablename__ = 'b_users_like_posts' id = db.Column(db.Integer, primary_key=True) # 主键 user_id = db.Column(db.Integer, nullable=False) user_like_post_id = db.Column(db.Integer, nullable=False) def to_dict(self): res_dict = { "id": self.id, "user_id": self.user_id, "user_like_post_id": self.user_like_post_id, } return res_dict
[ "jaysblog.extensions.db.String", "jaysblog.extensions.db.Column", "jaysblog.extensions.db.ForeignKey", "jaysblog.extensions.db.Enum", "jaysblog.extensions.db.relationship", "werkzeug.security.generate_password_hash", "werkzeug.security.check_password_hash" ]
[((408, 455), 'jaysblog.extensions.db.Column', 'db.Column', (['db.DateTime'], {'default': 'datetime.utcnow'}), '(db.DateTime, default=datetime.utcnow)\n', (417, 455), False, 'from jaysblog.extensions import db\n'), ((474, 547), 'jaysblog.extensions.db.Column', 'db.Column', (['db.DateTime'], {'default': 'datetime.utcnow', 'onupdate': 'datetime.utcnow'}), '(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)\n', (483, 547), False, 'from jaysblog.extensions import db\n'), ((875, 914), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (884, 914), False, 'from jaysblog.extensions import db\n'), ((1198, 1216), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {}), '(db.Text)\n', (1207, 1216), False, 'from jaysblog.extensions import db\n'), ((1340, 1376), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Boolean'], {'default': '(False)'}), '(db.Boolean, default=False)\n', (1349, 1376), False, 'from jaysblog.extensions import db\n'), ((1409, 1456), 'jaysblog.extensions.db.Column', 'db.Column', (['db.DateTime'], {'default': 'datetime.utcnow'}), '(db.DateTime, default=datetime.utcnow)\n', (1418, 1456), False, 'from jaysblog.extensions import db\n'), ((1485, 1517), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(1)'}), '(db.Integer, default=1)\n', (1494, 1517), False, 'from jaysblog.extensions import db\n'), ((2643, 2682), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (2652, 2682), False, 'from jaysblog.extensions import db\n'), ((2777, 2814), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'nullable': '(False)'}), '(db.Integer, nullable=False)\n', (2786, 2814), False, 'from jaysblog.extensions import db\n'), ((2911, 2945), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {'nullable': '(False)'}), '(db.Text, nullable=False)\n', (2920, 2945), False, 'from jaysblog.extensions import db\n'), ((2972, 3004), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(0)'}), '(db.Integer, default=0)\n', (2981, 3004), False, 'from jaysblog.extensions import db\n'), ((3032, 3064), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(0)'}), '(db.Integer, default=0)\n', (3041, 3064), False, 'from jaysblog.extensions import db\n'), ((3157, 3189), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(1)'}), '(db.Integer, default=1)\n', (3166, 3189), False, 'from jaysblog.extensions import db\n'), ((3221, 3253), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(1)'}), '(db.Integer, default=1)\n', (3230, 3253), False, 'from jaysblog.extensions import db\n'), ((3290, 3340), 'jaysblog.extensions.db.relationship', 'db.relationship', (['"""Comment"""'], {'backref': '"""comment_post"""'}), "('Comment', backref='comment_post')\n", (3305, 3340), False, 'from jaysblog.extensions import db\n'), ((3372, 3426), 'jaysblog.extensions.db.relationship', 'db.relationship', (['"""Category"""'], {'back_populates': '"""cg_posts"""'}), "('Category', back_populates='cg_posts')\n", (3387, 3426), False, 'from jaysblog.extensions import db\n'), ((5197, 5236), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (5206, 5236), False, 'from jaysblog.extensions import db\n'), ((5337, 5392), 'jaysblog.extensions.db.relationship', 'db.relationship', (['"""Post"""'], {'back_populates': '"""post_category"""'}), "('Post', back_populates='post_category')\n", (5352, 5392), False, 'from jaysblog.extensions import db\n'), ((5700, 5739), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (5709, 5739), False, 'from jaysblog.extensions import db\n'), ((5770, 5807), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'nullable': '(False)'}), '(db.Integer, nullable=False)\n', (5779, 5807), False, 'from jaysblog.extensions import db\n'), ((5840, 5874), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {'nullable': '(False)'}), '(db.Text, nullable=False)\n', (5849, 5874), False, 'from jaysblog.extensions import db\n'), ((5908, 5940), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(0)'}), '(db.Integer, default=0)\n', (5917, 5940), False, 'from jaysblog.extensions import db\n'), ((5974, 6006), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(0)'}), '(db.Integer, default=0)\n', (5983, 6006), False, 'from jaysblog.extensions import db\n'), ((6164, 6213), 'jaysblog.extensions.db.relationship', 'db.relationship', (['"""Reply"""'], {'backref': '"""reply_comment"""'}), "('Reply', backref='reply_comment')\n", (6179, 6213), False, 'from jaysblog.extensions import db\n'), ((7112, 7151), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (7121, 7151), False, 'from jaysblog.extensions import db\n'), ((7322, 7356), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {'nullable': '(False)'}), '(db.Text, nullable=False)\n', (7331, 7356), False, 'from jaysblog.extensions import db\n'), ((7385, 7417), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'default': '(0)'}), '(db.Integer, default=0)\n', (7394, 7417), False, 'from jaysblog.extensions import db\n'), ((8235, 8274), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (8244, 8274), False, 'from jaysblog.extensions import db\n'), ((8371, 8405), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {'nullable': '(False)'}), '(db.Text, nullable=False)\n', (8380, 8405), False, 'from jaysblog.extensions import db\n'), ((8433, 8480), 'jaysblog.extensions.db.Column', 'db.Column', (['db.DateTime'], {'default': 'datetime.utcnow'}), '(db.DateTime, default=datetime.utcnow)\n', (8442, 8480), False, 'from jaysblog.extensions import db\n'), ((8820, 8859), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (8829, 8859), False, 'from jaysblog.extensions import db\n'), ((8952, 8986), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Text'], {'nullable': '(False)'}), '(db.Text, nullable=False)\n', (8961, 8986), False, 'from jaysblog.extensions import db\n'), ((9014, 9062), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'nullable': '(False)', 'default': '(0)'}), '(db.Integer, nullable=False, default=0)\n', (9023, 9062), False, 'from jaysblog.extensions import db\n'), ((9641, 9680), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'primary_key': '(True)'}), '(db.Integer, primary_key=True)\n', (9650, 9680), False, 'from jaysblog.extensions import db\n'), ((9701, 9738), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'nullable': '(False)'}), '(db.Integer, nullable=False)\n', (9710, 9738), False, 'from jaysblog.extensions import db\n'), ((9763, 9800), 'jaysblog.extensions.db.Column', 'db.Column', (['db.Integer'], {'nullable': '(False)'}), '(db.Integer, nullable=False)\n', (9772, 9800), False, 'from jaysblog.extensions import db\n'), ((949, 962), 'jaysblog.extensions.db.String', 'db.String', (['(32)'], {}), '(32)\n', (958, 962), False, 'from jaysblog.extensions import db\n'), ((1017, 1031), 'jaysblog.extensions.db.String', 'db.String', (['(128)'], {}), '(128)\n', (1026, 1031), False, 'from jaysblog.extensions import db\n'), ((1080, 1093), 'jaysblog.extensions.db.String', 'db.String', (['(11)'], {}), '(11)\n', (1089, 1093), False, 'from jaysblog.extensions import db\n'), ((1138, 1151), 'jaysblog.extensions.db.String', 'db.String', (['(64)'], {}), '(64)\n', (1147, 1151), False, 'from jaysblog.extensions import db\n'), ((1250, 1264), 'jaysblog.extensions.db.String', 'db.String', (['(128)'], {}), '(128)\n', (1259, 1264), False, 'from jaysblog.extensions import db\n'), ((1299, 1313), 'jaysblog.extensions.db.String', 'db.String', (['(256)'], {}), '(256)\n', (1308, 1313), False, 'from jaysblog.extensions import db\n'), ((1571, 1594), 'jaysblog.extensions.db.Enum', 'db.Enum', (['"""MAN"""', '"""WOMAN"""'], {}), "('MAN', 'WOMAN')\n", (1578, 1594), False, 'from jaysblog.extensions import db\n'), ((1994, 2023), 'werkzeug.security.generate_password_hash', 'generate_password_hash', (['value'], {}), '(value)\n', (2016, 2023), False, 'from werkzeug.security import generate_password_hash, check_password_hash\n'), ((2190, 2239), 'werkzeug.security.check_password_hash', 'check_password_hash', (['self.password_hash', 'password'], {}), '(self.password_hash, password)\n', (2209, 2239), False, 'from werkzeug.security import generate_password_hash, check_password_hash\n'), ((2718, 2732), 'jaysblog.extensions.db.String', 'db.String', (['(256)'], {}), '(256)\n', (2727, 2732), False, 'from jaysblog.extensions import db\n'), ((2853, 2867), 'jaysblog.extensions.db.String', 'db.String', (['(512)'], {}), '(512)\n', (2862, 2867), False, 'from jaysblog.extensions import db\n'), ((3110, 3124), 'jaysblog.extensions.db.String', 'db.String', (['(256)'], {}), '(256)\n', (3119, 3124), False, 'from jaysblog.extensions import db\n'), ((3472, 3502), 'jaysblog.extensions.db.ForeignKey', 'db.ForeignKey', (['"""b_category.id"""'], {}), "('b_category.id')\n", (3485, 3502), False, 'from jaysblog.extensions import db\n'), ((5269, 5282), 'jaysblog.extensions.db.String', 'db.String', (['(64)'], {}), '(64)\n', (5278, 5282), False, 'from jaysblog.extensions import db\n'), ((6084, 6111), 'jaysblog.extensions.db.ForeignKey', 'db.ForeignKey', (['"""b_posts.id"""'], {}), "('b_posts.id')\n", (6097, 6111), False, 'from jaysblog.extensions import db\n'), ((7193, 7206), 'jaysblog.extensions.db.String', 'db.String', (['(32)'], {}), '(32)\n', (7202, 7206), False, 'from jaysblog.extensions import db\n'), ((7262, 7275), 'jaysblog.extensions.db.String', 'db.String', (['(32)'], {}), '(32)\n', (7271, 7275), False, 'from jaysblog.extensions import db\n'), ((7496, 7526), 'jaysblog.extensions.db.ForeignKey', 'db.ForeignKey', (['"""b_comments.id"""'], {}), "('b_comments.id')\n", (7509, 7526), False, 'from jaysblog.extensions import db\n'), ((8313, 8326), 'jaysblog.extensions.db.String', 'db.String', (['(32)'], {}), '(32)\n', (8322, 8326), False, 'from jaysblog.extensions import db\n'), ((8896, 8909), 'jaysblog.extensions.db.String', 'db.String', (['(32)'], {}), '(32)\n', (8905, 8909), False, 'from jaysblog.extensions import db\n'), ((9118, 9131), 'jaysblog.extensions.db.String', 'db.String', (['(50)'], {}), '(50)\n', (9127, 9131), False, 'from jaysblog.extensions import db\n')]
#!/usr/bin/env python # coding: utf-8 import yaml import json import sys import os sys.path.append('../venv/lib/python3.5/site-packages') from elasticsearch import Elasticsearch sys.path.append('../telemanom') class Config: '''Loads parameters from config.yaml into global object''' def __init__(self, path_to_config): if os.path.isfile(path_to_config): pass else: path_to_config = '../%s' %path_to_config setattr(self, "path_to_config", path_to_config) dictionary = None with open(path_to_config, "r") as f: dictionary = yaml.load(f.read()) try: for k,v in dictionary.items(): setattr(self, k, v) except: for k,v in dictionary.iteritems(): setattr(self, k, v) def build_group_lookup(self, path_to_groupings): channel_group_lookup = {} with open(path_to_groupings, "r") as f: groupings = json.loads(f.read()) for subsystem in groupings.keys(): for subgroup in groupings[subsystem].keys(): for chan in groupings[subsystem][subgroup]: channel_group_lookup[chan["key"]] = {} channel_group_lookup[chan["key"]]["subsystem"] = subsystem channel_group_lookup[chan["key"]]["subgroup"] = subgroup return channel_group_lookup
[ "os.path.isfile", "sys.path.append" ]
[((85, 139), 'sys.path.append', 'sys.path.append', (['"""../venv/lib/python3.5/site-packages"""'], {}), "('../venv/lib/python3.5/site-packages')\n", (100, 139), False, 'import sys\n'), ((181, 212), 'sys.path.append', 'sys.path.append', (['"""../telemanom"""'], {}), "('../telemanom')\n", (196, 212), False, 'import sys\n'), ((353, 383), 'os.path.isfile', 'os.path.isfile', (['path_to_config'], {}), '(path_to_config)\n', (367, 383), False, 'import os\n')]
# coding=utf-8 # *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** # *** Do not edit by hand unless you're certain you know what you are doing! *** import warnings import pulumi import pulumi.runtime from typing import Any, Mapping, Optional, Sequence, Union, overload from . import _utilities __all__ = [ 'GetNetworkResult', 'AwaitableGetNetworkResult', 'get_network', ] @pulumi.output_type class GetNetworkResult: """ A collection of values returned by getNetwork. """ def __init__(__self__, default=None, id=None, label=None, name=None, region=None): if default and not isinstance(default, bool): raise TypeError("Expected argument 'default' to be a bool") pulumi.set(__self__, "default", default) if id and not isinstance(id, str): raise TypeError("Expected argument 'id' to be a str") pulumi.set(__self__, "id", id) if label and not isinstance(label, str): raise TypeError("Expected argument 'label' to be a str") pulumi.set(__self__, "label", label) if name and not isinstance(name, str): raise TypeError("Expected argument 'name' to be a str") pulumi.set(__self__, "name", name) if region and not isinstance(region, str): raise TypeError("Expected argument 'region' to be a str") pulumi.set(__self__, "region", region) @property @pulumi.getter def default(self) -> bool: """ If is the default network. """ return pulumi.get(self, "default") @property @pulumi.getter def id(self) -> Optional[str]: """ A unique ID that can be used to identify and reference a Network. """ return pulumi.get(self, "id") @property @pulumi.getter def label(self) -> Optional[str]: """ The label used in the configuration. """ return pulumi.get(self, "label") @property @pulumi.getter def name(self) -> str: """ The name of the network. """ return pulumi.get(self, "name") @property @pulumi.getter def region(self) -> Optional[str]: return pulumi.get(self, "region") class AwaitableGetNetworkResult(GetNetworkResult): # pylint: disable=using-constant-test def __await__(self): if False: yield self return GetNetworkResult( default=self.default, id=self.id, label=self.label, name=self.name, region=self.region) def get_network(id: Optional[str] = None, label: Optional[str] = None, region: Optional[str] = None, opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableGetNetworkResult: """ Use this data source to access information about an existing resource. :param str id: The unique identifier of an existing Network. :param str label: The label of an existing Network. :param str region: The region of an existing Network. """ __args__ = dict() __args__['id'] = id __args__['label'] = label __args__['region'] = region if opts is None: opts = pulumi.InvokeOptions() if opts.version is None: opts.version = _utilities.get_version() __ret__ = pulumi.runtime.invoke('civo:index/getNetwork:getNetwork', __args__, opts=opts, typ=GetNetworkResult).value return AwaitableGetNetworkResult( default=__ret__.default, id=__ret__.id, label=__ret__.label, name=__ret__.name, region=__ret__.region)
[ "pulumi.InvokeOptions", "pulumi.set", "pulumi.runtime.invoke", "pulumi.get" ]
[((755, 795), 'pulumi.set', 'pulumi.set', (['__self__', '"""default"""', 'default'], {}), "(__self__, 'default', default)\n", (765, 795), False, 'import pulumi\n'), ((913, 943), 'pulumi.set', 'pulumi.set', (['__self__', '"""id"""', 'id'], {}), "(__self__, 'id', id)\n", (923, 943), False, 'import pulumi\n'), ((1070, 1106), 'pulumi.set', 'pulumi.set', (['__self__', '"""label"""', 'label'], {}), "(__self__, 'label', label)\n", (1080, 1106), False, 'import pulumi\n'), ((1230, 1264), 'pulumi.set', 'pulumi.set', (['__self__', '"""name"""', 'name'], {}), "(__self__, 'name', name)\n", (1240, 1264), False, 'import pulumi\n'), ((1394, 1432), 'pulumi.set', 'pulumi.set', (['__self__', '"""region"""', 'region'], {}), "(__self__, 'region', region)\n", (1404, 1432), False, 'import pulumi\n'), ((1572, 1599), 'pulumi.get', 'pulumi.get', (['self', '"""default"""'], {}), "(self, 'default')\n", (1582, 1599), False, 'import pulumi\n'), ((1782, 1804), 'pulumi.get', 'pulumi.get', (['self', '"""id"""'], {}), "(self, 'id')\n", (1792, 1804), False, 'import pulumi\n'), ((1961, 1986), 'pulumi.get', 'pulumi.get', (['self', '"""label"""'], {}), "(self, 'label')\n", (1971, 1986), False, 'import pulumi\n'), ((2120, 2144), 'pulumi.get', 'pulumi.get', (['self', '"""name"""'], {}), "(self, 'name')\n", (2130, 2144), False, 'import pulumi\n'), ((2233, 2259), 'pulumi.get', 'pulumi.get', (['self', '"""region"""'], {}), "(self, 'region')\n", (2243, 2259), False, 'import pulumi\n'), ((3243, 3265), 'pulumi.InvokeOptions', 'pulumi.InvokeOptions', ([], {}), '()\n', (3263, 3265), False, 'import pulumi\n'), ((3357, 3462), 'pulumi.runtime.invoke', 'pulumi.runtime.invoke', (['"""civo:index/getNetwork:getNetwork"""', '__args__'], {'opts': 'opts', 'typ': 'GetNetworkResult'}), "('civo:index/getNetwork:getNetwork', __args__, opts=\n opts, typ=GetNetworkResult)\n", (3378, 3462), False, 'import pulumi\n')]
''' Flask Application Config ''' import os from logging.config import dictConfig BASEDIR = os.path.abspath(os.path.dirname(__file__)) class Config: '''공통 Config''' JWT_SECRET_KEY = os.environ.get('FLASK_JWT_SECRET_KEY') # test only TEST_ACCESS_TOKEN = os.environ.get('FLASK_TEST_ACCESS_TOKEN') ADMIN_ID = os.environ.get('FLASK_ADMIN_ID', "iml") ADMIN_PW = os.environ.get('FLASK_ADMIN_PW', "iml") # DB_PROXY: basic, mysql, mongodb, redis, all DB_PROXY = os.environ.get('FLASK_DB_PROXY') if DB_PROXY in ['mysql', 'all']: MYSQL_URI = os.environ.get('FLASK_MYSQL_URI') if DB_PROXY in ['mongodb', 'all']: MONGO_URI = os.environ.get('FLASK_MONGO_URI') MONGO_DB_NAME = os.environ.get('FLASK_MONGO_DB_NAME') if DB_PROXY == ['reids', 'all']: REDIS_HOST = os.environ.get('FLASK_REDIS_HOST') REDIS_PORT = os.environ.get('FLASK_REDIS_PORT') REDIS_PW = os.environ.get('FLASK_REDIS_PW') ALLOWED_EXTENSION = {'txt', 'docs', 'md', 'hwp', 'ppt', 'pptx'} SLOW_API_TIME = 0.5 @staticmethod def init_app(app): '''전역 init_app 함수''' class TestingConfig(Config): '''Test 전용 Config''' DEBUG = True TESTING = True class DevelopmentConfig(Config): '''개발 환경 전용 Config''' DEBUG = True TESTING = False class ProductionConfig(Config): ''' 상용환경 전용 Config''' DEBUG = False TESTING = False @staticmethod def init_app(app): '''로거 등록 및 설정''' dictConfig({ 'version': 1, 'formatters': { 'default': { 'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', } }, 'handlers': { 'file': { 'level': 'INFO', 'class': 'logging.handlers.RotatingFileHandler', 'filename': './server_error.log', 'maxBytes': 1024 * 1024 * 5, 'backupCount': 5, 'formatter': 'default', }, }, 'root': { 'level': 'INFO', 'handlers': ['file'] } }) config = { 'development':DevelopmentConfig, 'production':ProductionConfig, 'testing':TestingConfig, 'default':DevelopmentConfig, }
[ "os.path.dirname", "os.environ.get", "logging.config.dictConfig" ]
[((108, 133), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (123, 133), False, 'import os\n'), ((192, 230), 'os.environ.get', 'os.environ.get', (['"""FLASK_JWT_SECRET_KEY"""'], {}), "('FLASK_JWT_SECRET_KEY')\n", (206, 230), False, 'import os\n'), ((271, 312), 'os.environ.get', 'os.environ.get', (['"""FLASK_TEST_ACCESS_TOKEN"""'], {}), "('FLASK_TEST_ACCESS_TOKEN')\n", (285, 312), False, 'import os\n'), ((328, 367), 'os.environ.get', 'os.environ.get', (['"""FLASK_ADMIN_ID"""', '"""iml"""'], {}), "('FLASK_ADMIN_ID', 'iml')\n", (342, 367), False, 'import os\n'), ((383, 422), 'os.environ.get', 'os.environ.get', (['"""FLASK_ADMIN_PW"""', '"""iml"""'], {}), "('FLASK_ADMIN_PW', 'iml')\n", (397, 422), False, 'import os\n'), ((489, 521), 'os.environ.get', 'os.environ.get', (['"""FLASK_DB_PROXY"""'], {}), "('FLASK_DB_PROXY')\n", (503, 521), False, 'import os\n'), ((580, 613), 'os.environ.get', 'os.environ.get', (['"""FLASK_MYSQL_URI"""'], {}), "('FLASK_MYSQL_URI')\n", (594, 613), False, 'import os\n'), ((673, 706), 'os.environ.get', 'os.environ.get', (['"""FLASK_MONGO_URI"""'], {}), "('FLASK_MONGO_URI')\n", (687, 706), False, 'import os\n'), ((731, 768), 'os.environ.get', 'os.environ.get', (['"""FLASK_MONGO_DB_NAME"""'], {}), "('FLASK_MONGO_DB_NAME')\n", (745, 768), False, 'import os\n'), ((827, 861), 'os.environ.get', 'os.environ.get', (['"""FLASK_REDIS_HOST"""'], {}), "('FLASK_REDIS_HOST')\n", (841, 861), False, 'import os\n'), ((883, 917), 'os.environ.get', 'os.environ.get', (['"""FLASK_REDIS_PORT"""'], {}), "('FLASK_REDIS_PORT')\n", (897, 917), False, 'import os\n'), ((937, 969), 'os.environ.get', 'os.environ.get', (['"""FLASK_REDIS_PW"""'], {}), "('FLASK_REDIS_PW')\n", (951, 969), False, 'import os\n'), ((1497, 1884), 'logging.config.dictConfig', 'dictConfig', (["{'version': 1, 'formatters': {'default': {'format':\n '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'}}, 'handlers':\n {'file': {'level': 'INFO', 'class':\n 'logging.handlers.RotatingFileHandler', 'filename':\n './server_error.log', 'maxBytes': 1024 * 1024 * 5, 'backupCount': 5,\n 'formatter': 'default'}}, 'root': {'level': 'INFO', 'handlers': ['file']}}"], {}), "({'version': 1, 'formatters': {'default': {'format':\n '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'}}, 'handlers':\n {'file': {'level': 'INFO', 'class':\n 'logging.handlers.RotatingFileHandler', 'filename':\n './server_error.log', 'maxBytes': 1024 * 1024 * 5, 'backupCount': 5,\n 'formatter': 'default'}}, 'root': {'level': 'INFO', 'handlers': ['file']}})\n", (1507, 1884), False, 'from logging.config import dictConfig\n')]
from django.db import models from django.core.validators import RegexValidator, ValidationError from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from smart_selects.db_fields import ChainedForeignKey, ChainedManyToManyField from ordered_model.models import OrderedModel # Create your models here. class Agency(models.Model): name = models.CharField(max_length=100, blank=False) abbreviation = models.CharField(max_length=10, null=True, blank=True) department = models.CharField(max_length=100, null=True, blank=True) omb_agency_code = models.IntegerField(null=True, blank=True) omb_bureau_code = models.IntegerField(null=True, blank=True) treasury_agency_code = models.IntegerField(null=True, blank=True) cgac_agency_code = models.IntegerField(null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name_plural = "Agencies" ordering = ('name',) class Subagency(models.Model): name = models.CharField(max_length=100, blank=False) abbreviation = models.CharField(max_length=10, null=True, blank=True) agency = models.ForeignKey(Agency) def __str__(self): return "%s - %s" % (self.agency, self.name) class Meta: ordering = ('name',) verbose_name_plural = "Subagencies" class ContractingOffice(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name class Meta: verbose_name = "Contracting Office" verbose_name_plural = "Contracting Offices" class ContractingOfficer(models.Model): name = models.CharField(max_length=100) contracting_office = models.ForeignKey(ContractingOffice) def __str__(self): return "%s - %s" % (self.name, self.contracting_office) class Meta: ordering = ('name',) verbose_name = "Contracting Officer" verbose_name_plural = "Contracting Officers" class COR(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name class Meta: ordering = ('name',) verbose_name = "Contracting Officer Representative" verbose_name_plural = "Contracting Officer Representatives" # Is the acquisition internal or external? class Track(models.Model): name = models.CharField(max_length=50) def __str__(self): return "%s" % (self.name) class Stage(OrderedModel): name = models.CharField(max_length=50) wip_limit = models.IntegerField(default=0, verbose_name="WIP Limit") def __str__(self): return "%s" % (self.name) class Meta(OrderedModel.Meta): pass class Actor(models.Model): name = models.CharField(max_length=200, blank=False) def __str__(self): return "%s" % (self.name) class Step(models.Model): actor = models.ForeignKey( Actor, blank=False ) track = models.ManyToManyField( Track, blank=False, through="StepTrackThroughModel" ) stage = models.ForeignKey( Stage, blank=False ) def __str__(self): return "%s - %s" % (self.stage, self.actor,) class Meta: ordering = ('steptrackthroughmodel__order',) class StepTrackThroughModel(OrderedModel): track = models.ForeignKey(Track) step = models.ForeignKey(Step) wip_limit = models.IntegerField(default=0, verbose_name="WIP Limit") order_with_respect_to = 'track' class Meta(OrderedModel.Meta): unique_together = ('track', 'step') ordering = ('track', 'order') class Vendor(models.Model): name = models.CharField(max_length=200, blank=False) email = models.EmailField(blank=False) duns = models.CharField(max_length=9, blank=False, validators=[ RegexValidator(regex='^\d{9}$', message="DUNS number must be 9 digits") ]) def __str__(self): return self.name class Role(models.Model): description = models.CharField(max_length=100, choices=( ('P', 'Product Lead'), ('A', 'Acquisition Lead'), ('T', 'Technical Lead') ), null=True, blank=True) teammate = models.ForeignKey(User, blank=True, null=True) def __str__(self): return "%s - %s" % (self.get_description_display(), self.teammate) class Acquisition(models.Model): SET_ASIDE_CHOICES = ( ("AbilityOne", "AbilityOne"), ("HUBZone Small Business", "HUBZone Small Business"), ("Multiple Small Business Categories", "Multiple Small Business Categories"), ("Other Than Small", "Other Than Small"), ("Service Disabled Veteran-owned Small Business", "Service Disabled Veteran-owned Small Business"), ("Small Business", "Small Business"), ("Small Disadvantaged Business (includes Section 8a)", "Small Disadvantaged Business (includes Section 8a)"), ("To Be Determined-BPA", "To Be Determined-BPA"), ("To Be Determined-IDIQ", "To Be Determined-IDIQ"), ("Veteran-Owned Small Business", "Veteran-Owned Small Business"), ("Woman-Owned Small Business", "Woman-Owned Small Business"), ) CONTRACT_TYPE_CHOICES = ( ("Cost No Fee", "Cost No Fee"), ("Cost Plus Award Fee", "Cost Plus Award Fee"), ("Cost Plus Fixed Fee", "Cost Plus Fixed Fee"), ("Cost Plus Incentive Fee", "Cost Plus Incentive Fee"), ("Cost Sharing", "Cost Sharing"), ("Fixed Price Award Fee", "Fixed Price Award Fee"), ("Fixed Price Incentive", "Fixed Price Incentive"), ("Fixed Price Labor Hours", "Fixed Price Labor Hours"), ("Fixed Price Level of Effort", "Fixed Price Level of Effort"), ("Fixed Price Time and Materials", "Fixed Price Time and Materials"), ("Fixed Price with Economic Price Adjustment", "Fixed Price with Economic Price Adjustment"), ("Fixed Price", "Fixed Price"), ("Interagency Agreement", "Interagency Agreement"), ("Labor Hours and Time and Materials", "Labor Hours and Time and Materials"), ("Labor Hours", "Labor Hours"), ("Order Dependent", "Order Dependent"), ("Time and Materials", "Time and Materials"), ) COMPETITION_STRATEGY_CHOICES = ( ("A/E Procedures", "A/E Procedures"), ("Competed under SAP", "Competed under SAP"), ("Competitive Delivery Order Fair Opportunity Provided", "Competitive Delivery Order Fair Opportunity Provided"), ("Competitive Schedule Buy", "Competitive Schedule Buy"), ("Fair Opportunity", "Fair Opportunity"), ("Follow On to Competed Action (FAR 6.302-1)", "Follow On to Competed Action (FAR 6.302-1)"), ("Follow On to Competed Action", "Follow On to Competed Action"), ("Full and Open after exclusion of sources (competitive small business \ set-asides, competitive 8a)", "Full and Open after exclusion of sources (competitive small \ business set-asides, competitive 8a)"), ("Full and Open Competition Unrestricted", "Full and Open Competition Unrestricted"), ("Full and Open Competition", "Full and Open Competition"), ("Limited Sources FSS Order", "Limited Sources FSS Order"), ("Limited Sources", "Limited Sources"), ("Non-Competitive Delivery Order", "Non-Competitive Delivery Order"), ("Not Available for Competition (e.g., 8a sole source, HUBZone & \ SDVOSB sole source, Ability One, all > SAT)", "Not Available for Competition (e.g., 8a sole source, HUBZone & \ SDVOSB sole source, Ability One, all > SAT)"), ("Not Competed (e.g., sole source, urgency, etc., all > SAT)", "Not Competed (e.g., sole source, urgency, etc., all > SAT)"), ("Not Competed under SAP (e.g., Urgent, Sole source, Logical \ Follow-On, 8a, HUBZone & SDVOSB sole source, all < SAT)", "Not Competed under SAP (e.g., Urgent, Sole source, Logical \ Follow-On, 8a, HUBZone & SDVOSB sole source, all < SAT)"), ("Partial Small Business Set-Aside", "Partial Small Business Set-Aside"), ("Set-Aside", "Set-Aside"), ("Sole Source", "Sole Source"), ) PROCUREMENT_METHOD_CHOICES = ( ("Ability One", "Ability One"), ("Basic Ordering Agreement", "Basic Ordering Agreement"), ("Blanket Purchase Agreement-BPA", "Blanket Purchase Agreement-BPA"), ("BPA Call", "BPA Call"), ("Call Order under GSA Schedules BPA", "Call Order under GSA Schedules BPA"), ("Commercial Item Contract", "Commercial Item Contract"), ("Contract modification", "Contract modification"), ("Contract", "Contract"), ("Definitive Contract other than IDV", "Definitive Contract other than IDV"), ("Definitive Contract", "Definitive Contract"), ("Government-wide Agency Contract-GWAC", "Government-wide Agency Contract-GWAC"), ("GSA Schedule Contract", "GSA Schedule Contract"), ("GSA Schedule", "GSA Schedule"), ("GSA Schedules Program BPA", "GSA Schedules Program BPA"), ("Indefinite Delivery Indefinite Quantity-IDIQ", "Indefinite Delivery Indefinite Quantity-IDIQ"), ("Indefinite Delivery Vehicle (IDV)", "Indefinite Delivery Vehicle (IDV)"), ("Indefinite Delivery Vehicle Base Contract", "Indefinite Delivery Vehicle Base Contract"), ("Multi-Agency Contract", "Multi-Agency Contract"), ("Negotiated", "Negotiated"), ("Order under GSA Federal Supply Schedules Program", "Order under GSA Federal Supply Schedules Program"), ("Order under GSA Schedules Program BPA", "Order under GSA Schedules Program BPA"), ("Order under GSA Schedules Program", "Order under GSA Schedules Program"), ("Order under IDV", "Order under IDV"), ("Purchase Order", "Purchase Order"), ("Sealed Bid", "Sealed Bid"), ) subagency = models.ForeignKey(Subagency) task = models.CharField(max_length=100, blank=False) description = models.TextField(max_length=500, null=True, blank=True) track = models.ForeignKey( Track, blank=False, related_name="%(class)s_track" ) step = ChainedForeignKey( Step, chained_field="track", chained_model_field="track", blank=False ) dollars = models.DecimalField(decimal_places=2, max_digits=14, null=True, blank=True) period_of_performance = models.DateField(null=True, blank=True) product_owner = models.CharField(max_length=50, null=True, blank=True) roles = models.ManyToManyField(Role, blank=True) contracting_officer = models.ForeignKey(ContractingOfficer, null=True, blank=True) contracting_officer_representative = models.ForeignKey(COR, null=True, blank=True) contracting_office = models.ForeignKey(ContractingOffice, null=True, blank=True) vendor = models.ForeignKey(Vendor, null=True, blank=True) rfq_id = models.IntegerField(null=True, blank=True, verbose_name="RFQ ID") naics = models.IntegerField( null=True, blank=True, verbose_name="NAICS Code" ) set_aside_status = models.CharField(max_length=100, null=True, blank=True, choices=SET_ASIDE_CHOICES) amount_of_competition = models.IntegerField(null=True, blank=True) contract_type = models.CharField(max_length=100, null=True, blank=True, choices=CONTRACT_TYPE_CHOICES) competition_strategy = models.CharField( max_length=100, null=True, blank=True, choices=COMPETITION_STRATEGY_CHOICES) procurement_method = models.CharField( max_length=100, null=True, blank=True, choices=PROCUREMENT_METHOD_CHOICES) award_date = models.DateField(null=True, blank=True) delivery_date = models.DateField(null=True, blank=True) def clean(self): print(self.step.track.all()) print(self.track) if self.track not in self.step.track.all(): raise ValidationError(_('Tracks are not equal.')) def __str__(self): return "%s (%s)" % (self.task, self.subagency) class Evaluator(models.Model): name = models.CharField(max_length=100) acquisition = models.ManyToManyField(Acquisition) def __str__(self): return self.name class Meta: ordering = ('name',) class Release(models.Model): acquisition = models.ForeignKey(Acquisition) def __str__(self): return self.id class Meta: ordering = ('id',)
[ "django.db.models.EmailField", "django.db.models.DateField", "django.utils.translation.ugettext_lazy", "django.db.models.TextField", "django.db.models.ForeignKey", "django.db.models.IntegerField", "smart_selects.db_fields.ChainedForeignKey", "django.core.validators.RegexValidator", "django.db.models...
[((388, 433), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'blank': '(False)'}), '(max_length=100, blank=False)\n', (404, 433), False, 'from django.db import models\n'), ((453, 507), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(10)', 'null': '(True)', 'blank': '(True)'}), '(max_length=10, null=True, blank=True)\n', (469, 507), False, 'from django.db import models\n'), ((525, 580), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'null': '(True)', 'blank': '(True)'}), '(max_length=100, null=True, blank=True)\n', (541, 580), False, 'from django.db import models\n'), ((603, 645), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (622, 645), False, 'from django.db import models\n'), ((668, 710), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (687, 710), False, 'from django.db import models\n'), ((738, 780), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (757, 780), False, 'from django.db import models\n'), ((804, 846), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (823, 846), False, 'from django.db import models\n'), ((1027, 1072), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'blank': '(False)'}), '(max_length=100, blank=False)\n', (1043, 1072), False, 'from django.db import models\n'), ((1092, 1146), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(10)', 'null': '(True)', 'blank': '(True)'}), '(max_length=10, null=True, blank=True)\n', (1108, 1146), False, 'from django.db import models\n'), ((1160, 1185), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Agency'], {}), '(Agency)\n', (1177, 1185), False, 'from django.db import models\n'), ((1404, 1436), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1420, 1436), False, 'from django.db import models\n'), ((1652, 1684), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1668, 1684), False, 'from django.db import models\n'), ((1710, 1746), 'django.db.models.ForeignKey', 'models.ForeignKey', (['ContractingOffice'], {}), '(ContractingOffice)\n', (1727, 1746), False, 'from django.db import models\n'), ((2017, 2049), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (2033, 2049), False, 'from django.db import models\n'), ((2356, 2387), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(50)'}), '(max_length=50)\n', (2372, 2387), False, 'from django.db import models\n'), ((2486, 2517), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(50)'}), '(max_length=50)\n', (2502, 2517), False, 'from django.db import models\n'), ((2534, 2590), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'default': '(0)', 'verbose_name': '"""WIP Limit"""'}), "(default=0, verbose_name='WIP Limit')\n", (2553, 2590), False, 'from django.db import models\n'), ((2738, 2783), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(200)', 'blank': '(False)'}), '(max_length=200, blank=False)\n', (2754, 2783), False, 'from django.db import models\n'), ((2882, 2919), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Actor'], {'blank': '(False)'}), '(Actor, blank=False)\n', (2899, 2919), False, 'from django.db import models\n'), ((2954, 3029), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Track'], {'blank': '(False)', 'through': '"""StepTrackThroughModel"""'}), "(Track, blank=False, through='StepTrackThroughModel')\n", (2976, 3029), False, 'from django.db import models\n'), ((3072, 3109), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Stage'], {'blank': '(False)'}), '(Stage, blank=False)\n', (3089, 3109), False, 'from django.db import models\n'), ((3336, 3360), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Track'], {}), '(Track)\n', (3353, 3360), False, 'from django.db import models\n'), ((3372, 3395), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Step'], {}), '(Step)\n', (3389, 3395), False, 'from django.db import models\n'), ((3412, 3468), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'default': '(0)', 'verbose_name': '"""WIP Limit"""'}), "(default=0, verbose_name='WIP Limit')\n", (3431, 3468), False, 'from django.db import models\n'), ((3664, 3709), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(200)', 'blank': '(False)'}), '(max_length=200, blank=False)\n', (3680, 3709), False, 'from django.db import models\n'), ((3722, 3752), 'django.db.models.EmailField', 'models.EmailField', ([], {'blank': '(False)'}), '(blank=False)\n', (3739, 3752), False, 'from django.db import models\n'), ((4003, 4147), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'choices': "(('P', 'Product Lead'), ('A', 'Acquisition Lead'), ('T', 'Technical Lead'))", 'null': '(True)', 'blank': '(True)'}), "(max_length=100, choices=(('P', 'Product Lead'), ('A',\n 'Acquisition Lead'), ('T', 'Technical Lead')), null=True, blank=True)\n", (4019, 4147), False, 'from django.db import models\n'), ((4205, 4251), 'django.db.models.ForeignKey', 'models.ForeignKey', (['User'], {'blank': '(True)', 'null': '(True)'}), '(User, blank=True, null=True)\n', (4222, 4251), False, 'from django.db import models\n'), ((10222, 10250), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Subagency'], {}), '(Subagency)\n', (10239, 10250), False, 'from django.db import models\n'), ((10262, 10307), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'blank': '(False)'}), '(max_length=100, blank=False)\n', (10278, 10307), False, 'from django.db import models\n'), ((10326, 10381), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(500)', 'null': '(True)', 'blank': '(True)'}), '(max_length=500, null=True, blank=True)\n', (10342, 10381), False, 'from django.db import models\n'), ((10394, 10463), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Track'], {'blank': '(False)', 'related_name': '"""%(class)s_track"""'}), "(Track, blank=False, related_name='%(class)s_track')\n", (10411, 10463), False, 'from django.db import models\n'), ((10517, 10609), 'smart_selects.db_fields.ChainedForeignKey', 'ChainedForeignKey', (['Step'], {'chained_field': '"""track"""', 'chained_model_field': '"""track"""', 'blank': '(False)'}), "(Step, chained_field='track', chained_model_field='track',\n blank=False)\n", (10534, 10609), False, 'from smart_selects.db_fields import ChainedForeignKey, ChainedManyToManyField\n'), ((10674, 10749), 'django.db.models.DecimalField', 'models.DecimalField', ([], {'decimal_places': '(2)', 'max_digits': '(14)', 'null': '(True)', 'blank': '(True)'}), '(decimal_places=2, max_digits=14, null=True, blank=True)\n', (10693, 10749), False, 'from django.db import models\n'), ((10812, 10851), 'django.db.models.DateField', 'models.DateField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (10828, 10851), False, 'from django.db import models\n'), ((10872, 10926), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(50)', 'null': '(True)', 'blank': '(True)'}), '(max_length=50, null=True, blank=True)\n', (10888, 10926), False, 'from django.db import models\n'), ((10939, 10979), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Role'], {'blank': '(True)'}), '(Role, blank=True)\n', (10961, 10979), False, 'from django.db import models\n'), ((11006, 11066), 'django.db.models.ForeignKey', 'models.ForeignKey', (['ContractingOfficer'], {'null': '(True)', 'blank': '(True)'}), '(ContractingOfficer, null=True, blank=True)\n', (11023, 11066), False, 'from django.db import models\n'), ((11152, 11197), 'django.db.models.ForeignKey', 'models.ForeignKey', (['COR'], {'null': '(True)', 'blank': '(True)'}), '(COR, null=True, blank=True)\n', (11169, 11197), False, 'from django.db import models\n'), ((11282, 11341), 'django.db.models.ForeignKey', 'models.ForeignKey', (['ContractingOffice'], {'null': '(True)', 'blank': '(True)'}), '(ContractingOffice, null=True, blank=True)\n', (11299, 11341), False, 'from django.db import models\n'), ((11398, 11446), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Vendor'], {'null': '(True)', 'blank': '(True)'}), '(Vendor, null=True, blank=True)\n', (11415, 11446), False, 'from django.db import models\n'), ((11460, 11525), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)', 'verbose_name': '"""RFQ ID"""'}), "(null=True, blank=True, verbose_name='RFQ ID')\n", (11479, 11525), False, 'from django.db import models\n'), ((11538, 11607), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)', 'verbose_name': '"""NAICS Code"""'}), "(null=True, blank=True, verbose_name='NAICS Code')\n", (11557, 11607), False, 'from django.db import models\n'), ((11661, 11748), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'null': '(True)', 'blank': '(True)', 'choices': 'SET_ASIDE_CHOICES'}), '(max_length=100, null=True, blank=True, choices=\n SET_ASIDE_CHOICES)\n', (11677, 11748), False, 'from django.db import models\n'), ((11812, 11854), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (11831, 11854), False, 'from django.db import models\n'), ((11875, 11966), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'null': '(True)', 'blank': '(True)', 'choices': 'CONTRACT_TYPE_CHOICES'}), '(max_length=100, null=True, blank=True, choices=\n CONTRACT_TYPE_CHOICES)\n', (11891, 11966), False, 'from django.db import models\n'), ((12026, 12124), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'null': '(True)', 'blank': '(True)', 'choices': 'COMPETITION_STRATEGY_CHOICES'}), '(max_length=100, null=True, blank=True, choices=\n COMPETITION_STRATEGY_CHOICES)\n', (12042, 12124), False, 'from django.db import models\n'), ((12194, 12290), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'null': '(True)', 'blank': '(True)', 'choices': 'PROCUREMENT_METHOD_CHOICES'}), '(max_length=100, null=True, blank=True, choices=\n PROCUREMENT_METHOD_CHOICES)\n', (12210, 12290), False, 'from django.db import models\n'), ((12352, 12391), 'django.db.models.DateField', 'models.DateField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (12368, 12391), False, 'from django.db import models\n'), ((12412, 12451), 'django.db.models.DateField', 'models.DateField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (12428, 12451), False, 'from django.db import models\n'), ((12774, 12806), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (12790, 12806), False, 'from django.db import models\n'), ((12825, 12860), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Acquisition'], {}), '(Acquisition)\n', (12847, 12860), False, 'from django.db import models\n'), ((13005, 13035), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Acquisition'], {}), '(Acquisition)\n', (13022, 13035), False, 'from django.db import models\n'), ((3829, 3901), 'django.core.validators.RegexValidator', 'RegexValidator', ([], {'regex': '"""^\\\\d{9}$"""', 'message': '"""DUNS number must be 9 digits"""'}), "(regex='^\\\\d{9}$', message='DUNS number must be 9 digits')\n", (3843, 3901), False, 'from django.core.validators import RegexValidator, ValidationError\n'), ((12623, 12649), 'django.utils.translation.ugettext_lazy', '_', (['"""Tracks are not equal."""'], {}), "('Tracks are not equal.')\n", (12624, 12649), True, 'from django.utils.translation import ugettext_lazy as _\n')]
from django import forms from .models import Connection, KoboUser, KoboData from django.contrib.admin.widgets import FilteredSelectMultiple from django.db.models import Q class ConnectionForm(forms.ModelForm): class Meta: model = Connection exclude = [] widgets = { 'auth_pass': forms.PasswordInput(), } class KoboUserForm(forms.ModelForm): class Meta: model = KoboUser exclude = [] surveys = forms.ModelMultipleChoiceField(queryset=KoboData.objects.filter(Q(tags__contains=['bns']) | Q(tags__contains=['nrgt'])), widget=FilteredSelectMultiple( 'Surveys', is_stacked=False), label='')
[ "django.contrib.admin.widgets.FilteredSelectMultiple", "django.db.models.Q", "django.forms.PasswordInput" ]
[((321, 342), 'django.forms.PasswordInput', 'forms.PasswordInput', ([], {}), '()\n', (340, 342), False, 'from django import forms\n'), ((602, 653), 'django.contrib.admin.widgets.FilteredSelectMultiple', 'FilteredSelectMultiple', (['"""Surveys"""'], {'is_stacked': '(False)'}), "('Surveys', is_stacked=False)\n", (624, 653), False, 'from django.contrib.admin.widgets import FilteredSelectMultiple\n'), ((538, 563), 'django.db.models.Q', 'Q', ([], {'tags__contains': "['bns']"}), "(tags__contains=['bns'])\n", (539, 563), False, 'from django.db.models import Q\n'), ((566, 592), 'django.db.models.Q', 'Q', ([], {'tags__contains': "['nrgt']"}), "(tags__contains=['nrgt'])\n", (567, 592), False, 'from django.db.models import Q\n')]
from operator import attrgetter import pyangbind.lib.xpathhelper as xpathhelper from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType from pyangbind.lib.base import PybindBase from decimal import Decimal from bitarray import bitarray import __builtin__ import hops class lsp(PybindBase): """ This class was auto-generated by the PythonClass plugin for PYANG from YANG module brocade-mpls-operational - based on the path /mpls-state/rsvp/igp-sync/link/lsp. Each member element of the container is represented as a class variable - with a specific YANG type. """ __slots__ = ('_pybind_generated_by', '_path_helper', '_yang_name', '_rest_name', '_extmethods', '__lsp_name','__lsp_instance_id','__path_name','__cspf_enabled','__rro_enabled','__frr_enabled','__nbr_down_enabled','__link_count','__nbr_down_inprogress','__cspf_hop_count','__rro_hop_count','__hops',) _yang_name = 'lsp' _rest_name = 'lsp' _pybind_generated_by = 'container' def __init__(self, *args, **kwargs): path_helper_ = kwargs.pop("path_helper", None) if path_helper_ is False: self._path_helper = False elif path_helper_ is not None and isinstance(path_helper_, xpathhelper.YANGPathHelper): self._path_helper = path_helper_ elif hasattr(self, "_parent"): path_helper_ = getattr(self._parent, "_path_helper", False) self._path_helper = path_helper_ else: self._path_helper = False extmethods = kwargs.pop("extmethods", None) if extmethods is False: self._extmethods = False elif extmethods is not None and isinstance(extmethods, dict): self._extmethods = extmethods elif hasattr(self, "_parent"): extmethods = getattr(self._parent, "_extmethods", None) self._extmethods = extmethods else: self._extmethods = False self.__path_name = YANGDynClass(base=unicode, is_leaf=True, yang_name="path-name", rest_name="path-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) self.__cspf_hop_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="cspf-hop-count", rest_name="cspf-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) self.__hops = YANGDynClass(base=YANGListType("index hop_type",hops.hops, yang_name="hops", rest_name="hops", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='index hop-type', extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}), is_container='list', yang_name="hops", rest_name="hops", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='list', is_config=False) self.__lsp_name = YANGDynClass(base=unicode, is_leaf=True, yang_name="lsp-name", rest_name="lsp-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) self.__nbr_down_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-enabled", rest_name="nbr-down-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) self.__rro_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="rro-enabled", rest_name="rro-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) self.__cspf_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="cspf-enabled", rest_name="cspf-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) self.__nbr_down_inprogress = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-inprogress", rest_name="nbr-down-inprogress", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) self.__lsp_instance_id = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="lsp-instance-id", rest_name="lsp-instance-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) self.__rro_hop_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="rro-hop-count", rest_name="rro-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) self.__frr_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="frr-enabled", rest_name="frr-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) self.__link_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="link-count", rest_name="link-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) load = kwargs.pop("load", None) if args: if len(args) > 1: raise TypeError("cannot create a YANG container with >1 argument") all_attr = True for e in self._pyangbind_elements: if not hasattr(args[0], e): all_attr = False break if not all_attr: raise ValueError("Supplied object did not have the correct attributes") for e in self._pyangbind_elements: nobj = getattr(args[0], e) if nobj._changed() is False: continue setmethod = getattr(self, "_set_%s" % e) if load is None: setmethod(getattr(args[0], e)) else: setmethod(getattr(args[0], e), load=load) def _path(self): if hasattr(self, "_parent"): return self._parent._path()+[self._yang_name] else: return [u'mpls-state', u'rsvp', u'igp-sync', u'link', u'lsp'] def _rest_path(self): if hasattr(self, "_parent"): if self._rest_name: return self._parent._rest_path()+[self._rest_name] else: return self._parent._rest_path() else: return [u'mpls-state', u'rsvp', u'igp-sync', u'link', u'lsp'] def _get_lsp_name(self): """ Getter method for lsp_name, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/lsp_name (string) YANG Description: LSP name """ return self.__lsp_name def _set_lsp_name(self, v, load=False): """ Setter method for lsp_name, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/lsp_name (string) If this variable is read-only (config: false) in the source YANG file, then _set_lsp_name is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_lsp_name() directly. YANG Description: LSP name """ parent = getattr(self, "_parent", None) if parent is not None and load is False: raise AttributeError("Cannot set keys directly when" + " within an instantiated list") if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=unicode, is_leaf=True, yang_name="lsp-name", rest_name="lsp-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """lsp_name must be of a type compatible with string""", 'defined-type': "string", 'generated-type': """YANGDynClass(base=unicode, is_leaf=True, yang_name="lsp-name", rest_name="lsp-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False)""", }) self.__lsp_name = t if hasattr(self, '_set'): self._set() def _unset_lsp_name(self): self.__lsp_name = YANGDynClass(base=unicode, is_leaf=True, yang_name="lsp-name", rest_name="lsp-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) def _get_lsp_instance_id(self): """ Getter method for lsp_instance_id, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/lsp_instance_id (uint32) YANG Description: Instance id of the lsp instance """ return self.__lsp_instance_id def _set_lsp_instance_id(self, v, load=False): """ Setter method for lsp_instance_id, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/lsp_instance_id (uint32) If this variable is read-only (config: false) in the source YANG file, then _set_lsp_instance_id is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_lsp_instance_id() directly. YANG Description: Instance id of the lsp instance """ parent = getattr(self, "_parent", None) if parent is not None and load is False: raise AttributeError("Cannot set keys directly when" + " within an instantiated list") if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="lsp-instance-id", rest_name="lsp-instance-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """lsp_instance_id must be of a type compatible with uint32""", 'defined-type': "uint32", 'generated-type': """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="lsp-instance-id", rest_name="lsp-instance-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False)""", }) self.__lsp_instance_id = t if hasattr(self, '_set'): self._set() def _unset_lsp_instance_id(self): self.__lsp_instance_id = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="lsp-instance-id", rest_name="lsp-instance-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) def _get_path_name(self): """ Getter method for path_name, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/path_name (string) YANG Description: LSP Path name """ return self.__path_name def _set_path_name(self, v, load=False): """ Setter method for path_name, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/path_name (string) If this variable is read-only (config: false) in the source YANG file, then _set_path_name is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_path_name() directly. YANG Description: LSP Path name """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=unicode, is_leaf=True, yang_name="path-name", rest_name="path-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """path_name must be of a type compatible with string""", 'defined-type': "string", 'generated-type': """YANGDynClass(base=unicode, is_leaf=True, yang_name="path-name", rest_name="path-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False)""", }) self.__path_name = t if hasattr(self, '_set'): self._set() def _unset_path_name(self): self.__path_name = YANGDynClass(base=unicode, is_leaf=True, yang_name="path-name", rest_name="path-name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='string', is_config=False) def _get_cspf_enabled(self): """ Getter method for cspf_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/cspf_enabled (boolean) YANG Description: CSPF enabled for LSP """ return self.__cspf_enabled def _set_cspf_enabled(self, v, load=False): """ Setter method for cspf_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/cspf_enabled (boolean) If this variable is read-only (config: false) in the source YANG file, then _set_cspf_enabled is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_cspf_enabled() directly. YANG Description: CSPF enabled for LSP """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="cspf-enabled", rest_name="cspf-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """cspf_enabled must be of a type compatible with boolean""", 'defined-type': "boolean", 'generated-type': """YANGDynClass(base=YANGBool, is_leaf=True, yang_name="cspf-enabled", rest_name="cspf-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False)""", }) self.__cspf_enabled = t if hasattr(self, '_set'): self._set() def _unset_cspf_enabled(self): self.__cspf_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="cspf-enabled", rest_name="cspf-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) def _get_rro_enabled(self): """ Getter method for rro_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/rro_enabled (boolean) YANG Description: RRO enabled for LSP """ return self.__rro_enabled def _set_rro_enabled(self, v, load=False): """ Setter method for rro_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/rro_enabled (boolean) If this variable is read-only (config: false) in the source YANG file, then _set_rro_enabled is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_rro_enabled() directly. YANG Description: RRO enabled for LSP """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="rro-enabled", rest_name="rro-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """rro_enabled must be of a type compatible with boolean""", 'defined-type': "boolean", 'generated-type': """YANGDynClass(base=YANGBool, is_leaf=True, yang_name="rro-enabled", rest_name="rro-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False)""", }) self.__rro_enabled = t if hasattr(self, '_set'): self._set() def _unset_rro_enabled(self): self.__rro_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="rro-enabled", rest_name="rro-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) def _get_frr_enabled(self): """ Getter method for frr_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/frr_enabled (boolean) YANG Description: FRR enabled for LSP """ return self.__frr_enabled def _set_frr_enabled(self, v, load=False): """ Setter method for frr_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/frr_enabled (boolean) If this variable is read-only (config: false) in the source YANG file, then _set_frr_enabled is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_frr_enabled() directly. YANG Description: FRR enabled for LSP """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="frr-enabled", rest_name="frr-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """frr_enabled must be of a type compatible with boolean""", 'defined-type': "boolean", 'generated-type': """YANGDynClass(base=YANGBool, is_leaf=True, yang_name="frr-enabled", rest_name="frr-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False)""", }) self.__frr_enabled = t if hasattr(self, '_set'): self._set() def _unset_frr_enabled(self): self.__frr_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="frr-enabled", rest_name="frr-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) def _get_nbr_down_enabled(self): """ Getter method for nbr_down_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/nbr_down_enabled (boolean) YANG Description: LSP Neighbour down is enabled """ return self.__nbr_down_enabled def _set_nbr_down_enabled(self, v, load=False): """ Setter method for nbr_down_enabled, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/nbr_down_enabled (boolean) If this variable is read-only (config: false) in the source YANG file, then _set_nbr_down_enabled is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_nbr_down_enabled() directly. YANG Description: LSP Neighbour down is enabled """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="nbr-down-enabled", rest_name="nbr-down-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """nbr_down_enabled must be of a type compatible with boolean""", 'defined-type': "boolean", 'generated-type': """YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-enabled", rest_name="nbr-down-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False)""", }) self.__nbr_down_enabled = t if hasattr(self, '_set'): self._set() def _unset_nbr_down_enabled(self): self.__nbr_down_enabled = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-enabled", rest_name="nbr-down-enabled", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) def _get_link_count(self): """ Getter method for link_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/link_count (uint32) YANG Description: Total links used by the LSP """ return self.__link_count def _set_link_count(self, v, load=False): """ Setter method for link_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/link_count (uint32) If this variable is read-only (config: false) in the source YANG file, then _set_link_count is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_link_count() directly. YANG Description: Total links used by the LSP """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="link-count", rest_name="link-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """link_count must be of a type compatible with uint32""", 'defined-type': "uint32", 'generated-type': """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="link-count", rest_name="link-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False)""", }) self.__link_count = t if hasattr(self, '_set'): self._set() def _unset_link_count(self): self.__link_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="link-count", rest_name="link-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) def _get_nbr_down_inprogress(self): """ Getter method for nbr_down_inprogress, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/nbr_down_inprogress (boolean) YANG Description: Neighbor down processing is in progress """ return self.__nbr_down_inprogress def _set_nbr_down_inprogress(self, v, load=False): """ Setter method for nbr_down_inprogress, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/nbr_down_inprogress (boolean) If this variable is read-only (config: false) in the source YANG file, then _set_nbr_down_inprogress is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_nbr_down_inprogress() directly. YANG Description: Neighbor down processing is in progress """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="nbr-down-inprogress", rest_name="nbr-down-inprogress", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """nbr_down_inprogress must be of a type compatible with boolean""", 'defined-type': "boolean", 'generated-type': """YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-inprogress", rest_name="nbr-down-inprogress", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False)""", }) self.__nbr_down_inprogress = t if hasattr(self, '_set'): self._set() def _unset_nbr_down_inprogress(self): self.__nbr_down_inprogress = YANGDynClass(base=YANGBool, is_leaf=True, yang_name="nbr-down-inprogress", rest_name="nbr-down-inprogress", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='boolean', is_config=False) def _get_cspf_hop_count(self): """ Getter method for cspf_hop_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/cspf_hop_count (uint32) YANG Description: CSPF hop count """ return self.__cspf_hop_count def _set_cspf_hop_count(self, v, load=False): """ Setter method for cspf_hop_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/cspf_hop_count (uint32) If this variable is read-only (config: false) in the source YANG file, then _set_cspf_hop_count is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_cspf_hop_count() directly. YANG Description: CSPF hop count """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="cspf-hop-count", rest_name="cspf-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """cspf_hop_count must be of a type compatible with uint32""", 'defined-type': "uint32", 'generated-type': """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="cspf-hop-count", rest_name="cspf-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False)""", }) self.__cspf_hop_count = t if hasattr(self, '_set'): self._set() def _unset_cspf_hop_count(self): self.__cspf_hop_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="cspf-hop-count", rest_name="cspf-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) def _get_rro_hop_count(self): """ Getter method for rro_hop_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/rro_hop_count (uint32) YANG Description: RRO hop rout """ return self.__rro_hop_count def _set_rro_hop_count(self, v, load=False): """ Setter method for rro_hop_count, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/rro_hop_count (uint32) If this variable is read-only (config: false) in the source YANG file, then _set_rro_hop_count is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_rro_hop_count() directly. YANG Description: RRO hop rout """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="rro-hop-count", rest_name="rro-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """rro_hop_count must be of a type compatible with uint32""", 'defined-type': "uint32", 'generated-type': """YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="rro-hop-count", rest_name="rro-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False)""", }) self.__rro_hop_count = t if hasattr(self, '_set'): self._set() def _unset_rro_hop_count(self): self.__rro_hop_count = YANGDynClass(base=RestrictedClassType(base_type=long, restriction_dict={'range': ['0..4294967295']}, int_size=32), is_leaf=True, yang_name="rro-hop-count", rest_name="rro-hop-count", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='uint32', is_config=False) def _get_hops(self): """ Getter method for hops, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/hops (list) YANG Description: MPLS Rsvp IGP Synchronization Hop information """ return self.__hops def _set_hops(self, v, load=False): """ Setter method for hops, mapped from YANG variable /mpls_state/rsvp/igp_sync/link/lsp/hops (list) If this variable is read-only (config: false) in the source YANG file, then _set_hops is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_hops() directly. YANG Description: MPLS Rsvp IGP Synchronization Hop information """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGListType("index hop_type",hops.hops, yang_name="hops", rest_name="hops", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='index hop-type', extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}), is_container='list', yang_name="hops", rest_name="hops", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='list', is_config=False) except (TypeError, ValueError): raise ValueError({ 'error-string': """hops must be of a type compatible with list""", 'defined-type': "list", 'generated-type': """YANGDynClass(base=YANGListType("index hop_type",hops.hops, yang_name="hops", rest_name="hops", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='index hop-type', extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}), is_container='list', yang_name="hops", rest_name="hops", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='list', is_config=False)""", }) self.__hops = t if hasattr(self, '_set'): self._set() def _unset_hops(self): self.__hops = YANGDynClass(base=YANGListType("index hop_type",hops.hops, yang_name="hops", rest_name="hops", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='index hop-type', extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}), is_container='list', yang_name="hops", rest_name="hops", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data', u'cli-suppress-show-path': None}}, namespace='urn:brocade.com:mgmt:brocade-mpls-operational', defining_module='brocade-mpls-operational', yang_type='list', is_config=False) lsp_name = __builtin__.property(_get_lsp_name) lsp_instance_id = __builtin__.property(_get_lsp_instance_id) path_name = __builtin__.property(_get_path_name) cspf_enabled = __builtin__.property(_get_cspf_enabled) rro_enabled = __builtin__.property(_get_rro_enabled) frr_enabled = __builtin__.property(_get_frr_enabled) nbr_down_enabled = __builtin__.property(_get_nbr_down_enabled) link_count = __builtin__.property(_get_link_count) nbr_down_inprogress = __builtin__.property(_get_nbr_down_inprogress) cspf_hop_count = __builtin__.property(_get_cspf_hop_count) rro_hop_count = __builtin__.property(_get_rro_hop_count) hops = __builtin__.property(_get_hops) _pyangbind_elements = {'lsp_name': lsp_name, 'lsp_instance_id': lsp_instance_id, 'path_name': path_name, 'cspf_enabled': cspf_enabled, 'rro_enabled': rro_enabled, 'frr_enabled': frr_enabled, 'nbr_down_enabled': nbr_down_enabled, 'link_count': link_count, 'nbr_down_inprogress': nbr_down_inprogress, 'cspf_hop_count': cspf_hop_count, 'rro_hop_count': rro_hop_count, 'hops': hops, }
[ "pyangbind.lib.yangtypes.YANGDynClass", "__builtin__.property", "pyangbind.lib.yangtypes.RestrictedClassType", "pyangbind.lib.yangtypes.YANGListType" ]
[((36786, 36821), '__builtin__.property', '__builtin__.property', (['_get_lsp_name'], {}), '(_get_lsp_name)\n', (36806, 36821), False, 'import __builtin__\n'), ((36842, 36884), '__builtin__.property', '__builtin__.property', (['_get_lsp_instance_id'], {}), '(_get_lsp_instance_id)\n', (36862, 36884), False, 'import __builtin__\n'), ((36899, 36935), '__builtin__.property', '__builtin__.property', (['_get_path_name'], {}), '(_get_path_name)\n', (36919, 36935), False, 'import __builtin__\n'), ((36953, 36992), '__builtin__.property', '__builtin__.property', (['_get_cspf_enabled'], {}), '(_get_cspf_enabled)\n', (36973, 36992), False, 'import __builtin__\n'), ((37009, 37047), '__builtin__.property', '__builtin__.property', (['_get_rro_enabled'], {}), '(_get_rro_enabled)\n', (37029, 37047), False, 'import __builtin__\n'), ((37064, 37102), '__builtin__.property', '__builtin__.property', (['_get_frr_enabled'], {}), '(_get_frr_enabled)\n', (37084, 37102), False, 'import __builtin__\n'), ((37124, 37167), '__builtin__.property', '__builtin__.property', (['_get_nbr_down_enabled'], {}), '(_get_nbr_down_enabled)\n', (37144, 37167), False, 'import __builtin__\n'), ((37183, 37220), '__builtin__.property', '__builtin__.property', (['_get_link_count'], {}), '(_get_link_count)\n', (37203, 37220), False, 'import __builtin__\n'), ((37245, 37291), '__builtin__.property', '__builtin__.property', (['_get_nbr_down_inprogress'], {}), '(_get_nbr_down_inprogress)\n', (37265, 37291), False, 'import __builtin__\n'), ((37311, 37352), '__builtin__.property', '__builtin__.property', (['_get_cspf_hop_count'], {}), '(_get_cspf_hop_count)\n', (37331, 37352), False, 'import __builtin__\n'), ((37371, 37411), '__builtin__.property', '__builtin__.property', (['_get_rro_hop_count'], {}), '(_get_rro_hop_count)\n', (37391, 37411), False, 'import __builtin__\n'), ((37421, 37452), '__builtin__.property', '__builtin__.property', (['_get_hops'], {}), '(_get_hops)\n', (37441, 37452), False, 'import __builtin__\n'), ((1968, 2308), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""path-name"""', 'rest_name': '"""path-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(base=unicode, is_leaf=True, yang_name='path-name', rest_name=\n 'path-name', parent=self, path_helper=self._path_helper, extmethods=\n self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (1980, 2308), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((3496, 3850), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""lsp-name"""', 'rest_name': '"""lsp-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'is_keyval': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(base=unicode, is_leaf=True, yang_name='lsp-name', rest_name=\n 'lsp-name', parent=self, path_helper=self._path_helper, extmethods=self\n ._extmethods, register_paths=True, is_keyval=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (3508, 3850), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((3861, 4218), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-enabled"""', 'rest_name': '"""nbr-down-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='nbr-down-enabled',\n rest_name='nbr-down-enabled', parent=self, path_helper=self.\n _path_helper, extmethods=self._extmethods, register_paths=True,\n namespace='urn:brocade.com:mgmt:brocade-mpls-operational',\n defining_module='brocade-mpls-operational', yang_type='boolean',\n is_config=False)\n", (3873, 4218), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((4223, 4567), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""rro-enabled"""', 'rest_name': '"""rro-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='rro-enabled',\n rest_name='rro-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (4235, 4567), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((4576, 4922), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""cspf-enabled"""', 'rest_name': '"""cspf-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='cspf-enabled',\n rest_name='cspf-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (4588, 4922), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((4938, 5301), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-inprogress"""', 'rest_name': '"""nbr-down-inprogress"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='nbr-down-inprogress',\n rest_name='nbr-down-inprogress', parent=self, path_helper=self.\n _path_helper, extmethods=self._extmethods, register_paths=True,\n namespace='urn:brocade.com:mgmt:brocade-mpls-operational',\n defining_module='brocade-mpls-operational', yang_type='boolean',\n is_config=False)\n", (4950, 5301), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((6216, 6560), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""frr-enabled"""', 'rest_name': '"""frr-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='frr-enabled',\n rest_name='frr-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (6228, 6560), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((10112, 10466), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""lsp-name"""', 'rest_name': '"""lsp-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'is_keyval': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(base=unicode, is_leaf=True, yang_name='lsp-name', rest_name=\n 'lsp-name', parent=self, path_helper=self._path_helper, extmethods=self\n ._extmethods, register_paths=True, is_keyval=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (10124, 10466), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((14950, 15290), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""path-name"""', 'rest_name': '"""path-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(base=unicode, is_leaf=True, yang_name='path-name', rest_name=\n 'path-name', parent=self, path_helper=self._path_helper, extmethods=\n self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (14962, 15290), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((17098, 17444), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""cspf-enabled"""', 'rest_name': '"""cspf-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='cspf-enabled',\n rest_name='cspf-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (17110, 17444), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((19235, 19579), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""rro-enabled"""', 'rest_name': '"""rro-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='rro-enabled',\n rest_name='rro-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (19247, 19579), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((21370, 21714), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""frr-enabled"""', 'rest_name': '"""frr-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='frr-enabled',\n rest_name='frr-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (21382, 21714), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((23610, 23967), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-enabled"""', 'rest_name': '"""nbr-down-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='nbr-down-enabled',\n rest_name='nbr-down-enabled', parent=self, path_helper=self.\n _path_helper, extmethods=self._extmethods, register_paths=True,\n namespace='urn:brocade.com:mgmt:brocade-mpls-operational',\n defining_module='brocade-mpls-operational', yang_type='boolean',\n is_config=False)\n", (23622, 23967), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((28317, 28680), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', ([], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-inprogress"""', 'rest_name': '"""nbr-down-inprogress"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(base=YANGBool, is_leaf=True, yang_name='nbr-down-inprogress',\n rest_name='nbr-down-inprogress', parent=self, path_helper=self.\n _path_helper, extmethods=self._extmethods, register_paths=True,\n namespace='urn:brocade.com:mgmt:brocade-mpls-operational',\n defining_module='brocade-mpls-operational', yang_type='boolean',\n is_config=False)\n", (28329, 28680), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((9089, 9446), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""lsp-name"""', 'rest_name': '"""lsp-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'is_keyval': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(v, base=unicode, is_leaf=True, yang_name='lsp-name', rest_name\n ='lsp-name', parent=self, path_helper=self._path_helper, extmethods=\n self._extmethods, register_paths=True, is_keyval=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (9101, 9446), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((13951, 14292), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'unicode', 'is_leaf': '(True)', 'yang_name': '"""path-name"""', 'rest_name': '"""path-name"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""string"""', 'is_config': '(False)'}), "(v, base=unicode, is_leaf=True, yang_name='path-name',\n rest_name='path-name', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='string', is_config=False)\n", (13963, 14292), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((16069, 16418), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""cspf-enabled"""', 'rest_name': '"""cspf-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(v, base=YANGBool, is_leaf=True, yang_name='cspf-enabled',\n rest_name='cspf-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (16081, 16418), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((18214, 18561), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""rro-enabled"""', 'rest_name': '"""rro-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(v, base=YANGBool, is_leaf=True, yang_name='rro-enabled',\n rest_name='rro-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (18226, 18561), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((20349, 20696), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""frr-enabled"""', 'rest_name': '"""frr-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(v, base=YANGBool, is_leaf=True, yang_name='frr-enabled',\n rest_name='frr-enabled', parent=self, path_helper=self._path_helper,\n extmethods=self._extmethods, register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (20361, 20696), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((22549, 22909), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-enabled"""', 'rest_name': '"""nbr-down-enabled"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(v, base=YANGBool, is_leaf=True, yang_name='nbr-down-enabled',\n rest_name='nbr-down-enabled', parent=self, path_helper=self.\n _path_helper, extmethods=self._extmethods, register_paths=True,\n namespace='urn:brocade.com:mgmt:brocade-mpls-operational',\n defining_module='brocade-mpls-operational', yang_type='boolean',\n is_config=False)\n", (22561, 22909), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((27232, 27600), 'pyangbind.lib.yangtypes.YANGDynClass', 'YANGDynClass', (['v'], {'base': 'YANGBool', 'is_leaf': '(True)', 'yang_name': '"""nbr-down-inprogress"""', 'rest_name': '"""nbr-down-inprogress"""', 'parent': 'self', 'path_helper': 'self._path_helper', 'extmethods': 'self._extmethods', 'register_paths': '(True)', 'namespace': '"""urn:brocade.com:mgmt:brocade-mpls-operational"""', 'defining_module': '"""brocade-mpls-operational"""', 'yang_type': '"""boolean"""', 'is_config': '(False)'}), "(v, base=YANGBool, is_leaf=True, yang_name=\n 'nbr-down-inprogress', rest_name='nbr-down-inprogress', parent=self,\n path_helper=self._path_helper, extmethods=self._extmethods,\n register_paths=True, namespace=\n 'urn:brocade.com:mgmt:brocade-mpls-operational', defining_module=\n 'brocade-mpls-operational', yang_type='boolean', is_config=False)\n", (27244, 27600), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((2335, 2435), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (2354, 2435), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((2772, 3091), 'pyangbind.lib.yangtypes.YANGListType', 'YANGListType', (['"""index hop_type"""', 'hops.hops'], {'yang_name': '"""hops"""', 'rest_name': '"""hops"""', 'parent': 'self', 'is_container': '"""list"""', 'user_ordered': '(False)', 'path_helper': 'self._path_helper', 'yang_keys': '"""index hop-type"""', 'extensions': "{u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}}"}), "('index hop_type', hops.hops, yang_name='hops', rest_name=\n 'hops', parent=self, is_container='list', user_ordered=False,\n path_helper=self._path_helper, yang_keys='index hop-type', extensions={\n u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}})\n", (2784, 3091), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((5328, 5428), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (5347, 5428), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((5792, 5892), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (5811, 5892), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((6585, 6685), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (6604, 6685), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((12777, 12877), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (12796, 12877), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((25940, 26040), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (25959, 26040), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((30695, 30795), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (30714, 30795), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((33110, 33210), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (33129, 33210), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((36070, 36389), 'pyangbind.lib.yangtypes.YANGListType', 'YANGListType', (['"""index hop_type"""', 'hops.hops'], {'yang_name': '"""hops"""', 'rest_name': '"""hops"""', 'parent': 'self', 'is_container': '"""list"""', 'user_ordered': '(False)', 'path_helper': 'self._path_helper', 'yang_keys': '"""index hop-type"""', 'extensions': "{u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}}"}), "('index hop_type', hops.hops, yang_name='hops', rest_name=\n 'hops', parent=self, is_container='list', user_ordered=False,\n path_helper=self._path_helper, yang_keys='index hop-type', extensions={\n u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}})\n", (36082, 36389), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n'), ((11524, 11624), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (11543, 11624), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((24759, 24859), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (24778, 24859), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((29482, 29582), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (29501, 29582), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((31905, 32005), 'pyangbind.lib.yangtypes.RestrictedClassType', 'RestrictedClassType', ([], {'base_type': 'long', 'restriction_dict': "{'range': ['0..4294967295']}", 'int_size': '(32)'}), "(base_type=long, restriction_dict={'range': [\n '0..4294967295']}, int_size=32)\n", (31924, 32005), False, 'from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType, RestrictedClassType, TypedListType\n'), ((34299, 34618), 'pyangbind.lib.yangtypes.YANGListType', 'YANGListType', (['"""index hop_type"""', 'hops.hops'], {'yang_name': '"""hops"""', 'rest_name': '"""hops"""', 'parent': 'self', 'is_container': '"""list"""', 'user_ordered': '(False)', 'path_helper': 'self._path_helper', 'yang_keys': '"""index hop-type"""', 'extensions': "{u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}}"}), "('index hop_type', hops.hops, yang_name='hops', rest_name=\n 'hops', parent=self, is_container='list', user_ordered=False,\n path_helper=self._path_helper, yang_keys='index hop-type', extensions={\n u'tailf-common': {u'callpoint': u'mpls-rsvp-igp-sync-hop-data',\n u'cli-suppress-show-path': None}})\n", (34311, 34618), False, 'from pyangbind.lib.yangtypes import YANGBool, YANGListType, YANGDynClass, ReferenceType\n')]
# -*- coding:utf-8 -*- # Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Data parallel callback.""" import logging import vega from vega.common import ClassFactory, ClassType from .callback import Callback logger = logging.getLogger(__name__) @ClassFactory.register(ClassType.CALLBACK) class Horovod(Callback): """Callback that saves the evaluated Performance.""" def __init__(self): """Initialize ModelCheckpoint callback.""" super(Horovod, self).__init__() self.priority = 260 def before_train(self, logs=None): """Be called before the training process.""" if not self.trainer.horovod: return if vega.is_torch_backend(): self._init_torch() def _init_torch(self): import torch import horovod.torch as hvd hvd.broadcast_parameters(self.trainer.model.state_dict(), root_rank=0) hvd.broadcast_optimizer_state(self.trainer.optimizer, root_rank=0) self.trainer._average_metrics = self._average_metrics def _average_metrics(self, metrics_results): import torch import horovod.torch as hvd for key, value in metrics_results.items(): tensor = torch.tensor(value) avg_tensor = hvd.allreduce(tensor, name=key) metrics_results[key] = avg_tensor.item() return metrics_results
[ "logging.getLogger", "horovod.torch.broadcast_optimizer_state", "horovod.torch.allreduce", "torch.tensor", "vega.common.ClassFactory.register", "vega.is_torch_backend" ]
[((791, 818), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (808, 818), False, 'import logging\n'), ((822, 863), 'vega.common.ClassFactory.register', 'ClassFactory.register', (['ClassType.CALLBACK'], {}), '(ClassType.CALLBACK)\n', (843, 863), False, 'from vega.common import ClassFactory, ClassType\n'), ((1250, 1273), 'vega.is_torch_backend', 'vega.is_torch_backend', ([], {}), '()\n', (1271, 1273), False, 'import vega\n'), ((1478, 1544), 'horovod.torch.broadcast_optimizer_state', 'hvd.broadcast_optimizer_state', (['self.trainer.optimizer'], {'root_rank': '(0)'}), '(self.trainer.optimizer, root_rank=0)\n', (1507, 1544), True, 'import horovod.torch as hvd\n'), ((1786, 1805), 'torch.tensor', 'torch.tensor', (['value'], {}), '(value)\n', (1798, 1805), False, 'import torch\n'), ((1831, 1862), 'horovod.torch.allreduce', 'hvd.allreduce', (['tensor'], {'name': 'key'}), '(tensor, name=key)\n', (1844, 1862), True, 'import horovod.torch as hvd\n')]
""" <NAME> Skeleton of https://github.com/pyhoneybot/honeybot/ """ import time import os import socket directory = "irc" if not os.path.exists(directory): os.makedirs(directory) target = open(os.path.join(directory, "log.txt"), "w") def message_checker(msgLine): sendvar = "" global mute mute = False completeLine = str(msgLine[1:]).replace("'b", "").split(":", 1) info = completeLine[0].split() message = (completeLine[1].split("\\r")[0]).replace("'b", "") sender = info[0][2:].split("!", 1)[0] refinedmsg = str(message.lower()) refinedmsgl = len(refinedmsg) print("Complete Line-->" + str(completeLine)) print("Info-->" + str(info)) print("Message-->" + str(message)) print("Sender-->" + str(sender) + "\n") def ping_checker(pingLine): if pingLine.find(bytes("PING", "utf8")) != -1: pingLine = pingLine.rstrip().split() if pingLine[0] == bytes("PING", "utf8"): irc.send(bytes("PONG ", "utf8") + pingLine[1] + bytes("\r\n", "utf8")) BOT_IRC_SERVER = "chat.freenode.net" BOT_IRC_CHANNEL = "##bottestingmu" # BOT_IRC_CHANNEL = "#python" BOT_IRC_PORT = 6667 BOT_NICKNAME = "appinventormuBot" # BOT_PASSWORD = '' irc = socket.socket() irc.connect((BOT_IRC_SERVER, BOT_IRC_PORT)) irc.recv(4096) irc.send(bytes("NICK " + BOT_NICKNAME + "\r\n", "utf8")) ping_checker(irc.recv(4096)) irc.send( bytes( "USER appinventormuBot appinventormuBot appinventormuBot : appinventormuBot IRC\r\n", "utf8", ) ) ping_checker(irc.recv(4096)) # irc.send(bytes('msg NickServ identify ' + BOT_PASSWORD + " \r\n" ,'utf8') ) # ping_checker(irc.recv(4096)) # irc.send(bytes('NICKSERV identify ' + BOT_NICKNAME+' '+BOT_PASSWORD+ '\r\n','utf8' ) ) # ping_checker(irc.recv(4096)) time.sleep(3) irc.send(bytes("JOIN " + BOT_IRC_CHANNEL + "\r\n", "utf8")) while 1: pass line = irc.recv(4096) print(line) ping_checker(line) if ( line.find(bytes("PRIVMSG", "utf8")) != -1 or line.find(bytes("NOTICE", "utf8")) != -1 ): message_checker(line) target.write(str(line)) target.flush()
[ "os.path.exists", "os.makedirs", "socket.socket", "os.path.join", "time.sleep" ]
[((1215, 1230), 'socket.socket', 'socket.socket', ([], {}), '()\n', (1228, 1230), False, 'import socket\n'), ((1782, 1795), 'time.sleep', 'time.sleep', (['(3)'], {}), '(3)\n', (1792, 1795), False, 'import time\n'), ((130, 155), 'os.path.exists', 'os.path.exists', (['directory'], {}), '(directory)\n', (144, 155), False, 'import os\n'), ((161, 183), 'os.makedirs', 'os.makedirs', (['directory'], {}), '(directory)\n', (172, 183), False, 'import os\n'), ((198, 232), 'os.path.join', 'os.path.join', (['directory', '"""log.txt"""'], {}), "(directory, 'log.txt')\n", (210, 232), False, 'import os\n')]
# coding: utf-8 """ Xenia Python Client Library Python Client Library to interact with the Xenia API. # noqa: E501 The version of the OpenAPI document: v2.1 Generated by: https://openapi-generator.tech """ import pprint import re # noqa: F401 import six from xenia_python_client_library.configuration import Configuration class AttachmentsList(object): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech Do not edit the class manually. """ """ Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. attribute_map (dict): The key is attribute name and the value is json key in definition. """ openapi_types = { 'id': 'str', 'source_name': 'str', 'destination_name': 'str', 'mapping': 'list[AttachmentFieldsList]' } attribute_map = { 'id': 'id', 'source_name': 'source_name', 'destination_name': 'destination_name', 'mapping': 'mapping' } def __init__(self, id=None, source_name=None, destination_name=None, mapping=None, local_vars_configuration=None): # noqa: E501 """AttachmentsList - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() self.local_vars_configuration = local_vars_configuration self._id = None self._source_name = None self._destination_name = None self._mapping = None self.discriminator = None if id is not None: self.id = id if source_name is not None: self.source_name = source_name if destination_name is not None: self.destination_name = destination_name if mapping is not None: self.mapping = mapping @property def id(self): """Gets the id of this AttachmentsList. # noqa: E501 :return: The id of this AttachmentsList. # noqa: E501 :rtype: str """ return self._id @id.setter def id(self, id): """Sets the id of this AttachmentsList. :param id: The id of this AttachmentsList. # noqa: E501 :type: str """ self._id = id @property def source_name(self): """Gets the source_name of this AttachmentsList. # noqa: E501 :return: The source_name of this AttachmentsList. # noqa: E501 :rtype: str """ return self._source_name @source_name.setter def source_name(self, source_name): """Sets the source_name of this AttachmentsList. :param source_name: The source_name of this AttachmentsList. # noqa: E501 :type: str """ self._source_name = source_name @property def destination_name(self): """Gets the destination_name of this AttachmentsList. # noqa: E501 :return: The destination_name of this AttachmentsList. # noqa: E501 :rtype: str """ return self._destination_name @destination_name.setter def destination_name(self, destination_name): """Sets the destination_name of this AttachmentsList. :param destination_name: The destination_name of this AttachmentsList. # noqa: E501 :type: str """ self._destination_name = destination_name @property def mapping(self): """Gets the mapping of this AttachmentsList. # noqa: E501 :return: The mapping of this AttachmentsList. # noqa: E501 :rtype: list[AttachmentFieldsList] """ return self._mapping @mapping.setter def mapping(self, mapping): """Sets the mapping of this AttachmentsList. :param mapping: The mapping of this AttachmentsList. # noqa: E501 :type: list[AttachmentFieldsList] """ self._mapping = mapping def to_dict(self): """Returns the model properties as a dict""" result = {} for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) if isinstance(value, list): result[attr] = list(map( lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): result[attr] = dict(map( lambda item: (item[0], item[1].to_dict()) if hasattr(item[1], "to_dict") else item, value.items() )) else: result[attr] = value return result def to_str(self): """Returns the string representation of the model""" return pprint.pformat(self.to_dict()) def __repr__(self): """For `print` and `pprint`""" return self.to_str() def __eq__(self, other): """Returns true if both objects are equal""" if not isinstance(other, AttachmentsList): return False return self.to_dict() == other.to_dict() def __ne__(self, other): """Returns true if both objects are not equal""" if not isinstance(other, AttachmentsList): return True return self.to_dict() != other.to_dict()
[ "six.iteritems", "xenia_python_client_library.configuration.Configuration" ]
[((4145, 4178), 'six.iteritems', 'six.iteritems', (['self.openapi_types'], {}), '(self.openapi_types)\n', (4158, 4178), False, 'import six\n'), ((1417, 1432), 'xenia_python_client_library.configuration.Configuration', 'Configuration', ([], {}), '()\n', (1430, 1432), False, 'from xenia_python_client_library.configuration import Configuration\n')]
################################################################################ # Create a Registration with the UI for a Role. # Each module's aushadha.py is screened for this # # Each Class is registered for a Role in UI # These can be used to generate Role based UI elements later. # # As of now string base role assignement is done. # This can be later extended to class based role ################################################################################ from .models import Chapter, Section,Diagnosis from AuShadha.apps.ui.ui import ui as UI UI.register('RegistryApp',Chapter ) UI.register('DiseaseCodes',Chapter) UI.register('ReferenceApp',Chapter)
[ "AuShadha.apps.ui.ui.ui.register" ]
[((564, 599), 'AuShadha.apps.ui.ui.ui.register', 'UI.register', (['"""RegistryApp"""', 'Chapter'], {}), "('RegistryApp', Chapter)\n", (575, 599), True, 'from AuShadha.apps.ui.ui import ui as UI\n'), ((600, 636), 'AuShadha.apps.ui.ui.ui.register', 'UI.register', (['"""DiseaseCodes"""', 'Chapter'], {}), "('DiseaseCodes', Chapter)\n", (611, 636), True, 'from AuShadha.apps.ui.ui import ui as UI\n'), ((636, 672), 'AuShadha.apps.ui.ui.ui.register', 'UI.register', (['"""ReferenceApp"""', 'Chapter'], {}), "('ReferenceApp', Chapter)\n", (647, 672), True, 'from AuShadha.apps.ui.ui import ui as UI\n')]
from tensorflow.keras import Sequential from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout import tensorflow.keras as keras import os import cv2 import numpy as np from sklearn.model_selection import train_test_split def data_prep(path, img_rows, img_cols, color): """ A function to preprocess the input data for a CNN. The images are resized, normalised to have pixel values between 0-1, converted into greyscale if required and put into a numpy array. Each class label is turned into a one hot pixel array and added to an ordered numpy array such that the order for the labels is the same as the images. The data is shuffled to make sure each batch is representative of the overall data during training which will reduce overfitting to each batch. This function requires that the images for each class are in a seperate directory. param: - path, a string of the path to the directory containing the images - img_rows, an integer for the number of rows the resized image should have - img_cols, an integer for the number of columns the resized image should have - color, a boolean that is set to true if the image should be in RGB colour space or false for greyscale return: - images, a numpy array of images with pixel values normalised to be between 0 and 1. numpy array dimensions are [number of images, number of rows, number of columns, number of chanels] - labels, a numpy array of labels associated with each image (labels are a one hot pixel numpy array [1, 0, 0, ...] or [0, 1, 0, ...], etc) """ images = [] labels = [] for image_class in os.listdir(path): print('image_class =', image_class) path_to_class_directory = os.path.join(path, image_class) for img_name in os.listdir(path_to_class_directory): true_path = os.path.join(path_to_class_directory, img_name) if color: images.append(cv2.imread(true_path, 1)/255.0) else: images.append(cv2.imread(true_path, 0)/255.0) # greyscale labels.append(os.listdir(path).index(image_class)) data = list(zip(images, labels)) np.random.shuffle(data) images, labels = zip(*data) images = [cv2.resize(img, (img_rows, img_cols), cv2.INTER_AREA) for img in images] # resize images to all be the same if color: images = np.array(images).reshape(len(images), img_rows, img_cols, 3) else: images = np.array(images).reshape(len(images), img_rows, img_cols, 1) labels = keras.utils.to_categorical(labels, num_classes=len(os.listdir(path))) return images, labels def build_CNN(img_rows, img_cols, color=False): model = Sequential() if color: model.add(Conv2D(20, kernel_size=(3, 3), strides=1, activation='relu', input_shape=(img_rows, img_cols, 3))) else: model.add(Conv2D(20, kernel_size=(3, 3), strides=1, activation='relu', input_shape=(img_rows, img_cols, 1))) model.add(Conv2D(20, kernel_size=(3, 3), strides=1, activation='relu')) model.add(Flatten()) #model.add(Dropout(0.25)) model.add(Dense(128, activation='relu')) model.add(Dense(num_classes, activation='softmax')) model.compile(loss=keras.losses.categorical_crossentropy, optimizer='adam', metrics=['accuracy']) return model def decode_labels(coded, class_names): """ A funtion to get the name of the class by decoding a one hot pixel array. Uses a list comprehension and boolean indexing. The list comprehension returns the index of the variable with the highest value in each one hot pixel array. That list is then used for boolean indexing with a numpy array to get a list of class_names for each label in coded. Param: - coded, a numpy array of coded labels - class_names, a list of the class_names in the same order they were coded (alphabetical) Return: - numpy array of class names for each label in coded """ return np.array(class_names)[[np.argmax(example) for example in coded]] def calc_accuracy(pred, real): """ A function to calculate the accuracy of a CNN when given a list of predicted classes and a list of the real classes Param: - pred, a numpy array of predicted classes - real, a numpy array of the real classes Return: - Accuracy as a decimal """ return sum(pred==real) / len(pred) if __name__ == '__main__': path = 'data' img_rows = 150 img_cols = 150 is_color = True model_filename = 'flare_cnn' print('\nloading training data\n') num_classes = len(os.listdir(path)) x, y = data_prep(path, img_rows, img_cols, color=is_color) x_train, x_test, y_train, y_test = train_test_split(x, y) print('\nbuilding model\n') cnn = build_CNN(img_rows, img_cols, color=is_color) print('\ntraining model\n') cnn.fit(x_train, y_train, batch_size=50, epochs=1, validation_split=0.2) print('\nsaving model\n') if is_color: model_filename = model_filename + '_RGB' + '.h5' else: model_filename = model_filename + '_grey' + '.h5' cnn.save(model_filename) print('\nsaved model to file {}\n'.format(model_filename)) print('\nloading model\n') loaded_cnn = keras.models.load_model(model_filename) print('\ngenerating predictions\n') predictions = loaded_cnn.predict(x_test) dec_preds = decode_labels(predictions, os.listdir(path)) dec_ytest = decode_labels(y_test, os.listdir(path)) # F1 score would probably be a better metric due to skew of training expample (num B > num C) print('\naccuracy =', calc_accuracy(dec_preds, dec_ytest))
[ "os.listdir", "tensorflow.keras.layers.Conv2D", "tensorflow.keras.Sequential", "sklearn.model_selection.train_test_split", "os.path.join", "numpy.argmax", "numpy.array", "tensorflow.keras.layers.Dense", "tensorflow.keras.models.load_model", "tensorflow.keras.layers.Flatten", "cv2.resize", "cv2...
[((1704, 1720), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (1714, 1720), False, 'import os\n'), ((2245, 2268), 'numpy.random.shuffle', 'np.random.shuffle', (['data'], {}), '(data)\n', (2262, 2268), True, 'import numpy as np\n'), ((2773, 2785), 'tensorflow.keras.Sequential', 'Sequential', ([], {}), '()\n', (2783, 2785), False, 'from tensorflow.keras import Sequential\n'), ((4835, 4857), 'sklearn.model_selection.train_test_split', 'train_test_split', (['x', 'y'], {}), '(x, y)\n', (4851, 4857), False, 'from sklearn.model_selection import train_test_split\n'), ((5379, 5418), 'tensorflow.keras.models.load_model', 'keras.models.load_model', (['model_filename'], {}), '(model_filename)\n', (5402, 5418), True, 'import tensorflow.keras as keras\n'), ((1800, 1831), 'os.path.join', 'os.path.join', (['path', 'image_class'], {}), '(path, image_class)\n', (1812, 1831), False, 'import os\n'), ((1856, 1891), 'os.listdir', 'os.listdir', (['path_to_class_directory'], {}), '(path_to_class_directory)\n', (1866, 1891), False, 'import os\n'), ((2315, 2368), 'cv2.resize', 'cv2.resize', (['img', '(img_rows, img_cols)', 'cv2.INTER_AREA'], {}), '(img, (img_rows, img_cols), cv2.INTER_AREA)\n', (2325, 2368), False, 'import cv2\n'), ((3058, 3118), 'tensorflow.keras.layers.Conv2D', 'Conv2D', (['(20)'], {'kernel_size': '(3, 3)', 'strides': '(1)', 'activation': '"""relu"""'}), "(20, kernel_size=(3, 3), strides=1, activation='relu')\n", (3064, 3118), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((3134, 3143), 'tensorflow.keras.layers.Flatten', 'Flatten', ([], {}), '()\n', (3141, 3143), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((3189, 3218), 'tensorflow.keras.layers.Dense', 'Dense', (['(128)'], {'activation': '"""relu"""'}), "(128, activation='relu')\n", (3194, 3218), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((3234, 3274), 'tensorflow.keras.layers.Dense', 'Dense', (['num_classes'], {'activation': '"""softmax"""'}), "(num_classes, activation='softmax')\n", (3239, 3274), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((4071, 4092), 'numpy.array', 'np.array', (['class_names'], {}), '(class_names)\n', (4079, 4092), True, 'import numpy as np\n'), ((4715, 4731), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (4725, 4731), False, 'import os\n'), ((5548, 5564), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (5558, 5564), False, 'import os\n'), ((5604, 5620), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (5614, 5620), False, 'import os\n'), ((1917, 1964), 'os.path.join', 'os.path.join', (['path_to_class_directory', 'img_name'], {}), '(path_to_class_directory, img_name)\n', (1929, 1964), False, 'import os\n'), ((2818, 2920), 'tensorflow.keras.layers.Conv2D', 'Conv2D', (['(20)'], {'kernel_size': '(3, 3)', 'strides': '(1)', 'activation': '"""relu"""', 'input_shape': '(img_rows, img_cols, 3)'}), "(20, kernel_size=(3, 3), strides=1, activation='relu', input_shape=(\n img_rows, img_cols, 3))\n", (2824, 2920), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((2945, 3047), 'tensorflow.keras.layers.Conv2D', 'Conv2D', (['(20)'], {'kernel_size': '(3, 3)', 'strides': '(1)', 'activation': '"""relu"""', 'input_shape': '(img_rows, img_cols, 1)'}), "(20, kernel_size=(3, 3), strides=1, activation='relu', input_shape=(\n img_rows, img_cols, 1))\n", (2951, 3047), False, 'from tensorflow.keras.layers import Conv2D, Flatten, Dense, Dropout\n'), ((4094, 4112), 'numpy.argmax', 'np.argmax', (['example'], {}), '(example)\n', (4103, 4112), True, 'import numpy as np\n'), ((2454, 2470), 'numpy.array', 'np.array', (['images'], {}), '(images)\n', (2462, 2470), True, 'import numpy as np\n'), ((2542, 2558), 'numpy.array', 'np.array', (['images'], {}), '(images)\n', (2550, 2558), True, 'import numpy as np\n'), ((2667, 2683), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (2677, 2683), False, 'import os\n'), ((2017, 2041), 'cv2.imread', 'cv2.imread', (['true_path', '(1)'], {}), '(true_path, 1)\n', (2027, 2041), False, 'import cv2\n'), ((2097, 2121), 'cv2.imread', 'cv2.imread', (['true_path', '(0)'], {}), '(true_path, 0)\n', (2107, 2121), False, 'import cv2\n'), ((2167, 2183), 'os.listdir', 'os.listdir', (['path'], {}), '(path)\n', (2177, 2183), False, 'import os\n')]
""" Oracle library """ import lib_common from lib_properties import pc def Graphic_colorbg(): return "#CC99FF" def EntityOntology(): return ( ["Db", "Schema", "Library"], ) # Ambiguity with tables, oracle or normal users. def MakeUri(dbName,schemaName,libraryName): return lib_common.gUriGen.UriMakeFromDict("oracle/library", { "Db" : dbName, "Schema" : schemaName, "Library" : libraryName } ) def AddInfo(grph,node,entity_ids_arr): # TODO: SPECIAL. Imported here to avoid circular inclusions, see oracle/package_body/__init__.py from sources_types.oracle import schema as oracle_schema argDb = entity_ids_arr[0] argSchema = entity_ids_arr[1] node_oraschema = oracle_schema.MakeUri( argDb, argSchema ) grph.add( ( node_oraschema, pc.property_oracle_library, node ) ) def EntityName(entity_ids_arr): return entity_ids_arr[0] + "." + entity_ids_arr[1] + "." + entity_ids_arr[2]
[ "sources_types.oracle.schema.MakeUri", "lib_common.gUriGen.UriMakeFromDict" ]
[((281, 399), 'lib_common.gUriGen.UriMakeFromDict', 'lib_common.gUriGen.UriMakeFromDict', (['"""oracle/library"""', "{'Db': dbName, 'Schema': schemaName, 'Library': libraryName}"], {}), "('oracle/library', {'Db': dbName,\n 'Schema': schemaName, 'Library': libraryName})\n", (315, 399), False, 'import lib_common\n'), ((676, 715), 'sources_types.oracle.schema.MakeUri', 'oracle_schema.MakeUri', (['argDb', 'argSchema'], {}), '(argDb, argSchema)\n', (697, 715), True, 'from sources_types.oracle import schema as oracle_schema\n')]
from myhdl import Signal, intbv, block, always_comb, ConcatSignal import myhdl from collections import OrderedDict import keyword def _is_valid_name(ident: str) -> bool: '''Determine if ident is a valid register or bitfield name. ''' if not isinstance(ident, str): raise TypeError("expected str, but got {!r}".format(type(ident))) if not ident.isidentifier(): return False if keyword.iskeyword(ident): return False return True @block def assign_bitfield_from_register(reg, bitfield, offset): if isinstance(bitfield.val, bool): @always_comb def assignment(): bitfield.next = reg[offset] else: start = offset stop = offset + len(bitfield) @always_comb def assignment(): bitfield.next = reg[stop:start] return assignment class Bitfields: def __eq__(self, other): if not ((self._bitfields_config == other._bitfields_config) and (self._initial_values == other._initial_values) and (self._register_width == other._register_width) and (self._reg_type == other._reg_type)): return False else: # The values also need to be the same for bf_name in self._bitfields_config: if getattr(self, bf_name) != getattr(other, bf_name): return False if self.register != other.register: return False return True def __init__( self, register_width, register_type, bitfields_config, initial_values=None): ''' Creates a MyHDL interface representing a series of bitfields. `register_width` is the width of the register that the bitfields sit on top of. `register_type` is one of `axi_read_write`, `axi_read_only` or `axi_write_only`. `initial_values` is an optional lookup for each bitfield when the register type is `axis_read_write`. If a bitfield has an initial value set, then, assuming the register_type is `axis_read_write`, the bitfield will be set to the initial value. If the register type is not `axis_read_write`, then a ValueError will be raised if this argument is not `None`. `bitfields_config` is a dictionary that provides the configuration for each bitfield on a register. The keys are the names of the bitfields and each key should point to a configuration dict. Each configution should have the `type` key, which should have data which is one of: - `uint` - `bool` - `const-uint` - `const-bool` In addition, it should also have keys which depend on the type, as follows: - `uint`: - `length` giving the length in bits of the uint - `offset` giving the offset of the bitfield. - `bool`: - `offset` giving the offset of the boolean value. - `const-uint`: - `length` giving the length in bits of the uint - `offset` giving the offset of the bitfield. - `const-value` giving the value of the constant. - `const-bool`: - `offset` giving the offset of the boolean balue. - `const-value` giving the value of the constant. Extra keys are ignored. Other constraints are enforced and will cause an error: - All bitfields must fit within the register width. - A `const-uint` and `const-bool` can only be set on a read-only register. - Overlapping bitfields are invalid. - No bitfield can be called 'register'. This is reserved for the full register representation. - Only read-write registers can have an initial value. An example bitfield entry might look something like: {'foo':{'type': 'uint', 'length': 6, 'offset': 0}, 'bar': {'type': 'bool', 'offset': 6}, 'baz': {'type': 'const-uint', 'length': 5, 'offset': 7, 'const-value': 15}} ''' if len(bitfields_config) == 0: raise ValueError('bitfields_config cannot be empty') if register_type not in ( 'axi_read_write', 'axi_read_only', 'axi_write_only'): raise ValueError( 'The register type must be one of `axi_read_write`, ' '`axi_read_only` or `axi_write_only`') if initial_values != None and register_type != 'axi_read_write': raise ValueError( '`initial_values` must be `None` if the register type ' 'is not `axi_read_write`') if initial_values is None: initial_values = {} # We always create a register attribute register_initial_val = 0 for bitfield in bitfields_config: offset = bitfields_config[bitfield]['offset'] try: init_val = initial_values[bitfield] except KeyError: init_val = 0 register_initial_val += init_val << offset self._reg_type = register_type self._register_width = register_width self._bitfields_config = bitfields_config self._initial_values = initial_values bitfield_masks = {} bitfield_starts = {} bitfield_stops = {} self._constant_vals = {} for bitfield in bitfields_config: if not _is_valid_name(bitfield): raise ValueError( 'Bitfield names must be valid python identifiers: ' '{}'.format(bitfield)) if bitfield[0] == '_': raise ValueError( 'Bitfield names cannot begin with an underscore: ' '{}'.format(bitfield)) if bitfield == 'register': raise ValueError('Bitfields cannot be named `register`.') if bitfields_config[bitfield]['type'] == 'uint': length = bitfields_config[bitfield]['length'] offset = bitfields_config[bitfield]['offset'] bf_signal = Signal(intbv(0)[length:]) mask = (2**length - 1) << offset bitfield_starts[offset] = bitfield bitfield_stops[bitfield] = offset + length elif bitfields_config[bitfield]['type'] == 'bool': offset = bitfields_config[bitfield]['offset'] bf_signal = Signal(False) mask = 1 << offset bitfield_starts[offset] = bitfield bitfield_stops[bitfield] = offset + 1 elif bitfields_config[bitfield]['type'] == 'const-uint': if register_type != 'axi_read_only': raise ValueError( 'The bitfield `{}` is of type `const-uint` which ' 'requires the register is read-only, but the register ' 'has been configured to be `{}`'.format( bitfield, register_type)) length = bitfields_config[bitfield]['length'] offset = bitfields_config[bitfield]['offset'] const_val = int(bitfields_config[bitfield]['const-value']) if (const_val >= 2**length or const_val < 0): raise ValueError( 'The bitfield const value, {}, is invalid for ' 'bitfield {}'.format(const_val, bitfield)) bf_signal = intbv(const_val)[length:] self._constant_vals[bitfield] = const_val # We also set the initial value for constants register_initial_val += const_val << offset mask = (2**length - 1) << offset bitfield_starts[offset] = bitfield bitfield_stops[bitfield] = offset + length elif bitfields_config[bitfield]['type'] == 'const-bool': if register_type != 'axi_read_only': raise ValueError( 'The bitfield `{}` is of type `const-bool` which ' 'requires the register is read-only, but the register ' 'has been configured to be `{}`'.format( bitfield, register_type)) offset = bitfields_config[bitfield]['offset'] const_val = bitfields_config[bitfield]['const-value'] if not isinstance(const_val, bool): raise ValueError( 'The bitfield const value, {}, is invalid for ' 'bitfield {}'.format(const_val, bitfield)) bf_signal = const_val self._constant_vals[bitfield] = const_val # We also set the initial value for constants register_initial_val += const_val << offset mask = 1 << offset bitfield_starts[offset] = bitfield bitfield_stops[bitfield] = offset + 1 else: raise ValueError('A bitfield type must be one of `uint`, ' '`bool`, `const-uint` or `const-bool`: ' '{}'.format(bitfield)) if mask >= 2**register_width: raise ValueError( 'The bitfield `{}` is out of range for a register of ' 'width {}'.format(bitfield, register_width)) # Check the bitfield doesn't overlap with any others for other_bf in bitfield_masks: if (bitfield_masks[other_bf] & mask) != 0: raise ValueError( 'Bitfield `{}` overlaps with bitfield `{}`'.format( bitfield, other_bf)) bitfield_masks[bitfield] = mask setattr(self, bitfield, bf_signal) # We now need to construct the packed version of the bitfields, # including padding. rev_concat_list = [] bitfield_starts_list = list(bitfield_starts.keys()) bitfield_starts_list.sort() if bitfield_starts_list[0] != 0: padding = intbv(0)[bitfield_starts_list[0]:] rev_concat_list.append(padding) for i, start in enumerate(bitfield_starts_list): bitfield = bitfield_starts[start] rev_concat_list.append(getattr(self, bitfield)) try: next_start = bitfield_starts_list[i + 1] # The higher up checks make sure padding_len should never be # negative. padding_len = next_start - bitfield_stops[bitfield] if padding_len > 0: padding = intbv(0)[padding_len:] rev_concat_list.append(padding) except IndexError: if bitfield_stops[bitfield] < register_width: padding = intbv(0)[ register_width - bitfield_stops[bitfield]:] rev_concat_list.append(padding) self.register = Signal(intbv(register_initial_val)[register_width:]) self._concat_list = rev_concat_list[::-1] self._bitfield_starts = bitfield_starts self._bitfield_masks = bitfield_masks @block def bitfield_connector(self): if self._reg_type in ('axi_read_write', 'axi_write_only'): instances = [] for bitfield_start in self._bitfield_starts: bitfield = getattr(self, self._bitfield_starts[bitfield_start]) instances.append( assign_bitfield_from_register( self.register, bitfield, bitfield_start)) return instances elif self._reg_type in ('axi_read_only'): if len(self._concat_list) == 1: # This is a hack to allow a concat signal to work in # all cases. An alternative would be to special case single # signals, but that doesn't work well with constants, which # themselves would require a special case, and some hackery to # have the constant read (and requiring initial_values to be # turned on). keep = Signal(True) keep.driven = True reg_signal = ConcatSignal(keep, self._concat_list[0]) else: reg_signal = ConcatSignal(*self._concat_list) @always_comb def assign_register(): self.register.next = reg_signal[self._register_width:] return assign_register class RegisterSet(object): pass class Registers(object): ''' A general purpose register definition. ''' @property def register_types(self): return self._register_types def __eq__(self, other): return (self._bitfields == other._bitfields and self._register_types == other._register_types and self._register_width == other._register_width) def __init__( self, register_list, register_types=None, register_width=32, initial_values=None, bitfields=None): ''' Constructs a MyHDL interface that encapsulates each register name given in `register_list`. The order of the registers in the list is kept. If `register_types` is set, it should be a dictionary like object that provides data of the form `axi_read_write`, `axi_read_only` or `axi_write_only` for the register name given by its key. If a register name is missing from `register_types`, then the register type defaults to `axi_read_write`. If `register_types` is `None`, then all the registers are `axi_read_write`. `register_width` gives the width in bits of each register that is created, defaulting to 32. `initial_values` is an optional dictionary that sets the initial value of a read-write register. A `ValueError` will be raised if an initial value is set for a non read-write register. The default is for the initial values to be zero. If a register has bitfields set (see below), then the dictionary entry should itself be a dictionary to the initial values for each bitfield. `bitfields` is an optional dictionary argument in which each register that is included in the dictionary is populated as a Bitfield interface rather than a signal. Each data in bitfields is passed directly as the bitfields_config argument to the initialisation of a `Bitfield` class. See the documentation for that class to see what form the data should be. ''' for name in register_list: if not _is_valid_name(name): raise ValueError('Invalid register name: {}'.format(name)) if register_types is None: # Create a register types dictionary so that the system can handle # an empty register types argument. register_types = {} self._register_width = register_width # Create an ordered dictionary self._register_types = OrderedDict() for each in register_types: if each not in register_list: # Check that the register types have a corresponding register # in the register list. If not error. raise ValueError( 'Invalid register in register_types: %s' % each) if initial_values is None: initial_values = {} if bitfields is None: bitfields = {} for initial_val_key in initial_values: if (register_types.get(initial_val_key, 'axi_read_write') != 'axi_read_write'): raise ValueError( 'Only read-write registers can take initial values: %s' % initial_val_key + ': ' + str(register_types[initial_val_key])) for name in register_list: register_type = register_types.get(name, 'axi_read_write') if name in bitfields: initial_vals = initial_values.get(name, None) setattr( self, name, Bitfields(register_width, register_type, bitfields[name], initial_values=initial_vals)) else: # Create the registers setattr(self, name, Signal( intbv(initial_values.get(name, 0))[register_width:])) # Populate the ordered dictionary with the appropriate # register types, defaulting to 'axi_read_write' self._register_types[name] = ( register_types.get(name, 'axi_read_write')) self._bitfields = bitfields
[ "collections.OrderedDict", "myhdl.Signal", "keyword.iskeyword", "myhdl.intbv", "myhdl.ConcatSignal" ]
[((417, 441), 'keyword.iskeyword', 'keyword.iskeyword', (['ident'], {}), '(ident)\n', (434, 441), False, 'import keyword\n'), ((15521, 15534), 'collections.OrderedDict', 'OrderedDict', ([], {}), '()\n', (15532, 15534), False, 'from collections import OrderedDict\n'), ((10488, 10496), 'myhdl.intbv', 'intbv', (['(0)'], {}), '(0)\n', (10493, 10496), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((11408, 11435), 'myhdl.intbv', 'intbv', (['register_initial_val'], {}), '(register_initial_val)\n', (11413, 11435), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((6743, 6756), 'myhdl.Signal', 'Signal', (['(False)'], {}), '(False)\n', (6749, 6756), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((12586, 12598), 'myhdl.Signal', 'Signal', (['(True)'], {}), '(True)\n', (12592, 12598), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((12664, 12704), 'myhdl.ConcatSignal', 'ConcatSignal', (['keep', 'self._concat_list[0]'], {}), '(keep, self._concat_list[0])\n', (12676, 12704), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((12753, 12785), 'myhdl.ConcatSignal', 'ConcatSignal', (['*self._concat_list'], {}), '(*self._concat_list)\n', (12765, 12785), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((6408, 6416), 'myhdl.intbv', 'intbv', (['(0)'], {}), '(0)\n', (6413, 6416), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((11047, 11055), 'myhdl.intbv', 'intbv', (['(0)'], {}), '(0)\n', (11052, 11055), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((7803, 7819), 'myhdl.intbv', 'intbv', (['const_val'], {}), '(const_val)\n', (7808, 7819), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n'), ((11246, 11254), 'myhdl.intbv', 'intbv', (['(0)'], {}), '(0)\n', (11251, 11254), False, 'from myhdl import Signal, intbv, block, always_comb, ConcatSignal\n')]
# Copyright (c) 2014 Simplistix Ltd # See license.txt for license details. from decimal import Decimal from testfixtures import RoundComparison as R, compare, ShouldRaise from unittest import TestCase from ..compat import PY2, PY3 class Tests(TestCase): def test_equal_yes_rhs(self): self.assertTrue(0.123457 == R(0.123456, 5)) def test_equal_yes_lhs(self): self.assertTrue(R(0.123456, 5) == 0.123457) def test_equal_no_rhs(self): self.assertFalse(0.123453 == R(0.123456, 5)) def test_equal_no_lhs(self): self.assertFalse(R(0.123456, 5) == 0.123453) def test_not_equal_yes_rhs(self): self.assertFalse(0.123457 != R(0.123456, 5)) def test_not_equal_yes_lhs(self): self.assertFalse(R(0.123456, 5) != 0.123457) def test_not_equal_no_rhs(self): self.assertTrue(0.123453 != R(0.123456, 5)) def test_not_equal_no_lhs(self): self.assertTrue(R(0.123456, 5) != 0.123453) def test_equal_in_sequence_rhs(self): self.assertEqual((1, 2, 0.123457), (1, 2, R(0.123456, 5))) def test_equal_in_sequence_lhs(self): self.assertEqual((1, 2, R(0.123456, 5)), (1, 2, 0.123457)) def test_not_equal_in_sequence_rhs(self): self.assertNotEqual((1, 2, 0.1236), (1, 2, R(0.123456, 5))) def test_not_equal_in_sequence_lhs(self): self.assertNotEqual((1, 2, R(0.123456, 5)), (1, 2, 0.1236)) def test_not_numeric_rhs(self): with ShouldRaise(TypeError): 'abc' == R(0.123456, 5) def test_not_numeric_lhs(self): with ShouldRaise(TypeError): R(0.123456, 5) == 'abc' def test_repr(self): compare('<R:0.12346 to 5 digits>', repr(R(0.123456, 5))) def test_str(self): compare('<R:0.12346 to 5 digits>', repr(R(0.123456, 5))) def test_str_negative(self): if PY3: expected = '<R:123500 to -2 digits>' else: expected = '<R:123500.0 to -2 digits>' compare(expected, repr(R(123456, -2))) TYPE_ERROR_DECIMAL = TypeError( "Cannot compare <R:0.12346 to 5 digits> with <class 'decimal.Decimal'>" ) def test_equal_yes_decimal_to_float_rhs(self): with ShouldRaise(self.TYPE_ERROR_DECIMAL, unless=PY2): self.assertTrue(Decimal("0.123457") == R(0.123456, 5)) def test_equal_yes_decimal_to_float_lhs(self): with ShouldRaise(self.TYPE_ERROR_DECIMAL, unless=PY2): self.assertTrue(R(0.123456, 5) == Decimal("0.123457")) def test_equal_no_decimal_to_float_rhs(self): with ShouldRaise(self.TYPE_ERROR_DECIMAL, unless=PY2): self.assertFalse(Decimal("0.123453") == R(0.123456, 5)) def test_equal_no_decimal_to_float_lhs(self): with ShouldRaise(self.TYPE_ERROR_DECIMAL, unless=PY2): self.assertFalse(R(0.123456, 5) == Decimal("0.123453")) TYPE_ERROR_FLOAT = TypeError( "Cannot compare <R:0.12346 to 5 digits> with <class 'float'>" ) def test_equal_yes_float_to_decimal_rhs(self): with ShouldRaise(self.TYPE_ERROR_FLOAT, unless=PY2): self.assertTrue(0.123457 == R(Decimal("0.123456"), 5)) def test_equal_yes_float_to_decimal_lhs(self): with ShouldRaise(self.TYPE_ERROR_FLOAT, unless=PY2): self.assertTrue(R(Decimal("0.123456"), 5) == 0.123457) def test_equal_no_float_to_decimal_rhs(self): with ShouldRaise(self.TYPE_ERROR_FLOAT, unless=PY2): self.assertFalse(0.123453 == R(Decimal("0.123456"), 5)) def test_equal_no_float_to_decimal_lhs(self): with ShouldRaise(self.TYPE_ERROR_FLOAT, unless=PY2): self.assertFalse(R(Decimal("0.123456"), 5) == 0.123453) def test_integer_float(self): with ShouldRaise(TypeError, unless=PY2): 1 == R(1.000001, 5) def test_float_integer(self): with ShouldRaise(TypeError, unless=PY2): R(1.000001, 5) == 1 def test_equal_yes_integer_other_rhs(self): self.assertTrue(10 == R(11, -1)) def test_equal_yes_integer_lhs(self): self.assertTrue(R(11, -1) == 10) def test_equal_no_integer_rhs(self): self.assertFalse(10 == R(16, -1)) def test_equal_no_integer_lhs(self): self.assertFalse(R(16, -1) == 10) def test_equal_integer_zero_precision(self): self.assertTrue(1 == R(1, 0)) def test_equal_yes_negative_precision(self): self.assertTrue(149.123 == R(101.123, -2)) def test_equal_no_negative_precision(self): self.assertFalse(149.123 == R(150.001, -2)) def test_decimal_yes_rhs(self): self.assertTrue(Decimal('0.123457') == R(Decimal('0.123456'), 5)) def test_decimal_yes_lhs(self): self.assertTrue(R(Decimal('0.123456'), 5) == Decimal('0.123457')) def test_decimal_no_rhs(self): self.assertFalse(Decimal('0.123453') == R(Decimal('0.123456'), 5)) def test_decimal_no_lhs(self): self.assertFalse(R(Decimal('0.123456'), 5) == Decimal('0.123453'))
[ "decimal.Decimal", "testfixtures.ShouldRaise", "testfixtures.RoundComparison" ]
[((1576, 1598), 'testfixtures.ShouldRaise', 'ShouldRaise', (['TypeError'], {}), '(TypeError)\n', (1587, 1598), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1686, 1708), 'testfixtures.ShouldRaise', 'ShouldRaise', (['TypeError'], {}), '(TypeError)\n', (1697, 1708), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2362, 2410), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_DECIMAL'], {'unless': 'PY2'}), '(self.TYPE_ERROR_DECIMAL, unless=PY2)\n', (2373, 2410), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2544, 2592), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_DECIMAL'], {'unless': 'PY2'}), '(self.TYPE_ERROR_DECIMAL, unless=PY2)\n', (2555, 2592), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2725, 2773), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_DECIMAL'], {'unless': 'PY2'}), '(self.TYPE_ERROR_DECIMAL, unless=PY2)\n', (2736, 2773), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2907, 2955), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_DECIMAL'], {'unless': 'PY2'}), '(self.TYPE_ERROR_DECIMAL, unless=PY2)\n', (2918, 2955), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3205, 3251), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_FLOAT'], {'unless': 'PY2'}), '(self.TYPE_ERROR_FLOAT, unless=PY2)\n', (3216, 3251), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3385, 3431), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_FLOAT'], {'unless': 'PY2'}), '(self.TYPE_ERROR_FLOAT, unless=PY2)\n', (3396, 3431), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3564, 3610), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_FLOAT'], {'unless': 'PY2'}), '(self.TYPE_ERROR_FLOAT, unless=PY2)\n', (3575, 3610), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3744, 3790), 'testfixtures.ShouldRaise', 'ShouldRaise', (['self.TYPE_ERROR_FLOAT'], {'unless': 'PY2'}), '(self.TYPE_ERROR_FLOAT, unless=PY2)\n', (3755, 3790), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3908, 3942), 'testfixtures.ShouldRaise', 'ShouldRaise', (['TypeError'], {'unless': 'PY2'}), '(TypeError, unless=PY2)\n', (3919, 3942), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4024, 4058), 'testfixtures.ShouldRaise', 'ShouldRaise', (['TypeError'], {'unless': 'PY2'}), '(TypeError, unless=PY2)\n', (4035, 4058), False, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((329, 343), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (330, 343), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((404, 418), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (405, 418), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((503, 517), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (504, 517), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((578, 592), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (579, 592), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((682, 696), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (683, 696), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((762, 776), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (763, 776), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((864, 878), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (865, 878), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((942, 956), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (943, 956), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1088, 1102), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1089, 1102), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1180, 1194), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1181, 1194), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1366, 1380), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1367, 1380), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1465, 1479), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1466, 1479), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1621, 1635), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1622, 1635), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1722, 1736), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1723, 1736), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1836, 1850), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1837, 1850), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((1942, 1956), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (1943, 1956), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2154, 2167), 'testfixtures.RoundComparison', 'R', (['(123456)', '(-2)'], {}), '(123456, -2)\n', (2155, 2167), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3961, 3975), 'testfixtures.RoundComparison', 'R', (['(1.000001)', '(5)'], {}), '(1.000001, 5)\n', (3962, 3975), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4072, 4086), 'testfixtures.RoundComparison', 'R', (['(1.000001)', '(5)'], {}), '(1.000001, 5)\n', (4073, 4086), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4171, 4180), 'testfixtures.RoundComparison', 'R', (['(11)', '(-1)'], {}), '(11, -1)\n', (4172, 4180), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4249, 4258), 'testfixtures.RoundComparison', 'R', (['(11)', '(-1)'], {}), '(11, -1)\n', (4250, 4258), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4339, 4348), 'testfixtures.RoundComparison', 'R', (['(16)', '(-1)'], {}), '(16, -1)\n', (4340, 4348), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4417, 4426), 'testfixtures.RoundComparison', 'R', (['(16)', '(-1)'], {}), '(16, -1)\n', (4418, 4426), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4513, 4520), 'testfixtures.RoundComparison', 'R', (['(1)', '(0)'], {}), '(1, 0)\n', (4514, 4520), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4607, 4621), 'testfixtures.RoundComparison', 'R', (['(101.123)', '(-2)'], {}), '(101.123, -2)\n', (4608, 4621), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4708, 4722), 'testfixtures.RoundComparison', 'R', (['(150.001)', '(-2)'], {}), '(150.001, -2)\n', (4709, 4722), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((4785, 4804), 'decimal.Decimal', 'Decimal', (['"""0.123457"""'], {}), "('0.123457')\n", (4792, 4804), False, 'from decimal import Decimal\n'), ((4925, 4944), 'decimal.Decimal', 'Decimal', (['"""0.123457"""'], {}), "('0.123457')\n", (4932, 4944), False, 'from decimal import Decimal\n'), ((5007, 5026), 'decimal.Decimal', 'Decimal', (['"""0.123453"""'], {}), "('0.123453')\n", (5014, 5026), False, 'from decimal import Decimal\n'), ((5147, 5166), 'decimal.Decimal', 'Decimal', (['"""0.123453"""'], {}), "('0.123453')\n", (5154, 5166), False, 'from decimal import Decimal\n'), ((2440, 2459), 'decimal.Decimal', 'Decimal', (['"""0.123457"""'], {}), "('0.123457')\n", (2447, 2459), False, 'from decimal import Decimal\n'), ((2463, 2477), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (2464, 2477), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2622, 2636), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (2623, 2636), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2640, 2659), 'decimal.Decimal', 'Decimal', (['"""0.123457"""'], {}), "('0.123457')\n", (2647, 2659), False, 'from decimal import Decimal\n'), ((2804, 2823), 'decimal.Decimal', 'Decimal', (['"""0.123453"""'], {}), "('0.123453')\n", (2811, 2823), False, 'from decimal import Decimal\n'), ((2827, 2841), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (2828, 2841), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((2986, 3000), 'testfixtures.RoundComparison', 'R', (['(0.123456)', '(5)'], {}), '(0.123456, 5)\n', (2987, 3000), True, 'from testfixtures import RoundComparison as R, compare, ShouldRaise\n'), ((3004, 3023), 'decimal.Decimal', 'Decimal', (['"""0.123453"""'], {}), "('0.123453')\n", (3011, 3023), False, 'from decimal import Decimal\n'), ((4810, 4829), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (4817, 4829), False, 'from decimal import Decimal\n'), ((4898, 4917), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (4905, 4917), False, 'from decimal import Decimal\n'), ((5032, 5051), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (5039, 5051), False, 'from decimal import Decimal\n'), ((5120, 5139), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (5127, 5139), False, 'from decimal import Decimal\n'), ((3295, 3314), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (3302, 3314), False, 'from decimal import Decimal\n'), ((3463, 3482), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (3470, 3482), False, 'from decimal import Decimal\n'), ((3655, 3674), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (3662, 3674), False, 'from decimal import Decimal\n'), ((3823, 3842), 'decimal.Decimal', 'Decimal', (['"""0.123456"""'], {}), "('0.123456')\n", (3830, 3842), False, 'from decimal import Decimal\n')]
# -*- coding=utf-8 -*- # author: dongrixinyu # contact: <EMAIL> # blog: https://github.com/dongrixinyu/ # file: bare_embedding.py # time: 2020-06-12 11:27 import os import pdb import logging from typing import Union, Optional, Dict, Any, Tuple import torch import torch.nn as nn from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence from jiotc.embeddings.base_embedding import BaseEmbedding from .base_model import BaseModel # Bidirectional LSTM neural network (many-to-one) class BiLSTMModel(BaseModel): @classmethod def get_default_hyper_parameters(cls) -> Dict[str, Dict[str, Any]]: return { 'layer_bi_lstm': { 'hidden_size': 128, 'num_layers': 1, 'dropout': 0.2, # 当 num_layers == 1 时失效 'bidirectional': True }, 'layer_dense': { 'activation': 'softmax' } } def __init__(self, embed_model: Optional[BaseEmbedding] = None, device: Union['cuda', 'cpu'] = None, hyper_parameters: Optional[Dict[str, Dict[str, Any]]] = None): ''' self.device self.embedding_layer self.embedding self.embedding_size self.num_classes 参数已知,可以直接使用 ''' super(BiLSTMModel, self).__init__(embed_model, device=device) self.hidden_size = hyper_parameters['layer_bi_lstm']['hidden_size'] self.num_layers = hyper_parameters['layer_bi_lstm']['num_layers'] self.dropout = hyper_parameters['layer_bi_lstm']['dropout'] self.lstm = nn.LSTM( self.embedding_size, self.hidden_size, self.num_layers, batch_first=True, bidirectional=True) self.fc = nn.Linear(self.hidden_size * 2, self.num_classes) # 2 for bidirection def forward(self, samples): masks = samples.gt(0) embeds = self.embedding_layer(samples) #.to(self.device) # 按长短调整样本顺序 seq_length = masks.sum(1) sorted_seq_length, perm_idx = seq_length.sort(descending=True) embeds = embeds[perm_idx, :] # 重新排序 pack_sequence = pack_padded_sequence( embeds, lengths=sorted_seq_length, batch_first=True) # Set initial states, involved with batch_size ''' h0 = torch.autograd.Variable(torch.randn( self.num_layers * 2, embeds.shape[0], self.hidden_size)).to(self.device) # 2 for bidirection c0 = torch.autograd.Variable(torch.randn( self.num_layers * 2, embeds.shape[0], self.hidden_size)).to(self.device) #''' # Forward propagate LSTM packed_output, _ = self.lstm(pack_sequence) #, (h0, c0)) # out: tensor of shape (batch_size, seq_length, hidden_size * 2) lstm_out, _ = pad_packed_sequence(packed_output, batch_first=True) _, unperm_idx = perm_idx.sort() lstm_out = lstm_out[unperm_idx, :] # dropout_layer lstm_out = lstm_out.permute(1, 0, 2) # [batch_size, seq_len, hidden_size * 2] => [seq_len, batch_size, hidden_size * 2] # disabled when not training lstm_out = F.dropout2d(lstm_out, p=self.dropout, training=self.training) lstm_out = lstm_out.permute(1, 0, 2) # [seq_len, batch_size, hidden_size * 2] => [batch_size, seq_len, hidden_size * 2] lstm_out_sum = torch.mean(lstm_out, dim=1) output = self.fc(lstm_out_sum) return output
[ "torch.nn.LSTM", "torch.mean", "torch.nn.utils.rnn.pack_padded_sequence", "torch.nn.Linear", "torch.nn.utils.rnn.pad_packed_sequence" ]
[((1650, 1756), 'torch.nn.LSTM', 'nn.LSTM', (['self.embedding_size', 'self.hidden_size', 'self.num_layers'], {'batch_first': '(True)', 'bidirectional': '(True)'}), '(self.embedding_size, self.hidden_size, self.num_layers, batch_first\n =True, bidirectional=True)\n', (1657, 1756), True, 'import torch.nn as nn\n'), ((1796, 1845), 'torch.nn.Linear', 'nn.Linear', (['(self.hidden_size * 2)', 'self.num_classes'], {}), '(self.hidden_size * 2, self.num_classes)\n', (1805, 1845), True, 'import torch.nn as nn\n'), ((2245, 2318), 'torch.nn.utils.rnn.pack_padded_sequence', 'pack_padded_sequence', (['embeds'], {'lengths': 'sorted_seq_length', 'batch_first': '(True)'}), '(embeds, lengths=sorted_seq_length, batch_first=True)\n', (2265, 2318), False, 'from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence\n'), ((2941, 2993), 'torch.nn.utils.rnn.pad_packed_sequence', 'pad_packed_sequence', (['packed_output'], {'batch_first': '(True)'}), '(packed_output, batch_first=True)\n', (2960, 2993), False, 'from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence\n'), ((3536, 3563), 'torch.mean', 'torch.mean', (['lstm_out'], {'dim': '(1)'}), '(lstm_out, dim=1)\n', (3546, 3563), False, 'import torch\n')]
from collections import namedtuple from dagster import check from dagster.config.config_type import ConfigType, ConfigTypeKind from dagster.config.field import Field from dagster.core.serdes import whitelist_for_serdes @whitelist_for_serdes class NonGenericTypeRefMeta(namedtuple('_NonGenericTypeRefMeta', 'key')): def __new__(cls, key): return super(NonGenericTypeRefMeta, cls).__new__(cls, check.str_param(key, 'key')) @whitelist_for_serdes class ConfigTypeMeta( namedtuple( '_ConfigTypeMeta', 'kind key given_name description ' 'type_param_refs ' # only valid for closed generics (Set, Tuple, List, Optional) 'enum_values ' # only valid for enums 'fields', # only valid for dicts and selectors ) ): def __new__( cls, kind, key, given_name, type_param_refs, enum_values, fields, description, ): return super(ConfigTypeMeta, cls).__new__( cls, kind=check.inst_param(kind, 'kind', ConfigTypeKind), key=check.str_param(key, 'key'), given_name=check.opt_str_param(given_name, 'given_name'), type_param_refs=None if type_param_refs is None else check.list_param(type_param_refs, 'type_param_refs', of_type=TypeRef), enum_values=None if enum_values is None else check.list_param(enum_values, 'enum_values', of_type=ConfigEnumValueMeta), fields=None if fields is None else check.list_param(fields, 'field', of_type=ConfigFieldMeta), description=check.opt_str_param(description, 'description'), ) @property def inner_type_refs(self): ''' This recurses through the type references with non-generic types as leaves. ''' def _doit(): next_level_refs = _get_next_level_refs(self) if next_level_refs: for next_level in next_level_refs: for inner_ref in _recurse_through_generics(next_level): yield inner_ref # there might be duplicate keys (esp for scalars) refs_by_key = {} for ref in _doit(): if ref.key not in refs_by_key: refs_by_key[ref.key] = ref return list(refs_by_key.values()) # This function is used by the recursive descent # through all the inner types. This does *not* # recursively descend through the type parameters # of generic types. It just gets the next level of # types. Either the direct type parameters of a # generic type. Or the type refs of all the fields # if it is a type with fields. def _get_next_level_refs(ref): # if a generic type, get type params # if a type with fields, get refs of the fields if ConfigTypeKind.is_closed_generic(ref.kind): return ref.type_param_refs elif ( ConfigTypeKind.has_fields(ref.kind) and ref.fields ): # still check fields because permissive return [field_meta.type_ref for field_meta in ref.fields] def _recurse_through_generics(ref): yield ref if isinstance(ref, ConfigTypeMeta) and ConfigTypeKind.is_closed_generic(ref.kind): for type_param_ref in ref.type_param_refs: for inner_ref in _recurse_through_generics(type_param_ref): yield inner_ref # A type reference in these serializable data structures are one of two things # 1) A closed generic type (e.g. List[Int] of Optional[Set[str]]) # 2) Or a reference to a non-generic type, such as Dict, Selector, or a Scalar. # Upon deserialization and when hydrated back to the graphql query, it will # be the responsibility of that module to maintain a dictionary of the # non-generic types and then do lookups into the dictionary in order to # to explode the entire type hierarchy requested by the client TypeRef = (ConfigTypeMeta, NonGenericTypeRefMeta) @whitelist_for_serdes class ConfigEnumValueMeta(namedtuple('_ConfigEnumValueMeta', 'value description')): def __new__(cls, value, description): return super(ConfigEnumValueMeta, cls).__new__( cls, value=check.str_param(value, 'value'), description=check.opt_str_param(description, 'description'), ) @whitelist_for_serdes class ConfigFieldMeta( namedtuple( '_ConfigFieldMeta', 'name type_ref is_required default_provided default_value_as_str description', ) ): def __new__( cls, name, type_ref, is_required, default_provided, default_value_as_str, description ): return super(ConfigFieldMeta, cls).__new__( cls, name=check.opt_str_param(name, 'name'), type_ref=check.inst_param(type_ref, 'type_ref', TypeRef), is_required=check.bool_param(is_required, 'is_required'), default_provided=check.bool_param(default_provided, 'default_provided'), default_value_as_str=check.opt_str_param(default_value_as_str, 'default_value_as_str'), description=check.opt_str_param(description, 'description'), ) def meta_from_field(name, field): check.str_param(name, 'name') check.inst_param(field, 'field', Field) return ConfigFieldMeta( name=name, type_ref=type_ref_of(field.config_type), is_required=field.is_required, default_provided=field.default_provided, default_value_as_str=field.default_value_as_str if field.default_provided else None, description=field.description, ) def type_ref_of(config_type): check.inst_param(config_type, 'config_type', ConfigType) if ConfigTypeKind.is_closed_generic(config_type.kind): return meta_from_config_type(config_type) else: return NonGenericTypeRefMeta(key=config_type.key) def type_refs_of(type_list): return list(map(type_ref_of, type_list)) if type_list is not None else None def meta_from_config_type(config_type): check.inst_param(config_type, 'config_type', ConfigType) return ConfigTypeMeta( key=config_type.key, given_name=config_type.given_name, kind=config_type.kind, description=config_type.description, type_param_refs=type_refs_of(config_type.type_params), enum_values=[ ConfigEnumValueMeta(ev.config_value, ev.description) for ev in config_type.enum_values ] if config_type.kind == ConfigTypeKind.ENUM else None, fields=[meta_from_field(name, field) for name, field in config_type.fields.items()] if ConfigTypeKind.has_fields(config_type.kind) else None, )
[ "dagster.check.list_param", "dagster.check.inst_param", "collections.namedtuple", "dagster.config.config_type.ConfigTypeKind.has_fields", "dagster.check.str_param", "dagster.check.opt_str_param", "dagster.check.bool_param", "dagster.config.config_type.ConfigTypeKind.is_closed_generic" ]
[((272, 315), 'collections.namedtuple', 'namedtuple', (['"""_NonGenericTypeRefMeta"""', '"""key"""'], {}), "('_NonGenericTypeRefMeta', 'key')\n", (282, 315), False, 'from collections import namedtuple\n'), ((486, 589), 'collections.namedtuple', 'namedtuple', (['"""_ConfigTypeMeta"""', '"""kind key given_name description type_param_refs enum_values fields"""'], {}), "('_ConfigTypeMeta',\n 'kind key given_name description type_param_refs enum_values fields')\n", (496, 589), False, 'from collections import namedtuple\n'), ((3960, 4015), 'collections.namedtuple', 'namedtuple', (['"""_ConfigEnumValueMeta"""', '"""value description"""'], {}), "('_ConfigEnumValueMeta', 'value description')\n", (3970, 4015), False, 'from collections import namedtuple\n'), ((4318, 4436), 'collections.namedtuple', 'namedtuple', (['"""_ConfigFieldMeta"""', '"""name type_ref is_required default_provided default_value_as_str description"""'], {}), "('_ConfigFieldMeta',\n 'name type_ref is_required default_provided default_value_as_str description'\n )\n", (4328, 4436), False, 'from collections import namedtuple\n'), ((2793, 2835), 'dagster.config.config_type.ConfigTypeKind.is_closed_generic', 'ConfigTypeKind.is_closed_generic', (['ref.kind'], {}), '(ref.kind)\n', (2825, 2835), False, 'from dagster.config.config_type import ConfigType, ConfigTypeKind\n'), ((5141, 5170), 'dagster.check.str_param', 'check.str_param', (['name', '"""name"""'], {}), "(name, 'name')\n", (5156, 5170), False, 'from dagster import check\n'), ((5175, 5214), 'dagster.check.inst_param', 'check.inst_param', (['field', '"""field"""', 'Field'], {}), "(field, 'field', Field)\n", (5191, 5214), False, 'from dagster import check\n'), ((5573, 5629), 'dagster.check.inst_param', 'check.inst_param', (['config_type', '"""config_type"""', 'ConfigType'], {}), "(config_type, 'config_type', ConfigType)\n", (5589, 5629), False, 'from dagster import check\n'), ((5637, 5687), 'dagster.config.config_type.ConfigTypeKind.is_closed_generic', 'ConfigTypeKind.is_closed_generic', (['config_type.kind'], {}), '(config_type.kind)\n', (5669, 5687), False, 'from dagster.config.config_type import ConfigType, ConfigTypeKind\n'), ((5964, 6020), 'dagster.check.inst_param', 'check.inst_param', (['config_type', '"""config_type"""', 'ConfigType'], {}), "(config_type, 'config_type', ConfigType)\n", (5980, 6020), False, 'from dagster import check\n'), ((3151, 3193), 'dagster.config.config_type.ConfigTypeKind.is_closed_generic', 'ConfigTypeKind.is_closed_generic', (['ref.kind'], {}), '(ref.kind)\n', (3183, 3193), False, 'from dagster.config.config_type import ConfigType, ConfigTypeKind\n'), ((407, 434), 'dagster.check.str_param', 'check.str_param', (['key', '"""key"""'], {}), "(key, 'key')\n", (422, 434), False, 'from dagster import check\n'), ((2891, 2926), 'dagster.config.config_type.ConfigTypeKind.has_fields', 'ConfigTypeKind.has_fields', (['ref.kind'], {}), '(ref.kind)\n', (2916, 2926), False, 'from dagster.config.config_type import ConfigType, ConfigTypeKind\n'), ((966, 1012), 'dagster.check.inst_param', 'check.inst_param', (['kind', '"""kind"""', 'ConfigTypeKind'], {}), "(kind, 'kind', ConfigTypeKind)\n", (982, 1012), False, 'from dagster import check\n'), ((1030, 1057), 'dagster.check.str_param', 'check.str_param', (['key', '"""key"""'], {}), "(key, 'key')\n", (1045, 1057), False, 'from dagster import check\n'), ((1082, 1127), 'dagster.check.opt_str_param', 'check.opt_str_param', (['given_name', '"""given_name"""'], {}), "(given_name, 'given_name')\n", (1101, 1127), False, 'from dagster import check\n'), ((1600, 1647), 'dagster.check.opt_str_param', 'check.opt_str_param', (['description', '"""description"""'], {}), "(description, 'description')\n", (1619, 1647), False, 'from dagster import check\n'), ((4151, 4182), 'dagster.check.str_param', 'check.str_param', (['value', '"""value"""'], {}), "(value, 'value')\n", (4166, 4182), False, 'from dagster import check\n'), ((4208, 4255), 'dagster.check.opt_str_param', 'check.opt_str_param', (['description', '"""description"""'], {}), "(description, 'description')\n", (4227, 4255), False, 'from dagster import check\n'), ((4658, 4691), 'dagster.check.opt_str_param', 'check.opt_str_param', (['name', '"""name"""'], {}), "(name, 'name')\n", (4677, 4691), False, 'from dagster import check\n'), ((4714, 4761), 'dagster.check.inst_param', 'check.inst_param', (['type_ref', '"""type_ref"""', 'TypeRef'], {}), "(type_ref, 'type_ref', TypeRef)\n", (4730, 4761), False, 'from dagster import check\n'), ((4787, 4831), 'dagster.check.bool_param', 'check.bool_param', (['is_required', '"""is_required"""'], {}), "(is_required, 'is_required')\n", (4803, 4831), False, 'from dagster import check\n'), ((4862, 4916), 'dagster.check.bool_param', 'check.bool_param', (['default_provided', '"""default_provided"""'], {}), "(default_provided, 'default_provided')\n", (4878, 4916), False, 'from dagster import check\n'), ((4951, 5016), 'dagster.check.opt_str_param', 'check.opt_str_param', (['default_value_as_str', '"""default_value_as_str"""'], {}), "(default_value_as_str, 'default_value_as_str')\n", (4970, 5016), False, 'from dagster import check\n'), ((5042, 5089), 'dagster.check.opt_str_param', 'check.opt_str_param', (['description', '"""description"""'], {}), "(description, 'description')\n", (5061, 5089), False, 'from dagster import check\n'), ((6563, 6606), 'dagster.config.config_type.ConfigTypeKind.has_fields', 'ConfigTypeKind.has_fields', (['config_type.kind'], {}), '(config_type.kind)\n', (6588, 6606), False, 'from dagster.config.config_type import ConfigType, ConfigTypeKind\n'), ((1218, 1287), 'dagster.check.list_param', 'check.list_param', (['type_param_refs', '"""type_param_refs"""'], {'of_type': 'TypeRef'}), "(type_param_refs, 'type_param_refs', of_type=TypeRef)\n", (1234, 1287), False, 'from dagster import check\n'), ((1370, 1443), 'dagster.check.list_param', 'check.list_param', (['enum_values', '"""enum_values"""'], {'of_type': 'ConfigEnumValueMeta'}), "(enum_values, 'enum_values', of_type=ConfigEnumValueMeta)\n", (1386, 1443), False, 'from dagster import check\n'), ((1516, 1574), 'dagster.check.list_param', 'check.list_param', (['fields', '"""field"""'], {'of_type': 'ConfigFieldMeta'}), "(fields, 'field', of_type=ConfigFieldMeta)\n", (1532, 1574), False, 'from dagster import check\n')]
######################################################### # 母比率の差の検定/タイプ1 ######################################################### import sys import math def error_usage(): sys.stderr.write("usage: " + sys.argv[0] + "\n") sys.stderr.write("\tこのプログラムは、4つの引数が必要です。\n\n") sys.stderr.write( "\t1.属性1のn数 2.属性1における比率p 3.属性2のn数 4.属性2における比率p\n") sys.stderr.write("\t例: 200 0.6 100 0.48\n\n") sys.stderr.write("\tただし、それぞれn数は30以上かつ比率pは[0<=p<=1]を満たすこと\n") sys.exit(1) # 引数がちょうど4つあるか? if len(sys.argv[1:]) != 4: error_usage() n1,p1,n2,p2 = map(float, sys.argv[1:]) p = ((n1*p1) + (n2*p2))/(n1+n2) # n数が30以上か? if (n1 < 30) or (n2 < 30): error_usage() # 比率は0から1の間か? if not (0 <= p1 <= 1) or not (0 <= p2 <= 1): error_usage() T = math.fabs(p1 - p2) / math.sqrt((p * (1-p)) * ((1/n1) + (1/n2))) if T >= 2.58: print("1%有意 (検定統計量:" + str(T) + ")") elif T >= 1.96: print("5%有意 (検定統計量:" + str(T) + ")") elif T >= 1.65: print("10%有意 (検定統計量:" + str(T) + ")") else: print("有意差なし (検定統計量:" + str(T) + ")")
[ "sys.stderr.write", "math.fabs", "math.sqrt", "sys.exit" ]
[((180, 228), 'sys.stderr.write', 'sys.stderr.write', (["('usage: ' + sys.argv[0] + '\\n')"], {}), "('usage: ' + sys.argv[0] + '\\n')\n", (196, 228), False, 'import sys\n'), ((233, 279), 'sys.stderr.write', 'sys.stderr.write', (['"""\tこのプログラムは、4つの引数が必要です。\n\n"""'], {}), "('\\tこのプログラムは、4つの引数が必要です。\\n\\n')\n", (249, 279), False, 'import sys\n'), ((284, 351), 'sys.stderr.write', 'sys.stderr.write', (['"""\t1.属性1のn数 2.属性1における比率p 3.属性2のn数 4.属性2における比率p\n"""'], {}), "('\\t1.属性1のn数 2.属性1における比率p 3.属性2のn数 4.属性2における比率p\\n')\n", (300, 351), False, 'import sys\n'), ((365, 410), 'sys.stderr.write', 'sys.stderr.write', (['"""\t例: 200 0.6 100 0.48\n\n"""'], {}), "('\\t例: 200 0.6 100 0.48\\n\\n')\n", (381, 410), False, 'import sys\n'), ((415, 475), 'sys.stderr.write', 'sys.stderr.write', (['"""\tただし、それぞれn数は30以上かつ比率pは[0<=p<=1]を満たすこと\n"""'], {}), "('\\tただし、それぞれn数は30以上かつ比率pは[0<=p<=1]を満たすこと\\n')\n", (431, 475), False, 'import sys\n'), ((480, 491), 'sys.exit', 'sys.exit', (['(1)'], {}), '(1)\n', (488, 491), False, 'import sys\n'), ((767, 785), 'math.fabs', 'math.fabs', (['(p1 - p2)'], {}), '(p1 - p2)\n', (776, 785), False, 'import math\n'), ((788, 830), 'math.sqrt', 'math.sqrt', (['(p * (1 - p) * (1 / n1 + 1 / n2))'], {}), '(p * (1 - p) * (1 / n1 + 1 / n2))\n', (797, 830), False, 'import math\n')]
# coding=utf-8 import functools from flask import Flask, session from flask import redirect from flask import request, make_response from flask import render_template from flask import url_for from flask_bootstrap import Bootstrap # 数据库处理 from db import * # json import json # 生成一个app app = Flask(__name__, instance_relative_config=True) bootstrap=Bootstrap(app) app.secret_key = 'lab3' # 对app执行请求页面地址到函数的绑定 @app.route("/", methods=("GET", "POST")) @app.route("/login", methods=("GET", "POST")) def login(): """Log in a registered user by adding the user id to the session.""" if request.method == "POST": # 客户端在login页面发起的POST请求 username = request.form["username"] password = request.form["password"] ipaddr = request.form["ipaddr"] database = request.form["database"] db = MyDefSQL(username, password, ipaddr, database) err = db.login() if err != '0': return render_template("login_fail.html", err=err) else: #print(err) session['username'] = username session['password'] = password session['ipaddr'] = ipaddr session['database'] = database return redirect(url_for('home')) else : # 客户端GET 请求login页面时 return render_template("login.html") # 主页面 @app.route("/home", methods=(["GET", "POST"])) def home(): return render_template("home.html") # 请求url为host/table的页面返回结果 @app.route("/table", methods=(["GET", "POST"])) def table(): # 出于简单考虑,每次请求都需要连接数据库,可以尝试使用其它context保存数据库连接 if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showtablecnt() if request.method == "POST": if 'clear' in request.form: return render_template("table.html", rows = '', dbname=session['database']) elif 'search' in request.form: return render_template("table.html", rows = tabs, dbname=session['database']) else: return render_template("table.html", rows = tabs, dbname=session['database']) # 客户管理页面 @app.route("/customer", methods=(["GET", "POST"])) def customer(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showcustomer() if tabs==None: tabs="" if request.method == "POST": if 'search' in request.form: # 是由search表单提交的post请求 searchinfo = {} # print(len(request.form[u"客户身份证号"])) for key,value in request.form.items(): # 注意这里key和value仍然是unicode编码,统一在db.py中处理! if len(value) != 0 and key!='search': # 做第一层过滤,使得可以表单中某块信息不填 searchinfo[key] = value tabs = db.customer_search(searchinfo) return render_template("customer.html", rows = tabs, dbname=session['database']) # 其它删改查需求,是由Ajax提交的post datas = json.loads(request.get_data(as_text=True)) function = datas["function"] datas = datas["inputdata"] # print(function) # print(datas[0][u"客户身份证号"]) if function == "delete": res = {'info':'删除成功!', 'errs':[]} for data in datas: err = db.customer_del(data) if err != '0': res['errs'].append([data[u"客户身份证号"],err]) if len(res['errs']) != 0: res['info'] = "删除失败!" return json.dumps(res) elif function == "insert": res = {'info':'插入成功!', 'errs':[]} for data in datas: err = db.customer_insert(data) if err != '0': res['errs'].append([data[u"客户身份证号"],err]) if len(res['errs']) != 0: res['info'] = "插入失败!" return json.dumps(res) elif function == "update": res = {'info':'修改成功!', 'errs':[]} for data in datas: err = db.customer_update(data) if err != '0': res['errs'].append([data[u"客户身份证号"],err]) if len(res['errs']) != 0: res['info'] = "修改失败!" return json.dumps(res) else: return render_template("customer.html", rows = tabs, dbname=session['database']) # 账户管理页面 # 储蓄账户 @app.route("/account/saving", methods=(["GET", "POST"])) def saving(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showaccount(True) if tabs==None: tabs="" if request.method == "POST": if 'search' in request.form: # 是由search表单提交的post请求 searchinfo = {} for key,value in request.form.items(): # 注意这里key和value仍然是unicode编码,统一在db.py中处理! if len(value) != 0 and key!='search': # 做第一层过滤,使得可以表单中某块信息不填 searchinfo[key] = value tabs = db.account_search(searchinfo, True) return render_template("account_saving.html", rows = tabs, dbname=session['database']) # 其它删改查需求,是由Ajax提交的post datas = json.loads(request.get_data(as_text=True)) function = datas["function"] datas = datas["inputdata"] # print(function) if function == "delete": res = {'info':'删除成功!', 'errs':[]} for data in datas: err = db.account_del(data, True) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "删除失败!" return json.dumps(res) elif function == "insert": res = {'info':'插入成功!', 'errs':[]} for data in datas: err = db.account_insert(data, True) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "插入失败!" return json.dumps(res) elif function == "update": res = {'info':'修改成功!', 'errs':[]} for data in datas: err = db.account_update(data, True) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "修改失败!" return json.dumps(res) else: return render_template("account_saving.html", rows = tabs, dbname=session['database']) # 支票账户 @app.route("/account/checking", methods=(["GET", "POST"])) def checking(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showaccount(False) if tabs==None: tabs="" if request.method == "POST": if 'search' in request.form: # 是由search表单提交的post请求 searchinfo = {} for key,value in request.form.items(): # 注意这里key和value仍然是unicode编码,统一在db.py中处理! if len(value) != 0 and key!='search': # 做第一层过滤,使得可以表单中某块信息不填 searchinfo[key] = value tabs = db.account_search(searchinfo, False) return render_template("account_checking.html", rows = tabs, dbname=session['database']) # 其它删改查需求,是由Ajax提交的post datas = json.loads(request.get_data(as_text=True)) function = datas["function"] datas = datas["inputdata"] # print(function) if function == "delete": res = {'info':'删除成功!', 'errs':[]} for data in datas: err = db.account_del(data, False) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "删除失败!" return json.dumps(res) elif function == "insert": res = {'info':'插入成功!', 'errs':[]} for data in datas: err = db.account_insert(data, False) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "插入失败!" return json.dumps(res) elif function == "update": res = {'info':'修改成功!', 'errs':[]} for data in datas: err = db.account_update(data, False) if err != '0': res['errs'].append([data[u"账户.账户号"],err]) if len(res['errs']) != 0: res['info'] = "修改失败!" return json.dumps(res) else: return render_template("account_checking.html", rows = tabs, dbname=session['database']) # 贷款管理页面 @app.route("/loan", methods=(["GET", "POST"])) def loan(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showloan() if tabs==None: tabs="" if request.method == "POST": if 'search' in request.form: # 是由search表单提交的post请求 searchinfo = {} for key,value in request.form.items(): # 注意这里key和value仍然是unicode编码,统一在db.py中处理! if len(value) != 0 and key!='search': # 做第一层过滤,使得可以表单中某块信息不填 searchinfo[key] = value tabs = db.loan_search(searchinfo) return render_template("loan.html", rows = tabs, dbname=session['database']) # 其它删改查需求,是由Ajax提交的post datas = json.loads(request.get_data(as_text=True)) function = datas["function"] datas = datas["inputdata"] # print(function) if function == "delete": res = {'info':'删除成功!', 'errs':[]} for data in datas: err = db.loan_del(data) if err != '0': res['errs'].append([data[u"贷款号"],err]) if len(res['errs']) != 0: res['info'] = "删除失败!" return json.dumps(res) elif function == "insert": res = {'info':'插入成功!', 'errs':[]} for data in datas: err = db.loan_insert(data) if err != '0': res['errs'].append([data[u"贷款号"],err]) if len(res['errs']) != 0: res['info'] = "插入失败!" return json.dumps(res) elif function == "release": res = {'info':'贷款发放成功!', 'errs':[]} for data in datas: err = db.loan_release(data) if err != '0': res['errs'].append([data[u"贷款号"],err]) if len(res['errs']) != 0: res['info'] = "贷款发放失败!" return json.dumps(res) else: return render_template("loan.html", rows = tabs, dbname=session['database']) # 业务统计 # 按月 @app.route("/statistic/month") def month(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.statistic_month() return render_template("statistic.html", how = u'月份', rows = tabs, dbname=session['database']) # 按季度 @app.route("/statistic/quarter") def quarter(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.statistic_quarter() return render_template("statistic.html", how = u'季度', rows = tabs, dbname=session['database']) # 按年 @app.route("/statistic/year") def year(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.statistic_year() return render_template("statistic.html", how = u'年份', rows = tabs, dbname=session['database']) # 测试新html页面 @app.route("/test") def test(): if 'username' in session: db = MyDefSQL(session['username'], session['password'], session['ipaddr'], session['database']) err = db.login() else: return redirect(url_for('login')) tabs = db.showtablecnt() return render_template("test.html", rows = tabs) # 测试URL下返回html page @app.route("/hello") def hello(): return "hello world!" #返回不存在页面的处理 @app.errorhandler(404) def not_found(e): return render_template("404.html") if __name__ == "__main__": app.run(host = "0.0.0.0", debug=True)
[ "flask.render_template", "flask.Flask", "flask.request.get_data", "flask.request.form.items", "json.dumps", "flask.url_for", "flask_bootstrap.Bootstrap" ]
[((308, 354), 'flask.Flask', 'Flask', (['__name__'], {'instance_relative_config': '(True)'}), '(__name__, instance_relative_config=True)\n', (313, 354), False, 'from flask import Flask, session\n'), ((366, 380), 'flask_bootstrap.Bootstrap', 'Bootstrap', (['app'], {}), '(app)\n', (375, 380), False, 'from flask_bootstrap import Bootstrap\n'), ((1459, 1487), 'flask.render_template', 'render_template', (['"""home.html"""'], {}), "('home.html')\n", (1474, 1487), False, 'from flask import render_template\n'), ((12185, 12273), 'flask.render_template', 'render_template', (['"""statistic.html"""'], {'how': 'u"""月份"""', 'rows': 'tabs', 'dbname': "session['database']"}), "('statistic.html', how=u'月份', rows=tabs, dbname=session[\n 'database'])\n", (12200, 12273), False, 'from flask import render_template\n'), ((12629, 12717), 'flask.render_template', 'render_template', (['"""statistic.html"""'], {'how': 'u"""季度"""', 'rows': 'tabs', 'dbname': "session['database']"}), "('statistic.html', how=u'季度', rows=tabs, dbname=session[\n 'database'])\n", (12644, 12717), False, 'from flask import render_template\n'), ((13063, 13151), 'flask.render_template', 'render_template', (['"""statistic.html"""'], {'how': 'u"""年份"""', 'rows': 'tabs', 'dbname': "session['database']"}), "('statistic.html', how=u'年份', rows=tabs, dbname=session[\n 'database'])\n", (13078, 13151), False, 'from flask import render_template\n'), ((13496, 13535), 'flask.render_template', 'render_template', (['"""test.html"""'], {'rows': 'tabs'}), "('test.html', rows=tabs)\n", (13511, 13535), False, 'from flask import render_template\n'), ((13694, 13721), 'flask.render_template', 'render_template', (['"""404.html"""'], {}), "('404.html')\n", (13709, 13721), False, 'from flask import render_template\n'), ((1347, 1376), 'flask.render_template', 'render_template', (['"""login.html"""'], {}), "('login.html')\n", (1362, 1376), False, 'from flask import render_template\n'), ((2232, 2300), 'flask.render_template', 'render_template', (['"""table.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('table.html', rows=tabs, dbname=session['database'])\n", (2247, 2300), False, 'from flask import render_template\n'), ((4661, 4732), 'flask.render_template', 'render_template', (['"""customer.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('customer.html', rows=tabs, dbname=session['database'])\n", (4676, 4732), False, 'from flask import render_template\n'), ((7045, 7122), 'flask.render_template', 'render_template', (['"""account_saving.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('account_saving.html', rows=tabs, dbname=session['database'])\n", (7060, 7122), False, 'from flask import render_template\n'), ((9438, 9517), 'flask.render_template', 'render_template', (['"""account_checking.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('account_checking.html', rows=tabs, dbname=session['database'])\n", (9453, 9517), False, 'from flask import render_template\n'), ((11754, 11821), 'flask.render_template', 'render_template', (['"""loan.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('loan.html', rows=tabs, dbname=session['database'])\n", (11769, 11821), False, 'from flask import render_template\n'), ((986, 1029), 'flask.render_template', 'render_template', (['"""login_fail.html"""'], {'err': 'err'}), "('login_fail.html', err=err)\n", (1001, 1029), False, 'from flask import render_template\n'), ((1856, 1872), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (1863, 1872), False, 'from flask import url_for\n'), ((2003, 2069), 'flask.render_template', 'render_template', (['"""table.html"""'], {'rows': '""""""', 'dbname': "session['database']"}), "('table.html', rows='', dbname=session['database'])\n", (2018, 2069), False, 'from flask import render_template\n'), ((2610, 2626), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (2617, 2626), False, 'from flask import url_for\n'), ((2920, 2940), 'flask.request.form.items', 'request.form.items', ([], {}), '()\n', (2938, 2940), False, 'from flask import request, make_response\n'), ((3215, 3286), 'flask.render_template', 'render_template', (['"""customer.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('customer.html', rows=tabs, dbname=session['database'])\n", (3230, 3286), False, 'from flask import render_template\n'), ((3350, 3380), 'flask.request.get_data', 'request.get_data', ([], {'as_text': '(True)'}), '(as_text=True)\n', (3366, 3380), False, 'from flask import request, make_response\n'), ((3872, 3887), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (3882, 3887), False, 'import json\n'), ((5054, 5070), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (5061, 5070), False, 'from flask import url_for\n'), ((5316, 5336), 'flask.request.form.items', 'request.form.items', ([], {}), '()\n', (5334, 5336), False, 'from flask import request, make_response\n'), ((5616, 5693), 'flask.render_template', 'render_template', (['"""account_saving.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('account_saving.html', rows=tabs, dbname=session['database'])\n", (5631, 5693), False, 'from flask import render_template\n'), ((5757, 5787), 'flask.request.get_data', 'request.get_data', ([], {'as_text': '(True)'}), '(as_text=True)\n', (5773, 5787), False, 'from flask import request, make_response\n'), ((6246, 6261), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (6256, 6261), False, 'import json\n'), ((7440, 7456), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (7447, 7456), False, 'from flask import url_for\n'), ((7703, 7723), 'flask.request.form.items', 'request.form.items', ([], {}), '()\n', (7721, 7723), False, 'from flask import request, make_response\n'), ((8004, 8083), 'flask.render_template', 'render_template', (['"""account_checking.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('account_checking.html', rows=tabs, dbname=session['database'])\n", (8019, 8083), False, 'from flask import render_template\n'), ((8147, 8177), 'flask.request.get_data', 'request.get_data', ([], {'as_text': '(True)'}), '(as_text=True)\n', (8163, 8177), False, 'from flask import request, make_response\n'), ((8637, 8652), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (8647, 8652), False, 'import json\n'), ((9819, 9835), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (9826, 9835), False, 'from flask import url_for\n'), ((10074, 10094), 'flask.request.form.items', 'request.form.items', ([], {}), '()\n', (10092, 10094), False, 'from flask import request, make_response\n'), ((10365, 10432), 'flask.render_template', 'render_template', (['"""loan.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('loan.html', rows=tabs, dbname=session['database'])\n", (10380, 10432), False, 'from flask import render_template\n'), ((10496, 10526), 'flask.request.get_data', 'request.get_data', ([], {'as_text': '(True)'}), '(as_text=True)\n', (10512, 10526), False, 'from flask import request, make_response\n'), ((10973, 10988), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (10983, 10988), False, 'import json\n'), ((12114, 12130), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (12121, 12130), False, 'from flask import url_for\n'), ((12556, 12572), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (12563, 12572), False, 'from flask import url_for\n'), ((12993, 13009), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (13000, 13009), False, 'from flask import url_for\n'), ((13428, 13444), 'flask.url_for', 'url_for', (['"""login"""'], {}), "('login')\n", (13435, 13444), False, 'from flask import url_for\n'), ((1273, 1288), 'flask.url_for', 'url_for', (['"""home"""'], {}), "('home')\n", (1280, 1288), False, 'from flask import url_for\n'), ((2132, 2200), 'flask.render_template', 'render_template', (['"""table.html"""'], {'rows': 'tabs', 'dbname': "session['database']"}), "('table.html', rows=tabs, dbname=session['database'])\n", (2147, 2200), False, 'from flask import render_template\n'), ((4244, 4259), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (4254, 4259), False, 'import json\n'), ((6623, 6638), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (6633, 6638), False, 'import json\n'), ((9015, 9030), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (9025, 9030), False, 'import json\n'), ((11338, 11353), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (11348, 11353), False, 'import json\n'), ((4616, 4631), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (4626, 4631), False, 'import json\n'), ((7000, 7015), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (7010, 7015), False, 'import json\n'), ((9393, 9408), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (9403, 9408), False, 'import json\n'), ((11709, 11724), 'json.dumps', 'json.dumps', (['res'], {}), '(res)\n', (11719, 11724), False, 'import json\n')]
# STL imports import random import logging import string import time import datetime import random import struct import sys from functools import wraps # Third party imports import numpy as np import faker from faker.providers import BaseProvider logging.getLogger('faker').setLevel(logging.ERROR) sys.path.append('.') # grpc from milvus.grpc_gen import milvus_pb2 def gen_vectors(num, dim): return [[random.random() for _ in range(dim)] for _ in range(num)] def gen_single_vector(dim): return [[random.random() for _ in range(dim)]] def gen_vector(nb, d, seed=np.random.RandomState(1234)): xb = seed.rand(nb, d).astype("float32") return xb.tolist() def gen_unique_str(str=None): prefix = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) return prefix if str is None else str + "_" + prefix def get_current_day(): return time.strftime('%Y-%m-%d', time.localtime()) def get_last_day(day): tmp = datetime.datetime.now() - datetime.timedelta(days=day) return tmp.strftime('%Y-%m-%d') def get_next_day(day): tmp = datetime.datetime.now() + datetime.timedelta(days=day) return tmp.strftime('%Y-%m-%d') def gen_long_str(num): string = '' for _ in range(num): char = random.choice('tomorrow') string += char def gen_one_binary(topk): ids = [random.randrange(10000000, 99999999) for _ in range(topk)] distances = [random.random() for _ in range(topk)] return milvus_pb2.TopKQueryResult(struct.pack(str(topk) + 'l', *ids), struct.pack(str(topk) + 'd', *distances)) def gen_nq_binaries(nq, topk): return [gen_one_binary(topk) for _ in range(nq)] def fake_query_bin_result(nq, topk): return gen_nq_binaries(nq, topk) class FakerProvider(BaseProvider): def collection_name(self): return 'collection_names' + str(random.randint(1000, 9999)) def name(self): return 'name' + str(random.randint(1000, 9999)) def dim(self): return random.randint(0, 999) fake = faker.Faker() fake.add_provider(FakerProvider) def collection_name_factory(): return fake.collection_name() def records_factory(dimension, nq): return [[random.random() for _ in range(dimension)] for _ in range(nq)] def binary_records_factory(dimension, nq): def binary_record(bsize): s_m = "abcdefghijklmnopqrstuvwxyz" s_list = [s_m[random.randint(0, 25)] for _ in range(bsize)] s = "".join(s_list) return bytes(s, encoding="ASCII") bs = dimension // 8 return [binary_record(bs) for _ in range(nq)] def integer_factory(nq): return [random.randint(0, 128) for _ in range(nq)] def time_it(func): @wraps(func) def inner(*args, **kwrgs): pref = time.perf_counter() result = func(*args, **kwrgs) delt = time.perf_counter() - pref print(f"[{func.__name__}][{delt:.4}s]") return result return inner
[ "logging.getLogger", "random.choice", "random.randrange", "time.perf_counter", "functools.wraps", "datetime.timedelta", "faker.Faker", "datetime.datetime.now", "random.random", "time.localtime", "sys.path.append", "random.randint", "numpy.random.RandomState" ]
[((301, 321), 'sys.path.append', 'sys.path.append', (['"""."""'], {}), "('.')\n", (316, 321), False, 'import sys\n'), ((2030, 2043), 'faker.Faker', 'faker.Faker', ([], {}), '()\n', (2041, 2043), False, 'import faker\n'), ((578, 605), 'numpy.random.RandomState', 'np.random.RandomState', (['(1234)'], {}), '(1234)\n', (599, 605), True, 'import numpy as np\n'), ((2697, 2708), 'functools.wraps', 'wraps', (['func'], {}), '(func)\n', (2702, 2708), False, 'from functools import wraps\n'), ((249, 275), 'logging.getLogger', 'logging.getLogger', (['"""faker"""'], {}), "('faker')\n", (266, 275), False, 'import logging\n'), ((918, 934), 'time.localtime', 'time.localtime', ([], {}), '()\n', (932, 934), False, 'import time\n'), ((971, 994), 'datetime.datetime.now', 'datetime.datetime.now', ([], {}), '()\n', (992, 994), False, 'import datetime\n'), ((997, 1025), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': 'day'}), '(days=day)\n', (1015, 1025), False, 'import datetime\n'), ((1097, 1120), 'datetime.datetime.now', 'datetime.datetime.now', ([], {}), '()\n', (1118, 1120), False, 'import datetime\n'), ((1123, 1151), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': 'day'}), '(days=day)\n', (1141, 1151), False, 'import datetime\n'), ((1269, 1294), 'random.choice', 'random.choice', (['"""tomorrow"""'], {}), "('tomorrow')\n", (1282, 1294), False, 'import random\n'), ((1357, 1393), 'random.randrange', 'random.randrange', (['(10000000)', '(99999999)'], {}), '(10000000, 99999999)\n', (1373, 1393), False, 'import random\n'), ((1433, 1448), 'random.random', 'random.random', ([], {}), '()\n', (1446, 1448), False, 'import random\n'), ((1998, 2020), 'random.randint', 'random.randint', (['(0)', '(999)'], {}), '(0, 999)\n', (2012, 2020), False, 'import random\n'), ((2628, 2650), 'random.randint', 'random.randint', (['(0)', '(128)'], {}), '(0, 128)\n', (2642, 2650), False, 'import random\n'), ((2755, 2774), 'time.perf_counter', 'time.perf_counter', ([], {}), '()\n', (2772, 2774), False, 'import time\n'), ((410, 425), 'random.random', 'random.random', ([], {}), '()\n', (423, 425), False, 'import random\n'), ((511, 526), 'random.random', 'random.random', ([], {}), '()\n', (524, 526), False, 'import random\n'), ((728, 779), 'random.choice', 'random.choice', (['(string.ascii_letters + string.digits)'], {}), '(string.ascii_letters + string.digits)\n', (741, 779), False, 'import random\n'), ((2195, 2210), 'random.random', 'random.random', ([], {}), '()\n', (2208, 2210), False, 'import random\n'), ((2828, 2847), 'time.perf_counter', 'time.perf_counter', ([], {}), '()\n', (2845, 2847), False, 'import time\n'), ((1858, 1884), 'random.randint', 'random.randint', (['(1000)', '(9999)'], {}), '(1000, 9999)\n', (1872, 1884), False, 'import random\n'), ((1935, 1961), 'random.randint', 'random.randint', (['(1000)', '(9999)'], {}), '(1000, 9999)\n', (1949, 1961), False, 'import random\n'), ((2398, 2419), 'random.randint', 'random.randint', (['(0)', '(25)'], {}), '(0, 25)\n', (2412, 2419), False, 'import random\n')]
import math import os import random import re import sys first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) m = int(first_multiple_input[1]) matrix = [] if (n>0 and m>0 and n<100 and m< 100): for _ in range(n): matrix_item = input() matrix.append(matrix_item) for _ in range(m): string = "" for cols in range (m): for rows in range (n): string += matrix[rows][cols] output = re.sub(r"\b[!@#$%& ]+\b"," ", string) print(output)
[ "re.sub" ]
[((468, 507), 're.sub', 're.sub', (['"""\\\\b[!@#$%& ]+\\\\b"""', '""" """', 'string'], {}), "('\\\\b[!@#$%& ]+\\\\b', ' ', string)\n", (474, 507), False, 'import re\n')]
import torch import torch.nn.functional as F import os.path as osp import json from torch_geometric.utils import precision, recall from torch_geometric.utils import f1_score, accuracy from torch.utils.tensorboard import SummaryWriter def train_epoch_classifier(model, train_loader, len_train, optimizer, device): model.train() loss_all = 0 for data in train_loader: data = data.to(device) optimizer.zero_grad() output, _ = model(data.x, data.edge_index, batch=data.batch) loss = F.nll_loss(F.log_softmax(output, dim=-1), data.y) loss.backward() loss_all += data.num_graphs * loss.item() optimizer.step() return loss_all / len_train def test_classifier(model, loader, device): model.eval() y = torch.tensor([]).long().to(device) yp = torch.tensor([]).long().to(device) loss_all = 0 for data in loader: data = data.to(device) pred, _ = model(data.x, data.edge_index, batch=data.batch) loss = F.nll_loss(F.log_softmax(pred, dim=-1), data.y) pred = pred.max(dim=1)[1] y = torch.cat([y, data.y]) yp = torch.cat([yp, pred]) loss_all += data.num_graphs * loss.item() return ( accuracy(y, yp), precision(y, yp, model.num_output).mean().item(), recall(y, yp, model.num_output).mean().item(), f1_score(y, yp, model.num_output).mean().item(), loss_all ) def train_cycle_classifier(task, train_loader, val_loader, test_loader, len_train, len_val, len_test, model, optimizer, device, base_path, epochs): best_acc = (0, 0) writer = SummaryWriter(base_path + '/plots') for epoch in range(epochs): loss = train_epoch_classifier(model, train_loader, len_train, optimizer, device) writer.add_scalar('Loss/train', loss, epoch) train_acc, train_prec, train_rec, train_f1, _ = test_classifier(model, train_loader, device) val_acc, val_prec, val_rec, val_f1, l = test_classifier(model, val_loader, device) writer.add_scalar('Accuracy/train', train_acc, epoch) writer.add_scalar('Accuracy/val', val_acc, epoch) writer.add_scalar('Loss/val', l / len_val, epoch) print(f'Epoch: {epoch}, Loss: {loss:.5f}') print(f'Train -> Acc: {train_acc:.5f} Rec: {train_rec:.5f} \ Prec: {train_prec:.5f} F1: {train_f1:.5f}') print(f'Val -> Acc: {val_acc:.5f} Rec: {val_rec:.5f} \ Prec: {val_prec:.5f} F1: {val_f1:.5f}') if best_acc[1] < val_acc: best_acc = train_acc, val_acc torch.save( model.state_dict(), osp.join(base_path + '/ckpt/', model.__class__.__name__ + ".pth") ) print("New best model saved!") with open(base_path + '/best_result.json', 'w') as outfile: json.dump({'train_acc': train_acc, 'val_acc': val_acc, 'train_rec': train_rec, 'val_rec': val_rec, 'train_f1': train_f1, 'val_f1': val_f1, 'train_prec': train_prec, 'val_prec': val_prec}, outfile) def train_epoch_regressor(model, train_loader, len_train, optimizer, device): model.train() loss_all = 0 for data in train_loader: data = data.to(device) optimizer.zero_grad() output, _ = model(data.x.float(), data.edge_index, batch=data.batch) loss = F.mse_loss(output, data.y) loss.backward() loss_all += data.num_graphs * loss.item() optimizer.step() return loss_all / len_train def test_regressor(model, loader, len_loader, device): model.eval() loss_all = 0 for data in loader: data = data.to(device) pred, _ = model(data.x.float(), data.edge_index, batch=data.batch) loss = F.mse_loss(pred, data.y).detach() loss_all += data.num_graphs * loss.item() return loss_all / len_loader def train_cycle_regressor(task, train_loader, val_loader, test_loader, len_train, len_val, len_test, model, optimizer, device, base_path, epochs): best_acc = (0, 0) writer = SummaryWriter(base_path + '/plots') best_error = (+10000, +10000) for epoch in range(epochs): loss = train_epoch_regressor(model, train_loader, len_train, optimizer, device) writer.add_scalar('Loss/train', loss, epoch) train_error = test_regressor(model, train_loader, len_train, device) val_error = test_regressor(model, val_loader, len_val, device) writer.add_scalar('MSE/train', train_error, epoch) writer.add_scalar('MSE/test', val_error, epoch) print(f'Epoch: {epoch}, Loss: {loss:.5f}') print(f'Training Error: {train_error:.5f}') print(f'Val Error: {val_error:.5f}') if best_error[1] > val_error: best_error = train_error, val_error torch.save( model.state_dict(), osp.join(base_path + '/ckpt/', model.__class__.__name__ + ".pth") ) print("New best model saved!") with open(base_path + '/best_result.json', 'w') as outfile: json.dump({'train_error': train_error, 'val_error': val_error}, outfile)
[ "torch.utils.tensorboard.SummaryWriter", "torch.nn.functional.mse_loss", "json.dump", "os.path.join", "torch.tensor", "torch_geometric.utils.f1_score", "torch.nn.functional.log_softmax", "torch_geometric.utils.recall", "torch_geometric.utils.precision", "torch_geometric.utils.accuracy", "torch.c...
[((1661, 1696), 'torch.utils.tensorboard.SummaryWriter', 'SummaryWriter', (["(base_path + '/plots')"], {}), "(base_path + '/plots')\n", (1674, 1696), False, 'from torch.utils.tensorboard import SummaryWriter\n'), ((4366, 4401), 'torch.utils.tensorboard.SummaryWriter', 'SummaryWriter', (["(base_path + '/plots')"], {}), "(base_path + '/plots')\n", (4379, 4401), False, 'from torch.utils.tensorboard import SummaryWriter\n'), ((1108, 1130), 'torch.cat', 'torch.cat', (['[y, data.y]'], {}), '([y, data.y])\n', (1117, 1130), False, 'import torch\n'), ((1144, 1165), 'torch.cat', 'torch.cat', (['[yp, pred]'], {}), '([yp, pred])\n', (1153, 1165), False, 'import torch\n'), ((1239, 1254), 'torch_geometric.utils.accuracy', 'accuracy', (['y', 'yp'], {}), '(y, yp)\n', (1247, 1254), False, 'from torch_geometric.utils import f1_score, accuracy\n'), ((3612, 3638), 'torch.nn.functional.mse_loss', 'F.mse_loss', (['output', 'data.y'], {}), '(output, data.y)\n', (3622, 3638), True, 'import torch.nn.functional as F\n'), ((537, 566), 'torch.nn.functional.log_softmax', 'F.log_softmax', (['output'], {'dim': '(-1)'}), '(output, dim=-1)\n', (550, 566), True, 'import torch.nn.functional as F\n'), ((1024, 1051), 'torch.nn.functional.log_softmax', 'F.log_softmax', (['pred'], {'dim': '(-1)'}), '(pred, dim=-1)\n', (1037, 1051), True, 'import torch.nn.functional as F\n'), ((2689, 2754), 'os.path.join', 'osp.join', (["(base_path + '/ckpt/')", "(model.__class__.__name__ + '.pth')"], {}), "(base_path + '/ckpt/', model.__class__.__name__ + '.pth')\n", (2697, 2754), True, 'import os.path as osp\n'), ((2926, 3130), 'json.dump', 'json.dump', (["{'train_acc': train_acc, 'val_acc': val_acc, 'train_rec': train_rec,\n 'val_rec': val_rec, 'train_f1': train_f1, 'val_f1': val_f1,\n 'train_prec': train_prec, 'val_prec': val_prec}", 'outfile'], {}), "({'train_acc': train_acc, 'val_acc': val_acc, 'train_rec':\n train_rec, 'val_rec': val_rec, 'train_f1': train_f1, 'val_f1': val_f1,\n 'train_prec': train_prec, 'val_prec': val_prec}, outfile)\n", (2935, 3130), False, 'import json\n'), ((4010, 4034), 'torch.nn.functional.mse_loss', 'F.mse_loss', (['pred', 'data.y'], {}), '(pred, data.y)\n', (4020, 4034), True, 'import torch.nn.functional as F\n'), ((5187, 5252), 'os.path.join', 'osp.join', (["(base_path + '/ckpt/')", "(model.__class__.__name__ + '.pth')"], {}), "(base_path + '/ckpt/', model.__class__.__name__ + '.pth')\n", (5195, 5252), True, 'import os.path as osp\n'), ((5424, 5496), 'json.dump', 'json.dump', (["{'train_error': train_error, 'val_error': val_error}", 'outfile'], {}), "({'train_error': train_error, 'val_error': val_error}, outfile)\n", (5433, 5496), False, 'import json\n'), ((779, 795), 'torch.tensor', 'torch.tensor', (['[]'], {}), '([])\n', (791, 795), False, 'import torch\n'), ((823, 839), 'torch.tensor', 'torch.tensor', (['[]'], {}), '([])\n', (835, 839), False, 'import torch\n'), ((1264, 1298), 'torch_geometric.utils.precision', 'precision', (['y', 'yp', 'model.num_output'], {}), '(y, yp, model.num_output)\n', (1273, 1298), False, 'from torch_geometric.utils import precision, recall\n'), ((1322, 1353), 'torch_geometric.utils.recall', 'recall', (['y', 'yp', 'model.num_output'], {}), '(y, yp, model.num_output)\n', (1328, 1353), False, 'from torch_geometric.utils import precision, recall\n'), ((1377, 1410), 'torch_geometric.utils.f1_score', 'f1_score', (['y', 'yp', 'model.num_output'], {}), '(y, yp, model.num_output)\n', (1385, 1410), False, 'from torch_geometric.utils import f1_score, accuracy\n')]
# nuScenes dev-kit. # Code written by <NAME>, 2020. import argparse import gc import os import random from typing import List from collections import defaultdict import cv2 import tqdm from nuimages.nuimages import NuImages def render_images(nuim: NuImages, mode: str = 'all', cam_name: str = None, log_name: str = None, sample_limit: int = 50, filter_categories: List[str] = None, out_type: str = 'image', out_dir: str = '~/Downloads/nuImages', cleanup: bool = True) -> None: """ Render a random selection of images and save them to disk. Note: The images rendered here are keyframes only. :param nuim: NuImages instance. :param mode: What to render: "image" for the image without annotations, "annotated" for the image with annotations, "trajectory" for a rendering of the trajectory of the vehice, "all" to render all of the above separately. :param cam_name: Only render images from a particular camera, e.g. "CAM_BACK'. :param log_name: Only render images from a particular log, e.g. "n013-2018-09-04-13-30-50+0800". :param sample_limit: Maximum number of samples (images) to render. Note that the mini split only includes 50 images. :param filter_categories: Specify a list of object_ann category names. Every sample that is rendered must contain annotations of any of those categories. :param out_type: The output type as one of the following: 'image': Renders a single image for the image keyframe of each sample. 'video': Renders a video for all images/pcls in the clip associated with each sample. :param out_dir: Folder to render the images to. :param cleanup: Whether to delete images after rendering the video. Not relevant for out_type == 'image'. """ # Check and convert inputs. assert out_type in ['image', 'video'], ' Error: Unknown out_type %s!' % out_type all_modes = ['image', 'annotated', 'trajectory'] assert mode in all_modes + ['all'], 'Error: Unknown mode %s!' % mode assert not (out_type == 'video' and mode == 'trajectory'), 'Error: Cannot render "trajectory" for videos!' if mode == 'all': if out_type == 'image': modes = all_modes elif out_type == 'video': modes = [m for m in all_modes if m not in ['annotated', 'trajectory']] else: raise Exception('Error" Unknown mode %s!' % mode) else: modes = [mode] if filter_categories is not None: category_names = [c['name'] for c in nuim.category] for category_name in filter_categories: assert category_name in category_names, 'Error: Invalid object_ann category %s!' % category_name # Create output folder. out_dir = os.path.expanduser(out_dir) if not os.path.isdir(out_dir): os.makedirs(out_dir) # Filter by camera. sample_tokens = [s['token'] for s in nuim.sample] if cam_name is not None: sample_tokens_cam = [] for sample_token in sample_tokens: sample = nuim.get('sample', sample_token) key_camera_token = sample['key_camera_token'] sensor = nuim.shortcut('sample_data', 'sensor', key_camera_token) if sensor['channel'] == cam_name: sample_tokens_cam.append(sample_token) sample_tokens = sample_tokens_cam # Filter by log. if log_name is not None: sample_tokens_cleaned = [] for sample_token in sample_tokens: sample = nuim.get('sample', sample_token) log = nuim.get('log', sample['log_token']) if log['logfile'] == log_name: sample_tokens_cleaned.append(sample_token) sample_tokens = sample_tokens_cleaned # Filter samples by category. if filter_categories is not None: # Get categories in each sample. sd_to_object_cat_names = defaultdict(lambda: set()) for object_ann in nuim.object_ann: category = nuim.get('category', object_ann['category_token']) sd_to_object_cat_names[object_ann['sample_data_token']].add(category['name']) # Filter samples. sample_tokens_cleaned = [] for sample_token in sample_tokens: sample = nuim.get('sample', sample_token) key_camera_token = sample['key_camera_token'] category_names = sd_to_object_cat_names[key_camera_token] if any([c in category_names for c in filter_categories]): sample_tokens_cleaned.append(sample_token) sample_tokens = sample_tokens_cleaned # Get a random selection of samples. random.shuffle(sample_tokens) # Limit number of samples. sample_tokens = sample_tokens[:sample_limit] print('Rendering %s for mode %s to folder %s...' % (out_type, mode, out_dir)) for sample_token in tqdm.tqdm(sample_tokens): sample = nuim.get('sample', sample_token) log = nuim.get('log', sample['log_token']) log_name = log['logfile'] key_camera_token = sample['key_camera_token'] sensor = nuim.shortcut('sample_data', 'sensor', key_camera_token) sample_cam_name = sensor['channel'] sd_tokens = nuim.get_sample_content(sample_token) # We cannot render a video if there are missing camera sample_datas. if len(sd_tokens) < 13 and out_type == 'video': print('Warning: Skipping video for sample token %s, as not all 13 frames exist!' % sample_token) continue for mode in modes: out_path_prefix = os.path.join(out_dir, '%s_%s_%s_%s' % (log_name, sample_token, sample_cam_name, mode)) if out_type == 'image': write_image(nuim, key_camera_token, mode, '%s.jpg' % out_path_prefix) elif out_type == 'video': write_video(nuim, sd_tokens, mode, out_path_prefix, cleanup=cleanup) def write_video(nuim: NuImages, sd_tokens: List[str], mode: str, out_path_prefix: str, cleanup: bool = True) -> None: """ Render a video by combining all the images of type mode for each sample_data. :param nuim: NuImages instance. :param sd_tokens: All sample_data tokens in chronological order. :param mode: The mode - see render_images(). :param out_path_prefix: The file prefix used for the images and video. :param cleanup: Whether to delete images after rendering the video. """ # Loop through each frame to create the video. out_paths = [] for i, sd_token in enumerate(sd_tokens): out_path = '%s_%d.jpg' % (out_path_prefix, i) out_paths.append(out_path) write_image(nuim, sd_token, mode, out_path) # Create video. first_im = cv2.imread(out_paths[0]) freq = 2 # Display frequency (Hz). fourcc = cv2.VideoWriter_fourcc(*'MJPG') video_path = '%s.avi' % out_path_prefix out = cv2.VideoWriter(video_path, fourcc, freq, first_im.shape[1::-1]) # Load each image and add to the video. for out_path in out_paths: im = cv2.imread(out_path) out.write(im) # Delete temporary image if requested. if cleanup: os.remove(out_path) # Finalize video. out.release() def write_image(nuim: NuImages, sd_token: str, mode: str, out_path: str) -> None: """ Render a single image of type mode for the given sample_data. :param nuim: NuImages instance. :param sd_token: The sample_data token. :param mode: The mode - see render_images(). :param out_path: The file to write the image to. """ if mode == 'annotated': nuim.render_image(sd_token, annotation_type='all', out_path=out_path) elif mode == 'image': nuim.render_image(sd_token, annotation_type='none', out_path=out_path) elif mode == 'trajectory': sample_data = nuim.get('sample_data', sd_token) nuim.render_trajectory(sample_data['sample_token'], out_path=out_path) else: raise Exception('Error: Unknown mode %s!' % mode) # Trigger garbage collection to avoid memory overflow from the render functions. gc.collect() if __name__ == '__main__': parser = argparse.ArgumentParser(description='Render a random selection of images and save them to disk.') parser.add_argument('--seed', type=int, default=42) # Set to 0 to disable. parser.add_argument('--version', type=str, default='v1.0-mini') parser.add_argument('--dataroot', type=str, default='/data/sets/nuimages') parser.add_argument('--verbose', type=int, default=1) parser.add_argument('--mode', type=str, default='all') parser.add_argument('--cam_name', type=str, default=None) parser.add_argument('--log_name', type=str, default=None) parser.add_argument('--sample_limit', type=int, default=50) parser.add_argument('--filter_categories', action='append') parser.add_argument('--out_type', type=str, default='image') parser.add_argument('--out_dir', type=str, default='~/Downloads/nuImages') args = parser.parse_args() # Set random seed for reproducible image selection. if args.seed != 0: random.seed(args.seed) # Initialize NuImages class. nuim_ = NuImages(version=args.version, dataroot=args.dataroot, verbose=bool(args.verbose), lazy=False) # Render images. render_images(nuim_, mode=args.mode, cam_name=args.cam_name, log_name=args.log_name, sample_limit=args.sample_limit, filter_categories=args.filter_categories, out_type=args.out_type, out_dir=args.out_dir)
[ "random.shuffle", "argparse.ArgumentParser", "os.makedirs", "tqdm.tqdm", "os.path.join", "random.seed", "cv2.VideoWriter", "os.path.isdir", "cv2.VideoWriter_fourcc", "gc.collect", "cv2.imread", "os.path.expanduser", "os.remove" ]
[((2879, 2906), 'os.path.expanduser', 'os.path.expanduser', (['out_dir'], {}), '(out_dir)\n', (2897, 2906), False, 'import os\n'), ((4761, 4790), 'random.shuffle', 'random.shuffle', (['sample_tokens'], {}), '(sample_tokens)\n', (4775, 4790), False, 'import random\n'), ((4979, 5003), 'tqdm.tqdm', 'tqdm.tqdm', (['sample_tokens'], {}), '(sample_tokens)\n', (4988, 5003), False, 'import tqdm\n'), ((6899, 6923), 'cv2.imread', 'cv2.imread', (['out_paths[0]'], {}), '(out_paths[0])\n', (6909, 6923), False, 'import cv2\n'), ((6977, 7008), 'cv2.VideoWriter_fourcc', 'cv2.VideoWriter_fourcc', (["*'MJPG'"], {}), "(*'MJPG')\n", (6999, 7008), False, 'import cv2\n'), ((7063, 7127), 'cv2.VideoWriter', 'cv2.VideoWriter', (['video_path', 'fourcc', 'freq', 'first_im.shape[1::-1]'], {}), '(video_path, fourcc, freq, first_im.shape[1::-1])\n', (7078, 7127), False, 'import cv2\n'), ((8284, 8296), 'gc.collect', 'gc.collect', ([], {}), '()\n', (8294, 8296), False, 'import gc\n'), ((8339, 8441), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ([], {'description': '"""Render a random selection of images and save them to disk."""'}), "(description=\n 'Render a random selection of images and save them to disk.')\n", (8362, 8441), False, 'import argparse\n'), ((2918, 2940), 'os.path.isdir', 'os.path.isdir', (['out_dir'], {}), '(out_dir)\n', (2931, 2940), False, 'import os\n'), ((2950, 2970), 'os.makedirs', 'os.makedirs', (['out_dir'], {}), '(out_dir)\n', (2961, 2970), False, 'import os\n'), ((7217, 7237), 'cv2.imread', 'cv2.imread', (['out_path'], {}), '(out_path)\n', (7227, 7237), False, 'import cv2\n'), ((9296, 9318), 'random.seed', 'random.seed', (['args.seed'], {}), '(args.seed)\n', (9307, 9318), False, 'import random\n'), ((5692, 5782), 'os.path.join', 'os.path.join', (['out_dir', "('%s_%s_%s_%s' % (log_name, sample_token, sample_cam_name, mode))"], {}), "(out_dir, '%s_%s_%s_%s' % (log_name, sample_token,\n sample_cam_name, mode))\n", (5704, 5782), False, 'import os\n'), ((7340, 7359), 'os.remove', 'os.remove', (['out_path'], {}), '(out_path)\n', (7349, 7359), False, 'import os\n')]
import os import sys cwd = os.getcwd() sys.path.append(cwd) import pickle import numpy as np import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj tasks = [ 'com_pos', 'com_vel', 'chassis_quat', 'chassis_ang_vel', 'toeFL_pos', 'toeFL_vel', 'toeFR_pos', 'toeFR_vel', 'toeRR_pos', 'toeRR_vel', 'toeRL_pos', 'toeRL_vel' ] weights = [ 'w_com', 'w_chassis_ori', 'w_toeFL', 'w_toeFR', 'w_toeRR', 'w_toeRL' ] rf_z = ['rf_z_max_toeFL', 'rf_z_max_toeFR', 'rf_z_max_toeRR', 'rf_z_max_toeRL'] time = [] phase = [] rf_cmd = [] des, act = dict(), dict() for topic in tasks: des[topic] = [] act[topic] = [] w = dict() for topic in weights: w[topic] = [] rf_z_max = dict() for topic in rf_z: rf_z_max[topic] = [] with open('data/pnc.pkl', 'rb') as file: while True: try: d = pickle.load(file) time.append(d['time']) phase.append(d['phase']) for topic in tasks: des[topic].append(d[topic + '_des']) act[topic].append(d[topic]) for topic in weights: w[topic].append(d[topic]) for topic in rf_z: rf_z_max[topic].append(d[topic]) rf_cmd.append(d['rf_cmd']) except EOFError: break for k, v in des.items(): des[k] = np.stack(v, axis=0) for k, v in act.items(): act[k] = np.stack(v, axis=0) rf_cmd = np.stack(rf_cmd, axis=0) phase = np.stack(phase, axis=0) ## ============================================================================= ## Plot Task ## ============================================================================= plot_task(time, des['com_pos'], act['com_pos'], des['com_vel'], act['com_vel'], phase, 'com lin') plot_task(time, des['chassis_quat'], act['chassis_quat'], des['chassis_ang_vel'], act['chassis_ang_vel'], phase, 'pelvis ori') plot_task(time, des['toeFL_pos'], act['toeFL_pos'], des['toeFL_vel'], act['toeFL_vel'], phase, 'left foot lin') plot_task(time, des['toeFR_pos'], act['toeFR_pos'], des['toeFR_vel'], act['toeFR_vel'], phase, 'left foot ori') plot_task(time, des['toeRR_pos'], act['toeRR_pos'], des['toeRR_vel'], act['toeRR_vel'], phase, 'right foot lin') plot_task(time, des['toeRL_pos'], act['toeRL_pos'], des['toeRL_vel'], act['toeRL_vel'], phase, 'right foot ori') ## ============================================================================= ## Plot WBC Solutions ## ============================================================================= plot_rf_quad(time, rf_cmd, phase) ## ============================================================================= ## Plot Weights and Max Reaction Force Z ## ============================================================================= plot_weights(time, w, phase) plot_rf_z_max(time, rf_z_max, phase) plt.show()
[ "matplotlib.use", "plot.helper.plot_rf_z_max", "pickle.load", "os.getcwd", "numpy.stack", "plot.helper.plot_weights", "plot.helper.plot_task", "sys.path.append", "plot.helper.plot_rf_quad", "matplotlib.pyplot.show" ]
[((27, 38), 'os.getcwd', 'os.getcwd', ([], {}), '()\n', (36, 38), False, 'import os\n'), ((39, 59), 'sys.path.append', 'sys.path.append', (['cwd'], {}), '(cwd)\n', (54, 59), False, 'import sys\n'), ((112, 135), 'matplotlib.use', 'matplotlib.use', (['"""TkAgg"""'], {}), "('TkAgg')\n", (126, 135), False, 'import matplotlib\n'), ((1524, 1548), 'numpy.stack', 'np.stack', (['rf_cmd'], {'axis': '(0)'}), '(rf_cmd, axis=0)\n', (1532, 1548), True, 'import numpy as np\n'), ((1557, 1580), 'numpy.stack', 'np.stack', (['phase'], {'axis': '(0)'}), '(phase, axis=0)\n', (1565, 1580), True, 'import numpy as np\n'), ((1758, 1860), 'plot.helper.plot_task', 'plot_task', (['time', "des['com_pos']", "act['com_pos']", "des['com_vel']", "act['com_vel']", 'phase', '"""com lin"""'], {}), "(time, des['com_pos'], act['com_pos'], des['com_vel'], act[\n 'com_vel'], phase, 'com lin')\n", (1767, 1860), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((1867, 1998), 'plot.helper.plot_task', 'plot_task', (['time', "des['chassis_quat']", "act['chassis_quat']", "des['chassis_ang_vel']", "act['chassis_ang_vel']", 'phase', '"""pelvis ori"""'], {}), "(time, des['chassis_quat'], act['chassis_quat'], des[\n 'chassis_ang_vel'], act['chassis_ang_vel'], phase, 'pelvis ori')\n", (1876, 1998), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2005, 2121), 'plot.helper.plot_task', 'plot_task', (['time', "des['toeFL_pos']", "act['toeFL_pos']", "des['toeFL_vel']", "act['toeFL_vel']", 'phase', '"""left foot lin"""'], {}), "(time, des['toeFL_pos'], act['toeFL_pos'], des['toeFL_vel'], act[\n 'toeFL_vel'], phase, 'left foot lin')\n", (2014, 2121), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2128, 2244), 'plot.helper.plot_task', 'plot_task', (['time', "des['toeFR_pos']", "act['toeFR_pos']", "des['toeFR_vel']", "act['toeFR_vel']", 'phase', '"""left foot ori"""'], {}), "(time, des['toeFR_pos'], act['toeFR_pos'], des['toeFR_vel'], act[\n 'toeFR_vel'], phase, 'left foot ori')\n", (2137, 2244), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2251, 2368), 'plot.helper.plot_task', 'plot_task', (['time', "des['toeRR_pos']", "act['toeRR_pos']", "des['toeRR_vel']", "act['toeRR_vel']", 'phase', '"""right foot lin"""'], {}), "(time, des['toeRR_pos'], act['toeRR_pos'], des['toeRR_vel'], act[\n 'toeRR_vel'], phase, 'right foot lin')\n", (2260, 2368), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2375, 2492), 'plot.helper.plot_task', 'plot_task', (['time', "des['toeRL_pos']", "act['toeRL_pos']", "des['toeRL_vel']", "act['toeRL_vel']", 'phase', '"""right foot ori"""'], {}), "(time, des['toeRL_pos'], act['toeRL_pos'], des['toeRL_vel'], act[\n 'toeRL_vel'], phase, 'right foot ori')\n", (2384, 2492), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2683, 2716), 'plot.helper.plot_rf_quad', 'plot_rf_quad', (['time', 'rf_cmd', 'phase'], {}), '(time, rf_cmd, phase)\n', (2695, 2716), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2921, 2949), 'plot.helper.plot_weights', 'plot_weights', (['time', 'w', 'phase'], {}), '(time, w, phase)\n', (2933, 2949), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2951, 2987), 'plot.helper.plot_rf_z_max', 'plot_rf_z_max', (['time', 'rf_z_max', 'phase'], {}), '(time, rf_z_max, phase)\n', (2964, 2987), False, 'from plot.helper import plot_task, plot_weights, plot_rf_z_max, plot_rf_quad, plot_vector_traj\n'), ((2989, 2999), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (2997, 2999), True, 'import matplotlib.pyplot as plt\n'), ((1437, 1456), 'numpy.stack', 'np.stack', (['v'], {'axis': '(0)'}), '(v, axis=0)\n', (1445, 1456), True, 'import numpy as np\n'), ((1495, 1514), 'numpy.stack', 'np.stack', (['v'], {'axis': '(0)'}), '(v, axis=0)\n', (1503, 1514), True, 'import numpy as np\n'), ((941, 958), 'pickle.load', 'pickle.load', (['file'], {}), '(file)\n', (952, 958), False, 'import pickle\n')]
from pyramid.httpexceptions import HTTPConflict from h.auth.util import client_authority from h.presenters import TrustedUserJSONPresenter from h.schemas import ValidationError from h.schemas.api.user import CreateUserAPISchema, UpdateUserAPISchema from h.services.user_unique import DuplicateUserError from h.views.api.config import api_config from h.views.api.exceptions import PayloadError @api_config( versions=["v1", "v2"], route_name="api.user_read", request_method="GET", link_name="user.read", description="Fetch a user", permission="read", ) def read(context, _request): """ Fetch a user. This API endpoint allows authorized clients (those able to provide a valid Client ID and Client Secret) to read users in their authority. """ return TrustedUserJSONPresenter(context.user).asdict() @api_config( versions=["v1", "v2"], route_name="api.users", request_method="POST", link_name="user.create", description="Create a new user", permission="create", ) def create(request): """ Create a user. This API endpoint allows authorised clients (those able to provide a valid Client ID and Client Secret) to create users in their authority. These users are created pre-activated, and are unable to log in to the web service directly. Note: the authority-enforcement logic herein is, by necessity, strange. The API accepts an ``authority`` parameter but the only valid value for the param is the client's verified authority. If the param does not match the client's authority, ``ValidationError`` is raised. :raises ValidationError: if ``authority`` param does not match client authority :raises HTTPConflict: if user already exists """ client_authority_ = client_authority(request) schema = CreateUserAPISchema() appstruct = schema.validate(_json_payload(request)) # Enforce authority match if appstruct["authority"] != client_authority_: raise ValidationError( "authority '{auth_param}' does not match client authority".format( auth_param=appstruct["authority"] ) ) user_unique_service = request.find_service(name="user_unique") try: user_unique_service.ensure_unique(appstruct, authority=client_authority_) except DuplicateUserError as err: raise HTTPConflict(str(err)) from err user_signup_service = request.find_service(name="user_signup") user = user_signup_service.signup(require_activation=False, **appstruct) presenter = TrustedUserJSONPresenter(user) return presenter.asdict() @api_config( versions=["v1", "v2"], route_name="api.user", request_method="PATCH", link_name="user.update", description="Update a user", permission="update", ) def update(user, request): """ Update a user. This API endpoint allows authorised clients (those able to provide a valid Client ID and Client Secret) to update users in their authority. """ schema = UpdateUserAPISchema() appstruct = schema.validate(_json_payload(request)) user_update_service = request.find_service(name="user_update") user = user_update_service.update(user, **appstruct) presenter = TrustedUserJSONPresenter(user) return presenter.asdict() def _json_payload(request): try: return request.json_body except ValueError as err: raise PayloadError() from err
[ "h.views.api.exceptions.PayloadError", "h.views.api.config.api_config", "h.schemas.api.user.CreateUserAPISchema", "h.presenters.TrustedUserJSONPresenter", "h.auth.util.client_authority", "h.schemas.api.user.UpdateUserAPISchema" ]
[((397, 558), 'h.views.api.config.api_config', 'api_config', ([], {'versions': "['v1', 'v2']", 'route_name': '"""api.user_read"""', 'request_method': '"""GET"""', 'link_name': '"""user.read"""', 'description': '"""Fetch a user"""', 'permission': '"""read"""'}), "(versions=['v1', 'v2'], route_name='api.user_read',\n request_method='GET', link_name='user.read', description='Fetch a user',\n permission='read')\n", (407, 558), False, 'from h.views.api.config import api_config\n'), ((850, 1018), 'h.views.api.config.api_config', 'api_config', ([], {'versions': "['v1', 'v2']", 'route_name': '"""api.users"""', 'request_method': '"""POST"""', 'link_name': '"""user.create"""', 'description': '"""Create a new user"""', 'permission': '"""create"""'}), "(versions=['v1', 'v2'], route_name='api.users', request_method=\n 'POST', link_name='user.create', description='Create a new user',\n permission='create')\n", (860, 1018), False, 'from h.views.api.config import api_config\n'), ((2676, 2840), 'h.views.api.config.api_config', 'api_config', ([], {'versions': "['v1', 'v2']", 'route_name': '"""api.user"""', 'request_method': '"""PATCH"""', 'link_name': '"""user.update"""', 'description': '"""Update a user"""', 'permission': '"""update"""'}), "(versions=['v1', 'v2'], route_name='api.user', request_method=\n 'PATCH', link_name='user.update', description='Update a user',\n permission='update')\n", (2686, 2840), False, 'from h.views.api.config import api_config\n'), ((1823, 1848), 'h.auth.util.client_authority', 'client_authority', (['request'], {}), '(request)\n', (1839, 1848), False, 'from h.auth.util import client_authority\n'), ((1862, 1883), 'h.schemas.api.user.CreateUserAPISchema', 'CreateUserAPISchema', ([], {}), '()\n', (1881, 1883), False, 'from h.schemas.api.user import CreateUserAPISchema, UpdateUserAPISchema\n'), ((2612, 2642), 'h.presenters.TrustedUserJSONPresenter', 'TrustedUserJSONPresenter', (['user'], {}), '(user)\n', (2636, 2642), False, 'from h.presenters import TrustedUserJSONPresenter\n'), ((3083, 3104), 'h.schemas.api.user.UpdateUserAPISchema', 'UpdateUserAPISchema', ([], {}), '()\n', (3102, 3104), False, 'from h.schemas.api.user import CreateUserAPISchema, UpdateUserAPISchema\n'), ((3303, 3333), 'h.presenters.TrustedUserJSONPresenter', 'TrustedUserJSONPresenter', (['user'], {}), '(user)\n', (3327, 3333), False, 'from h.presenters import TrustedUserJSONPresenter\n'), ((799, 837), 'h.presenters.TrustedUserJSONPresenter', 'TrustedUserJSONPresenter', (['context.user'], {}), '(context.user)\n', (823, 837), False, 'from h.presenters import TrustedUserJSONPresenter\n'), ((3480, 3494), 'h.views.api.exceptions.PayloadError', 'PayloadError', ([], {}), '()\n', (3492, 3494), False, 'from h.views.api.exceptions import PayloadError\n')]
import tkinter as tk from presentacion.formulario import FormularioPersona def centrar_ventana(ventana): aplicacion_ancho = 550 aplicacion_largo = 650 pantall_ancho = ventana.winfo_screenwidth() pantall_largo = ventana.winfo_screenheight() x = int((pantall_ancho/2) - (aplicacion_ancho/2)) y = int((pantall_largo/2) - (aplicacion_largo/2)) return ventana.geometry(f"{aplicacion_ancho}x{aplicacion_largo}+{x}+{y}") try: ventana=tk.Tk() centrar_ventana(ventana) ventana.title("Formulario") form = FormularioPersona(ventana) ventana.mainloop() except Exception as e: print("Existe un error : ", e)
[ "presentacion.formulario.FormularioPersona", "tkinter.Tk" ]
[((466, 473), 'tkinter.Tk', 'tk.Tk', ([], {}), '()\n', (471, 473), True, 'import tkinter as tk\n'), ((581, 607), 'presentacion.formulario.FormularioPersona', 'FormularioPersona', (['ventana'], {}), '(ventana)\n', (598, 607), False, 'from presentacion.formulario import FormularioPersona\n')]
from django.urls import path from .views import teams_all, team_vote urlpatterns = [ path('teams/all', teams_all, name="teams_all"), path('teams/<int:pk>', team_vote, name="team_vote"), ]
[ "django.urls.path" ]
[((90, 136), 'django.urls.path', 'path', (['"""teams/all"""', 'teams_all'], {'name': '"""teams_all"""'}), "('teams/all', teams_all, name='teams_all')\n", (94, 136), False, 'from django.urls import path\n'), ((142, 193), 'django.urls.path', 'path', (['"""teams/<int:pk>"""', 'team_vote'], {'name': '"""team_vote"""'}), "('teams/<int:pk>', team_vote, name='team_vote')\n", (146, 193), False, 'from django.urls import path\n')]
from Dataset import * from Network import * from Functions import * import os from fastai.distributed import * import argparse import torch try: #from apex.parallel import DistributedDataParallel as DDP from apex.fp16_utils import * from apex import amp, optimizers from apex.multi_tensor_apply import multi_tensor_applier except ImportError: raise ImportError("Please install apex from https://www.github.com/nvidia/apex to run this example.") from tqdm import tqdm def get_args(): parser = argparse.ArgumentParser() parser.add_argument('--gpu_id', type=str, default='0,1', help='which gpu to use') parser.add_argument('--path', type=str, default='/N/u/soodn/Carbonate/hubmap-kidney-segmentation', help='path of csv file with DNA sequences and labels') parser.add_argument('--epochs', type=int, default=32, help='number of epochs to train') parser.add_argument('--batch_size', type=int, default=64, help='size of each batch during training') parser.add_argument('--weight_decay', type=float, default=1e-5, help='weight dacay used in optimizer') parser.add_argument('--save_freq', type=int, default=1, help='saving checkpoints per save_freq epochs') parser.add_argument('--dropout', type=float, default=.1, help='transformer dropout') parser.add_argument('--lr', type=float, default=1e-3, help='learning rate') parser.add_argument('--nfolds', type=int, default=4, help='number of cross validation folds') parser.add_argument('--fold', type=int, default=0, help='which fold to train') parser.add_argument('--val_freq', type=int, default=1, help='which fold to train') parser.add_argument('--workers', type=int, default=8, help='number of workers for dataloader') parser.add_argument('--expansion', type=int, default=64, help='number of expansion pixels') parser.add_argument('--gradient_accumulation_steps', type=int, default=1, help='gradient_accumulation_steps') parser.add_argument('--transfer', default=1, help='transfer learning activated') opts = parser.parse_args() return opts opts=get_args() #set up gpu os.environ["CUDA_VISIBLE_DEVICES"] = opts.gpu_id device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') os.system('mkdir models') os.system('mkdir logs') #dice = Dice_th_pred(np.arange(0.2,0.7,0.01)) #datasets and dataloaders dataset = HuBMAPDataset(path=opts.path, fold=opts.fold, nfolds=opts.nfolds, train=True, tfms=get_aug()) val_dataset = HuBMAPDataset(path=opts.path, fold=opts.fold, nfolds=opts.nfolds, train=False) dataloader = DataLoader(dataset, batch_size=opts.batch_size, shuffle=True, num_workers=opts.workers, drop_last=True) val_dataloader = DataLoader(val_dataset, batch_size=opts.batch_size, shuffle=False, num_workers=opts.workers, drop_last=True) #model and optimizer model = UneXt50().cuda() #optimizer = Ranger(model.parameters(), lr=opts.lr, weight_decay=opts.weight_decay) optimizer = torch.optim.Adam(model.parameters(), lr=opts.lr, weight_decay=opts.weight_decay) # scheduler = torch.optim.lr_scheduler.OneCycleLR(optimizer=optimizer, pct_start=0.1, div_factor=1e3, # max_lr=1e-3, epochs=opts.epochs, steps_per_epoch=len(dataloader)) criterion=nn.BCEWithLogitsLoss() opt_level = 'O1' model, optimizer = amp.initialize(model, optimizer, opt_level=opt_level) model = nn.DataParallel(model) ####### Transfer learning ####### if opts.transfer == 1: best_model_path = "models_scratch/fold4.pth" state_dict = torch.load(best_model_path) model.load_state_dict(state_dict) #some more things logger=CSVLogger(['epoch','train_loss','val_loss','dice_coef'],f"logs/log_fold{opts.fold}.csv") metric=Dice_soft() best_metric=0 #training scheduler=torch.optim.lr_scheduler.OneCycleLR(optimizer=optimizer, pct_start=0.2, div_factor=1e2, max_lr=1e-4, epochs=opts.epochs, steps_per_epoch=len(dataloader)) for epoch in range(opts.epochs): train_loss=0 model.train(True) for data in tqdm(dataloader): img=data['img'].to(device) mask=data['mask'].to(device) img=cutout(img) output=model(img) loss=criterion(output,mask) with amp.scale_loss(loss, optimizer) as scaled_loss: scaled_loss.backward() torch.nn.utils.clip_grad_norm_(model.parameters(), 1) #if step%opts.gradient_accumulation_steps==0: optimizer.step() scheduler.step() optimizer.zero_grad() train_loss+=loss.item() #break train_loss/=len(dataloader) print(f"### validating for epoch {epoch} ###") val_loss=0 model.eval() metric.reset() with torch.no_grad(): for data in tqdm(val_dataloader): if img.shape[0]%2!=0: img=img[:-1] mask=mask[:-1] img=data['img'].to(device) mask=data['mask'].to(device) shape=img.shape output=model(img)[:,:,opts.expansion//2:-opts.expansion//2,opts.expansion//2:-opts.expansion//2] output[output != output] = 0 mask=mask[:,:,opts.expansion//2:-opts.expansion//2,opts.expansion//2:-opts.expansion//2] metric.accumulate(output.detach(), mask) loss=criterion(output,mask) val_loss+=loss.item() val_loss/=len(val_dataloader) metric_this_epoch=metric.value # metric_this_epoch=val_loss logger.log([epoch+1,train_loss,val_loss,metric_this_epoch]) if metric_this_epoch>best_metric: torch.save(model.state_dict(),f'models/fold{opts.fold}.pth') best_metric=metric_this_epoch
[ "apex.amp.scale_loss", "argparse.ArgumentParser", "torch.load", "tqdm.tqdm", "torch.no_grad", "apex.amp.initialize", "torch.cuda.is_available", "os.system" ]
[((2228, 2253), 'os.system', 'os.system', (['"""mkdir models"""'], {}), "('mkdir models')\n", (2237, 2253), False, 'import os\n'), ((2254, 2277), 'os.system', 'os.system', (['"""mkdir logs"""'], {}), "('mkdir logs')\n", (2263, 2277), False, 'import os\n'), ((3298, 3351), 'apex.amp.initialize', 'amp.initialize', (['model', 'optimizer'], {'opt_level': 'opt_level'}), '(model, optimizer, opt_level=opt_level)\n', (3312, 3351), False, 'from apex import amp, optimizers\n'), ((517, 542), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ([], {}), '()\n', (540, 542), False, 'import argparse\n'), ((3507, 3534), 'torch.load', 'torch.load', (['best_model_path'], {}), '(best_model_path)\n', (3517, 3534), False, 'import torch\n'), ((3984, 4000), 'tqdm.tqdm', 'tqdm', (['dataloader'], {}), '(dataloader)\n', (3988, 4000), False, 'from tqdm import tqdm\n'), ((2190, 2215), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (2213, 2215), False, 'import torch\n'), ((4645, 4660), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (4658, 4660), False, 'import torch\n'), ((4682, 4702), 'tqdm.tqdm', 'tqdm', (['val_dataloader'], {}), '(val_dataloader)\n', (4686, 4702), False, 'from tqdm import tqdm\n'), ((4174, 4205), 'apex.amp.scale_loss', 'amp.scale_loss', (['loss', 'optimizer'], {}), '(loss, optimizer)\n', (4188, 4205), False, 'from apex import amp, optimizers\n')]
""" NODE model definition and experiment setup. Neural Oblivious Decision Ensembles for Deep Learning on Tabular Data https://arxiv.org/abs/1909.06312 Model details: https://pytorch-tabular.readthedocs.io/en/latest/models/#nodemodel """ import logging import os.path import shutil from sklearn.metrics import classification_report from omegaconf import OmegaConf import optuna from optuna.samplers import TPESampler from pytorch_tabular import TabularModel from pytorch_tabular.models import NodeConfig from pytorch_tabular.config import ( DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig) from pytorch_tabular.utils import get_class_weighted_cross_entropy from optuna_utils import OptunaExperiments, run_experiments LOGGER = logging.getLogger(__name__) LABEL_COL = "retweet_label" # updated by train.py before running config = OmegaConf.create( {"max_epochs": 50, "lr_exp_min": -4, "lr_exp_max": -3, "alpha_exp_min": -4, "alpha_exp_max": -3, "batch_exp_min": 7, "batch_exp_max": 8, "num_trees_min": 512, "num_trees_max": 2560, "num_trees_step": 512, "depth_min": 4, "depth_max": 6, "categorical_cols": [ "entities.urls", "entities.media", "user_in_net", "has_covid_keyword", "user.followers_isna", "users_mention_isna", "following_users_isna", "users_reply_isna"], "exp_log_freq": 100, "seed": 1, "num_workers": 24, "embed_categorical": True} ) class Experiments(OptunaExperiments): def __init__( self, train_data, val_data, train_labels, val_labels, experiment_root, config): self.train_data_joined = train_data.copy() self.train_data_joined[LABEL_COL] = train_labels self.val_data_joined = val_data.copy() self.val_data_joined[LABEL_COL] = val_labels self.experiment_root = experiment_root self.config = config self.study = self.create_study() self.best_score = None self.cat_col_names = config.categorical_cols self.num_col_names = [ c for c in train_data.columns if c not in config.categorical_cols] self.data_config = DataConfig( target=[LABEL_COL], continuous_cols=self.num_col_names, categorical_cols=self.cat_col_names, normalize_continuous_features=False, num_workers=config.num_workers) self.weighted_loss = get_class_weighted_cross_entropy( train_labels.values.ravel(), mu=0.1) def create_study(self): sampler = TPESampler(seed=self.config.study_seed) study = optuna.create_study(sampler=sampler, direction="maximize") for trial_dict in self.config.default_trials: study.enqueue_trial(trial_dict) return study def optimize(self): self.study.optimize(self.objective, n_trials=self.config.n_trials) self.store_study() def objective(self, trial): lr_exp = trial.suggest_int( "lr_exp", self.config.lr_exp_min, self.config.lr_exp_max) lr = 10 ** lr_exp alpha_exp = trial.suggest_int( "alpha_exp", self.config.alpha_exp_min, self.config.alpha_exp_max) alpha = 10 ** alpha_exp batch_exp = trial.suggest_int( "batch_exp", self.config.batch_exp_min, self.config.batch_exp_max) batch_size = 2 ** batch_exp num_trees = trial.suggest_int( "num_trees", self.config.num_trees_min, self.config.num_trees_max, self.config.num_trees_step ) depth = trial.suggest_int( "depth", self.config.depth_min, self.config.depth_max) experiment_path = self.config.experiment_root checkpoints_path = os.path.join(experiment_path, "checkpoints") tb_logs = os.path.join(experiment_path, "tb_logs") run_name = "category_embedding" # store all just for the current optuna run if os.path.exists(checkpoints_path): shutil.rmtree(checkpoints_path) if os.path.exists(tb_logs): shutil.rmtree(tb_logs) trainer_config = TrainerConfig( auto_lr_find=False, gpus=1, deterministic=True, batch_size=batch_size, max_epochs=self.config.max_epochs, checkpoints_path=checkpoints_path, ) optimizer_config = OptimizerConfig( optimizer="AdamW", optimizer_params={"weight_decay": alpha} ) model_config = NodeConfig( task="classification", learning_rate=lr, loss=self.weighted_loss, num_trees=num_trees, depth=depth, embed_categorical=self.config.embed_categorical, ) experiment_config = ExperimentConfig( project_name=tb_logs, run_name=run_name, exp_log_freq=self.config.exp_log_freq ) tabular_model = TabularModel( data_config=self.data_config, model_config=model_config, optimizer_config=optimizer_config, trainer_config=trainer_config, experiment_config=experiment_config ) tabular_model.fit( train=self.train_data_joined, validation=self.val_data_joined, seed=self.config.seed, loss=self.weighted_loss) result = tabular_model.evaluate(self.val_data_joined) LOGGER.info(result) pred_df = tabular_model.predict(self.val_data_joined) val_predictions = pred_df.prediction.values out = classification_report( self.val_data_joined[LABEL_COL].values, val_predictions, digits=3, output_dict=True) LOGGER.info(out) f1 = out["macro avg"]["f1-score"] if self.best_score is None or f1 > self.best_score: self.best_score = f1 self.store_results(tabular_model, out) self.store_study() return f1 def run(config): run_experiments( config=config, experiments_class=Experiments)
[ "logging.getLogger", "pytorch_tabular.models.NodeConfig", "pytorch_tabular.config.OptimizerConfig", "sklearn.metrics.classification_report", "optuna_utils.run_experiments", "pytorch_tabular.config.ExperimentConfig", "pytorch_tabular.config.TrainerConfig", "shutil.rmtree", "optuna.samplers.TPESampler...
[((749, 776), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (766, 776), False, 'import logging\n'), ((852, 1394), 'omegaconf.OmegaConf.create', 'OmegaConf.create', (["{'max_epochs': 50, 'lr_exp_min': -4, 'lr_exp_max': -3, 'alpha_exp_min': -4,\n 'alpha_exp_max': -3, 'batch_exp_min': 7, 'batch_exp_max': 8,\n 'num_trees_min': 512, 'num_trees_max': 2560, 'num_trees_step': 512,\n 'depth_min': 4, 'depth_max': 6, 'categorical_cols': ['entities.urls',\n 'entities.media', 'user_in_net', 'has_covid_keyword',\n 'user.followers_isna', 'users_mention_isna', 'following_users_isna',\n 'users_reply_isna'], 'exp_log_freq': 100, 'seed': 1, 'num_workers': 24,\n 'embed_categorical': True}"], {}), "({'max_epochs': 50, 'lr_exp_min': -4, 'lr_exp_max': -3,\n 'alpha_exp_min': -4, 'alpha_exp_max': -3, 'batch_exp_min': 7,\n 'batch_exp_max': 8, 'num_trees_min': 512, 'num_trees_max': 2560,\n 'num_trees_step': 512, 'depth_min': 4, 'depth_max': 6,\n 'categorical_cols': ['entities.urls', 'entities.media', 'user_in_net',\n 'has_covid_keyword', 'user.followers_isna', 'users_mention_isna',\n 'following_users_isna', 'users_reply_isna'], 'exp_log_freq': 100,\n 'seed': 1, 'num_workers': 24, 'embed_categorical': True})\n", (868, 1394), False, 'from omegaconf import OmegaConf\n'), ((6141, 6202), 'optuna_utils.run_experiments', 'run_experiments', ([], {'config': 'config', 'experiments_class': 'Experiments'}), '(config=config, experiments_class=Experiments)\n', (6156, 6202), False, 'from optuna_utils import OptunaExperiments, run_experiments\n'), ((2263, 2444), 'pytorch_tabular.config.DataConfig', 'DataConfig', ([], {'target': '[LABEL_COL]', 'continuous_cols': 'self.num_col_names', 'categorical_cols': 'self.cat_col_names', 'normalize_continuous_features': '(False)', 'num_workers': 'config.num_workers'}), '(target=[LABEL_COL], continuous_cols=self.num_col_names,\n categorical_cols=self.cat_col_names, normalize_continuous_features=\n False, num_workers=config.num_workers)\n', (2273, 2444), False, 'from pytorch_tabular.config import DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig\n'), ((2657, 2696), 'optuna.samplers.TPESampler', 'TPESampler', ([], {'seed': 'self.config.study_seed'}), '(seed=self.config.study_seed)\n', (2667, 2696), False, 'from optuna.samplers import TPESampler\n'), ((2713, 2771), 'optuna.create_study', 'optuna.create_study', ([], {'sampler': 'sampler', 'direction': '"""maximize"""'}), "(sampler=sampler, direction='maximize')\n", (2732, 2771), False, 'import optuna\n'), ((4233, 4397), 'pytorch_tabular.config.TrainerConfig', 'TrainerConfig', ([], {'auto_lr_find': '(False)', 'gpus': '(1)', 'deterministic': '(True)', 'batch_size': 'batch_size', 'max_epochs': 'self.config.max_epochs', 'checkpoints_path': 'checkpoints_path'}), '(auto_lr_find=False, gpus=1, deterministic=True, batch_size=\n batch_size, max_epochs=self.config.max_epochs, checkpoints_path=\n checkpoints_path)\n', (4246, 4397), False, 'from pytorch_tabular.config import DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig\n'), ((4499, 4575), 'pytorch_tabular.config.OptimizerConfig', 'OptimizerConfig', ([], {'optimizer': '"""AdamW"""', 'optimizer_params': "{'weight_decay': alpha}"}), "(optimizer='AdamW', optimizer_params={'weight_decay': alpha})\n", (4514, 4575), False, 'from pytorch_tabular.config import DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig\n'), ((4634, 4802), 'pytorch_tabular.models.NodeConfig', 'NodeConfig', ([], {'task': '"""classification"""', 'learning_rate': 'lr', 'loss': 'self.weighted_loss', 'num_trees': 'num_trees', 'depth': 'depth', 'embed_categorical': 'self.config.embed_categorical'}), "(task='classification', learning_rate=lr, loss=self.weighted_loss,\n num_trees=num_trees, depth=depth, embed_categorical=self.config.\n embed_categorical)\n", (4644, 4802), False, 'from pytorch_tabular.models import NodeConfig\n'), ((4906, 5007), 'pytorch_tabular.config.ExperimentConfig', 'ExperimentConfig', ([], {'project_name': 'tb_logs', 'run_name': 'run_name', 'exp_log_freq': 'self.config.exp_log_freq'}), '(project_name=tb_logs, run_name=run_name, exp_log_freq=self\n .config.exp_log_freq)\n', (4922, 5007), False, 'from pytorch_tabular.config import DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig\n'), ((5074, 5254), 'pytorch_tabular.TabularModel', 'TabularModel', ([], {'data_config': 'self.data_config', 'model_config': 'model_config', 'optimizer_config': 'optimizer_config', 'trainer_config': 'trainer_config', 'experiment_config': 'experiment_config'}), '(data_config=self.data_config, model_config=model_config,\n optimizer_config=optimizer_config, trainer_config=trainer_config,\n experiment_config=experiment_config)\n', (5086, 5254), False, 'from pytorch_tabular import TabularModel\n'), ((5724, 5834), 'sklearn.metrics.classification_report', 'classification_report', (['self.val_data_joined[LABEL_COL].values', 'val_predictions'], {'digits': '(3)', 'output_dict': '(True)'}), '(self.val_data_joined[LABEL_COL].values,\n val_predictions, digits=3, output_dict=True)\n', (5745, 5834), False, 'from sklearn.metrics import classification_report\n'), ((4104, 4135), 'shutil.rmtree', 'shutil.rmtree', (['checkpoints_path'], {}), '(checkpoints_path)\n', (4117, 4135), False, 'import shutil\n'), ((4184, 4206), 'shutil.rmtree', 'shutil.rmtree', (['tb_logs'], {}), '(tb_logs)\n', (4197, 4206), False, 'import shutil\n')]
from django.db import models from django.core.urlresolvers import reverse from djnfusion import server, key from django.conf import settings from jsonfield import JSONField # TODO: change to this. Currently doesnt work. may have something to do with # the server not in __init__ # from packages.providers.infusionsoft import server, key from .managers import InfusionsoftTagManager, PackagePurchaseManager from packages.managers import PackageManager def remove_unused(_dict): return_dict = {} for _key, _value in _dict.iteritems(): if _value: return_dict[_key] = _value return return_dict def setdictattrs(obj, _dict): _dict = remove_unused(_dict) for _key, _value in _dict.iteritems(): setattr(obj, _key, _value) class Package(models.Model): """ Base for package classes """ name = models.CharField(max_length=255) courses = models.ManyToManyField("courses.Course", null=True, blank=True) lessons = models.ManyToManyField("lessons.Lesson", null=True, blank=True) groups = models.ManyToManyField("facebook_groups.FacebookGroup", null=True, blank=True) journals = models.ManyToManyField("journals.JournalQuestion", null=True, blank=True) objects = PackageManager() def __unicode__(self): return u'{}'.format(self.name if self.name else 'Package') def get_absolute_url(self): return reverse('packages:detail', kwargs={'pk': self.pk}) class PackagePurchase(models.Model): """ User's purchased packages. """ INACTIVE = 0 ACTIVE = 1 EXPIRED = 2 STATUS_CHOICES = [ [INACTIVE, 'Inactive'], [ACTIVE, 'Active'], [EXPIRED, 'Expired'], ] user = models.ForeignKey(settings.AUTH_USER_MODEL) package = models.ForeignKey('Package') status = models.IntegerField(choices=STATUS_CHOICES, default=INACTIVE) data = JSONField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = PackagePurchaseManager() def __unicode__(self): return u'{0} => {1}'.format(self.user, self.package) def set_status(self, status): self.status = status self.save() class InfusionsoftPackage(Package): """ Package with infusionsoft api hooks """ subscription_id = models.TextField(blank=True, null=True) product_id = models.TextField(blank=True, null=True) cycle = models.TextField(blank=True, null=True) frequency = models.TextField(blank=True, null=True) pre_authorize_amount = models.TextField(blank=True, null=True) prorate = models.TextField(blank=True, null=True) active = models.TextField(blank=True, null=True) plan_price = models.TextField(blank=True, null=True) product_price = models.TextField(blank=True, null=True) description = models.TextField(blank=True, null=True) status = models.TextField(blank=True, null=True) action_set_id = models.TextField(blank=True, null=True) tag = models.OneToOneField("InfusionsoftTag", blank=True, null=True) purchase_url = models.URLField(blank=True, null=True) def save(self, *args, **kwargs): sync_data = self._get_sync_data(product_id=self.product_id) if self.product_id else None if sync_data: setdictattrs(self, sync_data) return super(InfusionsoftPackage, self).save(*args, **kwargs) def sync(self): sync_data = self._get_sync_data() if sync_data: setdictattrs(self, sync_data) self.save() def _get_sync_data(self, product_id=None): subscription_data = self._get_subscription_data(product_id) product_data = self._get_product_data(product_id) if subscription_data and product_data: package_data = dict({ "id": self.id, "pk": self.pk, "action_set_id": self.action_set_id, "name": product_data.get("ProductName"), "subscription_id": subscription_data.get("Id"), "product_id": subscription_data.get("ProductId"), "cycle": subscription_data.get("Cycle"), "frequency": subscription_data.get("Frequency"), "prorate": subscription_data.get("Prorate"), "active": subscription_data.get("Active"), "plan_price": subscription_data.get("PlanPrice"), "product_price": product_data.get("ProductPrice"), "description": product_data.get("Description"), "status": product_data.get("Status"), }) elif product_data: # product but not subscription package_data = dict({ "id": self.id, "pk": self.pk, "action_set_id": self.action_set_id, "name": product_data.get("ProductName"), "product_id": product_data.get("Id"), "product_price": product_data.get("ProductPrice"), "description": product_data.get("Description"), "status": product_data.get("Status"), }) return package_data if package_data else None def _get_subscription_data(self, product_id=None): product_id = product_id if product_id else self.product_id if product_id: results = server.DataService.findByField(key, "SubscriptionPlan", 10, 0, "productid", product_id, ["Id", "ProductId", "Cycle", "Frequency", "PreAuthorizeAmount", "Prorate", "Active", "PlanPrice"]); return results[0] if len(results) else None def _get_product_data(self, product_id=None): product_id = product_id if product_id else self.product_id if product_id: results = server.DataService.findByField(key, "Product", 10, 0, "id", product_id, ["Id", "ProductName", "ProductPrice", "Description", "Status", "IsPackage"]); return results[0] if len(results) else None def cancel_subscription(self, contactId, actionSetId): results = server.ContactService.runActionSequence(key, contactId, actionSetId) return results @property def price(self): return self.plan_price if self.plan_price else self.product_price class InfusionsoftTag(models.Model): ''' Infusionsoft Tag (ContactGroup) ''' remote_id = models.TextField() group_category_id = models.TextField(blank=True, null=True) group_name = models.TextField(blank=True, null=True) group_description = models.TextField(blank=True, null=True) objects = InfusionsoftTagManager() def __unicode__(self): return u'{}'.format(self.group_name if self.group_name else u'InfusionsoftTag Object') def save(self, *args, **kwargs): remote_id = kwargs.get('remote_id') if kwargs.get('remote_id') else self.remote_id sync_data = self._get_sync_data(remote_id=remote_id) if remote_id else None if sync_data: obj = InfusionsoftTag(**sync_data) return super(InfusionsoftTag, obj).save(*args, **kwargs) else: return super(InfusionsoftTag, self).save(*args, **kwargs) def sync(self): sync_data = self._get_sync_data() if sync_data: self = InfusionsoftTag(**sync_data) self.save() def _get_sync_data(self, remote_id=None): provider_data = self._get_provider_data(remote_id) if provider_data: tag_data = dict({ "id": self.id, "pk": self.pk, "remote_id": provider_data.get("Id"), "group_category_id": provider_data.get("GroupCategoryId"), "group_name": provider_data.get("GroupName"), "group_description": provider_data.get("GroupDescription"), }) return tag_data def _get_provider_data(self, remote_id=None): remote_id = remote_id if remote_id else self.remote_id if remote_id: results = server.DataService.findByField(key, "ContactGroup", 10, 0, "id", remote_id, ["Id", "GroupCategoryId", "GroupName", "GroupDescription"]); return results[0] if len(results) else None
[ "djnfusion.server.ContactService.runActionSequence", "django.db.models.OneToOneField", "django.db.models.TextField", "django.db.models.IntegerField", "django.db.models.ForeignKey", "django.db.models.ManyToManyField", "django.core.urlresolvers.reverse", "packages.managers.PackageManager", "djnfusion....
[((856, 888), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(255)'}), '(max_length=255)\n', (872, 888), False, 'from django.db import models\n'), ((903, 966), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""courses.Course"""'], {'null': '(True)', 'blank': '(True)'}), "('courses.Course', null=True, blank=True)\n", (925, 966), False, 'from django.db import models\n'), ((981, 1044), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""lessons.Lesson"""'], {'null': '(True)', 'blank': '(True)'}), "('lessons.Lesson', null=True, blank=True)\n", (1003, 1044), False, 'from django.db import models\n'), ((1058, 1136), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""facebook_groups.FacebookGroup"""'], {'null': '(True)', 'blank': '(True)'}), "('facebook_groups.FacebookGroup', null=True, blank=True)\n", (1080, 1136), False, 'from django.db import models\n'), ((1188, 1261), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['"""journals.JournalQuestion"""'], {'null': '(True)', 'blank': '(True)'}), "('journals.JournalQuestion', null=True, blank=True)\n", (1210, 1261), False, 'from django.db import models\n'), ((1315, 1331), 'packages.managers.PackageManager', 'PackageManager', ([], {}), '()\n', (1329, 1331), False, 'from packages.managers import PackageManager\n'), ((1851, 1894), 'django.db.models.ForeignKey', 'models.ForeignKey', (['settings.AUTH_USER_MODEL'], {}), '(settings.AUTH_USER_MODEL)\n', (1868, 1894), False, 'from django.db import models\n'), ((1909, 1937), 'django.db.models.ForeignKey', 'models.ForeignKey', (['"""Package"""'], {}), "('Package')\n", (1926, 1937), False, 'from django.db import models\n'), ((1951, 2012), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'choices': 'STATUS_CHOICES', 'default': 'INACTIVE'}), '(choices=STATUS_CHOICES, default=INACTIVE)\n', (1970, 2012), False, 'from django.db import models\n'), ((2024, 2056), 'jsonfield.JSONField', 'JSONField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2033, 2056), False, 'from jsonfield import JSONField\n'), ((2074, 2113), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (2094, 2113), False, 'from django.db import models\n'), ((2131, 2166), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now': '(True)'}), '(auto_now=True)\n', (2151, 2166), False, 'from django.db import models\n'), ((2496, 2535), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2512, 2535), False, 'from django.db import models\n'), ((2553, 2592), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2569, 2592), False, 'from django.db import models\n'), ((2605, 2644), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2621, 2644), False, 'from django.db import models\n'), ((2661, 2700), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2677, 2700), False, 'from django.db import models\n'), ((2728, 2767), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2744, 2767), False, 'from django.db import models\n'), ((2782, 2821), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2798, 2821), False, 'from django.db import models\n'), ((2835, 2874), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2851, 2874), False, 'from django.db import models\n'), ((2892, 2931), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2908, 2931), False, 'from django.db import models\n'), ((2952, 2991), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (2968, 2991), False, 'from django.db import models\n'), ((3010, 3049), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (3026, 3049), False, 'from django.db import models\n'), ((3063, 3102), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (3079, 3102), False, 'from django.db import models\n'), ((3123, 3162), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (3139, 3162), False, 'from django.db import models\n'), ((3173, 3235), 'django.db.models.OneToOneField', 'models.OneToOneField', (['"""InfusionsoftTag"""'], {'blank': '(True)', 'null': '(True)'}), "('InfusionsoftTag', blank=True, null=True)\n", (3193, 3235), False, 'from django.db import models\n'), ((3255, 3293), 'django.db.models.URLField', 'models.URLField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (3270, 3293), False, 'from django.db import models\n'), ((6690, 6708), 'django.db.models.TextField', 'models.TextField', ([], {}), '()\n', (6706, 6708), False, 'from django.db import models\n'), ((6733, 6772), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (6749, 6772), False, 'from django.db import models\n'), ((6790, 6829), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (6806, 6829), False, 'from django.db import models\n'), ((6854, 6893), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (6870, 6893), False, 'from django.db import models\n'), ((1475, 1525), 'django.core.urlresolvers.reverse', 'reverse', (['"""packages:detail"""'], {'kwargs': "{'pk': self.pk}"}), "('packages:detail', kwargs={'pk': self.pk})\n", (1482, 1525), False, 'from django.core.urlresolvers import reverse\n'), ((6323, 6391), 'djnfusion.server.ContactService.runActionSequence', 'server.ContactService.runActionSequence', (['key', 'contactId', 'actionSetId'], {}), '(key, contactId, actionSetId)\n', (6362, 6391), False, 'from djnfusion import server, key\n'), ((5536, 5730), 'djnfusion.server.DataService.findByField', 'server.DataService.findByField', (['key', '"""SubscriptionPlan"""', '(10)', '(0)', '"""productid"""', 'product_id', "['Id', 'ProductId', 'Cycle', 'Frequency', 'PreAuthorizeAmount', 'Prorate',\n 'Active', 'PlanPrice']"], {}), "(key, 'SubscriptionPlan', 10, 0, 'productid',\n product_id, ['Id', 'ProductId', 'Cycle', 'Frequency',\n 'PreAuthorizeAmount', 'Prorate', 'Active', 'PlanPrice'])\n", (5566, 5730), False, 'from djnfusion import server, key\n'), ((5991, 6144), 'djnfusion.server.DataService.findByField', 'server.DataService.findByField', (['key', '"""Product"""', '(10)', '(0)', '"""id"""', 'product_id', "['Id', 'ProductName', 'ProductPrice', 'Description', 'Status', 'IsPackage']"], {}), "(key, 'Product', 10, 0, 'id', product_id, [\n 'Id', 'ProductName', 'ProductPrice', 'Description', 'Status', 'IsPackage'])\n", (6021, 6144), False, 'from djnfusion import server, key\n'), ((8345, 8484), 'djnfusion.server.DataService.findByField', 'server.DataService.findByField', (['key', '"""ContactGroup"""', '(10)', '(0)', '"""id"""', 'remote_id', "['Id', 'GroupCategoryId', 'GroupName', 'GroupDescription']"], {}), "(key, 'ContactGroup', 10, 0, 'id', remote_id,\n ['Id', 'GroupCategoryId', 'GroupName', 'GroupDescription'])\n", (8375, 8484), False, 'from djnfusion import server, key\n')]
import numpy as np import matplotlib.pyplot as plt from tqdm import trange class CFG: n = 10 mean = 0.0 variance = 1.0 t = 1000 esp = [0, 0.01, 0.05, 0.1, 0.15, 0.2] n_try = 2000 class bandit(): def __init__(self, m, v): self.m = m self.v = v self.mean = 0.0 self.cnt = 0 def reset(self): self.mean = 0.0 self.cnt = 0 def get_reward(self): reward = self.v * np.random.randn() + self.m return reward def update(self, reward): self.cnt += 1 self.mean = self.mean + 1/self.cnt * (reward - self.mean) def get_result(e): bandits = [bandit(np.random.randn(),CFG.variance) for i in range(CFG.n)] res = [] global cnt for _ in range(CFG.t): if (np.random.random()<e): choose = np.random.choice(CFG.n) else: choose = np.argmax([ban.mean for ban in bandits]) val = bandits[choose].get_reward() res.append(val) bandits[choose].update(val) # print(res) return res plt.figure(figsize=(20, 10)) for e in CFG.esp: res = np.zeros(CFG.t) for tr in trange(CFG.n_try): res += get_result(e) print(res.shape) res /= CFG.n_try # print(res) plt.plot(res, label = e) print(f'done {e}') plt.xlabel('step') plt.ylabel('average reward') plt.legend() plt.savefig('figure_2_1.png') plt.show()
[ "matplotlib.pyplot.savefig", "matplotlib.pyplot.ylabel", "numpy.random.random", "numpy.random.choice", "matplotlib.pyplot.xlabel", "matplotlib.pyplot.plot", "numpy.argmax", "matplotlib.pyplot.figure", "numpy.zeros", "numpy.random.randn", "tqdm.trange", "matplotlib.pyplot.legend", "matplotlib...
[((1088, 1116), 'matplotlib.pyplot.figure', 'plt.figure', ([], {'figsize': '(20, 10)'}), '(figsize=(20, 10))\n', (1098, 1116), True, 'import matplotlib.pyplot as plt\n'), ((1336, 1354), 'matplotlib.pyplot.xlabel', 'plt.xlabel', (['"""step"""'], {}), "('step')\n", (1346, 1354), True, 'import matplotlib.pyplot as plt\n'), ((1355, 1383), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""average reward"""'], {}), "('average reward')\n", (1365, 1383), True, 'import matplotlib.pyplot as plt\n'), ((1384, 1396), 'matplotlib.pyplot.legend', 'plt.legend', ([], {}), '()\n', (1394, 1396), True, 'import matplotlib.pyplot as plt\n'), ((1397, 1426), 'matplotlib.pyplot.savefig', 'plt.savefig', (['"""figure_2_1.png"""'], {}), "('figure_2_1.png')\n", (1408, 1426), True, 'import matplotlib.pyplot as plt\n'), ((1427, 1437), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (1435, 1437), True, 'import matplotlib.pyplot as plt\n'), ((1146, 1161), 'numpy.zeros', 'np.zeros', (['CFG.t'], {}), '(CFG.t)\n', (1154, 1161), True, 'import numpy as np\n'), ((1176, 1193), 'tqdm.trange', 'trange', (['CFG.n_try'], {}), '(CFG.n_try)\n', (1182, 1193), False, 'from tqdm import trange\n'), ((1287, 1309), 'matplotlib.pyplot.plot', 'plt.plot', (['res'], {'label': 'e'}), '(res, label=e)\n', (1295, 1309), True, 'import matplotlib.pyplot as plt\n'), ((671, 688), 'numpy.random.randn', 'np.random.randn', ([], {}), '()\n', (686, 688), True, 'import numpy as np\n'), ((794, 812), 'numpy.random.random', 'np.random.random', ([], {}), '()\n', (810, 812), True, 'import numpy as np\n'), ((838, 861), 'numpy.random.choice', 'np.random.choice', (['CFG.n'], {}), '(CFG.n)\n', (854, 861), True, 'import numpy as np\n'), ((897, 937), 'numpy.argmax', 'np.argmax', (['[ban.mean for ban in bandits]'], {}), '([ban.mean for ban in bandits])\n', (906, 937), True, 'import numpy as np\n'), ((460, 477), 'numpy.random.randn', 'np.random.randn', ([], {}), '()\n', (475, 477), True, 'import numpy as np\n')]
from dataclasses import dataclass from .base import _MiscOptionBase from application.src.misc.sampling import PurposesOfSampling @dataclass class Editor(_MiscOptionBase): name = "Purpose of sampling" id = "purpose_of_sampling" link = "misc_bp.submit_purpose_of_sampling" description = "The reason the sample was collected " \ "<em>e.g. diagnostic testing</em>" @classmethod def get_values(cls) -> list: return PurposesOfSampling.fetch_list() @classmethod def save(cls, data: list) -> None: PurposesOfSampling.save_by_procedure(data)
[ "application.src.misc.sampling.PurposesOfSampling.fetch_list", "application.src.misc.sampling.PurposesOfSampling.save_by_procedure" ]
[((454, 485), 'application.src.misc.sampling.PurposesOfSampling.fetch_list', 'PurposesOfSampling.fetch_list', ([], {}), '()\n', (483, 485), False, 'from application.src.misc.sampling import PurposesOfSampling\n'), ((552, 594), 'application.src.misc.sampling.PurposesOfSampling.save_by_procedure', 'PurposesOfSampling.save_by_procedure', (['data'], {}), '(data)\n', (588, 594), False, 'from application.src.misc.sampling import PurposesOfSampling\n')]
from rest_framework import status from rest_framework.authentication import SessionAuthentication, BasicAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.views import APIView from apprest.plugins.icat.helpers.complex_encoder import JsonResponse from apprest.plugins.icat.services.ICAT import ICATService class GetInvestigationUsers(APIView): """ get: Return: Users involved in an investigation """ authentication_classes = (SessionAuthentication, BasicAuthentication) permission_classes = (IsAuthenticated,) pagination_class = None def get(self, request, *args, **kwargs): service = ICATService() investigation_id = self.kwargs.get('investigation_id') investigation_users = service.get_users_involved_in_investigation(investigation_id, request) return JsonResponse(investigation_users, status=status.HTTP_200_OK)
[ "apprest.plugins.icat.helpers.complex_encoder.JsonResponse", "apprest.plugins.icat.services.ICAT.ICATService" ]
[((669, 682), 'apprest.plugins.icat.services.ICAT.ICATService', 'ICATService', ([], {}), '()\n', (680, 682), False, 'from apprest.plugins.icat.services.ICAT import ICATService\n'), ((863, 923), 'apprest.plugins.icat.helpers.complex_encoder.JsonResponse', 'JsonResponse', (['investigation_users'], {'status': 'status.HTTP_200_OK'}), '(investigation_users, status=status.HTTP_200_OK)\n', (875, 923), False, 'from apprest.plugins.icat.helpers.complex_encoder import JsonResponse\n')]
import unittest from table_tests.utils import BaseTestNoFlushTable from evaluator.hashtable8 import NO_FLUSH_8 class TestNoFlush8Table(BaseTestNoFlushTable): TOCOMPARE = NO_FLUSH_8 TABLE = [0] * len(TOCOMPARE) VISIT = [0] * len(TOCOMPARE) NUM_CARDS = 8 def test_noflush8_table(self): self.assertListEqual(self.TABLE, self.TOCOMPARE) if __name__ == "__main__": unittest.main()
[ "unittest.main" ]
[((380, 395), 'unittest.main', 'unittest.main', ([], {}), '()\n', (393, 395), False, 'import unittest\n')]
''' Leetcode problem No 862 Shortest Subarray with Sum at Least K Solution written by <NAME> on 1 July, 2018 ''' import collections class Solution(object): def shortestSubarray(self, A, K): """ :type A: List[int] :type K: int :rtype: int """ n = len(A) B = [0] * (n + 1) for i in range(n): B[i+1] = B[i] + A[i] d = collections.deque() ans = n + 1 for i in range(n+1): while d and B[i] - B[d[0]] >= K: ans = min(ans, i-d.popleft()) while d and B[i] <= B[d[-1]]: d.pop() d.append(i) return ans if ans <= n else -1 def main(): s = Solution() print(s.shortestSubarray([2,-1,2], 3)) print(s.shortestSubarray([1,2], 4)) print(s.shortestSubarray([1], 1)) print(s.shortestSubarray([1,2,3,-5,4,-7,5,-8,6,-9,7,8,-4], 5)) #1 print(s.shortestSubarray([1,2,-5,3,-5,4,-7,5,-8,6,-9,7,8,-4], 5)) main()
[ "collections.deque" ]
[((403, 422), 'collections.deque', 'collections.deque', ([], {}), '()\n', (420, 422), False, 'import collections\n')]
# coding=utf-8 import logging import random import string import sys import unittest from time import time, sleep import apiritif import os import re from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, TimeoutException from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import Select from selenium.webdriver.support import expected_conditions as econd from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.keys import Keys from bzt.resources.selenium_extras import waiter, get_locator class TestSc1(unittest.TestCase): def setUp(self): self.vars = {} timeout = 2.0 options = webdriver.FirefoxOptions() profile = webdriver.FirefoxProfile() profile.set_preference('webdriver.log.file', '/somewhere/webdriver.log') options.set_capability('unhandledPromptBehavior', 'ignore') self.driver = webdriver.Firefox(profile, options=options) self.driver.implicitly_wait(timeout) apiritif.put_into_thread_store(timeout=timeout, func_mode=False, driver=self.driver, windows={}, scenario_name='sc1') def _1_httpsblazedemocomsetup1(self): with apiritif.smart_transaction('https://blazedemo.com/setup1'): self.driver.get('https://blazedemo.com/setup1') def _2_setup2(self): with apiritif.smart_transaction('setup2'): self.driver.get('https://blazedemo.com/setup2') waiter() def _3_httpsblazedemocommain1(self): with apiritif.smart_transaction('https://blazedemo.com/main1'): self.driver.get('https://blazedemo.com/main1') def _4_main2(self): with apiritif.smart_transaction('main2'): self.driver.get('https://blazedemo.com/main2') waiter() def _5_httpsblazedemocomteardown1(self): with apiritif.smart_transaction('https://blazedemo.com/teardown1'): self.driver.get('https://blazedemo.com/teardown1') def _6_teardown2(self): with apiritif.smart_transaction('teardown2'): self.driver.get('https://blazedemo.com/teardown2') waiter() def test_sc1(self): try: self._1_httpsblazedemocomsetup1() self._2_setup2() self._3_httpsblazedemocommain1() self._4_main2() finally: apiritif.set_stage("teardown") # can't be interrupted self._5_httpsblazedemocomteardown1() self._6_teardown2() def tearDown(self): if self.driver: self.driver.quit()
[ "apiritif.put_into_thread_store", "selenium.webdriver.Firefox", "apiritif.set_stage", "apiritif.smart_transaction", "selenium.webdriver.FirefoxOptions", "bzt.resources.selenium_extras.waiter", "selenium.webdriver.FirefoxProfile" ]
[((779, 805), 'selenium.webdriver.FirefoxOptions', 'webdriver.FirefoxOptions', ([], {}), '()\n', (803, 805), False, 'from selenium import webdriver\n'), ((824, 850), 'selenium.webdriver.FirefoxProfile', 'webdriver.FirefoxProfile', ([], {}), '()\n', (848, 850), False, 'from selenium import webdriver\n'), ((1022, 1065), 'selenium.webdriver.Firefox', 'webdriver.Firefox', (['profile'], {'options': 'options'}), '(profile, options=options)\n', (1039, 1065), False, 'from selenium import webdriver\n'), ((1119, 1241), 'apiritif.put_into_thread_store', 'apiritif.put_into_thread_store', ([], {'timeout': 'timeout', 'func_mode': '(False)', 'driver': 'self.driver', 'windows': '{}', 'scenario_name': '"""sc1"""'}), "(timeout=timeout, func_mode=False, driver=\n self.driver, windows={}, scenario_name='sc1')\n", (1149, 1241), False, 'import apiritif\n'), ((1333, 1391), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""https://blazedemo.com/setup1"""'], {}), "('https://blazedemo.com/setup1')\n", (1359, 1391), False, 'import apiritif\n'), ((1492, 1528), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""setup2"""'], {}), "('setup2')\n", (1518, 1528), False, 'import apiritif\n'), ((1603, 1611), 'bzt.resources.selenium_extras.waiter', 'waiter', ([], {}), '()\n', (1609, 1611), False, 'from bzt.resources.selenium_extras import waiter, get_locator\n'), ((1667, 1724), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""https://blazedemo.com/main1"""'], {}), "('https://blazedemo.com/main1')\n", (1693, 1724), False, 'import apiritif\n'), ((1823, 1858), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""main2"""'], {}), "('main2')\n", (1849, 1858), False, 'import apiritif\n'), ((1932, 1940), 'bzt.resources.selenium_extras.waiter', 'waiter', ([], {}), '()\n', (1938, 1940), False, 'from bzt.resources.selenium_extras import waiter, get_locator\n'), ((2000, 2061), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""https://blazedemo.com/teardown1"""'], {}), "('https://blazedemo.com/teardown1')\n", (2026, 2061), False, 'import apiritif\n'), ((2168, 2207), 'apiritif.smart_transaction', 'apiritif.smart_transaction', (['"""teardown2"""'], {}), "('teardown2')\n", (2194, 2207), False, 'import apiritif\n'), ((2285, 2293), 'bzt.resources.selenium_extras.waiter', 'waiter', ([], {}), '()\n', (2291, 2293), False, 'from bzt.resources.selenium_extras import waiter, get_locator\n'), ((2509, 2539), 'apiritif.set_stage', 'apiritif.set_stage', (['"""teardown"""'], {}), "('teardown')\n", (2527, 2539), False, 'import apiritif\n')]
__description__ = \ """ Fitter subclass for performing bayesian (MCMC) fits. """ __author__ = "<NAME>" __date__ = "2017-05-10" from .base import Fitter import emcee, corner import numpy as np import scipy.optimize as optimize import multiprocessing class BayesianFitter(Fitter): """ """ def __init__(self,num_walkers=100,initial_walker_spread=1e-4,ml_guess=True, num_steps=100,burn_in=0.1,num_threads=1): """ Initialize the bayesian fitter Parameters ---------- num_walkers : int > 0 how many markov chains to have in the analysis initial_walker_spread : float each walker is initialized with parameters sampled from normal distributions with mean equal to the initial guess and a standard deviation of guess*initial_walker_spread ml_guess : bool if true, do an ML optimization to get the initial guess num_steps: number of steps to run the markov chains burn_in : float between 0 and 1 fraction of samples to discard from the start of the run num_threads : int or `"max"` number of threads to use. if `"max"`, use the total number of cpus. [NOT YET IMPLEMENTED] """ Fitter.__init__(self) self._num_walkers = num_walkers self._initial_walker_spread = initial_walker_spread self._ml_guess = ml_guess self._num_steps = num_steps self._burn_in = burn_in self._num_threads = num_threads if self._num_threads == "max": self._num_threads = multiprocessing.cpu_count() if not type(self._num_threads) == int and self._num_threads > 0: err = "num_threads must be 'max' or a positive integer\n" raise ValueError(err) if self._num_threads != 1: err = "multithreading has not yet been (fully) implemented.\n" raise NotImplementedError(err) self._success = None self.fit_type = "bayesian" def ln_prior(self,param): """ Log prior of fit parameters. Priors are uniform between bounds and set to -np.inf outside of bounds. Parameters ---------- param : array of floats parameters to fit Returns ------- float value for log of priors. """ # If a paramter falls outside of the bounds, make the prior -infinity if np.sum(param < self._bounds[0,:]) > 0 or np.sum(param > self._bounds[1,:]) > 0: return -np.inf # otherwise, uniform return 0.0 def ln_prob(self,param): """ Posterior probability of model parameters. Parameters ---------- param : array of floats parameters to fit Returns ------- float value for log posterior proability """ # Calcualte prior. If not finite, this solution has an -infinity log # likelihood ln_prior = self.ln_prior(param) if not np.isfinite(ln_prior): return -np.inf # Calcualte likelihood. If not finite, this solution has an -infinity # log likelihood ln_like = self.ln_like(param) if not np.isfinite(ln_like): return -np.inf # log posterior is log prior plus log likelihood return ln_prior + ln_like def fit(self,model,parameters,bounds,y_obs,y_err=None,param_names=None): """ Fit the parameters. Parameters ---------- model : callable model to fit. model should take "parameters" as its only argument. this should (usually) be GlobalFit._y_calc parameters : array of floats parameters to be optimized. usually constructed by GlobalFit._prep_fit bounds : list list of two lists containing lower and upper bounds y_obs : array of floats observations in an concatenated array y_err : array of floats or None standard deviation of each observation. if None, each observation is assigned an error of 1/num_obs param_names : array of str names of parameters. If None, parameters assigned names p0,p1,..pN """ self._model = model self._y_obs = y_obs # Convert the bounds (list of lower and upper lists) into a 2d numpy array self._bounds = np.array(bounds) # If no error is specified, assign the error as 1/N, identical for all # points self._y_err = y_err if y_err is None: self._y_err = np.array([1/len(self._y_obs) for i in range(len(self._y_obs))]) if param_names is None: self._param_names = ["p{}".format(i) for i in range(len(parameters))] else: self._param_names = param_names[:] # Make initial guess (ML or just whatever the paramters sent in were) if self._ml_guess: fn = lambda *args: -self.weighted_residuals(*args) ml_fit = optimize.least_squares(fn,x0=parameters,bounds=self._bounds) self._initial_guess = np.copy(ml_fit.x) else: self._initial_guess = np.copy(parameters) # Create walker positions # Size of perturbation in parameter depends on the scale of the parameter perturb_size = self._initial_guess*self._initial_walker_spread ndim = len(parameters) pos = [self._initial_guess + np.random.randn(ndim)*perturb_size for i in range(self._num_walkers)] # Sample using walkers self._fit_result = emcee.EnsembleSampler(self._num_walkers, ndim, self.ln_prob, threads=self._num_threads) self._fit_result.run_mcmc(pos, self._num_steps) # Create list of samples to_discard = int(round(self._burn_in*self._num_steps,0)) self._samples = self._fit_result.chain[:,to_discard:,:].reshape((-1,ndim)) self._lnprob = self._fit_result.lnprobability[:,:].reshape(-1) # Get mean and standard deviation self._estimate = np.mean(self._samples,axis=0) self._stdev = np.std(self._samples,axis=0) # Calculate 95% confidence intervals self._ninetyfive = [] lower = int(round(0.025*self._samples.shape[0],0)) upper = int(round(0.975*self._samples.shape[0],0)) for i in range(self._samples.shape[1]): nf = np.sort(self._samples[:,i]) self._ninetyfive.append([nf[lower],nf[upper]]) self._ninetyfive = np.array(self._ninetyfive) self._success = True @property def fit_info(self): """ Information about the Bayesian run. """ output = {} output["Num walkers"] = self._num_walkers output["Initial walker spread"] = self._initial_walker_spread output["Use ML guess"] = self._ml_guess output["Num steps"] = self._num_steps output["Burn in"] = self._burn_in output["Final sample number"] = len(self._samples[:,0]) output["Num threads"] = self._num_threads return output @property def samples(self): """ Bayesian samples. """ return self._samples
[ "numpy.mean", "numpy.copy", "scipy.optimize.least_squares", "numpy.sort", "multiprocessing.cpu_count", "emcee.EnsembleSampler", "numpy.array", "numpy.sum", "numpy.isfinite", "numpy.std", "numpy.random.randn" ]
[((4549, 4565), 'numpy.array', 'np.array', (['bounds'], {}), '(bounds)\n', (4557, 4565), True, 'import numpy as np\n'), ((5769, 5861), 'emcee.EnsembleSampler', 'emcee.EnsembleSampler', (['self._num_walkers', 'ndim', 'self.ln_prob'], {'threads': 'self._num_threads'}), '(self._num_walkers, ndim, self.ln_prob, threads=self.\n _num_threads)\n', (5790, 5861), False, 'import emcee, corner\n'), ((6284, 6314), 'numpy.mean', 'np.mean', (['self._samples'], {'axis': '(0)'}), '(self._samples, axis=0)\n', (6291, 6314), True, 'import numpy as np\n'), ((6336, 6365), 'numpy.std', 'np.std', (['self._samples'], {'axis': '(0)'}), '(self._samples, axis=0)\n', (6342, 6365), True, 'import numpy as np\n'), ((6739, 6765), 'numpy.array', 'np.array', (['self._ninetyfive'], {}), '(self._ninetyfive)\n', (6747, 6765), True, 'import numpy as np\n'), ((1658, 1685), 'multiprocessing.cpu_count', 'multiprocessing.cpu_count', ([], {}), '()\n', (1683, 1685), False, 'import multiprocessing\n'), ((3126, 3147), 'numpy.isfinite', 'np.isfinite', (['ln_prior'], {}), '(ln_prior)\n', (3137, 3147), True, 'import numpy as np\n'), ((3335, 3355), 'numpy.isfinite', 'np.isfinite', (['ln_like'], {}), '(ln_like)\n', (3346, 3355), True, 'import numpy as np\n'), ((5175, 5237), 'scipy.optimize.least_squares', 'optimize.least_squares', (['fn'], {'x0': 'parameters', 'bounds': 'self._bounds'}), '(fn, x0=parameters, bounds=self._bounds)\n', (5197, 5237), True, 'import scipy.optimize as optimize\n'), ((5270, 5287), 'numpy.copy', 'np.copy', (['ml_fit.x'], {}), '(ml_fit.x)\n', (5277, 5287), True, 'import numpy as np\n'), ((5336, 5355), 'numpy.copy', 'np.copy', (['parameters'], {}), '(parameters)\n', (5343, 5355), True, 'import numpy as np\n'), ((6624, 6652), 'numpy.sort', 'np.sort', (['self._samples[:, i]'], {}), '(self._samples[:, i])\n', (6631, 6652), True, 'import numpy as np\n'), ((2524, 2558), 'numpy.sum', 'np.sum', (['(param < self._bounds[0, :])'], {}), '(param < self._bounds[0, :])\n', (2530, 2558), True, 'import numpy as np\n'), ((2565, 2599), 'numpy.sum', 'np.sum', (['(param > self._bounds[1, :])'], {}), '(param > self._bounds[1, :])\n', (2571, 2599), True, 'import numpy as np\n'), ((5625, 5646), 'numpy.random.randn', 'np.random.randn', (['ndim'], {}), '(ndim)\n', (5640, 5646), True, 'import numpy as np\n')]
# -*- coding: utf-8 -*- # We must always import the relevant libraries for our problem at hand. NumPy and TensorFlow are required for this example. # https://www.kaggle.com/c/costa-rican-household-poverty-prediction/data#_=_ import numpy as np np.set_printoptions(threshold='nan') import matplotlib.pyplot as plt import tensorflow as tf import pandas as pd def toInt(x): if x == 'yes': return 1 else: if x == 'no': return 0 else: return x costa_rica_household = pd.read_csv('data/train.csv') #x1 = costa_rica_household.describe() #x1["v2a1"] costa_rica_household.head() list(costa_rica_household.dtypes) #costa_rica_household = costa_rica_household.fillna(0) costa_rica_household = costa_rica_household.fillna(costa_rica_household.mean()) #costa_rica_household["idhogar"] = costa_rica_household["idhogar"].apply(lambda x: int(x, 16)) #costa_rica_household["dependency"] = costa_rica_household["dependency"].apply(lambda x: toInt(x)) #costa_rica_household["edjefe"] = costa_rica_household["edjefe"].apply(lambda x: toInt(x))//edjefa #costa_rica_household.loc[costa_rica_household['dependency'] == "'<='"] #v1 = costa_rica_household[costa_rica_household['dependency'].apply(lambda x: type(x) == str)]['dependency'] #col_name = costa_rica_household.columns #print(list(col_name)) #costa_rica_household[["age", "SQBage", "agesq", "r4h1", "r4h2"]] cols_to_norm = ['v2a1', 'hacdor', 'rooms', 'hacapo', 'v14a', 'refrig', 'v18q', 'v18q1', 'tamhog', 'tamviv', 'escolari', 'rez_esc', 'hhsize', 'paredblolad', 'paredzocalo', 'paredpreb', 'pareddes', 'paredmad', 'paredzinc', 'paredfibras', 'paredother', 'pisomoscer', 'pisocemento', 'pisoother', 'pisonatur', 'pisonotiene', 'pisomadera', 'techozinc', 'techoentrepiso', 'techocane', 'techootro', 'cielorazo', 'abastaguadentro', 'abastaguafuera', 'abastaguano', 'public', 'planpri', 'noelec', 'coopele', 'sanitario1', 'sanitario2', 'sanitario3', 'sanitario5', 'sanitario6', 'energcocinar1', 'energcocinar2', 'energcocinar3', 'energcocinar4', 'elimbasu1', 'elimbasu2', 'elimbasu3', 'elimbasu4', 'elimbasu5', 'elimbasu6', 'epared1', 'epared2', 'epared3', 'etecho1', 'etecho2', 'etecho3', 'eviv1', 'eviv2', 'eviv3', 'dis', 'male', 'female', 'estadocivil1', 'estadocivil2', 'estadocivil3', 'estadocivil4', 'estadocivil5', 'estadocivil6', 'estadocivil7', 'parentesco1', 'parentesco2', 'parentesco3', 'parentesco4', 'parentesco5', 'parentesco6', 'parentesco7', 'parentesco8', 'parentesco9', 'parentesco10', 'parentesco11', 'parentesco12', 'hogar_nin', 'hogar_adul', 'hogar_mayor', 'hogar_total', 'meaneduc', 'instlevel1', 'instlevel2', 'instlevel3', 'instlevel4', 'instlevel5', 'instlevel6', 'instlevel7', 'instlevel8', 'instlevel9', 'bedrooms', 'overcrowding', 'tipovivi1', 'tipovivi2', 'tipovivi3', 'tipovivi4', 'tipovivi5', 'computer', 'television', 'mobilephone', 'qmobilephone', 'lugar1', 'lugar2', 'lugar3', 'lugar4', 'lugar5', 'lugar6', 'area1', 'area2', 'SQBescolari', 'SQBhogar_total', 'SQBedjefe', 'SQBhogar_nin', 'SQBovercrowding', 'SQBdependency', 'SQBmeaned', 'agesq'] cat_cols_to_norm = ['r4h1', 'r4h2', 'r4h3', 'r4m1', 'r4m2', 'r4m3', 'r4t1', 'r4t2', 'r4t3'] cols_of_interest = ['v2a1', 'hacdor', 'rooms', 'hacapo', 'v14a', 'refrig', 'v18q', 'v18q1', 'r4h1', 'r4h2', 'r4h3', 'r4m1', 'r4m2', 'r4m3', 'r4t1', 'r4t2', 'r4t3', 'tamhog', 'tamviv', 'escolari', 'rez_esc', 'hhsize', 'paredblolad', 'paredzocalo', 'paredpreb', 'pareddes', 'paredmad', 'paredzinc', 'paredfibras', 'paredother', 'pisomoscer', 'pisocemento', 'pisoother', 'pisonatur', 'pisonotiene', 'pisomadera', 'techozinc', 'techoentrepiso', 'techocane', 'techootro', 'cielorazo', 'abastaguadentro', 'abastaguafuera', 'abastaguano', 'public', 'planpri', 'noelec', 'coopele', 'sanitario1', 'sanitario2', 'sanitario3', 'sanitario5', 'sanitario6', 'energcocinar1', 'energcocinar2', 'energcocinar3', 'energcocinar4', 'elimbasu1', 'elimbasu2', 'elimbasu3', 'elimbasu4', 'elimbasu5', 'elimbasu6', 'epared1', 'epared2', 'epared3', 'etecho1', 'etecho2', 'etecho3', 'eviv1', 'eviv2', 'eviv3', 'dis', 'male', 'female', 'estadocivil1', 'estadocivil2', 'estadocivil3', 'estadocivil4', 'estadocivil5', 'estadocivil6', 'estadocivil7', 'parentesco1', 'parentesco2', 'parentesco3', 'parentesco4', 'parentesco5', 'parentesco6', 'parentesco7', 'parentesco8', 'parentesco9', 'parentesco10', 'parentesco11', 'parentesco12', 'hogar_nin', 'hogar_adul', 'hogar_mayor', 'hogar_total', 'meaneduc', 'instlevel1', 'instlevel2', 'instlevel3', 'instlevel4', 'instlevel5', 'instlevel6', 'instlevel7', 'instlevel8', 'instlevel9', 'bedrooms', 'overcrowding', 'tipovivi1', 'tipovivi2', 'tipovivi3', 'tipovivi4', 'tipovivi5', 'computer', 'television', 'mobilephone', 'qmobilephone', 'lugar1', 'lugar2', 'lugar3', 'lugar4', 'lugar5', 'lugar6', 'area1', 'area2', 'SQBescolari', 'SQBhogar_total', 'SQBedjefe', 'SQBhogar_nin', 'SQBovercrowding', 'SQBdependency', 'SQBmeaned', 'agesq'] #costa_rica_household[cols_to_norm] = costa_rica_household[cols_to_norm].apply(lambda x: (x - x.min())/(x.max() - x.min())) #costa_rica_household[cat_cols_to_norm] = costa_rica_household[cat_cols_to_norm].apply(lambda x: (x - x.min())/(x.max() - x.min())) costa_rica_household[cols_of_interest] = costa_rica_household[cols_of_interest].apply(lambda x: (x - x.min())/(x.max() - x.min())) feat_cols = [] for col_name in cols_to_norm: col_name = tf.feature_column.numeric_column(col_name) feat_cols.append(col_name) age_range_count = [1,2,3,4,5,7] r4h1_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4h1'), boundaries=age_range_count) r4h2_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4h2'), boundaries=age_range_count) r4h3_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4h3'), boundaries=age_range_count) crossed_r4h = tf.feature_column.crossed_column([r4h1_bucket, r4h2_bucket, r4h3_bucket], 100) #fc = [r4h1_bucket, r4h2_bucket, r4h3_bucket, crossed_r4h] r4m1_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4m1'), boundaries=age_range_count) r4m2_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4m2'), boundaries=age_range_count) r4m3_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4m3'), boundaries=age_range_count) crossed_r4m = tf.feature_column.crossed_column([r4m1_bucket, r4m2_bucket, r4m3_bucket], 100) r4t1_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4t1'), boundaries=age_range_count) r4t2_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4t2'), boundaries=age_range_count) r4t3_bucket = tf.feature_column.bucketized_column(tf.feature_column.numeric_column('r4t3'), boundaries=age_range_count) crossed_r4t = tf.feature_column.crossed_column([r4t1_bucket, r4t2_bucket, r4t3_bucket], 100) feat_cols.extend([r4h1_bucket, r4h2_bucket, r4h3_bucket, crossed_r4h, r4m1_bucket, r4m2_bucket, r4m3_bucket, crossed_r4m, r4t1_bucket, r4t2_bucket, r4t3_bucket, crossed_r4t]) len(feat_cols) feat_cols[138] estimator = tf.estimator.LinearClassifier(feature_columns=feat_cols, n_classes=4) #costa_rica_household[(costa_rica_household.Target == 4)] x_data = costa_rica_household.drop('Id', axis=1).drop('edjefa', axis=1).drop('idhogar', axis=1).drop('dependency', axis=1).drop('Target', axis=1) #x_data['idhogar'] #x_data.describe() #x_data.head() labels = costa_rica_household['Target'] labels.head() from sklearn.model_selection import train_test_split X_train, X_eval, y_train, y_eval = train_test_split(x_data, labels, test_size=0.3, random_state=101) print(X_train.shape, y_eval.shape) input_func = tf.estimator.inputs.pandas_input_fn(x=X_train, y=y_train, batch_size=10, num_epochs=100, shuffle=True) estimator.train(input_fn=input_func,steps=1000) eval_input_func = tf.estimator.inputs.pandas_input_fn(x=X_eval, y=y_eval, batch_size=10, num_epochs=1, shuffle=False) eval_metrics = estimator.evaluate(input_fn=eval_input_func) print('Eval metrics') print(eval_metrics) pred_input_func = tf.estimator.inputs.pandas_input_fn(x=X_eval, shuffle=False) predictions = [] for predict in estimator.predict(input_fn=pred_input_func): predictions.append(predict) predictions #categorical_columun_voc = tf.feature_column.embedding_column(categorical_columun_voc, 4) dnn_classifier = tf.estimator.DNNClassifier(hidden_units=[10, 10, 10], feature_columns=feat_cols, n_classes=2) dnn_classifier.train(input_fn=input_func,steps=1000) dnn_eval_metrics = dnn_classifier.evaluate(input_fn=eval_input_func) dnn_eval_metrics
[ "tensorflow.feature_column.crossed_column", "tensorflow.estimator.DNNClassifier", "pandas.read_csv", "sklearn.model_selection.train_test_split", "tensorflow.estimator.LinearClassifier", "tensorflow.feature_column.numeric_column", "tensorflow.estimator.inputs.pandas_input_fn", "numpy.set_printoptions" ...
[((245, 281), 'numpy.set_printoptions', 'np.set_printoptions', ([], {'threshold': '"""nan"""'}), "(threshold='nan')\n", (264, 281), True, 'import numpy as np\n'), ((521, 550), 'pandas.read_csv', 'pd.read_csv', (['"""data/train.csv"""'], {}), "('data/train.csv')\n", (532, 550), True, 'import pandas as pd\n'), ((6250, 6328), 'tensorflow.feature_column.crossed_column', 'tf.feature_column.crossed_column', (['[r4h1_bucket, r4h2_bucket, r4h3_bucket]', '(100)'], {}), '([r4h1_bucket, r4h2_bucket, r4h3_bucket], 100)\n', (6282, 6328), True, 'import tensorflow as tf\n'), ((6763, 6841), 'tensorflow.feature_column.crossed_column', 'tf.feature_column.crossed_column', (['[r4m1_bucket, r4m2_bucket, r4m3_bucket]', '(100)'], {}), '([r4m1_bucket, r4m2_bucket, r4m3_bucket], 100)\n', (6795, 6841), True, 'import tensorflow as tf\n'), ((7217, 7295), 'tensorflow.feature_column.crossed_column', 'tf.feature_column.crossed_column', (['[r4t1_bucket, r4t2_bucket, r4t3_bucket]', '(100)'], {}), '([r4t1_bucket, r4t2_bucket, r4t3_bucket], 100)\n', (7249, 7295), True, 'import tensorflow as tf\n'), ((7517, 7586), 'tensorflow.estimator.LinearClassifier', 'tf.estimator.LinearClassifier', ([], {'feature_columns': 'feat_cols', 'n_classes': '(4)'}), '(feature_columns=feat_cols, n_classes=4)\n', (7546, 7586), True, 'import tensorflow as tf\n'), ((7989, 8054), 'sklearn.model_selection.train_test_split', 'train_test_split', (['x_data', 'labels'], {'test_size': '(0.3)', 'random_state': '(101)'}), '(x_data, labels, test_size=0.3, random_state=101)\n', (8005, 8054), False, 'from sklearn.model_selection import train_test_split\n'), ((8104, 8210), 'tensorflow.estimator.inputs.pandas_input_fn', 'tf.estimator.inputs.pandas_input_fn', ([], {'x': 'X_train', 'y': 'y_train', 'batch_size': '(10)', 'num_epochs': '(100)', 'shuffle': '(True)'}), '(x=X_train, y=y_train, batch_size=10,\n num_epochs=100, shuffle=True)\n', (8139, 8210), True, 'import tensorflow as tf\n'), ((8274, 8377), 'tensorflow.estimator.inputs.pandas_input_fn', 'tf.estimator.inputs.pandas_input_fn', ([], {'x': 'X_eval', 'y': 'y_eval', 'batch_size': '(10)', 'num_epochs': '(1)', 'shuffle': '(False)'}), '(x=X_eval, y=y_eval, batch_size=10,\n num_epochs=1, shuffle=False)\n', (8309, 8377), True, 'import tensorflow as tf\n'), ((8498, 8558), 'tensorflow.estimator.inputs.pandas_input_fn', 'tf.estimator.inputs.pandas_input_fn', ([], {'x': 'X_eval', 'shuffle': '(False)'}), '(x=X_eval, shuffle=False)\n', (8533, 8558), True, 'import tensorflow as tf\n'), ((8789, 8887), 'tensorflow.estimator.DNNClassifier', 'tf.estimator.DNNClassifier', ([], {'hidden_units': '[10, 10, 10]', 'feature_columns': 'feat_cols', 'n_classes': '(2)'}), '(hidden_units=[10, 10, 10], feature_columns=\n feat_cols, n_classes=2)\n', (8815, 8887), True, 'import tensorflow as tf\n'), ((5768, 5810), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['col_name'], {}), '(col_name)\n', (5800, 5810), True, 'import tensorflow as tf\n'), ((5926, 5966), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4h1"""'], {}), "('r4h1')\n", (5958, 5966), True, 'import tensorflow as tf\n'), ((6046, 6086), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4h2"""'], {}), "('r4h2')\n", (6078, 6086), True, 'import tensorflow as tf\n'), ((6166, 6206), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4h3"""'], {}), "('r4h3')\n", (6198, 6206), True, 'import tensorflow as tf\n'), ((6439, 6479), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4m1"""'], {}), "('r4m1')\n", (6471, 6479), True, 'import tensorflow as tf\n'), ((6559, 6599), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4m2"""'], {}), "('r4m2')\n", (6591, 6599), True, 'import tensorflow as tf\n'), ((6679, 6719), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4m3"""'], {}), "('r4m3')\n", (6711, 6719), True, 'import tensorflow as tf\n'), ((6893, 6933), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4t1"""'], {}), "('r4t1')\n", (6925, 6933), True, 'import tensorflow as tf\n'), ((7013, 7053), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4t2"""'], {}), "('r4t2')\n", (7045, 7053), True, 'import tensorflow as tf\n'), ((7133, 7173), 'tensorflow.feature_column.numeric_column', 'tf.feature_column.numeric_column', (['"""r4t3"""'], {}), "('r4t3')\n", (7165, 7173), True, 'import tensorflow as tf\n')]
"""JSON implementations of authentication queries.""" # pylint: disable=no-init # Numerous classes don't require __init__. # pylint: disable=too-many-public-methods,too-few-public-methods # Number of methods are defined in specification # pylint: disable=protected-access # Access to protected methods allowed in package json package scope # pylint: disable=too-many-ancestors # Inheritance defined in specification from .. import utilities from ..osid import queries as osid_queries from ..primitives import Id from ..utilities import get_registry from dlkit.abstract_osid.authentication import queries as abc_authentication_queries from dlkit.abstract_osid.osid import errors class AgentQuery(abc_authentication_queries.AgentQuery, osid_queries.OsidObjectQuery): """This is the query for searching agents. Each method specifies an ``AND`` term while multiple invocations of the same method produce a nested ``OR``. The following example returns agents whose display name begins with "Tom" and whose "login name" is "tom" or "tjcoppet" in an agent record specified by ``companyAgentType``. Agent Query query = session.getAgentQuery(); query.matchDisplayName("Tom*", wildcardStringMatchType, true); companyAgentQuery = query.getAgentQueryRecord(companyAgentType); companyAgentQuery.matchLoginName("tom"); companyAgentQuery = query.getAgentQueryRecord(companyAgentType); companyAgentQuery.matchLoginName("tjcoppet"); AgentList agentList = session.getAgentsByQuery(query); """ def __init__(self, runtime): self._namespace = 'authentication.Agent' self._runtime = runtime record_type_data_sets = get_registry('AGENT_RECORD_TYPES', runtime) self._all_supported_record_type_data_sets = record_type_data_sets self._all_supported_record_type_ids = [] for data_set in record_type_data_sets: self._all_supported_record_type_ids.append(str(Id(**record_type_data_sets[data_set]))) osid_queries.OsidObjectQuery.__init__(self, runtime) @utilities.arguments_not_none def match_resource_id(self, agency_id, match): """Sets the resource ``Id`` for this query. arg: agency_id (osid.id.Id): a resource ``Id`` arg: match (boolean): ``true`` for a positive match, ``false`` for a negative match raise: NullArgument - ``agency_id`` is ``null`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceQuery.match_avatar_id self._add_match('resourceId', str(agency_id), match) def clear_resource_id_terms(self): """Clears the resource ``Id`` terms. *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceQuery.clear_avatar_id self._clear_terms('resourceId') resource_id_terms = property(fdel=clear_resource_id_terms) def supports_resource_query(self): """Tests if a ``ResourceQuery`` is available. return: (boolean) - ``true`` if a resource query is available, ``false`` otherwise *compliance: mandatory -- This method must be implemented.* """ raise errors.Unimplemented() def get_resource_query(self): """Gets the query for a resource. Multiple retrievals produce a nested ``OR`` term. return: (osid.resource.ResourceQuery) - the resource query raise: Unimplemented - ``supports_resource_query()`` is ``false`` *compliance: optional -- This method must be implemented if ``supports_resource_query()`` is ``true``.* """ raise errors.Unimplemented() resource_query = property(fget=get_resource_query) @utilities.arguments_not_none def match_any_resource(self, match): """Matches agents with any resource. arg: match (boolean): ``true`` if to match agents with a resource, ``false`` to match agents with no resource *compliance: mandatory -- This method must be implemented.* """ raise errors.Unimplemented() def clear_resource_terms(self): """Clears the resource terms. *compliance: mandatory -- This method must be implemented.* """ raise errors.Unimplemented() resource_terms = property(fdel=clear_resource_terms) @utilities.arguments_not_none def match_agency_id(self, agency_id, match): """Sets the agency ``Id`` for this query. arg: agency_id (osid.id.Id): an agency ``Id`` arg: match (boolean): ``true`` for a positive match, ``false`` for negative match raise: NullArgument - ``agency_id`` is ``null`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceQuery.match_bin_id self._add_match('assignedAgencyIds', str(agency_id), match) def clear_agency_id_terms(self): """Clears the agency ``Id`` terms. *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceQuery.clear_bin_id_terms self._clear_terms('assignedAgencyIds') agency_id_terms = property(fdel=clear_agency_id_terms) def supports_agency_query(self): """Tests if an ``AgencyQuery`` is available. return: (boolean) - ``true`` if an agency query is available, ``false`` otherwise *compliance: mandatory -- This method must be implemented.* """ raise errors.Unimplemented() def get_agency_query(self): """Gets the query for an agency. Multiple retrievals produce a nested ``OR`` term. return: (osid.authentication.AgencyQuery) - the agency query raise: Unimplemented - ``supports_agency_query()`` is ``false`` *compliance: optional -- This method must be implemented if ``supports_agency_query()`` is ``true``.* """ raise errors.Unimplemented() agency_query = property(fget=get_agency_query) def clear_agency_terms(self): """Clears the agency terms. *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceQuery.clear_group_terms self._clear_terms('agency') agency_terms = property(fdel=clear_agency_terms) @utilities.arguments_not_none def get_agent_query_record(self, agent_record_type): """Gets the agent query record corresponding to the given ``Agent`` record ``Type``. Multiple retrievals produce a nested ``OR`` term. arg: agent_record_type (osid.type.Type): an agent record type return: (osid.authentication.records.AgentQueryRecord) - the agent query record raise: NullArgument - ``agent_record_type`` is ``null`` raise: OperationFailed - unable to complete request raise: Unsupported - ``has_record_type(agent_record_type)`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ raise errors.Unimplemented()
[ "dlkit.abstract_osid.osid.errors.Unimplemented" ]
[((3335, 3357), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (3355, 3357), False, 'from dlkit.abstract_osid.osid import errors\n'), ((3800, 3822), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (3820, 3822), False, 'from dlkit.abstract_osid.osid import errors\n'), ((4233, 4255), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (4253, 4255), False, 'from dlkit.abstract_osid.osid import errors\n'), ((4427, 4449), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (4447, 4449), False, 'from dlkit.abstract_osid.osid import errors\n'), ((5746, 5768), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (5766, 5768), False, 'from dlkit.abstract_osid.osid import errors\n'), ((6190, 6212), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (6210, 6212), False, 'from dlkit.abstract_osid.osid import errors\n'), ((7335, 7357), 'dlkit.abstract_osid.osid.errors.Unimplemented', 'errors.Unimplemented', ([], {}), '()\n', (7355, 7357), False, 'from dlkit.abstract_osid.osid import errors\n')]
# Adapted by <NAME>, 2019 # # Based on Detectron.pytorch/lib/roi_data/fast_rcnn.py # Original license text: # -------------------------------------------------------- # Copyright (c) 2017-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## """Construct minibatches for Fast R-CNN training. Handles the minibatch blobs that are specific to Fast R-CNN. Other blobs that are generic to RPN, etc. are handled by their respecitive roi_data modules. """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import numpy as np import numpy.random as npr import logging from core.config import cfg import utils_rel.boxes_rel as box_utils_rel import utils.blob as blob_utils import utils.fpn as fpn_utils logger = logging.getLogger(__name__) def add_rel_blobs(blobs, im_scales, roidb): """Add blobs needed for training Fast R-CNN style models.""" # Sample training RoIs from each image and append them to the blob lists for im_i, entry in enumerate(roidb): frcn_blobs = _sample_pairs(entry, im_scales[im_i], im_i) for k, v in frcn_blobs.items(): blobs[k].append(v) # Concat the training blob lists into tensors for k, v in blobs.items(): if isinstance(v, list) and len(v) > 0: blobs[k] = np.concatenate(v) if cfg.FPN.FPN_ON and cfg.FPN.MULTILEVEL_ROIS: _add_rel_multilevel_rois(blobs) return True def _sample_pairs(roidb, im_scale, batch_idx): """Generate a random sample of RoIs comprising foreground and background examples. """ fg_pairs_per_image = cfg.TRAIN.FG_REL_SIZE_PER_IM pairs_per_image = int(cfg.TRAIN.FG_REL_SIZE_PER_IM / cfg.TRAIN.FG_REL_FRACTION) # need much more pairs since it's quadratic max_pair_overlaps = roidb['max_pair_overlaps'] if cfg.MODEL.MULTI_RELATION: prd_gt_overlaps = roidb['prd_gt_overlaps'].toarray() prd_class_num = prd_gt_overlaps.shape[1] gt_pair_inds, gt_pair_class = np.where(prd_gt_overlaps > 1.0 - 1e-4) fg_pair_inds, fg_pair_class = np.where((prd_gt_overlaps >= cfg.TRAIN.FG_THRESH) & (prd_gt_overlaps <= 1.0 - 1e-4)) hash_gt_pair_inds = prd_class_num * gt_pair_inds + gt_pair_class hash_fg_pair_inds = prd_class_num * fg_pair_inds + fg_pair_class fg_pairs_per_this_image = np.minimum(fg_pairs_per_image, hash_gt_pair_inds.size + hash_fg_pair_inds.size) if hash_fg_pair_inds.size > 0 and fg_pairs_per_this_image > hash_gt_pair_inds.size: hash_fg_pair_inds = npr.choice( hash_fg_pair_inds, size=(fg_pairs_per_this_image - hash_gt_pair_inds.size), replace=False) hash_fg_pair_inds = np.append(hash_fg_pair_inds, hash_gt_pair_inds) elif fg_pairs_per_this_image <= hash_gt_pair_inds.size: hash_gt_pair_inds = npr.choice( hash_gt_pair_inds, size=fg_pairs_per_this_image, replace=False) hash_fg_pair_inds = hash_gt_pair_inds else: hash_fg_pair_inds = hash_gt_pair_inds blob_dict = {} if cfg.MODEL.USE_BG: bg_pair_inds, bg_pair_class_inds = np.where((prd_gt_overlaps < cfg.TRAIN.BG_THRESH_HI)) hash_bg_pair_inds = prd_class_num * bg_pair_inds + bg_pair_class_inds bg_pairs_per_this_image = pairs_per_image - fg_pairs_per_this_image bg_pairs_per_this_image = np.minimum(bg_pairs_per_this_image, hash_bg_pair_inds.size) if hash_bg_pair_inds.size > 0: hash_bg_pair_inds = npr.choice( hash_bg_pair_inds, size=bg_pairs_per_this_image, replace=False) hash_keep_pair_inds = np.append(hash_fg_pair_inds, hash_bg_pair_inds) multi_prd_labels = np.zeros(hash_keep_pair_inds.size, dtype=np.int32) multi_prd_labels[:hash_fg_pair_inds.size] = 1.0 #fg_multi_prd_labels keep_pair_inds = np.append(hash_fg_pair_inds // prd_class_num, hash_bg_pair_inds // prd_class_num) keep_pair_class = np.append(hash_fg_pair_inds % prd_class_num, hash_bg_pair_inds % prd_class_num) else: multi_prd_labels = np.ones(fg_multi_prd_labels.size, dtype=np.int32) #fg_multi_prd_labels keep_pair_inds = np.append(hash_fg_pair_inds // prd_class_num) keep_pair_class = np.append(hash_fg_pair_inds % prd_class_num) blob_dict['multi_prd_labels_int32'] = multi_prd_labels.astype(np.int32, copy=False) blob_dict['keep_pair_class_int32'] = keep_pair_class.astype(np.int32, copy=False) blob_dict['fg_size'] = np.array([hash_fg_pair_inds.size], dtype=np.int32) else: gt_pair_inds = np.where(max_pair_overlaps > 1.0 - 1e-4)[0] fg_pair_inds = np.where((max_pair_overlaps >= cfg.TRAIN.FG_THRESH) & (max_pair_overlaps <= 1.0 - 1e-4))[0] fg_pairs_per_this_image = np.minimum(fg_pairs_per_image, gt_pair_inds.size + fg_pair_inds.size) # Sample foreground regions without replacement if fg_pair_inds.size > 0 and fg_pairs_per_this_image > gt_pair_inds.size: fg_pair_inds = npr.choice( fg_pair_inds, size=(fg_pairs_per_this_image - gt_pair_inds.size), replace=False) fg_pair_inds = np.append(fg_pair_inds, gt_pair_inds) elif fg_pairs_per_this_image <= gt_pair_inds.size: gt_pair_inds = npr.choice( gt_pair_inds, size=fg_pairs_per_this_image, replace=False) fg_pair_inds = gt_pair_inds else: fg_pair_inds = gt_pair_inds # Label is the class each RoI has max overlap with fg_prd_labels = roidb['max_prd_classes'][fg_pair_inds] blob_dict = dict( fg_prd_labels_int32=fg_prd_labels.astype(np.int32, copy=False)) if cfg.MODEL.USE_BG: bg_pair_inds = np.where((max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))[0] # Compute number of background RoIs to take from this image (guarding # against there being fewer than desired) bg_pairs_per_this_image = pairs_per_image - fg_pairs_per_this_image bg_pairs_per_this_image = np.minimum(bg_pairs_per_this_image, bg_pair_inds.size) # Sample foreground regions without replacement if bg_pair_inds.size > 0: bg_pair_inds = npr.choice( bg_pair_inds, size=bg_pairs_per_this_image, replace=False) # logger.info('{} : {}'.format(fg_pair_inds.size, bg_pair_inds.size)) keep_pair_inds = np.append(fg_pair_inds, bg_pair_inds) all_prd_labels = np.zeros(keep_pair_inds.size, dtype=np.int32) all_prd_labels[:fg_pair_inds.size] = fg_prd_labels + 1 # class should start from 1 else: keep_pair_inds = fg_pair_inds all_prd_labels = fg_prd_labels blob_dict['all_prd_labels_int32'] = all_prd_labels.astype(np.int32, copy=False) blob_dict['fg_size'] = np.array([fg_pair_inds.size], dtype=np.int32) # this is used to check if there is at least one fg to learn sampled_sbj_boxes = roidb['sbj_boxes'][keep_pair_inds] sampled_obj_boxes = roidb['obj_boxes'][keep_pair_inds] sampled_all_boxes = roidb['all_boxes'] det_labels = roidb['det_labels'] sampled_sbj_inds = roidb['sbj_id'][keep_pair_inds] sampled_obj_inds = roidb['obj_id'][keep_pair_inds] # Scale rois and format as (batch_idx, x1, y1, x2, y2) sampled_sbj_rois = sampled_sbj_boxes * im_scale sampled_obj_rois = sampled_obj_boxes * im_scale sampled_all_rois = sampled_all_boxes * im_scale repeated_batch_idx = batch_idx * blob_utils.ones((keep_pair_inds.shape[0], 1)) all_boxes_repeated_batch_idx = batch_idx * blob_utils.ones((sampled_all_boxes.shape[0], 1)) sampled_sbj_rois = np.hstack((repeated_batch_idx, sampled_sbj_rois)) sampled_obj_rois = np.hstack((repeated_batch_idx, sampled_obj_rois)) sampled_all_rois = np.hstack((all_boxes_repeated_batch_idx, sampled_all_rois)) int_repeated_batch_idx = batch_idx * np.ones((keep_pair_inds.shape[0], 1), dtype=np.int) blob_dict['sbj_inds'] = np.hstack((repeated_batch_idx, sampled_sbj_inds.reshape(-1, 1))) blob_dict['obj_inds'] = np.hstack((repeated_batch_idx, sampled_obj_inds.reshape(-1, 1))) blob_dict['sbj_rois'] = sampled_sbj_rois blob_dict['obj_rois'] = sampled_obj_rois blob_dict['det_rois'] = sampled_all_rois blob_dict['det_labels'] = det_labels sampled_rel_rois = box_utils_rel.rois_union(sampled_sbj_rois, sampled_obj_rois) blob_dict['rel_rois'] = sampled_rel_rois if cfg.MODEL.USE_SPATIAL_FEAT: sampled_spt_feat = box_utils_rel.get_spt_features( sampled_sbj_boxes, sampled_obj_boxes, roidb['width'], roidb['height']) blob_dict['spt_feat'] = sampled_spt_feat if cfg.MODEL.USE_FREQ_BIAS: sbj_labels = roidb['max_sbj_classes'][keep_pair_inds] obj_labels = roidb['max_obj_classes'][keep_pair_inds] blob_dict['all_sbj_labels_int32'] = sbj_labels.astype(np.int32, copy=False) blob_dict['all_obj_labels_int32'] = obj_labels.astype(np.int32, copy=False) if cfg.MODEL.USE_NODE_CONTRASTIVE_LOSS or cfg.MODEL.USE_NODE_CONTRASTIVE_SO_AWARE_LOSS or cfg.MODEL.USE_NODE_CONTRASTIVE_P_AWARE_LOSS: nodes_per_image = cfg.MODEL.NODE_SAMPLE_SIZE max_sbj_overlaps = roidb['max_sbj_overlaps'] max_obj_overlaps = roidb['max_obj_overlaps'] # sbj # Here a naturally existing assumption is, each positive sbj should have at least one positive obj sbj_pos_pair_pos_inds = np.where((max_pair_overlaps >= cfg.TRAIN.FG_THRESH))[0] sbj_pos_obj_pos_pair_neg_inds = np.where((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))[0] sbj_pos_obj_neg_pair_neg_inds = np.where((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps < cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))[0] if sbj_pos_pair_pos_inds.size > 0: sbj_pos_pair_pos_inds = npr.choice( sbj_pos_pair_pos_inds, size=int(min(nodes_per_image, sbj_pos_pair_pos_inds.size)), replace=False) if sbj_pos_obj_pos_pair_neg_inds.size > 0: sbj_pos_obj_pos_pair_neg_inds = npr.choice( sbj_pos_obj_pos_pair_neg_inds, size=int(min(nodes_per_image, sbj_pos_obj_pos_pair_neg_inds.size)), replace=False) sbj_pos_pair_neg_inds = sbj_pos_obj_pos_pair_neg_inds if nodes_per_image - sbj_pos_obj_pos_pair_neg_inds.size > 0 and sbj_pos_obj_neg_pair_neg_inds.size > 0: sbj_pos_obj_neg_pair_neg_inds = npr.choice( sbj_pos_obj_neg_pair_neg_inds, size=int(min(nodes_per_image - sbj_pos_obj_pos_pair_neg_inds.size, sbj_pos_obj_neg_pair_neg_inds.size)), replace=False) sbj_pos_pair_neg_inds = np.append(sbj_pos_pair_neg_inds, sbj_pos_obj_neg_pair_neg_inds) sbj_pos_inds = np.append(sbj_pos_pair_pos_inds, sbj_pos_pair_neg_inds) binary_labels_sbj_pos = np.zeros(sbj_pos_inds.size, dtype=np.int32) binary_labels_sbj_pos[:sbj_pos_pair_pos_inds.size] = 1 blob_dict['binary_labels_sbj_pos_int32'] = binary_labels_sbj_pos.astype(np.int32, copy=False) prd_pos_labels_sbj_pos = roidb['max_prd_classes'][sbj_pos_pair_pos_inds] prd_labels_sbj_pos = np.zeros(sbj_pos_inds.size, dtype=np.int32) prd_labels_sbj_pos[:sbj_pos_pair_pos_inds.size] = prd_pos_labels_sbj_pos + 1 blob_dict['prd_labels_sbj_pos_int32'] = prd_labels_sbj_pos.astype(np.int32, copy=False) sbj_labels_sbj_pos = roidb['max_sbj_classes'][sbj_pos_inds] + 1 # 1. set all obj labels > 0 obj_labels_sbj_pos = roidb['max_obj_classes'][sbj_pos_inds] + 1 # 2. find those negative obj max_obj_overlaps_sbj_pos = roidb['max_obj_overlaps'][sbj_pos_inds] obj_neg_inds_sbj_pos = np.where(max_obj_overlaps_sbj_pos < cfg.TRAIN.FG_THRESH)[0] obj_labels_sbj_pos[obj_neg_inds_sbj_pos] = 0 blob_dict['sbj_labels_sbj_pos_int32'] = sbj_labels_sbj_pos.astype(np.int32, copy=False) blob_dict['obj_labels_sbj_pos_int32'] = obj_labels_sbj_pos.astype(np.int32, copy=False) # this is for freq bias in RelDN blob_dict['sbj_labels_sbj_pos_fg_int32'] = roidb['max_sbj_classes'][sbj_pos_inds].astype(np.int32, copy=False) blob_dict['obj_labels_sbj_pos_fg_int32'] = roidb['max_obj_classes'][sbj_pos_inds].astype(np.int32, copy=False) sampled_sbj_boxes_sbj_pos = roidb['sbj_boxes'][sbj_pos_inds] sampled_obj_boxes_sbj_pos = roidb['obj_boxes'][sbj_pos_inds] # Scale rois and format as (batch_idx, x1, y1, x2, y2) sampled_sbj_rois_sbj_pos = sampled_sbj_boxes_sbj_pos * im_scale sampled_obj_rois_sbj_pos = sampled_obj_boxes_sbj_pos * im_scale repeated_batch_idx = batch_idx * blob_utils.ones((sbj_pos_inds.shape[0], 1)) sampled_sbj_rois_sbj_pos = np.hstack((repeated_batch_idx, sampled_sbj_rois_sbj_pos)) sampled_obj_rois_sbj_pos = np.hstack((repeated_batch_idx, sampled_obj_rois_sbj_pos)) blob_dict['sbj_rois_sbj_pos'] = sampled_sbj_rois_sbj_pos blob_dict['obj_rois_sbj_pos'] = sampled_obj_rois_sbj_pos sampled_rel_rois_sbj_pos = box_utils_rel.rois_union(sampled_sbj_rois_sbj_pos, sampled_obj_rois_sbj_pos) blob_dict['rel_rois_sbj_pos'] = sampled_rel_rois_sbj_pos _, inds_unique_sbj_pos, inds_reverse_sbj_pos = np.unique( sampled_sbj_rois_sbj_pos, return_index=True, return_inverse=True, axis=0) assert inds_reverse_sbj_pos.shape[0] == sampled_sbj_rois_sbj_pos.shape[0] blob_dict['inds_unique_sbj_pos'] = inds_unique_sbj_pos blob_dict['inds_reverse_sbj_pos'] = inds_reverse_sbj_pos if cfg.MODEL.USE_SPATIAL_FEAT: sampled_spt_feat_sbj_pos = box_utils_rel.get_spt_features( sampled_sbj_boxes_sbj_pos, sampled_obj_boxes_sbj_pos, roidb['width'], roidb['height']) blob_dict['spt_feat_sbj_pos'] = sampled_spt_feat_sbj_pos # obj # Here a naturally existing assumption is, each positive obj should have at least one positive sbj obj_pos_pair_pos_inds = np.where((max_pair_overlaps >= cfg.TRAIN.FG_THRESH))[0] obj_pos_sbj_pos_pair_neg_inds = np.where((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))[0] obj_pos_sbj_neg_pair_neg_inds = np.where((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps < cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))[0] if obj_pos_pair_pos_inds.size > 0: obj_pos_pair_pos_inds = npr.choice( obj_pos_pair_pos_inds, size=int(min(nodes_per_image, obj_pos_pair_pos_inds.size)), replace=False) if obj_pos_sbj_pos_pair_neg_inds.size > 0: obj_pos_sbj_pos_pair_neg_inds = npr.choice( obj_pos_sbj_pos_pair_neg_inds, size=int(min(nodes_per_image, obj_pos_sbj_pos_pair_neg_inds.size)), replace=False) obj_pos_pair_neg_inds = obj_pos_sbj_pos_pair_neg_inds if nodes_per_image - obj_pos_sbj_pos_pair_neg_inds.size > 0 and obj_pos_sbj_neg_pair_neg_inds.size: obj_pos_sbj_neg_pair_neg_inds = npr.choice( obj_pos_sbj_neg_pair_neg_inds, size=int(min(nodes_per_image - obj_pos_sbj_pos_pair_neg_inds.size, obj_pos_sbj_neg_pair_neg_inds.size)), replace=False) obj_pos_pair_neg_inds = np.append(obj_pos_pair_neg_inds, obj_pos_sbj_neg_pair_neg_inds) obj_pos_inds = np.append(obj_pos_pair_pos_inds, obj_pos_pair_neg_inds) binary_labels_obj_pos = np.zeros(obj_pos_inds.size, dtype=np.int32) binary_labels_obj_pos[:obj_pos_pair_pos_inds.size] = 1 blob_dict['binary_labels_obj_pos_int32'] = binary_labels_obj_pos.astype(np.int32, copy=False) prd_pos_labels_obj_pos = roidb['max_prd_classes'][obj_pos_pair_pos_inds] prd_labels_obj_pos = np.zeros(obj_pos_inds.size, dtype=np.int32) prd_labels_obj_pos[:obj_pos_pair_pos_inds.size] = prd_pos_labels_obj_pos + 1 blob_dict['prd_labels_obj_pos_int32'] = prd_labels_obj_pos.astype(np.int32, copy=False) obj_labels_obj_pos = roidb['max_obj_classes'][obj_pos_inds] + 1 # 1. set all sbj labels > 0 sbj_labels_obj_pos = roidb['max_sbj_classes'][obj_pos_inds] + 1 # 2. find those negative sbj max_sbj_overlaps_obj_pos = roidb['max_sbj_overlaps'][obj_pos_inds] sbj_neg_inds_obj_pos = np.where(max_sbj_overlaps_obj_pos < cfg.TRAIN.FG_THRESH)[0] sbj_labels_obj_pos[sbj_neg_inds_obj_pos] = 0 blob_dict['sbj_labels_obj_pos_int32'] = sbj_labels_obj_pos.astype(np.int32, copy=False) blob_dict['obj_labels_obj_pos_int32'] = obj_labels_obj_pos.astype(np.int32, copy=False) # this is for freq bias in RelDN blob_dict['sbj_labels_obj_pos_fg_int32'] = roidb['max_sbj_classes'][obj_pos_inds].astype(np.int32, copy=False) blob_dict['obj_labels_obj_pos_fg_int32'] = roidb['max_obj_classes'][obj_pos_inds].astype(np.int32, copy=False) sampled_sbj_boxes_obj_pos = roidb['sbj_boxes'][obj_pos_inds] sampled_obj_boxes_obj_pos = roidb['obj_boxes'][obj_pos_inds] # Scale rois and format as (batch_idx, x1, y1, x2, y2) sampled_sbj_rois_obj_pos = sampled_sbj_boxes_obj_pos * im_scale sampled_obj_rois_obj_pos = sampled_obj_boxes_obj_pos * im_scale repeated_batch_idx = batch_idx * blob_utils.ones((obj_pos_inds.shape[0], 1)) sampled_sbj_rois_obj_pos = np.hstack((repeated_batch_idx, sampled_sbj_rois_obj_pos)) sampled_obj_rois_obj_pos = np.hstack((repeated_batch_idx, sampled_obj_rois_obj_pos)) blob_dict['sbj_rois_obj_pos'] = sampled_sbj_rois_obj_pos blob_dict['obj_rois_obj_pos'] = sampled_obj_rois_obj_pos sampled_rel_rois_obj_pos = box_utils_rel.rois_union(sampled_sbj_rois_obj_pos, sampled_obj_rois_obj_pos) blob_dict['rel_rois_obj_pos'] = sampled_rel_rois_obj_pos _, inds_unique_obj_pos, inds_reverse_obj_pos = np.unique( sampled_obj_rois_obj_pos, return_index=True, return_inverse=True, axis=0) assert inds_reverse_obj_pos.shape[0] == sampled_obj_rois_obj_pos.shape[0] blob_dict['inds_unique_obj_pos'] = inds_unique_obj_pos blob_dict['inds_reverse_obj_pos'] = inds_reverse_obj_pos if cfg.MODEL.USE_SPATIAL_FEAT: sampled_spt_feat_obj_pos = box_utils_rel.get_spt_features( sampled_sbj_boxes_obj_pos, sampled_obj_boxes_obj_pos, roidb['width'], roidb['height']) blob_dict['spt_feat_obj_pos'] = sampled_spt_feat_obj_pos return blob_dict def _add_rel_multilevel_rois(blobs): """By default training RoIs are added for a single feature map level only. When using FPN, the RoIs must be distributed over different FPN levels according the level assignment heuristic (see: modeling.FPN. map_rois_to_fpn_levels). """ lvl_min = cfg.FPN.ROI_MIN_LEVEL lvl_max = cfg.FPN.ROI_MAX_LEVEL def _distribute_rois_over_fpn_levels(rois_blob_names): """Distribute rois over the different FPN levels.""" # Get target level for each roi # Recall blob rois are in (batch_idx, x1, y1, x2, y2) format, hence take # the box coordinates from columns 1:5 lowest_target_lvls = None for rois_blob_name in rois_blob_names: target_lvls = fpn_utils.map_rois_to_fpn_levels( blobs[rois_blob_name][:, 1:5], lvl_min, lvl_max) if lowest_target_lvls is None: lowest_target_lvls = target_lvls else: lowest_target_lvls = np.minimum(lowest_target_lvls, target_lvls) for rois_blob_name in rois_blob_names: # Add per FPN level roi blobs named like: <rois_blob_name>_fpn<lvl> fpn_utils.add_multilevel_roi_blobs( blobs, rois_blob_name, blobs[rois_blob_name], lowest_target_lvls, lvl_min, lvl_max) _distribute_rois_over_fpn_levels(['sbj_rois']) _distribute_rois_over_fpn_levels(['obj_rois']) _distribute_rois_over_fpn_levels(['rel_rois']) _distribute_rois_over_fpn_levels(['det_rois']) if cfg.MODEL.USE_NODE_CONTRASTIVE_LOSS or cfg.MODEL.USE_NODE_CONTRASTIVE_SO_AWARE_LOSS or cfg.MODEL.USE_NODE_CONTRASTIVE_P_AWARE_LOSS: _distribute_rois_over_fpn_levels(['sbj_rois_sbj_pos']) _distribute_rois_over_fpn_levels(['obj_rois_sbj_pos']) _distribute_rois_over_fpn_levels(['rel_rois_sbj_pos']) _distribute_rois_over_fpn_levels(['sbj_rois_obj_pos']) _distribute_rois_over_fpn_levels(['obj_rois_obj_pos']) _distribute_rois_over_fpn_levels(['rel_rois_obj_pos'])
[ "logging.getLogger", "numpy.minimum", "numpy.ones", "numpy.hstack", "numpy.where", "utils_rel.boxes_rel.get_spt_features", "numpy.unique", "numpy.random.choice", "utils_rel.boxes_rel.rois_union", "numpy.append", "numpy.array", "numpy.zeros", "utils.fpn.add_multilevel_roi_blobs", "numpy.con...
[((1404, 1431), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (1421, 1431), False, 'import logging\n'), ((8692, 8741), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_sbj_rois)'], {}), '((repeated_batch_idx, sampled_sbj_rois))\n', (8701, 8741), True, 'import numpy as np\n'), ((8765, 8814), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_obj_rois)'], {}), '((repeated_batch_idx, sampled_obj_rois))\n', (8774, 8814), True, 'import numpy as np\n'), ((8838, 8897), 'numpy.hstack', 'np.hstack', (['(all_boxes_repeated_batch_idx, sampled_all_rois)'], {}), '((all_boxes_repeated_batch_idx, sampled_all_rois))\n', (8847, 8897), True, 'import numpy as np\n'), ((9386, 9446), 'utils_rel.boxes_rel.rois_union', 'box_utils_rel.rois_union', (['sampled_sbj_rois', 'sampled_obj_rois'], {}), '(sampled_sbj_rois, sampled_obj_rois)\n', (9410, 9446), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((2669, 2709), 'numpy.where', 'np.where', (['(prd_gt_overlaps > 1.0 - 0.0001)'], {}), '(prd_gt_overlaps > 1.0 - 0.0001)\n', (2677, 2709), True, 'import numpy as np\n'), ((2746, 2836), 'numpy.where', 'np.where', (['((prd_gt_overlaps >= cfg.TRAIN.FG_THRESH) & (prd_gt_overlaps <= 1.0 - 0.0001))'], {}), '((prd_gt_overlaps >= cfg.TRAIN.FG_THRESH) & (prd_gt_overlaps <= 1.0 -\n 0.0001))\n', (2754, 2836), True, 'import numpy as np\n'), ((3081, 3160), 'numpy.minimum', 'np.minimum', (['fg_pairs_per_image', '(hash_gt_pair_inds.size + hash_fg_pair_inds.size)'], {}), '(fg_pairs_per_image, hash_gt_pair_inds.size + hash_fg_pair_inds.size)\n', (3091, 3160), True, 'import numpy as np\n'), ((5375, 5425), 'numpy.array', 'np.array', (['[hash_fg_pair_inds.size]'], {'dtype': 'np.int32'}), '([hash_fg_pair_inds.size], dtype=np.int32)\n', (5383, 5425), True, 'import numpy as np\n'), ((5702, 5771), 'numpy.minimum', 'np.minimum', (['fg_pairs_per_image', '(gt_pair_inds.size + fg_pair_inds.size)'], {}), '(fg_pairs_per_image, gt_pair_inds.size + fg_pair_inds.size)\n', (5712, 5771), True, 'import numpy as np\n'), ((7838, 7883), 'numpy.array', 'np.array', (['[fg_pair_inds.size]'], {'dtype': 'np.int32'}), '([fg_pair_inds.size], dtype=np.int32)\n', (7846, 7883), True, 'import numpy as np\n'), ((8522, 8567), 'utils.blob.ones', 'blob_utils.ones', (['(keep_pair_inds.shape[0], 1)'], {}), '((keep_pair_inds.shape[0], 1))\n', (8537, 8567), True, 'import utils.blob as blob_utils\n'), ((8615, 8663), 'utils.blob.ones', 'blob_utils.ones', (['(sampled_all_boxes.shape[0], 1)'], {}), '((sampled_all_boxes.shape[0], 1))\n', (8630, 8663), True, 'import utils.blob as blob_utils\n'), ((8944, 8995), 'numpy.ones', 'np.ones', (['(keep_pair_inds.shape[0], 1)'], {'dtype': 'np.int'}), '((keep_pair_inds.shape[0], 1), dtype=np.int)\n', (8951, 8995), True, 'import numpy as np\n'), ((9554, 9660), 'utils_rel.boxes_rel.get_spt_features', 'box_utils_rel.get_spt_features', (['sampled_sbj_boxes', 'sampled_obj_boxes', "roidb['width']", "roidb['height']"], {}), "(sampled_sbj_boxes, sampled_obj_boxes, roidb[\n 'width'], roidb['height'])\n", (9584, 9660), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((12174, 12229), 'numpy.append', 'np.append', (['sbj_pos_pair_pos_inds', 'sbj_pos_pair_neg_inds'], {}), '(sbj_pos_pair_pos_inds, sbj_pos_pair_neg_inds)\n', (12183, 12229), True, 'import numpy as np\n'), ((12262, 12305), 'numpy.zeros', 'np.zeros', (['sbj_pos_inds.size'], {'dtype': 'np.int32'}), '(sbj_pos_inds.size, dtype=np.int32)\n', (12270, 12305), True, 'import numpy as np\n'), ((12581, 12624), 'numpy.zeros', 'np.zeros', (['sbj_pos_inds.size'], {'dtype': 'np.int32'}), '(sbj_pos_inds.size, dtype=np.int32)\n', (12589, 12624), True, 'import numpy as np\n'), ((14187, 14244), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_sbj_rois_sbj_pos)'], {}), '((repeated_batch_idx, sampled_sbj_rois_sbj_pos))\n', (14196, 14244), True, 'import numpy as np\n'), ((14280, 14337), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_obj_rois_sbj_pos)'], {}), '((repeated_batch_idx, sampled_obj_rois_sbj_pos))\n', (14289, 14337), True, 'import numpy as np\n'), ((14503, 14579), 'utils_rel.boxes_rel.rois_union', 'box_utils_rel.rois_union', (['sampled_sbj_rois_sbj_pos', 'sampled_obj_rois_sbj_pos'], {}), '(sampled_sbj_rois_sbj_pos, sampled_obj_rois_sbj_pos)\n', (14527, 14579), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((14700, 14787), 'numpy.unique', 'np.unique', (['sampled_sbj_rois_sbj_pos'], {'return_index': '(True)', 'return_inverse': '(True)', 'axis': '(0)'}), '(sampled_sbj_rois_sbj_pos, return_index=True, return_inverse=True,\n axis=0)\n', (14709, 14787), True, 'import numpy as np\n'), ((17119, 17174), 'numpy.append', 'np.append', (['obj_pos_pair_pos_inds', 'obj_pos_pair_neg_inds'], {}), '(obj_pos_pair_pos_inds, obj_pos_pair_neg_inds)\n', (17128, 17174), True, 'import numpy as np\n'), ((17207, 17250), 'numpy.zeros', 'np.zeros', (['obj_pos_inds.size'], {'dtype': 'np.int32'}), '(obj_pos_inds.size, dtype=np.int32)\n', (17215, 17250), True, 'import numpy as np\n'), ((17526, 17569), 'numpy.zeros', 'np.zeros', (['obj_pos_inds.size'], {'dtype': 'np.int32'}), '(obj_pos_inds.size, dtype=np.int32)\n', (17534, 17569), True, 'import numpy as np\n'), ((19132, 19189), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_sbj_rois_obj_pos)'], {}), '((repeated_batch_idx, sampled_sbj_rois_obj_pos))\n', (19141, 19189), True, 'import numpy as np\n'), ((19225, 19282), 'numpy.hstack', 'np.hstack', (['(repeated_batch_idx, sampled_obj_rois_obj_pos)'], {}), '((repeated_batch_idx, sampled_obj_rois_obj_pos))\n', (19234, 19282), True, 'import numpy as np\n'), ((19448, 19524), 'utils_rel.boxes_rel.rois_union', 'box_utils_rel.rois_union', (['sampled_sbj_rois_obj_pos', 'sampled_obj_rois_obj_pos'], {}), '(sampled_sbj_rois_obj_pos, sampled_obj_rois_obj_pos)\n', (19472, 19524), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((19645, 19732), 'numpy.unique', 'np.unique', (['sampled_obj_rois_obj_pos'], {'return_index': '(True)', 'return_inverse': '(True)', 'axis': '(0)'}), '(sampled_obj_rois_obj_pos, return_index=True, return_inverse=True,\n axis=0)\n', (19654, 19732), True, 'import numpy as np\n'), ((1948, 1965), 'numpy.concatenate', 'np.concatenate', (['v'], {}), '(v)\n', (1962, 1965), True, 'import numpy as np\n'), ((3285, 3388), 'numpy.random.choice', 'npr.choice', (['hash_fg_pair_inds'], {'size': '(fg_pairs_per_this_image - hash_gt_pair_inds.size)', 'replace': '(False)'}), '(hash_fg_pair_inds, size=fg_pairs_per_this_image -\n hash_gt_pair_inds.size, replace=False)\n', (3295, 3388), True, 'import numpy.random as npr\n'), ((3436, 3483), 'numpy.append', 'np.append', (['hash_fg_pair_inds', 'hash_gt_pair_inds'], {}), '(hash_fg_pair_inds, hash_gt_pair_inds)\n', (3445, 3483), True, 'import numpy as np\n'), ((3894, 3944), 'numpy.where', 'np.where', (['(prd_gt_overlaps < cfg.TRAIN.BG_THRESH_HI)'], {}), '(prd_gt_overlaps < cfg.TRAIN.BG_THRESH_HI)\n', (3902, 3944), True, 'import numpy as np\n'), ((4173, 4232), 'numpy.minimum', 'np.minimum', (['bg_pairs_per_this_image', 'hash_bg_pair_inds.size'], {}), '(bg_pairs_per_this_image, hash_bg_pair_inds.size)\n', (4183, 4232), True, 'import numpy as np\n'), ((4442, 4489), 'numpy.append', 'np.append', (['hash_fg_pair_inds', 'hash_bg_pair_inds'], {}), '(hash_fg_pair_inds, hash_bg_pair_inds)\n', (4451, 4489), True, 'import numpy as np\n'), ((4529, 4579), 'numpy.zeros', 'np.zeros', (['hash_keep_pair_inds.size'], {'dtype': 'np.int32'}), '(hash_keep_pair_inds.size, dtype=np.int32)\n', (4537, 4579), True, 'import numpy as np\n'), ((4703, 4788), 'numpy.append', 'np.append', (['(hash_fg_pair_inds // prd_class_num)', '(hash_bg_pair_inds // prd_class_num)'], {}), '(hash_fg_pair_inds // prd_class_num, hash_bg_pair_inds //\n prd_class_num)\n', (4712, 4788), True, 'import numpy as np\n'), ((4815, 4894), 'numpy.append', 'np.append', (['(hash_fg_pair_inds % prd_class_num)', '(hash_bg_pair_inds % prd_class_num)'], {}), '(hash_fg_pair_inds % prd_class_num, hash_bg_pair_inds % prd_class_num)\n', (4824, 4894), True, 'import numpy as np\n'), ((4940, 4989), 'numpy.ones', 'np.ones', (['fg_multi_prd_labels.size'], {'dtype': 'np.int32'}), '(fg_multi_prd_labels.size, dtype=np.int32)\n', (4947, 4989), True, 'import numpy as np\n'), ((5040, 5085), 'numpy.append', 'np.append', (['(hash_fg_pair_inds // prd_class_num)'], {}), '(hash_fg_pair_inds // prd_class_num)\n', (5049, 5085), True, 'import numpy as np\n'), ((5116, 5160), 'numpy.append', 'np.append', (['(hash_fg_pair_inds % prd_class_num)'], {}), '(hash_fg_pair_inds % prd_class_num)\n', (5125, 5160), True, 'import numpy as np\n'), ((5468, 5510), 'numpy.where', 'np.where', (['(max_pair_overlaps > 1.0 - 0.0001)'], {}), '(max_pair_overlaps > 1.0 - 0.0001)\n', (5476, 5510), True, 'import numpy as np\n'), ((5535, 5629), 'numpy.where', 'np.where', (['((max_pair_overlaps >= cfg.TRAIN.FG_THRESH) & (max_pair_overlaps <= 1.0 - \n 0.0001))'], {}), '((max_pair_overlaps >= cfg.TRAIN.FG_THRESH) & (max_pair_overlaps <=\n 1.0 - 0.0001))\n', (5543, 5629), True, 'import numpy as np\n'), ((5937, 6030), 'numpy.random.choice', 'npr.choice', (['fg_pair_inds'], {'size': '(fg_pairs_per_this_image - gt_pair_inds.size)', 'replace': '(False)'}), '(fg_pair_inds, size=fg_pairs_per_this_image - gt_pair_inds.size,\n replace=False)\n', (5947, 6030), True, 'import numpy.random as npr\n'), ((6073, 6110), 'numpy.append', 'np.append', (['fg_pair_inds', 'gt_pair_inds'], {}), '(fg_pair_inds, gt_pair_inds)\n', (6082, 6110), True, 'import numpy as np\n'), ((6992, 7046), 'numpy.minimum', 'np.minimum', (['bg_pairs_per_this_image', 'bg_pair_inds.size'], {}), '(bg_pairs_per_this_image, bg_pair_inds.size)\n', (7002, 7046), True, 'import numpy as np\n'), ((7380, 7417), 'numpy.append', 'np.append', (['fg_pair_inds', 'bg_pair_inds'], {}), '(fg_pair_inds, bg_pair_inds)\n', (7389, 7417), True, 'import numpy as np\n'), ((7447, 7492), 'numpy.zeros', 'np.zeros', (['keep_pair_inds.size'], {'dtype': 'np.int32'}), '(keep_pair_inds.size, dtype=np.int32)\n', (7455, 7492), True, 'import numpy as np\n'), ((10493, 10543), 'numpy.where', 'np.where', (['(max_pair_overlaps >= cfg.TRAIN.FG_THRESH)'], {}), '(max_pair_overlaps >= cfg.TRAIN.FG_THRESH)\n', (10501, 10543), True, 'import numpy as np\n'), ((10589, 10735), 'numpy.where', 'np.where', (['((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps >= cfg.TRAIN\n .FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))'], {}), '((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps >=\n cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))\n', (10597, 10735), True, 'import numpy as np\n'), ((10873, 11018), 'numpy.where', 'np.where', (['((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps < cfg.TRAIN.\n FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))'], {}), '((max_sbj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_obj_overlaps <\n cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))\n', (10881, 11018), True, 'import numpy as np\n'), ((12087, 12150), 'numpy.append', 'np.append', (['sbj_pos_pair_neg_inds', 'sbj_pos_obj_neg_pair_neg_inds'], {}), '(sbj_pos_pair_neg_inds, sbj_pos_obj_neg_pair_neg_inds)\n', (12096, 12150), True, 'import numpy as np\n'), ((13129, 13185), 'numpy.where', 'np.where', (['(max_obj_overlaps_sbj_pos < cfg.TRAIN.FG_THRESH)'], {}), '(max_obj_overlaps_sbj_pos < cfg.TRAIN.FG_THRESH)\n', (13137, 13185), True, 'import numpy as np\n'), ((14108, 14151), 'utils.blob.ones', 'blob_utils.ones', (['(sbj_pos_inds.shape[0], 1)'], {}), '((sbj_pos_inds.shape[0], 1))\n', (14123, 14151), True, 'import utils.blob as blob_utils\n'), ((15085, 15206), 'utils_rel.boxes_rel.get_spt_features', 'box_utils_rel.get_spt_features', (['sampled_sbj_boxes_sbj_pos', 'sampled_obj_boxes_sbj_pos', "roidb['width']", "roidb['height']"], {}), "(sampled_sbj_boxes_sbj_pos,\n sampled_obj_boxes_sbj_pos, roidb['width'], roidb['height'])\n", (15115, 15206), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((15442, 15492), 'numpy.where', 'np.where', (['(max_pair_overlaps >= cfg.TRAIN.FG_THRESH)'], {}), '(max_pair_overlaps >= cfg.TRAIN.FG_THRESH)\n', (15450, 15492), True, 'import numpy as np\n'), ((15538, 15684), 'numpy.where', 'np.where', (['((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps >= cfg.TRAIN\n .FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))'], {}), '((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps >=\n cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))\n', (15546, 15684), True, 'import numpy as np\n'), ((15822, 15967), 'numpy.where', 'np.where', (['((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps < cfg.TRAIN.\n FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))'], {}), '((max_obj_overlaps >= cfg.TRAIN.FG_THRESH) & (max_sbj_overlaps <\n cfg.TRAIN.FG_THRESH) & (max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI))\n', (15830, 15967), True, 'import numpy as np\n'), ((17032, 17095), 'numpy.append', 'np.append', (['obj_pos_pair_neg_inds', 'obj_pos_sbj_neg_pair_neg_inds'], {}), '(obj_pos_pair_neg_inds, obj_pos_sbj_neg_pair_neg_inds)\n', (17041, 17095), True, 'import numpy as np\n'), ((18074, 18130), 'numpy.where', 'np.where', (['(max_sbj_overlaps_obj_pos < cfg.TRAIN.FG_THRESH)'], {}), '(max_sbj_overlaps_obj_pos < cfg.TRAIN.FG_THRESH)\n', (18082, 18130), True, 'import numpy as np\n'), ((19053, 19096), 'utils.blob.ones', 'blob_utils.ones', (['(obj_pos_inds.shape[0], 1)'], {}), '((obj_pos_inds.shape[0], 1))\n', (19068, 19096), True, 'import utils.blob as blob_utils\n'), ((20030, 20151), 'utils_rel.boxes_rel.get_spt_features', 'box_utils_rel.get_spt_features', (['sampled_sbj_boxes_obj_pos', 'sampled_obj_boxes_obj_pos', "roidb['width']", "roidb['height']"], {}), "(sampled_sbj_boxes_obj_pos,\n sampled_obj_boxes_obj_pos, roidb['width'], roidb['height'])\n", (20060, 20151), True, 'import utils_rel.boxes_rel as box_utils_rel\n'), ((21019, 21104), 'utils.fpn.map_rois_to_fpn_levels', 'fpn_utils.map_rois_to_fpn_levels', (['blobs[rois_blob_name][:, 1:5]', 'lvl_min', 'lvl_max'], {}), '(blobs[rois_blob_name][:, 1:5], lvl_min,\n lvl_max)\n', (21051, 21104), True, 'import utils.fpn as fpn_utils\n'), ((21448, 21571), 'utils.fpn.add_multilevel_roi_blobs', 'fpn_utils.add_multilevel_roi_blobs', (['blobs', 'rois_blob_name', 'blobs[rois_blob_name]', 'lowest_target_lvls', 'lvl_min', 'lvl_max'], {}), '(blobs, rois_blob_name, blobs[\n rois_blob_name], lowest_target_lvls, lvl_min, lvl_max)\n', (21482, 21571), True, 'import utils.fpn as fpn_utils\n'), ((3580, 3654), 'numpy.random.choice', 'npr.choice', (['hash_gt_pair_inds'], {'size': 'fg_pairs_per_this_image', 'replace': '(False)'}), '(hash_gt_pair_inds, size=fg_pairs_per_this_image, replace=False)\n', (3590, 3654), True, 'import numpy.random as npr\n'), ((4312, 4386), 'numpy.random.choice', 'npr.choice', (['hash_bg_pair_inds'], {'size': 'bg_pairs_per_this_image', 'replace': '(False)'}), '(hash_bg_pair_inds, size=bg_pairs_per_this_image, replace=False)\n', (4322, 4386), True, 'import numpy.random as npr\n'), ((6197, 6266), 'numpy.random.choice', 'npr.choice', (['gt_pair_inds'], {'size': 'fg_pairs_per_this_image', 'replace': '(False)'}), '(gt_pair_inds, size=fg_pairs_per_this_image, replace=False)\n', (6207, 6266), True, 'import numpy.random as npr\n'), ((6667, 6719), 'numpy.where', 'np.where', (['(max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI)'], {}), '(max_pair_overlaps < cfg.TRAIN.BG_THRESH_HI)\n', (6675, 6719), True, 'import numpy as np\n'), ((7176, 7245), 'numpy.random.choice', 'npr.choice', (['bg_pair_inds'], {'size': 'bg_pairs_per_this_image', 'replace': '(False)'}), '(bg_pair_inds, size=bg_pairs_per_this_image, replace=False)\n', (7186, 7245), True, 'import numpy.random as npr\n'), ((21265, 21308), 'numpy.minimum', 'np.minimum', (['lowest_target_lvls', 'target_lvls'], {}), '(lowest_target_lvls, target_lvls)\n', (21275, 21308), True, 'import numpy as np\n')]
import time import re from src.core.tables import Table, MigrationTable from src.core.constraints import Index class MysqlTable(Table): @staticmethod def _join_cols(cols): '''Join and escape a list''' return ', '.join(['`%s`' % i for i in cols]) @staticmethod def _join_conditionals(row_dict): '''Create a joined conditional statement for updates return escaped string of `key`=val, `key`='val' for dictionary ''' equalities = [] for key, val in row_dict.items(): temp = '`{}`='.format(key) if isinstance(val, (int, float)): temp += '{}'.format(val) elif isinstance(val, str): temp += '\'{}\''.format(val) else: raise TypeError('Value %s, type %s not recognised as a number or string' % (val, type(val))) equalities.append(temp) return ', '.join(equalities) @staticmethod def _qualify(table, cols): '''Qualify, join and escape the list''' return ', '.join(['`{}`.`{}`'.format(table, c) for c in cols]) @staticmethod def _equals(cols, new_table, new_cols): '''Qualify, join and equate''' return ', '.join('`{}`=`{}`.`{}`'.format(cols[i], new_table, new_cols[i]) for i in range(len(cols))) def insert_row(self, row_dict): """Add a row to the table""" sql = self.commands.insert_row( self.name, self._join_cols(row_dict.keys()), self._join_values(row_dict.values()) ) self.execute(sql) return self.db.last_row def get_column_definition(self, column_name): '''Get the sql column definition Selects the column type, and YES or NO from the column, IS NULLABLE. That's enough information to re-create the column. ''' sql = self.commands.column_definition(self.db.name, self.name, column_name) ans = self.execute(sql)[0] if ans[1] == 'NO': return '{} NOT NULL'.format(ans[0]) else: return ans[0] def rename_column(self, old_name, new_name): '''Rename a column''' self.execute(self.commands.rename_column( self.name, old_name, new_name, self.get_column_definition(old_name)) ) @property def create_statement(self): """Get table create statement""" query = self.commands.get_table_create_statement(self.name) if self.db.table_exists(self.name): statement = self.execute(query)[0][1] statement = re.sub('\s+', ' ', statement) return statement raise ValueError('Table does not exist, no create statement') @property def indexes(self): """Return list of indexes""" indexes = self.execute(self.commands.get_indexes(self.name)) return [Index(tup[0], tup[2], tup[1], tup[4]) for tup in indexes] class MySqlMigrationTable(MysqlTable, MigrationTable): def create_from_source(self): """Create new table like source_table""" create_statement = self.source.create_statement.replace( 'CREATE TABLE `{}`'.format(self.source.name), 'CREATE TABLE `{}`' ) self.create_from_statement(create_statement) def _trigger_name(self, method_type): 'Create trigger name' name = 'migration_trigger_{}_{}'.format(method_type, self.source.name) return name[:self.db.config['MAX_LENGTH_NAME']] def create_insert_trigger(self): '''Set insert Triggers. 'NEW' and 'OLD' are mysql references see https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html ''' sql = self.commands.insert_trigger( self._trigger_name('insert'), self.source.name, self.name, self._join_cols(self.intersection.dest_columns), self._qualify('NEW', self.intersection.origin_columns)) import pdb pdb.set_trace() print(sql) self.execute(sql) def create_delete_trigger(self): '''Set delete triggers 'NEW' and 'OLD' are mysql references see https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html ''' sql = self.commands.delete_trigger( self._trigger_name('delete'), self.source.name, self.name, self.primary_key_column) self.execute(sql) def create_update_trigger(self): '''Set update triggers 'NEW' and 'OLD' are mysql references see https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html ''' sql = self.commands.update_trigger( self._trigger_name('update'), self.source.name, self.name, self._equals(self.intersection.dest_columns, 'NEW', self.intersection.origin_columns), self.primary_key_column ) self.execute(sql) def rename_tables(self): 'Rename the tables' self.delete_triggers() retries = 0 source_name, archive_name, migrate_name = self.source.name, self.source.archive_name, self.name while True: try: self.execute(self.commands.rename_table(source_name, archive_name, migrate_name)) break except Exception as e: retries += 1 if retries > self.db.config['MAX_RENAME_RETRIES']: self.create_triggers() return False # TODO: make sure this is a Lock wait timeout error before retrying print('Rename retry %d, error: %s' % (retries, e)) time.sleep(self.db.donfig['RETRY_SLEEP_TIME']) self.name, self.source.name = self.source.name, self.archive_name print("Rename complete!") return True
[ "re.sub", "src.core.constraints.Index", "time.sleep", "pdb.set_trace" ]
[((4067, 4082), 'pdb.set_trace', 'pdb.set_trace', ([], {}), '()\n', (4080, 4082), False, 'import pdb\n'), ((2658, 2688), 're.sub', 're.sub', (['"""\\\\s+"""', '""" """', 'statement'], {}), "('\\\\s+', ' ', statement)\n", (2664, 2688), False, 'import re\n'), ((2948, 2985), 'src.core.constraints.Index', 'Index', (['tup[0]', 'tup[2]', 'tup[1]', 'tup[4]'], {}), '(tup[0], tup[2], tup[1], tup[4])\n', (2953, 2985), False, 'from src.core.constraints import Index\n'), ((5782, 5828), 'time.sleep', 'time.sleep', (["self.db.donfig['RETRY_SLEEP_TIME']"], {}), "(self.db.donfig['RETRY_SLEEP_TIME'])\n", (5792, 5828), False, 'import time\n')]
''' Local DB Authentication module. .. moduleauthor:: <NAME> <<EMAIL>> ''' import logging from django.contrib.auth.models import User, Group from django.contrib.auth.backends import ModelBackend from tardis.tardis_portal.auth.interfaces import AuthProvider, GroupProvider, UserProvider logger = logging.getLogger(__name__) auth_key = u'localdb' auth_display_name = u'Local DB' _modelBackend = ModelBackend() class DjangoAuthBackend(AuthProvider): """Authenticate against Django's Model Backend. """ def authenticate(self, request): """authenticate a user, this expect the user will be using form based auth and the *username* and *password* will be passed in as **POST** variables. :param request: a HTTP Request instance :type request: :class:`django.http.HttpRequest` """ username = request.POST['username'] password = request.POST['password'] if not username or not password: return None return _modelBackend.authenticate(username, password) def get_user(self, user_id): try: user = User.objects.get(username=user_id) except User.DoesNotExist: user = None return user class DjangoGroupProvider(GroupProvider): name = u'django_group' def getGroups(self, user): """return an iteration of the available groups. """ groups = user.groups.all() return [g.id for g in groups] def getGroupById(self, id): """return the group associated with the id:: {"id": 123, "display": "Group Name",} """ groupObj = Group.objects.get(id=id) if groupObj: return {'id': id, 'display': groupObj.name} return None def searchGroups(self, **filter): result = [] groups = Group.objects.filter(**filter) for g in groups: users = [u.username for u in User.objects.filter(groups=g)] result += [{'id': g.id, 'display': g.name, 'members': users}] return result class DjangoUserProvider(UserProvider): name = u'django_user' def getUserById(self, id): """ return the user dictionary in the format of:: {"id": 123, "first_name": "John", "last_name": "Smith", "email": "<EMAIL>"} """ try: userObj = User.objects.get(username=id) return {'id': id, 'first_name': userObj.first_name, 'last_name': userObj.last_name, 'email': userObj.email} except User.DoesNotExist: return None django_user = DjangoUserProvider.name django_group = DjangoGroupProvider.name
[ "logging.getLogger", "django.contrib.auth.models.Group.objects.get", "django.contrib.auth.models.Group.objects.filter", "django.contrib.auth.models.User.objects.filter", "django.contrib.auth.backends.ModelBackend", "django.contrib.auth.models.User.objects.get" ]
[((301, 328), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (318, 328), False, 'import logging\n'), ((403, 417), 'django.contrib.auth.backends.ModelBackend', 'ModelBackend', ([], {}), '()\n', (415, 417), False, 'from django.contrib.auth.backends import ModelBackend\n'), ((1669, 1693), 'django.contrib.auth.models.Group.objects.get', 'Group.objects.get', ([], {'id': 'id'}), '(id=id)\n', (1686, 1693), False, 'from django.contrib.auth.models import User, Group\n'), ((1867, 1897), 'django.contrib.auth.models.Group.objects.filter', 'Group.objects.filter', ([], {}), '(**filter)\n', (1887, 1897), False, 'from django.contrib.auth.models import User, Group\n'), ((1131, 1165), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'username': 'user_id'}), '(username=user_id)\n', (1147, 1165), False, 'from django.contrib.auth.models import User, Group\n'), ((2478, 2507), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'username': 'id'}), '(username=id)\n', (2494, 2507), False, 'from django.contrib.auth.models import User, Group\n'), ((1964, 1993), 'django.contrib.auth.models.User.objects.filter', 'User.objects.filter', ([], {'groups': 'g'}), '(groups=g)\n', (1983, 1993), False, 'from django.contrib.auth.models import User, Group\n')]
import os import time from pathlib import Path from flask import Flask, jsonify, abort, request, Response, Request import concurrent.futures import threading import requests import logging import ast from urllib.parse import urlparse from flask import current_app as app from urllib3.exceptions import InsecureRequestWarning from yaml import safe_load # Local modules from elasticsearch.indexer import Indexer from libs.assay_type import AssayType # HuBMAP commons from hubmap_commons.hm_auth import AuthHelper # Set logging fromat and level (default is warning) # All the API logging is forwarded to the uWSGI server and gets written into the log file `uwsgo-entity-api.log` # Log rotation is handled via logrotate on the host system with a configuration file # Do NOT handle log file and rotation via the Python logging to avoid issues with multi-worker processes logging.basicConfig(format='[%(asctime)s] %(levelname)s in %(module)s:%(lineno)d: %(message)s', level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S') logger = logging.getLogger(__name__) # Specify the absolute path of the instance folder and use the config file relative to the instance path app = Flask(__name__, instance_path=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance'), instance_relative_config=True) app.config.from_pyfile('app.cfg') # load the index configurations and set the default INDICES = safe_load((Path(__file__).absolute().parent / 'instance/search-config.yaml').read_text()) DEFAULT_INDEX_WITHOUT_PREFIX = INDICES['default_index'] logger.debug("############ INDICES config LOADED") logger.debug(INDICES) # Remove trailing slash / from URL base to avoid "//" caused by config with trailing slash DEFAULT_ELASTICSEARCH_URL = INDICES['indices'][DEFAULT_INDEX_WITHOUT_PREFIX]['elasticsearch']['url'].strip('/') DEFAULT_ENTITY_API_URL = INDICES['indices'][DEFAULT_INDEX_WITHOUT_PREFIX]['document_source_endpoint'].strip('/') # Suppress InsecureRequestWarning warning when requesting status on https with ssl cert verify disabled requests.packages.urllib3.disable_warnings(category = InsecureRequestWarning) #################################################################################################### ## Register error handlers #################################################################################################### # Error handler for 400 Bad Request with custom error message @app.errorhandler(400) def http_bad_request(e): return jsonify(error=str(e)), 400 # Error handler for 401 Unauthorized with custom error message @app.errorhandler(401) def http_unauthorized(e): return jsonify(error=str(e)), 401 # Error handler for 403 Forbidden with custom error message @app.errorhandler(403) def http_forbidden(e): return jsonify(error=str(e)), 403 # Error handler for 500 Internal Server Error with custom error message @app.errorhandler(500) def http_internal_server_error(e): return jsonify(error=str(e)), 500 #################################################################################################### ## AuthHelper initialization #################################################################################################### # Initialize AuthHelper class and ensure singleton try: if AuthHelper.isInitialized() == False: auth_helper_instance = AuthHelper.create(app.config['APP_CLIENT_ID'], app.config['APP_CLIENT_SECRET']) logger.info("Initialized AuthHelper class successfully :)") else: auth_helper_instance = AuthHelper.instance() except Exception: msg = "Failed to initialize the AuthHelper class" # Log the full stack trace, prepend a line with our message logger.exception(msg) #################################################################################################### ## Default route #################################################################################################### @app.route('/', methods = ['GET']) def index(): return "Hello! This is HuBMAP Search API service :)" #################################################################################################### ## Assay type API #################################################################################################### @app.route('/assaytype', methods = ['GET']) def assaytypes(): primary = None simple = False for key, val in request.args.items(): if key == 'primary': primary = val.lower() == "true" elif key == 'simple': simple = val.lower() == "true" else: abort(400, f'invalid request parameter {key}') if primary is None: name_l = [name for name in AssayType.iter_names()] else: name_l = [name for name in AssayType.iter_names(primary=primary)] if simple: return jsonify(result=name_l) else: return jsonify(result=[AssayType(name).to_json() for name in name_l]) @app.route('/assaytype/<name>', methods = ['GET']) @app.route('/assayname', methods = ['POST']) def assayname(name=None): if name is None: request_json_required(request) try: name = request.json['name'] except Exception: abort(400, 'request contains no "name" field') try: return jsonify(AssayType(name).to_json()) except Exception as e: abort(400, str(e)) #################################################################################################### ## API #################################################################################################### # Both HTTP GET and HTTP POST can be used to execute search with body against ElasticSearch REST API. # general search uses the DEFAULT_INDEX @app.route('/search', methods = ['GET', 'POST']) def search(): # Always expect a json body request_json_required(request) logger.info("======search with no index provided======") logger.info ("default_index: " + DEFAULT_INDEX_WITHOUT_PREFIX) # Determine the target real index in Elasticsearch to be searched against # Use the DEFAULT_INDEX_WITHOUT_PREFIX since /search doesn't take any index target_index = get_target_index(request, DEFAULT_INDEX_WITHOUT_PREFIX) # get URL for that index es_url = INDICES['indices'][DEFAULT_INDEX_WITHOUT_PREFIX]['elasticsearch']['url'].strip('/') # Return the elasticsearch resulting json data as json string return execute_query('_search', request, target_index, es_url) # Both HTTP GET and HTTP POST can be used to execute search with body against ElasticSearch REST API. # Note: the index in URL is not he real index in Elasticsearch, it's that index without prefix @app.route('/<index_without_prefix>/search', methods = ['GET', 'POST']) def search_by_index(index_without_prefix): # Always expect a json body request_json_required(request) # Make sure the requested index in URL is valid validate_index(index_without_prefix) logger.info("======requested index_without_prefix======") logger.info(index_without_prefix) # Determine the target real index in Elasticsearch to be searched against target_index = get_target_index(request, index_without_prefix) # get URL for that index es_url = INDICES['indices'][index_without_prefix]['elasticsearch']['url'].strip('/') # Return the elasticsearch resulting json data as json string return execute_query('_search', request, target_index, es_url) # HTTP GET can be used to execute search with body against ElasticSearch REST API. @app.route('/count', methods = ['GET']) def count(): # Always expect a json body request_json_required(request) logger.info("======count with no index provided======") # Determine the target real index in Elasticsearch to be searched against target_index = get_target_index(request, DEFAULT_INDEX_WITHOUT_PREFIX) # get URL for that index es_url = INDICES['indices'][DEFAULT_INDEX_WITHOUT_PREFIX]['elasticsearch']['url'].strip('/') # Return the elasticsearch resulting json data as json string return execute_query('_count', request, target_index, es_url) # HTTP GET can be used to execute search with body against ElasticSearch REST API. # Note: the index in URL is not he real index in Elasticsearch, it's that index without prefix @app.route('/<index_without_prefix>/count', methods = ['GET']) def count_by_index(index_without_prefix): # Always expect a json body request_json_required(request) # Make sure the requested index in URL is valid validate_index(index_without_prefix) logger.info("======requested index_without_prefix======") logger.info(index_without_prefix) # Determine the target real index in Elasticsearch to be searched against target_index = get_target_index(request, index_without_prefix) # get URL for that index es_url = INDICES['indices'][index_without_prefix]['elasticsearch']['url'].strip('/') # Return the elasticsearch resulting json data as json string return execute_query('_count', request, target_index, es_url) # Get a list of indices @app.route('/indices', methods = ['GET']) def indices(): # Return the resulting json data as json string result = { "indices": get_filtered_indices() } return jsonify(result) # Get the status of Elasticsearch cluster by calling the health API # This shows the connection status and the cluster health status (if connected) @app.route('/status', methods = ['GET']) def status(): response_data = { # Use strip() to remove leading and trailing spaces, newlines, and tabs 'version': ((Path(__file__).absolute().parent.parent / 'VERSION').read_text()).strip(), 'build': ((Path(__file__).absolute().parent.parent / 'BUILD').read_text()).strip(), 'elasticsearch_connection': False } target_url = DEFAULT_ELASTICSEARCH_URL + '/_cluster/health' #target_url = app.config['ELASTICSEARCH_URL'] + '/_cluster/health' resp = requests.get(url = target_url) if resp.status_code == 200: response_data['elasticsearch_connection'] = True # If connected, we also get the cluster health status status_dict = resp.json() # Add new key response_data['elasticsearch_status'] = status_dict['status'] return jsonify(response_data) # This reindex function will also reindex Collection and Upload # in addition to the Dataset, Donor, Sample entities @app.route('/reindex/<uuid>', methods=['PUT']) def reindex(uuid): # Reindex individual document doesn't require the token to belong # to the HuBMAP-Data-Admin group # since this is being used by entity-api and ingest-api too token = get_user_token(request.headers) try: indexer = init_indexer(token) threading.Thread(target=indexer.reindex, args=[uuid]).start() # indexer.reindex(uuid) # for non-thread logger.info(f"Started to reindex uuid: {uuid}") except Exception as e: logger.exception(e) internal_server_error(e) return f"Request of reindexing {uuid} accepted", 202 # Live reindex without first deleting and recreating the indices # This just deletes the old document and add the latest document of each entity (if still available) @app.route('/reindex-all', methods=['PUT']) def reindex_all(): # The token needs to belong to the HuBMAP-Data-Admin group # to be able to trigger a live reindex for all documents token = get_user_token(request.headers, admin_access_required = True) saved_request = request.headers logger.debug(saved_request) try: indexer = init_indexer(token) threading.Thread(target=reindex_all_uuids, args=[indexer, token]).start() logger.info('Started live reindex all') except Exception as e: logger.exception(e) internal_server_error(e) return 'Request of live reindex all documents accepted', 202 #################################################################################################### ## Internal Functions Used By API #################################################################################################### # Throws error for 400 Bad Reqeust with message def bad_request_error(err_msg): abort(400, description = err_msg) # Throws error for 401 Unauthorized with message def unauthorized_error(err_msg): abort(401, description = err_msg) # Throws error for 403 Forbidden with message def forbidden_error(err_msg): abort(403, description = err_msg) # Throws error for 500 Internal Server Error with message def internal_server_error(err_msg): abort(500, description = err_msg) # Get user infomation dict based on the http request(headers) # `group_required` is a boolean, when True, 'hmgroupids' is in the output def get_user_info_for_access_check(request, group_required): return auth_helper_instance.getUserInfoUsingRequest(request, group_required) """ Parase the token from Authorization header Parameters ---------- request_headers: request.headers The http request headers admin_access_required : bool If the token is required to belong to the HuBMAP-Data-Admin group, default to False Returns ------- str The token string if valid """ def get_user_token(request_headers, admin_access_required = False): # Get user token from Authorization header # getAuthorizationTokens() also handles MAuthorization header but we are not using that here try: user_token = auth_helper_instance.getAuthorizationTokens(request_headers) except Exception: msg = "Failed to parse the Authorization token by calling commons.auth_helper.getAuthorizationTokens()" # Log the full stack trace, prepend a line with our message logger.exception(msg) internal_server_error(msg) # The user_token is flask.Response on error if isinstance(user_token, Response): # The Response.data returns binary string, need to decode unauthorized_error(user_token.data.decode()) if admin_access_required: # By now the token is already a valid token # But we also need to ensure the user belongs to HuBMAP-Data-Admin group # in order to execute the live reindex-all # Return a 403 response if the user doesn't belong to HuBMAP-Data-Admin group if not user_in_hubmap_data_admin_group(request): forbidden_error("Access not granted") return user_token """ Check if the user with token belongs to the HuBMAP-Data-Admin group Parameters ---------- request : falsk.request The flask http request object that containing the Authorization header with a valid Globus nexus token for checking group information Returns ------- bool True if the user belongs to HuBMAP-Data-Admin group, otherwise False """ def user_in_hubmap_data_admin_group(request): try: # The property 'hmgroupids' is ALWASYS in the output with using get_user_info() # when the token in request is a nexus_token user_info = get_user_info(request) hubmap_data_admin_group_uuid = auth_helper_instance.groupNameToId('HuBMAP-Data-Admin')['uuid'] except Exception as e: # Log the full stack trace, prepend a line with our message logger.exception(e) # If the token is not a nexus token, no group information available # The commons.hm_auth.AuthCache would return a Response with 500 error message # We treat such cases as the user not in the HuBMAP-Data-Admin group return False return (hubmap_data_admin_group_uuid in user_info['hmgroupids']) """ Get user infomation dict based on the http request(headers) The result will be used by the trigger methods Parameters ---------- request : Flask request object The Flask request passed from the API endpoint Returns ------- dict A dict containing all the user info { "scope": "urn:globus:auth:scope:nexus.api.globus.org:groups", "name": "<NAME>", "iss": "https://auth.globus.org", "client_id": "21f293b0-5fa5-4ee1-9e0e-3cf88bd70114", "active": True, "nbf": 1603761442, "token_type": "Bearer", "aud": ["nexus.api.globus.org", "21f293b0-5fa5-4ee1-9e0e-3cf88bd70114"], "iat": 1603761442, "dependent_tokens_cache_id": "af2d5979090a97536619e8fbad1ebd0afa875c880a0d8058cddf510fc288555c", "exp": 1603934242, "sub": "c0f8907a-ec78-48a7-9c85-7da995b05446", "email": "<EMAIL>", "username": "<EMAIL>", "hmscopes": ["urn:globus:auth:scope:nexus.api.globus.org:groups"], } """ def get_user_info(request): # `group_required` is a boolean, when True, 'hmgroupids' is in the output user_info = auth_helper_instance.getUserInfoUsingRequest(request, True) logger.debug("======get_user_info()======") logger.debug(user_info) # It returns error response when: # - invalid header or token # - token is valid but not nexus token, can't find group info if isinstance(user_info, Response): # Bubble up the actual error message from commons # The Response.data returns binary string, need to decode msg = user_info.get_data().decode() # Log the full stack trace, prepend a line with our message logger.exception(msg) raise Exception(msg) return user_info # Always expect a json body def request_json_required(request): if not request.is_json: bad_request_error("A JSON body and appropriate Content-Type header are required") # We'll need to verify the requested index in URL is valid def validate_index(index_without_prefix): separator = ',' #indices = get_filtered_indices() indices = INDICES['indices'].keys() if index_without_prefix not in indices: bad_request_error(f"Invalid index name. Use one of the following: {separator.join(indices)}") # Determine the target real index in Elasticsearch bases on the request header and given index (without prefix) # The Authorization header with globus token is optional # Case #1: Authorization header is missing, default to use the `hm_public_<index_without_prefix>`. # Case #2: Authorization header with valid token, but the member doesn't belong to the HuBMAP-Read group, direct the call to `hm_public_<index_without_prefix>`. # Case #3: Authorization header presents but with invalid or expired token, return 401 (if someone is sending a token, they might be expecting more than public stuff). # Case #4: Authorization header presents with a valid token that has the group access, direct the call to `hm_consortium_<index_without_prefix>`. def get_target_index(request, index_without_prefix): # Case #1 and #2 target_index = INDICES['indices'][index_without_prefix]['public'] # Keys in request.headers are case insensitive if 'Authorization' in request.headers: # user_info is a dict user_info = get_user_info_for_access_check(request, True) logger.info("======user_info======") logger.info(user_info) # Case #3 if isinstance(user_info, Response): # Notify the client with 401 error message unauthorized_error("The globus token in the HTTP 'Authorization: Bearer <globus-token>' header is either invalid or expired.") # Otherwise, we check user_info['hmgroupids'] list # Key 'hmgroupids' presents only when group_required is True else: # Case #4 if app.config['GLOBUS_HUBMAP_READ_GROUP_UUID'] in user_info['hmgroupids']: #target_index = app.config['PRIVATE_INDEX_PREFIX'] + index_without_prefix target_index = INDICES['indices'][index_without_prefix]['private'] return target_index # Make a call to Elasticsearch def execute_query(query_against, request, index, es_url, query=None): supported_query_against = ['_search', '_count'] separator = ',' if query_against not in supported_query_against: bad_request_error(f"Query against '{query_against}' is not supported by Search API. Use one of the following: {separator.join(supported_query_against)}") # Determine the target real index in Elasticsearch to be searched against #index = get_target_index(request, index_without_prefix) #target_url = app.config['ELASTICSEARCH_URL'] + '/' + target_index + '/' + query_against #es_url = INDICES['indices'][index_without_prefix]['elasticsearch']['url'].strip('/') logger.debug('es_url') logger.debug(es_url) logger.debug(type(es_url)) # use the index es connection target_url = es_url + '/' + index + '/' + query_against logger.debug("Target url: " + target_url) if query is None: # Parse incoming json string into json data(python dict object) json_data = request.get_json() # All we need to do is to simply pass the search json to elasticsearch # The request json may contain "access_group" in this case # Will also pass through the query string in URL target_url = target_url + get_query_string(request.url) # Make a request with json data # The use of json parameter converts python dict to json string and adds content-type: application/json automatically else: json_data = query logger.debug(json_data) resp = requests.post(url=target_url, json=json_data) logger.debug("==========response==========") logger.debug(resp) try: return jsonify(resp.json()) except Exception as e: logger.debug(e) raise e # Return the elasticsearch resulting json data as json string return jsonify(resp) # Get the query string from orignal request def get_query_string(url): query_string = '' parsed_url = urlparse(url) logger.debug("======parsed_url======") logger.debug(parsed_url) # Add the ? at beginning of the query string if not empty if not parsed_url.query: query_string = '?' + parsed_url.query return query_string # Get a list of entity uuids via entity-api for a given entity type: # Collection, Donor, Sample, Dataset, Submission. Case-insensitive. def get_uuids_by_entity_type(entity_type, token): entity_type = entity_type.lower() request_headers = create_request_headers_for_auth(token) # Use different entity-api endpoint for Collection if entity_type == 'collection': #url = app.config['ENTITY_API_URL'] + "/collections?property=uuid" url = DEFAULT_ENTITY_API_URL + "/collections?property=uuid" else: #url = app.config['ENTITY_API_URL'] + "/" + entity_type + "/entities?property=uuid" url = DEFAULT_ENTITY_API_URL + "/" + entity_type + "/entities?property=uuid" response = requests.get(url, headers = request_headers, verify = False) if response.status_code != 200: internal_server_error("get_uuids_by_entity_type() failed to make a request to entity-api for entity type: " + entity_type) uuids_list = response.json() return uuids_list # Create a dict with HTTP Authorization header with Bearer token def create_request_headers_for_auth(token): auth_header_name = 'Authorization' auth_scheme = 'Bearer' headers_dict = { # Don't forget the space between scheme and the token value auth_header_name: auth_scheme + ' ' + token } return headers_dict def get_uuids_from_es(index, es_url): uuids = [] size = 10_000 query = { "size": size, "from": len(uuids), "_source": ["_id"], "query": { "bool": { "must": [], "filter": [ { "match_all": {} } ], "should": [], "must_not": [] } } } end_of_list = False while not end_of_list: logger.debug("Searching ES for uuids...") logger.debug(es_url) resp = execute_query('_search', None, index, es_url, query) logger.debug('Got a response from ES...') ret_obj = resp.get_json() uuids.extend(hit['_id'] for hit in ret_obj.get('hits').get('hits')) total = ret_obj.get('hits').get('total').get('value') if total <= len(uuids): end_of_list = True else: query['from'] = len(uuids) return uuids def init_indexer(token): return Indexer( INDICES, app.config['APP_CLIENT_ID'], app.config['APP_CLIENT_SECRET'], token ) def reindex_all_uuids(indexer, token): with app.app_context(): try: logger.info("############# Reindex Live Started #############") start = time.time() # Make calls to entity-api to get a list of uuids for each entity type donor_uuids_list = get_uuids_by_entity_type("donor", token) sample_uuids_list = get_uuids_by_entity_type("sample", token) dataset_uuids_list = get_uuids_by_entity_type("dataset", token) upload_uuids_list = get_uuids_by_entity_type("upload", token) public_collection_uuids_list = get_uuids_by_entity_type("collection", token) logger.debug("merging sets into a one list...") # Merge into a big list that with no duplicates all_entities_uuids = set(donor_uuids_list + sample_uuids_list + dataset_uuids_list + upload_uuids_list + public_collection_uuids_list) es_uuids = [] #for index in ast.literal_eval(app.config['INDICES']).keys(): logger.debug("looping through the indices...") logger.debug(INDICES['indices'].keys()) index_names = get_all_indice_names() logger.debug(index_names) for index in index_names.keys(): all_indices = index_names[index] # get URL for that index es_url = INDICES['indices'][index]['elasticsearch']['url'].strip('/') for actual_index in all_indices: es_uuids.extend(get_uuids_from_es(actual_index, es_url)) es_uuids = set(es_uuids) logger.debug("looping through the UUIDs...") # Remove entities found in Elasticserach but no longer in neo4j for uuid in es_uuids: if uuid not in all_entities_uuids: logger.debug(f"Entity of uuid: {uuid} found in Elasticserach but no longer in neo4j. Delete it from Elasticserach.") indexer.delete(uuid) logger.debug("Starting multi-thread reindexing ...") # Reindex in multi-treading mode for: # - each public collection # - each upload, only add to the hm_consortium_entities index (private index of the default) # - each donor and its descendants in the tree futures_list = [] results = [] with concurrent.futures.ThreadPoolExecutor() as executor: public_collection_futures_list = [executor.submit(indexer.index_public_collection, uuid, reindex = True) for uuid in public_collection_uuids_list] upload_futures_list = [executor.submit(indexer.index_upload, uuid, reindex = True) for uuid in upload_uuids_list] donor_futures_list = [executor.submit(indexer.index_tree, uuid) for uuid in donor_uuids_list] # Append the above three lists into one futures_list = public_collection_futures_list + upload_futures_list + donor_futures_list for f in concurrent.futures.as_completed(futures_list): logger.debug(f.result()) end = time.time() logger.info(f"############# Live Reindex-All Completed. Total time used: {end - start} seconds. #############") except Exception as e: logger.error(e) # Gets a list of actually public and private indice names def get_all_indice_names(): all_names = {} try: indices = INDICES['indices'].keys() for i in indices: index_info = {} index_names = [] public_index = INDICES['indices'][i]['public'] private_index = INDICES['indices'][i]['private'] index_names.append(public_index) index_names.append(private_index) index_info[i] = index_names all_names.update(index_info) except Exception as e: raise e return all_names # Get a list of filtered Elasticsearch indices to expose to end users without the prefix def get_filtered_indices(): # just get all the defined index keys from the yml file indices = INDICES['indices'].keys() return list(indices) # For local development/testing if __name__ == "__main__": try: app.run(host='0.0.0.0', port="5005") except Exception as e: print("Error during starting debug server.") print(str(e)) logger.error(e, exc_info=True) print("Error during startup check the log file for further information")
[ "logging.getLogger", "requests.post", "flask.request.args.items", "flask.current_app.route", "libs.assay_type.AssayType.iter_names", "flask.current_app.app_context", "flask.current_app.errorhandler", "flask.jsonify", "flask.current_app.config.from_pyfile", "pathlib.Path", "flask.abort", "hubma...
[((870, 1024), 'logging.basicConfig', 'logging.basicConfig', ([], {'format': '"""[%(asctime)s] %(levelname)s in %(module)s:%(lineno)d: %(message)s"""', 'level': 'logging.DEBUG', 'datefmt': '"""%Y-%m-%d %H:%M:%S"""'}), "(format=\n '[%(asctime)s] %(levelname)s in %(module)s:%(lineno)d: %(message)s',\n level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S')\n", (889, 1024), False, 'import logging\n'), ((1025, 1052), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (1042, 1052), False, 'import logging\n'), ((1296, 1329), 'flask.current_app.config.from_pyfile', 'app.config.from_pyfile', (['"""app.cfg"""'], {}), "('app.cfg')\n", (1318, 1329), True, 'from flask import current_app as app\n'), ((2035, 2110), 'requests.packages.urllib3.disable_warnings', 'requests.packages.urllib3.disable_warnings', ([], {'category': 'InsecureRequestWarning'}), '(category=InsecureRequestWarning)\n', (2077, 2110), False, 'import requests\n'), ((2407, 2428), 'flask.current_app.errorhandler', 'app.errorhandler', (['(400)'], {}), '(400)\n', (2423, 2428), True, 'from flask import current_app as app\n'), ((2557, 2578), 'flask.current_app.errorhandler', 'app.errorhandler', (['(401)'], {}), '(401)\n', (2573, 2578), True, 'from flask import current_app as app\n'), ((2705, 2726), 'flask.current_app.errorhandler', 'app.errorhandler', (['(403)'], {}), '(403)\n', (2721, 2726), True, 'from flask import current_app as app\n'), ((2862, 2883), 'flask.current_app.errorhandler', 'app.errorhandler', (['(500)'], {}), '(500)\n', (2878, 2883), True, 'from flask import current_app as app\n'), ((3967, 3998), 'flask.current_app.route', 'app.route', (['"""/"""'], {'methods': "['GET']"}), "('/', methods=['GET'])\n", (3976, 3998), True, 'from flask import current_app as app\n'), ((4294, 4334), 'flask.current_app.route', 'app.route', (['"""/assaytype"""'], {'methods': "['GET']"}), "('/assaytype', methods=['GET'])\n", (4303, 4334), True, 'from flask import current_app as app\n'), ((4974, 5021), 'flask.current_app.route', 'app.route', (['"""/assaytype/<name>"""'], {'methods': "['GET']"}), "('/assaytype/<name>', methods=['GET'])\n", (4983, 5021), True, 'from flask import current_app as app\n'), ((5025, 5066), 'flask.current_app.route', 'app.route', (['"""/assayname"""'], {'methods': "['POST']"}), "('/assayname', methods=['POST'])\n", (5034, 5066), True, 'from flask import current_app as app\n'), ((5770, 5815), 'flask.current_app.route', 'app.route', (['"""/search"""'], {'methods': "['GET', 'POST']"}), "('/search', methods=['GET', 'POST'])\n", (5779, 5815), True, 'from flask import current_app as app\n'), ((6728, 6796), 'flask.current_app.route', 'app.route', (['"""/<index_without_prefix>/search"""'], {'methods': "['GET', 'POST']"}), "('/<index_without_prefix>/search', methods=['GET', 'POST'])\n", (6737, 6796), True, 'from flask import current_app as app\n'), ((7594, 7630), 'flask.current_app.route', 'app.route', (['"""/count"""'], {'methods': "['GET']"}), "('/count', methods=['GET'])\n", (7603, 7630), True, 'from flask import current_app as app\n'), ((8373, 8432), 'flask.current_app.route', 'app.route', (['"""/<index_without_prefix>/count"""'], {'methods': "['GET']"}), "('/<index_without_prefix>/count', methods=['GET'])\n", (8382, 8432), True, 'from flask import current_app as app\n'), ((9169, 9207), 'flask.current_app.route', 'app.route', (['"""/indices"""'], {'methods': "['GET']"}), "('/indices', methods=['GET'])\n", (9178, 9207), True, 'from flask import current_app as app\n'), ((9518, 9555), 'flask.current_app.route', 'app.route', (['"""/status"""'], {'methods': "['GET']"}), "('/status', methods=['GET'])\n", (9527, 9555), True, 'from flask import current_app as app\n'), ((10538, 10583), 'flask.current_app.route', 'app.route', (['"""/reindex/<uuid>"""'], {'methods': "['PUT']"}), "('/reindex/<uuid>', methods=['PUT'])\n", (10547, 10583), True, 'from flask import current_app as app\n'), ((11359, 11401), 'flask.current_app.route', 'app.route', (['"""/reindex-all"""'], {'methods': "['PUT']"}), "('/reindex-all', methods=['PUT'])\n", (11368, 11401), True, 'from flask import current_app as app\n'), ((4413, 4433), 'flask.request.args.items', 'request.args.items', ([], {}), '()\n', (4431, 4433), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((9352, 9367), 'flask.jsonify', 'jsonify', (['result'], {}), '(result)\n', (9359, 9367), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((10061, 10089), 'requests.get', 'requests.get', ([], {'url': 'target_url'}), '(url=target_url)\n', (10073, 10089), False, 'import requests\n'), ((10395, 10417), 'flask.jsonify', 'jsonify', (['response_data'], {}), '(response_data)\n', (10402, 10417), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((12345, 12376), 'flask.abort', 'abort', (['(400)'], {'description': 'err_msg'}), '(400, description=err_msg)\n', (12350, 12376), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((12466, 12497), 'flask.abort', 'abort', (['(401)'], {'description': 'err_msg'}), '(401, description=err_msg)\n', (12471, 12497), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((12581, 12612), 'flask.abort', 'abort', (['(403)'], {'description': 'err_msg'}), '(403, description=err_msg)\n', (12586, 12612), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((12714, 12745), 'flask.abort', 'abort', (['(500)'], {'description': 'err_msg'}), '(500, description=err_msg)\n', (12719, 12745), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((21468, 21513), 'requests.post', 'requests.post', ([], {'url': 'target_url', 'json': 'json_data'}), '(url=target_url, json=json_data)\n', (21481, 21513), False, 'import requests\n'), ((21775, 21788), 'flask.jsonify', 'jsonify', (['resp'], {}), '(resp)\n', (21782, 21788), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((21900, 21913), 'urllib.parse.urlparse', 'urlparse', (['url'], {}), '(url)\n', (21908, 21913), False, 'from urllib.parse import urlparse\n'), ((22893, 22949), 'requests.get', 'requests.get', (['url'], {'headers': 'request_headers', 'verify': '(False)'}), '(url, headers=request_headers, verify=False)\n', (22905, 22949), False, 'import requests\n'), ((24588, 24678), 'elasticsearch.indexer.Indexer', 'Indexer', (['INDICES', "app.config['APP_CLIENT_ID']", "app.config['APP_CLIENT_SECRET']", 'token'], {}), "(INDICES, app.config['APP_CLIENT_ID'], app.config[\n 'APP_CLIENT_SECRET'], token)\n", (24595, 24678), False, 'from elasticsearch.indexer import Indexer\n'), ((3253, 3279), 'hubmap_commons.hm_auth.AuthHelper.isInitialized', 'AuthHelper.isInitialized', ([], {}), '()\n', (3277, 3279), False, 'from hubmap_commons.hm_auth import AuthHelper\n'), ((3321, 3400), 'hubmap_commons.hm_auth.AuthHelper.create', 'AuthHelper.create', (["app.config['APP_CLIENT_ID']", "app.config['APP_CLIENT_SECRET']"], {}), "(app.config['APP_CLIENT_ID'], app.config['APP_CLIENT_SECRET'])\n", (3338, 3400), False, 'from hubmap_commons.hm_auth import AuthHelper\n'), ((3561, 3582), 'hubmap_commons.hm_auth.AuthHelper.instance', 'AuthHelper.instance', ([], {}), '()\n', (3580, 3582), False, 'from hubmap_commons.hm_auth import AuthHelper\n'), ((4861, 4883), 'flask.jsonify', 'jsonify', ([], {'result': 'name_l'}), '(result=name_l)\n', (4868, 4883), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((20938, 20956), 'flask.request.get_json', 'request.get_json', ([], {}), '()\n', (20954, 20956), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((24761, 24778), 'flask.current_app.app_context', 'app.app_context', ([], {}), '()\n', (24776, 24778), True, 'from flask import current_app as app\n'), ((29038, 29074), 'flask.current_app.run', 'app.run', ([], {'host': '"""0.0.0.0"""', 'port': '"""5005"""'}), "(host='0.0.0.0', port='5005')\n", (29045, 29074), True, 'from flask import current_app as app\n'), ((24901, 24912), 'time.time', 'time.time', ([], {}), '()\n', (24910, 24912), False, 'import time\n'), ((27908, 27919), 'time.time', 'time.time', ([], {}), '()\n', (27917, 27919), False, 'import time\n'), ((1224, 1249), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (1239, 1249), False, 'import os\n'), ((4607, 4653), 'flask.abort', 'abort', (['(400)', 'f"""invalid request parameter {key}"""'], {}), "(400, f'invalid request parameter {key}')\n", (4612, 4653), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((4714, 4736), 'libs.assay_type.AssayType.iter_names', 'AssayType.iter_names', ([], {}), '()\n', (4734, 4736), False, 'from libs.assay_type import AssayType\n'), ((4783, 4820), 'libs.assay_type.AssayType.iter_names', 'AssayType.iter_names', ([], {'primary': 'primary'}), '(primary=primary)\n', (4803, 4820), False, 'from libs.assay_type import AssayType\n'), ((5246, 5292), 'flask.abort', 'abort', (['(400)', '"""request contains no "name" field"""'], {}), '(400, \'request contains no "name" field\')\n', (5251, 5292), False, 'from flask import Flask, jsonify, abort, request, Response, Request\n'), ((10875, 10928), 'threading.Thread', 'threading.Thread', ([], {'target': 'indexer.reindex', 'args': '[uuid]'}), '(target=indexer.reindex, args=[uuid])\n', (10891, 10928), False, 'import threading\n'), ((11742, 11807), 'threading.Thread', 'threading.Thread', ([], {'target': 'reindex_all_uuids', 'args': '[indexer, token]'}), '(target=reindex_all_uuids, args=[indexer, token])\n', (11758, 11807), False, 'import threading\n'), ((5325, 5340), 'libs.assay_type.AssayType', 'AssayType', (['name'], {}), '(name)\n', (5334, 5340), False, 'from libs.assay_type import AssayType\n'), ((1404, 1418), 'pathlib.Path', 'Path', (['__file__'], {}), '(__file__)\n', (1408, 1418), False, 'from pathlib import Path\n'), ((4925, 4940), 'libs.assay_type.AssayType', 'AssayType', (['name'], {}), '(name)\n', (4934, 4940), False, 'from libs.assay_type import AssayType\n'), ((9695, 9709), 'pathlib.Path', 'Path', (['__file__'], {}), '(__file__)\n', (9699, 9709), False, 'from pathlib import Path\n'), ((9789, 9803), 'pathlib.Path', 'Path', (['__file__'], {}), '(__file__)\n', (9793, 9803), False, 'from pathlib import Path\n')]
#!/usr/bin/env python # # Creates resources # This script creates VPC/security group/keypair if not already present import logging import os import sys import time from . import aws_util as u from . import util DRYRUN = False DEBUG = True # Names of Amazon resources that are created. These settings are fixed across # all runs, and correspond to resources created once per user per region. PUBLIC_TCP_RANGES = [ 22, # ssh (8888, 8899), # ipython notebook ports 6379, # redis port (6006, 6016) # tensorboard ports ] PUBLIC_UDP_RANGES = [(60000, 61000)] # mosh ports logger = logging.getLogger(__name__) def network_setup(): """Creates VPC if it doesn't already exists, configures it for public internet access, returns vpc, subnet, security_group""" ec2 = u.get_ec2_resource() client = u.get_ec2_client() existing_vpcs = u.get_vpc_dict() zones = u.get_zones() # create VPC from scratch. Remove this if default VPC works well enough. vpc_name = u.get_vpc_name() if u.get_vpc_name() in existing_vpcs: logger.info("Reusing VPC " + vpc_name) vpc = existing_vpcs[vpc_name] else: logger.info("Creating VPC " + vpc_name) vpc = ec2.create_vpc(CidrBlock='192.168.0.0/16') # enable DNS on the VPC local_response = vpc.modify_attribute(EnableDnsHostnames={"Value": True}) assert u.is_good_response(local_response) local_response = vpc.modify_attribute(EnableDnsSupport={"Value": True}) assert u.is_good_response(local_response) vpc.create_tags(Tags=u.create_name_tags(vpc_name)) vpc.wait_until_available() gateways = u.get_gateway_dict(vpc) gateway_name = u.get_gateway_name() if gateway_name in gateways: logger.info("Reusing gateways " + gateway_name) else: logger.info("Creating internet gateway " + gateway_name) ig = ec2.create_internet_gateway() ig.attach_to_vpc(VpcId=vpc.id) ig.create_tags(Tags=u.create_name_tags(gateway_name)) # check that attachment succeeded attach_state = u.extract_attr_for_match(ig.attachments, State=-1, VpcId=vpc.id) assert attach_state == 'available', "vpc %s is in state %s" % (vpc.id, attach_state) route_table = vpc.create_route_table() route_table_name = u.get_route_table_name() route_table.create_tags(Tags=u.create_name_tags(route_table_name)) dest_cidr = '0.0.0.0/0' route_table.create_route(DestinationCidrBlock=dest_cidr, GatewayId=ig.id) assert len(zones) <= 16 # for cidr/20 to fit into cidr/16 ip = 0 for zone in zones: cidr_block = '192.168.%d.0/20' % (ip,) ip += 16 logging.info("Creating subnet %s in zone %s" % (cidr_block, zone)) subnet = vpc.create_subnet(CidrBlock=cidr_block, AvailabilityZone=zone) subnet.create_tags(Tags=[{'Key': 'Name', 'Value': f'{vpc_name}-subnet'}, {'Key': 'Region', 'Value': zone}]) local_response = client.modify_subnet_attribute(MapPublicIpOnLaunch={'Value': True}, SubnetId=subnet.id) assert u.is_good_response(local_response) u.wait_until_available(subnet) assert subnet.map_public_ip_on_launch, "Subnet doesn't enable public IP by default, why?" route_table.associate_with_subnet(SubnetId=subnet.id) existing_security_groups = u.get_security_group_dict(vpc.id) security_group_name = u.get_security_group_name() if security_group_name in existing_security_groups: logger.info("Reusing security group " + security_group_name) security_group = existing_security_groups[security_group_name] assert security_group.vpc_id == vpc.id, f"Found security group {security_group} " \ f"attached to {security_group.vpc_id} but expected {vpc.id}" else: logging.info("Creating security group " + security_group_name) security_group = ec2.create_security_group( GroupName=security_group_name, Description=security_group_name, VpcId=vpc.id) cidr_ip = os.environ.get('SCLUSTER_SECURITY_GROUP_CidrIp', '0.0.0.0/0') security_group.create_tags(Tags=u.create_name_tags(security_group_name)) # allow ICMP access for public ping security_group.authorize_ingress( CidrIp='0.0.0.0/0', IpProtocol='icmp', FromPort=-1, ToPort=-1 ) # open public ports # always include SSH port which is required for basic functionality assert 22 in PUBLIC_TCP_RANGES, "Must enable SSH access" for port in PUBLIC_TCP_RANGES: if util.is_iterable(port): assert len(port) == 2 from_port, to_port = port else: from_port, to_port = port, port response = security_group.authorize_ingress( IpProtocol="tcp", CidrIp=cidr_ip, FromPort=from_port, ToPort=to_port ) assert u.is_good_response(response) for port in PUBLIC_UDP_RANGES: if util.is_iterable(port): assert len(port) == 2 from_port, to_port = port else: from_port, to_port = port, port response = security_group.authorize_ingress(IpProtocol="udp", CidrIp=cidr_ip, FromPort=from_port, ToPort=to_port) assert u.is_good_response(response) return vpc, security_group def keypair_setup(): """Creates keypair if necessary, saves private key locally, returns contents of private key file.""" os.system('mkdir -p ' + u.PRIVATE_KEY_LOCATION) keypair_name = u.get_keypair_name() keypair = u.get_keypair_dict().get(keypair_name, None) keypair_fn = u.get_keypair_fn() if keypair: print("Reusing keypair " + keypair_name) # check that local pem file exists and is readable assert os.path.exists( keypair_fn), "Keypair %s exists, but corresponding .pem file %s is not found, delete keypair %s through " \ "console and run again to recreate keypair/.pem together" % ( keypair_name, keypair_fn, keypair_name) keypair_contents = open(keypair_fn).read() assert len(keypair_contents) > 0 else: print("Creating keypair " + keypair_name) ec2 = u.get_ec2_resource() assert not os.path.exists( keypair_fn), "previous keypair exists, delete it with 'sudo rm %s' and also delete corresponding " \ "keypair through console" % (keypair_fn) keypair = ec2.create_key_pair(KeyName=keypair_name) open(keypair_fn, 'w').write(keypair.key_material) os.system('chmod 400 ' + keypair_fn) return keypair def placement_group_setup(group_name): """Creates placement_group group if necessary. Returns True if new placement_group group was created, False otherwise.""" existing_placement_groups = u.get_placement_group_dict() group = existing_placement_groups.get(group_name, None) if group: assert group.state == 'available' assert group.strategy == 'cluster' print("Reusing group ", group.name) return group print("Creating group " + group_name) ec2 = u.get_ec2_resource() group = ec2.create_placement_group(GroupName=group_name, Strategy='cluster') return group def create_resources(): logger.info(f"Creating {u.get_prefix()} resources in region {u.get_region()}") vpc, security_group = network_setup() keypair_setup() # saves private key locally to keypair_fn # create EFS efss = u.get_efs_dict() efs_name = u.get_efs_name() efs_id = efss.get(efs_name, '') if not efs_id: logger.info("Creating EFS " + efs_name) efs_id = u.create_efs(efs_name) else: logger.info("Reusing EFS " + efs_name) efs_client = u.get_efs_client() # create mount target for each subnet in the VPC # added retries because efs is not immediately available max_failures = 10 retry_interval_sec = 1 for subnet in vpc.subnets.all(): for retry_attempt in range(max_failures): try: sys.stdout.write("Creating efs mount target for %s ... " % (subnet.availability_zone,)) sys.stdout.flush() response = efs_client.create_mount_target( FileSystemId=efs_id, SubnetId=subnet.id, SecurityGroups=[security_group.id] ) if u.is_good_response(response): logger.info("success") break except Exception as e: if 'already exists' in str(e): # ignore "already exists" errors logger.info('already exists') break # Takes couple of seconds for EFS to come online, with # errors like this: # Creating efs mount target for us-east-1f ... Failed with An error occurred (IncorrectFileSystemLifeCycleState) when calling the CreateMountTarget operation: None, retrying in 1 sec logger.info("Got %s, retrying in %s sec" % (str(e), retry_interval_sec)) time.sleep(retry_interval_sec) else: logger.info("Giving up.") if __name__ == '__main__': create_resources()
[ "logging.getLogger", "os.path.exists", "os.environ.get", "time.sleep", "os.system", "sys.stdout.flush", "logging.info", "sys.stdout.write" ]
[((595, 622), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (612, 622), False, 'import logging\n'), ((5900, 5947), 'os.system', 'os.system', (["('mkdir -p ' + u.PRIVATE_KEY_LOCATION)"], {}), "('mkdir -p ' + u.PRIVATE_KEY_LOCATION)\n", (5909, 5947), False, 'import os\n'), ((3934, 3996), 'logging.info', 'logging.info', (["('Creating security group ' + security_group_name)"], {}), "('Creating security group ' + security_group_name)\n", (3946, 3996), False, 'import logging\n'), ((4165, 4226), 'os.environ.get', 'os.environ.get', (['"""SCLUSTER_SECURITY_GROUP_CidrIp"""', '"""0.0.0.0/0"""'], {}), "('SCLUSTER_SECURITY_GROUP_CidrIp', '0.0.0.0/0')\n", (4179, 4226), False, 'import os\n'), ((6223, 6249), 'os.path.exists', 'os.path.exists', (['keypair_fn'], {}), '(keypair_fn)\n', (6237, 6249), False, 'import os\n'), ((7016, 7052), 'os.system', 'os.system', (["('chmod 400 ' + keypair_fn)"], {}), "('chmod 400 ' + keypair_fn)\n", (7025, 7052), False, 'import os\n'), ((2745, 2811), 'logging.info', 'logging.info', (["('Creating subnet %s in zone %s' % (cidr_block, zone))"], {}), "('Creating subnet %s in zone %s' % (cidr_block, zone))\n", (2757, 2811), False, 'import logging\n'), ((6698, 6724), 'os.path.exists', 'os.path.exists', (['keypair_fn'], {}), '(keypair_fn)\n', (6712, 6724), False, 'import os\n'), ((8518, 8610), 'sys.stdout.write', 'sys.stdout.write', (["('Creating efs mount target for %s ... ' % (subnet.availability_zone,))"], {}), "('Creating efs mount target for %s ... ' % (subnet.\n availability_zone,))\n", (8534, 8610), False, 'import sys\n'), ((8622, 8640), 'sys.stdout.flush', 'sys.stdout.flush', ([], {}), '()\n', (8638, 8640), False, 'import sys\n'), ((9577, 9607), 'time.sleep', 'time.sleep', (['retry_interval_sec'], {}), '(retry_interval_sec)\n', (9587, 9607), False, 'import time\n')]
# # Copyright (c) 2020, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import warnings try: from numba import cuda except ImportError: cuda = None try: import psutil except ImportError: psutil = None def _pynvml_mem_size(kind="total", index=0): import pynvml pynvml.nvmlInit() size = None if kind == "free": size = int(pynvml.nvmlDeviceGetMemoryInfo(pynvml.nvmlDeviceGetHandleByIndex(index)).free) elif kind == "total": size = int(pynvml.nvmlDeviceGetMemoryInfo(pynvml.nvmlDeviceGetHandleByIndex(index)).total) else: raise ValueError("{0} not a supported option for device_mem_size.".format(kind)) pynvml.nvmlShutdown() return size def device_mem_size(kind="total", cpu=False): # Use psutil (if available) for cpu mode if cpu and psutil: if kind == "total": return psutil.virtual_memory().total elif kind == "free": return psutil.virtual_memory().free elif cpu: warnings.warn("Please install psutil for full cpu=True support.") # Assume 1GB of memory return int(1e9) if kind not in ["free", "total"]: raise ValueError("{0} not a supported option for device_mem_size.".format(kind)) try: if kind == "free": return int(cuda.current_context().get_memory_info()[0]) else: return int(cuda.current_context().get_memory_info()[1]) except NotImplementedError: if kind == "free": # Not using NVML "free" memory, because it will not include RMM-managed memory warnings.warn("get_memory_info is not supported. Using total device memory from NVML.") size = _pynvml_mem_size(kind="total", index=0) return size def get_rmm_size(size): return (size // 256) * 256
[ "pynvml.nvmlShutdown", "pynvml.nvmlDeviceGetHandleByIndex", "pynvml.nvmlInit", "psutil.virtual_memory", "numba.cuda.current_context", "warnings.warn" ]
[((809, 826), 'pynvml.nvmlInit', 'pynvml.nvmlInit', ([], {}), '()\n', (824, 826), False, 'import pynvml\n'), ((1192, 1213), 'pynvml.nvmlShutdown', 'pynvml.nvmlShutdown', ([], {}), '()\n', (1211, 1213), False, 'import pynvml\n'), ((1523, 1588), 'warnings.warn', 'warnings.warn', (['"""Please install psutil for full cpu=True support."""'], {}), "('Please install psutil for full cpu=True support.')\n", (1536, 1588), False, 'import warnings\n'), ((1394, 1417), 'psutil.virtual_memory', 'psutil.virtual_memory', ([], {}), '()\n', (1415, 1417), False, 'import psutil\n'), ((2120, 2212), 'warnings.warn', 'warnings.warn', (['"""get_memory_info is not supported. Using total device memory from NVML."""'], {}), "(\n 'get_memory_info is not supported. Using total device memory from NVML.')\n", (2133, 2212), False, 'import warnings\n'), ((916, 956), 'pynvml.nvmlDeviceGetHandleByIndex', 'pynvml.nvmlDeviceGetHandleByIndex', (['index'], {}), '(index)\n', (949, 956), False, 'import pynvml\n'), ((1472, 1495), 'psutil.virtual_memory', 'psutil.virtual_memory', ([], {}), '()\n', (1493, 1495), False, 'import psutil\n'), ((1040, 1080), 'pynvml.nvmlDeviceGetHandleByIndex', 'pynvml.nvmlDeviceGetHandleByIndex', (['index'], {}), '(index)\n', (1073, 1080), False, 'import pynvml\n'), ((1831, 1853), 'numba.cuda.current_context', 'cuda.current_context', ([], {}), '()\n', (1851, 1853), False, 'from numba import cuda\n'), ((1913, 1935), 'numba.cuda.current_context', 'cuda.current_context', ([], {}), '()\n', (1933, 1935), False, 'from numba import cuda\n')]
import re import argparse import os import sys import logging import traceback import pysatl class EtsiTs101955(object): COMMENT_MARKER = "REM" COMMAND_MARKER = "CMD" RESET_MARKER = "RST" INIT_MARKER = "INI" OFF_MARKER = "OFF" def __init__(self, cmdHandler): self._cmdHandler = cmdHandler def runStream(self, scriptStream, *, line_cnt = 0): lineBuf = "" for line in scriptStream: line_cnt += 1 if line in ["\n", "\r"]: line = "" elif len(line): while line[-1] in ["\n", "\r"]: # remove end of line characters line = line[:-1] if 0 == len(line): continue if 0 == len(line): continue lineBreak = line[-1] == "\\" if lineBreak: lineBuf += line[:-1] continue line = lineBuf + line lineBuf = "" logging.debug("line %4d: '%s'" % (line_cnt, line)) if 0 == len(line): continue if line.startswith(EtsiTs101955.COMMENT_MARKER): self._cmdHandler.comment(line[len(EtsiTs101955.COMMENT_MARKER):]) continue tokens = line.split() if tokens[0] == EtsiTs101955.RESET_MARKER: self._cmdHandler.reset() elif tokens[0] == EtsiTs101955.OFF_MARKER: self._cmdHandler.off() elif tokens[0] == EtsiTs101955.INIT_MARKER: datstr = line[len(tokens[0]):] dat = pysatl.Utils.ba(datstr) self._cmdHandler.init(dat) elif tokens[0] == EtsiTs101955.COMMAND_MARKER: params = line[len(tokens[0]):] cmd_params_pattern = re.compile(r"(.*)\[(.*)\]\s*\((.*)\)") matchRes = cmd_params_pattern.match(params) if matchRes is not None: capdustr = matchRes.group(1) leDatStr = matchRes.group(2).replace(" ","").replace("\t","").lower() swStr = matchRes.group(3).replace(" ","").replace("\t","").lower() else: cmd_params_pattern = re.compile(r"(.*)\s*\((.*)\)") matchRes = cmd_params_pattern.match(params) capdustr = matchRes.group(1) leDatStr = "" swStr = matchRes.group(2) swStr = swStr.replace(" ","").replace("\t","").lower() capdu = pysatl.CAPDU.from_hexstr(capdustr) rapdu = self._cmdHandler.apdu(capdu,leDatStr,swStr) swlist = swStr.split(",") swMatch = False for sw in swlist: swMatch |= rapdu.matchSW(sw) if not swMatch: raise Exception("RAPDU does not match any of the expected status word") if not rapdu.matchDATA(leDatStr): raise Exception("RAPDU does not match expected outgoing data") else: raise Exception("line %d, syntax not supported: '%s'"%(line_cnt,line)) def runFile(scriptFile, apduHandler): tool = EtsiTs101955(apduHandler) with open(scriptFile) as script: tool.runStream(script) class CmdHandler(object): """Base class for command handlers""" def __init__(self): pass def apdu(self, capdu, leDatStr="", swStr=""): dat = pysatl.Utils.ba(leDatStr.replace('x','0')) sw=0 swStr = swStr.split(",")[0] for i in range(0,len(swStr)): d = swStr[i] sw = (sw << 4) | int(d,16) sw1=sw >> 8 sw2=sw & 0xFF rapdu = pysatl.RAPDU(SW1=sw1,SW2=sw2, DATA=dat) line = "CMD " header_len = 4 lc=len(capdu.DATA) if lc: header_len = 5 if lc>255: header_len = 7 else: header_len = 5 if capdu.LE>256: header_len = 7 dat = capdu.to_ba() line += pysatl.Utils.hexstr(dat[:header_len]) if len(capdu.DATA) > 0: line += " \\\n " dat = capdu.DATA while len(dat) > 16: line += pysatl.Utils.hexstr(dat[0:16]) + " \\\n " dat = dat[16:] line += pysatl.Utils.hexstr(dat) if len(rapdu.DATA) > 0: line += " \\\n [" dat = rapdu.DATA while len(dat) > 16: line += pysatl.Utils.hexstr(dat[0:16]) + " \\\n " dat = dat[16:] line += pysatl.Utils.hexstr(dat) line += " ] \\\n" elif capdu.LE > 0: line += " []" line += " ("+ pysatl.Utils.hexstr(rapdu.swBytes()) +")" logging.info(line) return rapdu def reset(self): logging.info("RST") def init(self, dat): logging.info("INIT "+pysatl.Utils.hexstr(dat)) def off(self): logging.info("OFF") def comment(self, msg): logging.info("REM %s" % (msg)) class ApduTool(object): """ETSI TS 101 955 script player""" def __init__(self, argv): scriptname = os.path.basename(__file__) parser = argparse.ArgumentParser(scriptname) #TODO: pass argv to parser. levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL') parser.add_argument('--log-level', default='INFO', choices=levels) parser.add_argument('--script', default="stdin", help='path to script', type=str) options = parser.parse_args() root = logging.getLogger() root.setLevel(options.log_level) if options.script == "stdin": player = EtsiTs101955(CmdHandler()) player.runStream(sys.stdin) else: EtsiTs101955.runFile(options.script,CmdHandler()) if __name__ == "__main__": ApduTool(sys.argv)
[ "logging.getLogger", "logging.debug", "argparse.ArgumentParser", "re.compile", "pysatl.RAPDU", "pysatl.Utils.ba", "os.path.basename", "pysatl.CAPDU.from_hexstr", "pysatl.Utils.hexstr", "logging.info" ]
[((3787, 3827), 'pysatl.RAPDU', 'pysatl.RAPDU', ([], {'SW1': 'sw1', 'SW2': 'sw2', 'DATA': 'dat'}), '(SW1=sw1, SW2=sw2, DATA=dat)\n', (3799, 3827), False, 'import pysatl\n'), ((4140, 4177), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat[:header_len]'], {}), '(dat[:header_len])\n', (4159, 4177), False, 'import pysatl\n'), ((4864, 4882), 'logging.info', 'logging.info', (['line'], {}), '(line)\n', (4876, 4882), False, 'import logging\n'), ((4934, 4953), 'logging.info', 'logging.info', (['"""RST"""'], {}), "('RST')\n", (4946, 4953), False, 'import logging\n'), ((5063, 5082), 'logging.info', 'logging.info', (['"""OFF"""'], {}), "('OFF')\n", (5075, 5082), False, 'import logging\n'), ((5120, 5148), 'logging.info', 'logging.info', (["('REM %s' % msg)"], {}), "('REM %s' % msg)\n", (5132, 5148), False, 'import logging\n'), ((5268, 5294), 'os.path.basename', 'os.path.basename', (['__file__'], {}), '(__file__)\n', (5284, 5294), False, 'import os\n'), ((5312, 5347), 'argparse.ArgumentParser', 'argparse.ArgumentParser', (['scriptname'], {}), '(scriptname)\n', (5335, 5347), False, 'import argparse\n'), ((5669, 5688), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (5686, 5688), False, 'import logging\n'), ((999, 1049), 'logging.debug', 'logging.debug', (['("line %4d: \'%s\'" % (line_cnt, line))'], {}), '("line %4d: \'%s\'" % (line_cnt, line))\n', (1012, 1049), False, 'import logging\n'), ((4418, 4442), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat'], {}), '(dat)\n', (4437, 4442), False, 'import pysatl\n'), ((4684, 4708), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat'], {}), '(dat)\n', (4703, 4708), False, 'import pysatl\n'), ((5009, 5033), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat'], {}), '(dat)\n', (5028, 5033), False, 'import pysatl\n'), ((4325, 4355), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat[0:16]'], {}), '(dat[0:16])\n', (4344, 4355), False, 'import pysatl\n'), ((4591, 4621), 'pysatl.Utils.hexstr', 'pysatl.Utils.hexstr', (['dat[0:16]'], {}), '(dat[0:16])\n', (4610, 4621), False, 'import pysatl\n'), ((1623, 1646), 'pysatl.Utils.ba', 'pysatl.Utils.ba', (['datstr'], {}), '(datstr)\n', (1638, 1646), False, 'import pysatl\n'), ((1833, 1875), 're.compile', 're.compile', (['"""(.*)\\\\[(.*)\\\\]\\\\s*\\\\((.*)\\\\)"""'], {}), "('(.*)\\\\[(.*)\\\\]\\\\s*\\\\((.*)\\\\)')\n", (1843, 1875), False, 'import re\n'), ((2581, 2615), 'pysatl.CAPDU.from_hexstr', 'pysatl.CAPDU.from_hexstr', (['capdustr'], {}), '(capdustr)\n', (2605, 2615), False, 'import pysatl\n'), ((2262, 2294), 're.compile', 're.compile', (['"""(.*)\\\\s*\\\\((.*)\\\\)"""'], {}), "('(.*)\\\\s*\\\\((.*)\\\\)')\n", (2272, 2294), False, 'import re\n')]
#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2017 <EMAIL> # Licensed under the MIT license (http://opensource.org/licenses/MIT) import cffi import ctypes.util import platform ffi = cffi.FFI() ffi.cdef(""" struct hid_device_info { char *path; unsigned short vendor_id; unsigned short product_id; wchar_t *serial_number; unsigned short release_number; wchar_t *manufacturer_string; wchar_t *product_string; unsigned short usage_page; unsigned short usage; int interface_number; struct hid_device_info *next; }; typedef struct hid_device_ hid_device; int hid_init(void); int hid_exit(void); struct hid_device_info* hid_enumerate(unsigned short, unsigned short); void hid_free_enumeration (struct hid_device_info *devs); hid_device* hid_open (unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number); hid_device* hid_open_path (const char *path); int hid_write (hid_device *device, const unsigned char *data, size_t length); int hid_read_timeout (hid_device *dev, unsigned char *data, size_t length, int milliseconds); int hid_read (hid_device *device, unsigned char *data, size_t length); int hid_set_nonblocking (hid_device *device, int nonblock); int hid_send_feature_report (hid_device *device, const unsigned char *data, size_t length); int hid_get_feature_report (hid_device *device, unsigned char *data, size_t length); void hid_close (hid_device *device); int hid_get_manufacturer_string (hid_device *device, wchar_t *string, size_t maxlen); int hid_get_product_string (hid_device *device, wchar_t *string, size_t maxlen); int hid_get_serial_number_string (hid_device *device, wchar_t *string, size_t maxlen); int hid_get_indexed_string (hid_device *device, int string_index, wchar_t *string, size_t maxlen); const wchar_t* hid_error (hid_device *device); """) if "Windows" in platform.platform(): try: hidapi = ffi.dlopen('hidapi.dll') except: hidapi = ffi.dlopen(ctypes.util.find_library('hidapi.dll')) else: try: hidapi = ffi.dlopen('hidapi-libusb') except: hidapi = ffi.dlopen(ctypes.util.find_library('hidapi-libusb')) def _c_to_py_str(val): if val == ffi.NULL: return None new_val = ffi.string(val) if type(new_val) == bytes or type(new_val) == bytearray: return new_val.decode("utf-8") else: return new_val class HIDException(Exception): pass class Device: def __init__(self, cdata): """ """ if cdata == ffi.NULL: raise TypeError self.path = _c_to_py_str(cdata.path) self.vendor_id = cdata.vendor_id self.product_id = cdata.product_id self.release_number = cdata.release_number self.manufacturer_string = _c_to_py_str(cdata.manufacturer_string) self.product_string = _c_to_py_str(cdata.product_string) self.serial_number = _c_to_py_str(cdata.serial_number) self.usage_page = cdata.usage_page self.usage = cdata.usage self.interface_number = cdata.interface_number self._device = None self._is_open = False def __del__(self): self.close() def open(self): if self._is_open: raise HIDException("Failed to open device: Device already open") path = self.path.encode('utf-8') dev = hidapi.hid_open_path(path) if dev: self._is_open = True self._device = dev else: raise HIDException("Failed to open device") def close(self): """ Closes the hid device """ if self._is_open: self._is_open = False hidapi.hid_close(self._device) def description(self): return self.info.description() def write(self, data, report_id=0): """ Writes `bytes` to the hid device. """ if not self._is_open: raise HIDException("Device not open") write_data = bytearray([report_id]) + bytearray(data) cdata = ffi.new("const unsigned char[]", bytes(write_data)) num_written = hidapi.hid_write(self._device, cdata, len(write_data)) if num_written < 0: raise HIDException("Failed to write to HID device: " + str(num_written)) else: return num_written def read(self, size=64, timeout=None): """ Read from the hid device. Returns bytes read or None if no bytes read. size: number of bytes to read timeout: length to wait in milliseconds """ if not self._is_open: raise HIDException("Device not open") data = [0] * size cdata = ffi.new("unsigned char[]", data) bytes_read = 0 if timeout == None: bytes_read = hidapi.hid_read(self._device, cdata, len(cdata)) else: bytes_read = hidapi.hid_read_timeout(self._device, cdata, len(cdata), timeout) if bytes_read < 0: raise HIDException("Failed to read from HID device: " + str(bytes_read)) elif bytes_read == 0: return None else: return bytearray(cdata) def set_nonblocking(self, enable_nonblocking): if not self._is_open: raise HIDException("Device not open") if type(enable_nonblocking) != bool: raise TypeError hidapi.hid_set_nonblocking(self._device, enable_nonblocking) def is_open(self): return _is_open def is_connected(self): """ Checks if the USB device is still connected """ if self._is_open: err = hidapi.hid_read_timeout(self._device, ffi.NULL, 0, 0) if err == -1: return False else: return True else: en = Enumeration(vid=self.vendor_id, pid=self.product_id).find(path=self.path) if len(en) == 0: return False else: return True # int hid_send_feature_report (hid_device *device, const unsigned char *data, size_t length); # def send_feature_report(self, data): # cdata = ffi.new("const unsigned char[]", data) # hidapi.hid_send_feature_report(self._device, cdata, length) # pass # def get_feature_report(self, size=64): # hid_data = bytes([report_id]) + bytes(data) # cdata = ffi.new("unsigned char[]", data) # hidapi.hid_send_feature_report(self._device, cdata, length) # pass def get_error(self): err_str = hidapi.hid_error(self._device) if err_str == ffi.NULL: return None else: return ffi.string(err_str) def _get_prod_string_common(self, hid_fn): max_len = 128 str_buf = ffi.new("wchar_t[]", bytearray(max_len).decode('utf-8')) ret = hid_fn(self._device, str_buf, max_len) if ret < 0: raise HIDException(self._device.get_error()) else: assert(ret == 0) return ffi.string(str_buf) # Probably don't need these excpet for get_indexed_string, since they won't # change from the values found in the enumeration def get_manufacture_string(self): """ Get the manufacturer string of the device from its device descriptor """ return self._get_prod_string_common(hidapi.hid_get_manufacturer_string) def get_product_string(self): """ Get the product string of the device from its device descriptor """ return self._get_prod_string_common(hidapi.hid_get_product_string) def get_serial_number(self): """ Get the serial number string of the device from its device descriptor """ return self._get_prod_string_common(hidapi.hid_get_serial_number_string) def get_indexed_string(self, index): """ Get the string with the given index from the device """ max_len = 128 str_buf = ffi.new("wchar_t[]", str(bytearray(max_len))) ret = hidapi.hid_get_indexed_string(self._device, index, str_buf, max_len) if ret < 0: raise HIDException(self._device.get_error()) elif ret == 0: return None else: return ffi.string(str_buf).encode('utf-8') def description(self): return \ """Device: {} | {:x}:{:x} | {} | {} | {} release_number: {} usage_page: {} usage: {} interface_number: {}\ """.format(self.path, self.vendor_id, self.product_id, self.manufacturer_string, self.product_string, self.serial_number, self.release_number, self.usage_page, self.usage, self.interface_number ) class Enumeration: def __init__(self, vid=0, pid=0): self.device_list = _hid_enumerate(vid, pid) def show(self): for dev in self.device_list: print(dev.description()) def find(self, vid=None, pid=None, serial=None, interface=None, \ path=None, release_number=None, manufacturer=None, product=None, usage=None, usage_page=None): """ Attempts to open a device in the HID enumeration list. This function is only away of devices that were present when the object was created. """ result = [] for dev in self.device_list: if vid and dev.vendor_id != vid: continue if pid and dev.product_id != pid: continue if serial and dev.serial_number != serial: continue if interface and dev.interface_number != interface: continue if path and dev.path != path: continue if manufacturer and dev.manufacturer_string != manufacturer: continue if product and dev.product_string != product: continue if release_number and dev.release_number != release_number: continue if usage and dev.usage != usage: continue if usage_page and dev.usage_page != usage_page: continue result.append(dev) return result def _hid_enumerate(vendor_id=0, product_id=0): """ Enumerates all the hid devices for VID:PID. Returns a list of `DeviceInfo`. If vid is 0, then match any vendor id. Similarly, if pid is 0, match any product id. If both are zero, enumerate all HID devices. """ start = hidapi.hid_enumerate(vendor_id, product_id) result = [] cur = ffi.new("struct hid_device_info*"); cur = start # Copy everything into python list while cur != ffi.NULL: result.append(Device(cur)) cur = cur.next # Free the C memory hidapi.hid_free_enumeration(start) return result # def hid_open(vendor_id, product_id, serial=None): # """ # """ # if serial == None: # serial = ffi.NULL # else: # if type(serial) == bytes or type(serial) == bytearray: # serial = serial.decode('utf-8') # serial = ffi.new("wchar_t[]", serial) # dev = hidapi.hid_open(vendor_id, product_id, serial) # if dev: # return Device(dev) # else: # None if __name__ == "__main__": # Examples from easyhid import Enumeration # Stores an enumertion of all the connected USB HID devices en = Enumeration() # return a list of devices based on the search parameters devices = en.find(manufacturer="Company", product="Widget", interface=3) # print a description of the devices found for dev in devices: print(dev.description()) # open a device dev.open() # write some bytes to the device dev.write(bytearray([0, 1, 2, 3])) # read some bytes print(dev.read()) # close a device dev.close()
[ "easyhid.Enumeration", "platform.platform", "cffi.FFI" ]
[((196, 206), 'cffi.FFI', 'cffi.FFI', ([], {}), '()\n', (204, 206), False, 'import cffi\n'), ((1868, 1887), 'platform.platform', 'platform.platform', ([], {}), '()\n', (1885, 1887), False, 'import platform\n'), ((11515, 11528), 'easyhid.Enumeration', 'Enumeration', ([], {}), '()\n', (11526, 11528), False, 'from easyhid import Enumeration\n'), ((5838, 5890), 'easyhid.Enumeration', 'Enumeration', ([], {'vid': 'self.vendor_id', 'pid': 'self.product_id'}), '(vid=self.vendor_id, pid=self.product_id)\n', (5849, 5890), False, 'from easyhid import Enumeration\n')]
#!/usr/bin/env python3 import anki_vector import paho.mqtt.client as mqtt import time ############################################################################### def main(): voltage = 0 batlevel = 0 charging = 0 docked = 0 status = "error" ltime = time.strftime("%d.%m.%Y %H:%M:%S") try: # Connect to Vector and get battery info with anki_vector.Robot(behavior_control_level=None, cache_animation_lists=False) as robot: battery_state = robot.get_battery_state() voltage = battery_state.battery_volts batlevel = battery_state.battery_level charging = battery_state.is_charging docked = battery_state.is_on_charger_platform status = get_status(robot) except: print("couldn't connect to Vector") # In the openHAB channel, use a jsonpath transform to get specific values like this: JSONPATH:$..voltage data = {} data['robots'] = [] data['robots'].append({ 'name': 'Vector Green', 'voltage': voltage, 'batlevel': batlevel, 'charging': charging, 'docked': docked, 'time': ltime, 'status': status }) # Configure and publish data to mqtt do_mqtt(data) ############################################################################### def get_status(robot): status = "error" if robot.status.are_motors_moving: status = "Vector is moving" if robot.status.are_wheels_moving: status = "Vector's wheels are moving" if robot.status.is_animating: status = "Vector is animating" if robot.status.is_being_held: status = "Vector is being held" if robot.status.is_button_pressed: status = "Vector's button was button pressed" if robot.status.is_carrying_block: status = "Vector is carrying his block" if robot.status.is_charging: status = "Vector is currently charging" if robot.status.is_cliff_detected: status = "Vector has detected a cliff" if robot.status.is_docking_to_marker: status = "Vector has found a marker and is docking to it" if robot.status.is_falling: status = "Vector is falling" if robot.status.is_head_in_pos: status = "Vector's head is in position" if robot.status.is_in_calm_power_mode: status = "Vector is in calm power mode" if robot.status.is_lift_in_pos: status = "Vector's arm is in position" if robot.status.is_on_charger: status = "Vector is on the charger" if robot.status.is_pathing: status = "Vector is traversing a path" if robot.status.is_picked_up: status = "Vector is picked up" if robot.status.is_robot_moving: status = "Vector is in motion" return status ############################################################################### def on_publish(client, userdata, mid): print("Message published to broker") ############################################################################### def do_mqtt(data): # define variables for MQTT MQTT_HOST = "192.168.0.7" MQTT_TOPIC = "Vector" MQTT_PORT = 1883 MQTT_KEEPALIVE_INTERVAL = 20 MQTT_USER = "YOUR_MQTT_USER" MQTT_PW = "<PASSWORD>" # Convert it to text? Not sure why I did this but it works. Yay, 1am programming. MQTT_MSG = str(data) # Initiate MQTT Client mqttc = mqtt.Client() # Set username and password for the Broker mqttc.username_pw_set(MQTT_USER, MQTT_PW) # Register publish callback function #mqttc.on_publish = on_publish # Connect with MQTT Broker mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL) # Publish message to MQTT Broker mqttc.publish(MQTT_TOPIC,MQTT_MSG) # Disconnect from MQTT_Broker mqttc.disconnect() ############################################################################### if __name__ == "__main__": main()
[ "paho.mqtt.client.Client", "anki_vector.Robot", "time.strftime" ]
[((287, 321), 'time.strftime', 'time.strftime', (['"""%d.%m.%Y %H:%M:%S"""'], {}), "('%d.%m.%Y %H:%M:%S')\n", (300, 321), False, 'import time\n'), ((3490, 3503), 'paho.mqtt.client.Client', 'mqtt.Client', ([], {}), '()\n', (3501, 3503), True, 'import paho.mqtt.client as mqtt\n'), ((398, 473), 'anki_vector.Robot', 'anki_vector.Robot', ([], {'behavior_control_level': 'None', 'cache_animation_lists': '(False)'}), '(behavior_control_level=None, cache_animation_lists=False)\n', (415, 473), False, 'import anki_vector\n')]
import time from beacontools import BeaconScanner, IBeaconFilter def callback(bt_addr, rssi, packet, additional_info): print("<%s, %d> %s %s" % (bt_addr, rssi, packet, additional_info)) # scan for all iBeacon advertisements from beacons with the specified uuid scanner = BeaconScanner(callback, device_filter=IBeaconFilter(uuid="e2c56db5-dffb-48d2-b060-d0f5a71096e0") ) scanner.start() time.sleep(10) scanner.stop()
[ "beacontools.IBeaconFilter", "time.sleep" ]
[((398, 412), 'time.sleep', 'time.sleep', (['(10)'], {}), '(10)\n', (408, 412), False, 'import time\n'), ((321, 379), 'beacontools.IBeaconFilter', 'IBeaconFilter', ([], {'uuid': '"""e2c56db5-dffb-48d2-b060-d0f5a71096e0"""'}), "(uuid='e2c56db5-dffb-48d2-b060-d0f5a71096e0')\n", (334, 379), False, 'from beacontools import BeaconScanner, IBeaconFilter\n')]
# Desafio 61 Curso em Video Python # By Rafabr from estrutura_modelo import cabecalho, rodape cabecalho(61, "Termos de uma Progressão Aritmética - II") while True: try: p0 = float(input('Digite o Termo inicial da PA: ')) r = float(input('Digite a razão da PA: ')) except ValueError: print('Voçe digitou um valor indevido!\n') continue break n = 1 print() while (n <= 10): print(f'Termo {n}:'.ljust(10) + f'{p0 + (n-1)*r}') n += 1 rodape()
[ "estrutura_modelo.rodape", "estrutura_modelo.cabecalho" ]
[((96, 153), 'estrutura_modelo.cabecalho', 'cabecalho', (['(61)', '"""Termos de uma Progressão Aritmética - II"""'], {}), "(61, 'Termos de uma Progressão Aritmética - II')\n", (105, 153), False, 'from estrutura_modelo import cabecalho, rodape\n'), ((490, 498), 'estrutura_modelo.rodape', 'rodape', ([], {}), '()\n', (496, 498), False, 'from estrutura_modelo import cabecalho, rodape\n')]
from setuptools import setup tests_require = [ 'cov-core', 'mock', 'nose2', ] setup(name='steinlib', version='0.1', description='Python bindings for Steinlib format.', url='http://github.com/leandron/steinlib', author='<NAME>', author_email='<EMAIL>', license='MIT', packages=['steinlib'], tests_require=tests_require, test_suite='nose2.collector.collector', zip_safe=False)
[ "setuptools.setup" ]
[((108, 424), 'setuptools.setup', 'setup', ([], {'name': '"""steinlib"""', 'version': '"""0.1"""', 'description': '"""Python bindings for Steinlib format."""', 'url': '"""http://github.com/leandron/steinlib"""', 'author': '"""<NAME>"""', 'author_email': '"""<EMAIL>"""', 'license': '"""MIT"""', 'packages': "['steinlib']", 'tests_require': 'tests_require', 'test_suite': '"""nose2.collector.collector"""', 'zip_safe': '(False)'}), "(name='steinlib', version='0.1', description=\n 'Python bindings for Steinlib format.', url=\n 'http://github.com/leandron/steinlib', author='<NAME>', author_email=\n '<EMAIL>', license='MIT', packages=['steinlib'], tests_require=\n tests_require, test_suite='nose2.collector.collector', zip_safe=False)\n", (113, 424), False, 'from setuptools import setup\n')]
# -*- coding:utf-8 -*- """ @File : test_template @Author : Chen @Contact : <EMAIL> @Date : 2021/1/20 20:09 @Desc : """ # 导包 import pytest import requests from time import sleep from api.template_api import TemplateAPI from tools.get_log import GetLog from tools.read_file import read_json import allure # 获取日志器 log = GetLog.get_log() @allure.feature('测试类模板') @pytest.skip("参考模板, 不执行") class TestTemplate: session = None # 初始化方法 @classmethod def setup_class(cls): cls.session = requests.Session() # 初始化session对象 cls.template = TemplateAPI() # 结束方法 @classmethod def teardown_class(cls): cls.session.close() @classmethod def setup(cls): sleep(1.5) # 测试方法 @allure.story("测试方法模板-add") @pytest.mark.parametrize(("attr1", "attr2", "success", "expect"), read_json("test_add")) def test_add(self, attr1, attr2, success, expect): # 添加功能API调用 response = self.template.api_add(self.session, attr1, attr2) # 打印日志 log.info("添加功能-状态码为: {}".format(response.status_code)) # 断言状态码 assert response.status_code == expect, "状态码断言失败" @allure.story("测试方法模板-upd") @pytest.mark.parametrize(("attr1", "attr2", "success", "expect"), read_json("test_upd")) def test_upd(self, attr1, attr2, success, expect): # 添加功能API调用 response = self.template.api_upd(self.session, attr1, attr2) # 打印日志 log.info("修改功能-状态码为: {}".format(response.status_code)) # 断言状态码 assert response.status_code == expect, "状态码断言失败" @allure.story("测试方法模板-get") @pytest.mark.parametrize(("attr1", "attr2", "success", "expect"), read_json("test_get")) def test_get(self, attr1, attr2, success, expect): # 添加功能API调用 response = self.template.api_get(self.session, attr1, attr2) # 打印日志 log.info("查询功能-状态码为: {}".format(response.status_code)) # 断言状态码 assert response.status_code == expect, "状态码断言失败" @allure.story("测试方法模板-del") @pytest.mark.parametrize(("uid", "success", "expect"), read_json("test_del")) def test_del(self, uid, success, expect): # 添加功能API调用 response = self.template.api_del(self.session, uid) # 打印日志 log.info("删除功能-状态码为: {}".format(response.status_code)) # 断言状态码 assert response.status_code == expect, "状态码断言失败"
[ "requests.Session", "allure.story", "api.template_api.TemplateAPI", "time.sleep", "allure.feature", "pytest.skip", "tools.read_file.read_json", "tools.get_log.GetLog.get_log" ]
[((321, 337), 'tools.get_log.GetLog.get_log', 'GetLog.get_log', ([], {}), '()\n', (335, 337), False, 'from tools.get_log import GetLog\n'), ((341, 364), 'allure.feature', 'allure.feature', (['"""测试类模板"""'], {}), "('测试类模板')\n", (355, 364), False, 'import allure\n'), ((366, 390), 'pytest.skip', 'pytest.skip', (['"""参考模板, 不执行"""'], {}), "('参考模板, 不执行')\n", (377, 390), False, 'import pytest\n'), ((742, 768), 'allure.story', 'allure.story', (['"""测试方法模板-add"""'], {}), "('测试方法模板-add')\n", (754, 768), False, 'import allure\n'), ((1163, 1189), 'allure.story', 'allure.story', (['"""测试方法模板-upd"""'], {}), "('测试方法模板-upd')\n", (1175, 1189), False, 'import allure\n'), ((1584, 1610), 'allure.story', 'allure.story', (['"""测试方法模板-get"""'], {}), "('测试方法模板-get')\n", (1596, 1610), False, 'import allure\n'), ((2005, 2031), 'allure.story', 'allure.story', (['"""测试方法模板-del"""'], {}), "('测试方法模板-del')\n", (2017, 2031), False, 'import allure\n'), ((508, 526), 'requests.Session', 'requests.Session', ([], {}), '()\n', (524, 526), False, 'import requests\n'), ((568, 581), 'api.template_api.TemplateAPI', 'TemplateAPI', ([], {}), '()\n', (579, 581), False, 'from api.template_api import TemplateAPI\n'), ((714, 724), 'time.sleep', 'sleep', (['(1.5)'], {}), '(1.5)\n', (719, 724), False, 'from time import sleep\n'), ((839, 860), 'tools.read_file.read_json', 'read_json', (['"""test_add"""'], {}), "('test_add')\n", (848, 860), False, 'from tools.read_file import read_json\n'), ((1260, 1281), 'tools.read_file.read_json', 'read_json', (['"""test_upd"""'], {}), "('test_upd')\n", (1269, 1281), False, 'from tools.read_file import read_json\n'), ((1681, 1702), 'tools.read_file.read_json', 'read_json', (['"""test_get"""'], {}), "('test_get')\n", (1690, 1702), False, 'from tools.read_file import read_json\n'), ((2091, 2112), 'tools.read_file.read_json', 'read_json', (['"""test_del"""'], {}), "('test_del')\n", (2100, 2112), False, 'from tools.read_file import read_json\n')]
# -*- coding: utf-8 -*- import botocore.exceptions import logging import dockerfilegenerator.lib.constants as constants import dockerfilegenerator.lib.exceptions as exceptions import dockerfilegenerator.lib.versions as versions import dockerfilegenerator.lib.jsonstore as jsonstore import dockerfilegenerator.lib.s3store as s3store import dockerfilegenerator.lib.github as github logger = logging.getLogger() TRACKED_TOOLS = { "terraform": versions.get_latest_hashicorp_terraform_version, "packer": versions.get_latest_hashicorp_packer_version, "go": versions.get_latest_golango_go_version } class UtilsMixin: @property def tools_current_versions(self): if not hasattr(self, "_tools_current_versions"): self._tools_current_versions = None if self._tools_current_versions is None: self._tools_current_versions = dict( (tool_name, self.dockerfile.version(tool_name)) for tool_name in self.dockerfile.json) return self._tools_current_versions @property def tools_next_versions(self): if not hasattr(self, "_tools_next_versions"): self._tools_next_versions = None if self._tools_next_versions is None: self._tools_next_versions = dict( (tool_name, TRACKED_TOOLS[tool_name]()) for tool_name in TRACKED_TOOLS) return self._tools_next_versions def update_dockerfile_versions(self): dockerfile_changed = False for tool in self.tools_current_versions: # TODO: Refactor this method... if self.dockerfile.force_version(tool): logger.info("Update versions: %s has force_version" % tool) continue if tool == self.dockerfile.dockerfile_repo_name: continue current_version = self.tools_current_versions[tool] next_version = self.tools_next_versions.get(tool, None) if next_version is None: logger.info("Update versions: %s has no next version" % tool) continue if current_version == next_version: logger.info( "Update versions: %s has no changed version" % tool) continue self.dockerfile.set_version(tool, next_version) logger.info("Update versions: %s has next version %s" % (tool, next_version)) dockerfile_changed = True if dockerfile_changed: self.dockerfile.set_next_version_dockerfile() return dockerfile_changed class DockerfileGeneratorLambda(UtilsMixin): def __init__(self): self.s3bucket = s3store.get_s3_bucket_manager() self.dockerfile_repo = github.get_github_repository( constants.DOCKERFILE_GITHUB_REPO) self.dockerfile = jsonstore.get_dockerfile(self.dockerfile_repo) self._internal_state = None self.exit_code = 0 @property def internal_state(self): """ Get the state from AWS S3 json file, or use the one from Github, if there is none.""" if self._internal_state is None: internal_state = self.s3bucket.read_object( constants.INTERNAL_STATE_FILE) if internal_state is None: logger.info("Internal state: No state from S3") internal_state = self.dockerfile.dump self.save_state_to_s3(internal_state) self._internal_state = jsonstore.Store(internal_state) return self._internal_state def update_files_on_github(self): template_dockerfile = self.dockerfile_repo.get_file_contents( constants.TEMPLATE_GITHUB_DOCKERFILE_PATH) template_readme = self.dockerfile_repo.get_file_contents( constants.TEMPLATE_GITHUB_README_PATH) commit_msg = self.dockerfile.update_summary(self.internal_state) commit_files = [ (constants.INTERNAL_STATE_FILE, self.dockerfile.dump), ("Dockerfile", template_dockerfile.format( **self.dockerfile.template_variables)), ("README.md", template_readme.format( **self.dockerfile.template_variables))] logger.info("Updating files on Github with message:\n\t%s" % commit_msg) self.dockerfile_repo.commit(commit_files, commit_msg) def save_state_to_s3(self, content): try: logger.info("Saving state to S3") self.s3bucket.write_object(constants.INTERNAL_STATE_FILE, content) except (botocore.exceptions.ClientError, Exception) as e: raise exceptions.LambdaException( "Error: Uploading object to s3 bucket: %s" % (str(e))) def main(self): if self.update_dockerfile_versions(): self.update_files_on_github() self.save_state_to_s3(self.dockerfile.dump) return self.exit_code # Making Lambda Service happy def lambda_handler(): return DockerfileGeneratorLambda().main()
[ "logging.getLogger", "dockerfilegenerator.lib.jsonstore.get_dockerfile", "dockerfilegenerator.lib.jsonstore.Store", "dockerfilegenerator.lib.s3store.get_s3_bucket_manager", "dockerfilegenerator.lib.github.get_github_repository" ]
[((392, 411), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (409, 411), False, 'import logging\n'), ((2721, 2752), 'dockerfilegenerator.lib.s3store.get_s3_bucket_manager', 's3store.get_s3_bucket_manager', ([], {}), '()\n', (2750, 2752), True, 'import dockerfilegenerator.lib.s3store as s3store\n'), ((2784, 2846), 'dockerfilegenerator.lib.github.get_github_repository', 'github.get_github_repository', (['constants.DOCKERFILE_GITHUB_REPO'], {}), '(constants.DOCKERFILE_GITHUB_REPO)\n', (2812, 2846), True, 'import dockerfilegenerator.lib.github as github\n'), ((2886, 2932), 'dockerfilegenerator.lib.jsonstore.get_dockerfile', 'jsonstore.get_dockerfile', (['self.dockerfile_repo'], {}), '(self.dockerfile_repo)\n', (2910, 2932), True, 'import dockerfilegenerator.lib.jsonstore as jsonstore\n'), ((3537, 3568), 'dockerfilegenerator.lib.jsonstore.Store', 'jsonstore.Store', (['internal_state'], {}), '(internal_state)\n', (3552, 3568), True, 'import dockerfilegenerator.lib.jsonstore as jsonstore\n')]
# coding: utf-8 """ FreeClimb API FreeClimb is a cloud-based application programming interface (API) that puts the power of the Vail platform in your hands. FreeClimb simplifies the process of creating applications that can use a full range of telephony features without requiring specialized or on-site telephony equipment. Using the FreeClimb REST API to write applications is easy! You have the option to use the language of your choice or hit the API directly. Your application can execute a command by issuing a RESTful request to the FreeClimb API. The base URL to send HTTP requests to the FreeClimb REST API is: /apiserver. FreeClimb authenticates and processes your request. # noqa: E501 The version of the OpenAPI document: 1.0.0 Contact: <EMAIL> Generated by: https://openapi-generator.tech """ import pprint import re # noqa: F401 import six from freeclimb.configuration import Configuration class MessageResult(object): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech Do not edit the class manually. """ """ Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. attribute_map (dict): The key is attribute name and the value is json key in definition. """ openapi_types = { 'uri': 'str', 'date_created': 'str', 'date_updated': 'str', 'revision': 'int', 'account_id': 'str', 'message_id': 'str', 'status': 'str', '_from': 'str', 'to': 'str', 'text': 'str', 'direction': 'str', 'notification_url': 'str' } attribute_map = { 'uri': 'uri', 'date_created': 'dateCreated', 'date_updated': 'dateUpdated', 'revision': 'revision', 'account_id': 'accountId', 'message_id': 'messageId', 'status': 'status', '_from': 'from', 'to': 'to', 'text': 'text', 'direction': 'direction', 'notification_url': 'notificationUrl' } def __init__(self, uri=None, date_created=None, date_updated=None, revision=None, account_id=None, message_id=None, status=None, _from=None, to=None, text=None, direction=None, notification_url=None, local_vars_configuration=None): # noqa: E501 """MessageResult - a model defined in OpenAPI""" # noqa: E501 if local_vars_configuration is None: local_vars_configuration = Configuration() self.local_vars_configuration = local_vars_configuration self._uri = None self._date_created = None self._date_updated = None self._revision = None self._account_id = None self._message_id = None self._status = None self.__from = None self._to = None self._text = None self._direction = None self._notification_url = None self.discriminator = None if uri is not None: self.uri = uri if date_created is not None: self.date_created = date_created if date_updated is not None: self.date_updated = date_updated if revision is not None: self.revision = revision if account_id is not None: self.account_id = account_id if message_id is not None: self.message_id = message_id if status is not None: self.status = status if _from is not None: self._from = _from if to is not None: self.to = to if text is not None: self.text = text if direction is not None: self.direction = direction if notification_url is not None: self.notification_url = notification_url @property def uri(self): """Gets the uri of this MessageResult. # noqa: E501 The URI for this resource, relative to /apiserver. # noqa: E501 :return: The uri of this MessageResult. # noqa: E501 :rtype: str """ return self._uri @uri.setter def uri(self, uri): """Sets the uri of this MessageResult. The URI for this resource, relative to /apiserver. # noqa: E501 :param uri: The uri of this MessageResult. # noqa: E501 :type: str """ self._uri = uri @property def date_created(self): """Gets the date_created of this MessageResult. # noqa: E501 The date that this resource was created (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). # noqa: E501 :return: The date_created of this MessageResult. # noqa: E501 :rtype: str """ return self._date_created @date_created.setter def date_created(self, date_created): """Sets the date_created of this MessageResult. The date that this resource was created (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). # noqa: E501 :param date_created: The date_created of this MessageResult. # noqa: E501 :type: str """ self._date_created = date_created @property def date_updated(self): """Gets the date_updated of this MessageResult. # noqa: E501 The date that this resource was last updated (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). # noqa: E501 :return: The date_updated of this MessageResult. # noqa: E501 :rtype: str """ return self._date_updated @date_updated.setter def date_updated(self, date_updated): """Sets the date_updated of this MessageResult. The date that this resource was last updated (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). # noqa: E501 :param date_updated: The date_updated of this MessageResult. # noqa: E501 :type: str """ self._date_updated = date_updated @property def revision(self): """Gets the revision of this MessageResult. # noqa: E501 Revision count for the resource. This count is set to 1 on creation and is incremented every time it is updated. # noqa: E501 :return: The revision of this MessageResult. # noqa: E501 :rtype: int """ return self._revision @revision.setter def revision(self, revision): """Sets the revision of this MessageResult. Revision count for the resource. This count is set to 1 on creation and is incremented every time it is updated. # noqa: E501 :param revision: The revision of this MessageResult. # noqa: E501 :type: int """ self._revision = revision @property def account_id(self): """Gets the account_id of this MessageResult. # noqa: E501 String that uniquely identifies this account resource. # noqa: E501 :return: The account_id of this MessageResult. # noqa: E501 :rtype: str """ return self._account_id @account_id.setter def account_id(self, account_id): """Sets the account_id of this MessageResult. String that uniquely identifies this account resource. # noqa: E501 :param account_id: The account_id of this MessageResult. # noqa: E501 :type: str """ self._account_id = account_id @property def message_id(self): """Gets the message_id of this MessageResult. # noqa: E501 String that uniquely identifies this message resource # noqa: E501 :return: The message_id of this MessageResult. # noqa: E501 :rtype: str """ return self._message_id @message_id.setter def message_id(self, message_id): """Sets the message_id of this MessageResult. String that uniquely identifies this message resource # noqa: E501 :param message_id: The message_id of this MessageResult. # noqa: E501 :type: str """ self._message_id = message_id @property def status(self): """Gets the status of this MessageResult. # noqa: E501 Indicates the state of the message through the message lifecycle including: new, queued, rejected, sending, sent, failed, received, undelivered, expired, deleted, and unknown # noqa: E501 :return: The status of this MessageResult. # noqa: E501 :rtype: str """ return self._status @status.setter def status(self, status): """Sets the status of this MessageResult. Indicates the state of the message through the message lifecycle including: new, queued, rejected, sending, sent, failed, received, undelivered, expired, deleted, and unknown # noqa: E501 :param status: The status of this MessageResult. # noqa: E501 :type: str """ allowed_values = ["new", "queued", "rejected", "sending", "sent", "failed", "received", "undelivered", "expired", "deleted", "unknown"] # noqa: E501 if self.local_vars_configuration.client_side_validation and status not in allowed_values: # noqa: E501 raise ValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) self._status = status @property def _from(self): """Gets the _from of this MessageResult. # noqa: E501 Phone number in E.164 format that sent the message. # noqa: E501 :return: The _from of this MessageResult. # noqa: E501 :rtype: str """ return self.__from @_from.setter def _from(self, _from): """Sets the _from of this MessageResult. Phone number in E.164 format that sent the message. # noqa: E501 :param _from: The _from of this MessageResult. # noqa: E501 :type: str """ self.__from = _from @property def to(self): """Gets the to of this MessageResult. # noqa: E501 Phone number in E.164 format that received the message. # noqa: E501 :return: The to of this MessageResult. # noqa: E501 :rtype: str """ return self._to @to.setter def to(self, to): """Sets the to of this MessageResult. Phone number in E.164 format that received the message. # noqa: E501 :param to: The to of this MessageResult. # noqa: E501 :type: str """ self._to = to @property def text(self): """Gets the text of this MessageResult. # noqa: E501 Message contents # noqa: E501 :return: The text of this MessageResult. # noqa: E501 :rtype: str """ return self._text @text.setter def text(self, text): """Sets the text of this MessageResult. Message contents # noqa: E501 :param text: The text of this MessageResult. # noqa: E501 :type: str """ self._text = text @property def direction(self): """Gets the direction of this MessageResult. # noqa: E501 Noting whether the message was inbound or outbound # noqa: E501 :return: The direction of this MessageResult. # noqa: E501 :rtype: str """ return self._direction @direction.setter def direction(self, direction): """Sets the direction of this MessageResult. Noting whether the message was inbound or outbound # noqa: E501 :param direction: The direction of this MessageResult. # noqa: E501 :type: str """ self._direction = direction @property def notification_url(self): """Gets the notification_url of this MessageResult. # noqa: E501 URL invoked when message sent # noqa: E501 :return: The notification_url of this MessageResult. # noqa: E501 :rtype: str """ return self._notification_url @notification_url.setter def notification_url(self, notification_url): """Sets the notification_url of this MessageResult. URL invoked when message sent # noqa: E501 :param notification_url: The notification_url of this MessageResult. # noqa: E501 :type: str """ self._notification_url = notification_url def to_dict(self): """Returns the model properties as a dict""" result = {} for attr, _ in six.iteritems(self.openapi_types): value = getattr(self, attr) attr = self.to_camel_case(attr) if isinstance(value, list): result[attr] = list(map( lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): result[attr] = dict(map( lambda item: (item[0], item[1].to_dict()) if hasattr(item[1], "to_dict") else item, value.items() )) elif value is None: continue else: result[attr] = value return result def to_str(self): """Returns the string representation of the model""" return pprint.pformat(self.to_dict()) def __repr__(self): """For `print` and `pprint`""" return self.to_str() def __eq__(self, other): """Returns true if both objects are equal""" if not isinstance(other, MessageResult): return False return self.to_dict() == other.to_dict() def __ne__(self, other): """Returns true if both objects are not equal""" if not isinstance(other, MessageResult): return True return self.to_dict() != other.to_dict() def to_camel_case(self, snake_str): components = snake_str.split('_') return components[0] + ''.join(x.title() for x in components[1:])
[ "six.iteritems", "freeclimb.configuration.Configuration" ]
[((12557, 12590), 'six.iteritems', 'six.iteritems', (['self.openapi_types'], {}), '(self.openapi_types)\n', (12570, 12590), False, 'import six\n'), ((2550, 2565), 'freeclimb.configuration.Configuration', 'Configuration', ([], {}), '()\n', (2563, 2565), False, 'from freeclimb.configuration import Configuration\n')]
from kdbush import KDBush # test data points = [ [54,1],[97,21],[65,35],[33,54],[95,39],[54,3],[53,54],[84,72],[33,34],[43,15],[52,83],[81,23],[1,61],[38,74], [11,91],[24,56],[90,31],[25,57],[46,61],[29,69],[49,60],[4,98],[71,15],[60,25],[38,84],[52,38],[94,51],[13,25], [77,73],[88,87],[6,27],[58,22],[53,28],[27,91],[96,98],[93,14],[22,93],[45,94],[18,28],[35,15],[19,81],[20,81], [67,53],[43,3],[47,66],[48,34],[46,12],[32,38],[43,12],[39,94],[88,62],[66,14],[84,30],[72,81],[41,92],[26,4], [6,76],[47,21],[57,70],[71,82],[50,68],[96,18],[40,31],[78,53],[71,90],[32,14],[55,6],[32,88],[62,32],[21,67], [73,81],[44,64],[29,50],[70,5],[6,22],[68,3],[11,23],[20,42],[21,73],[63,86],[9,40],[99,2],[99,76],[56,77], [83,6],[21,72],[78,30],[75,53],[41,11],[95,20],[30,38],[96,82],[65,48],[33,18],[87,28],[10,10],[40,34], [10,20],[47,29],[46,78]] ids = [ 97, 74, 95, 30, 77, 38, 76, 27, 80, 55, 72, 90, 88, 48, 43, 46, 65, 39, 62, 93, 9, 96, 47, 8, 3, 12, 15, 14, 21, 41, 36, 40, 69, 56, 85, 78, 17, 71, 44, 19, 18, 13, 99, 24, 67, 33, 37, 49, 54, 57, 98, 45, 23, 31, 66, 68, 0, 32, 5, 51, 75, 73, 84, 35, 81, 22, 61, 89, 1, 11, 86, 52, 94, 16, 2, 6, 25, 92, 42, 20, 60, 58, 83, 79, 64, 10, 59, 53, 26, 87, 4, 63, 50, 7, 28, 82, 70, 29, 34, 91] coords = [ 10,20,6,22,10,10,6,27,20,42,18,28,11,23,13,25,9,40,26,4,29,50,30,38,41,11,43,12,43,3,46,12,32,14,35,15,40,31,33,18, 43,15,40,34,32,38,33,34,33,54,1,61,24,56,11,91,4,98,20,81,22,93,19,81,21,67,6,76,21,72,21,73,25,57,44,64,47,66,29, 69,46,61,38,74,46,78,38,84,32,88,27,91,45,94,39,94,41,92,47,21,47,29,48,34,60,25,58,22,55,6,62,32,54,1,53,28,54,3, 66,14,68,3,70,5,83,6,93,14,99,2,71,15,96,18,95,20,97,21,81,23,78,30,84,30,87,28,90,31,65,35,53,54,52,38,65,48,67, 53,49,60,50,68,57,70,56,77,63,86,71,90,52,83,71,82,72,81,94,51,75,53,95,39,78,53,88,62,84,72,77,73,99,76,73,81,88, 87,96,98,96,82] index = KDBush(points) result = index.range(20, 30, 50, 70) print(result) # [60, 20, 45, 3, 17, 71, 44, 19, 18, 15, 69, 90, 62, 96, 47, 8, 77, 72] for id in result: p = points[id] if p[0] < 20 or p[0] > 50 or p[1] < 30 or p[1] > 70: print("FAIL") for id in result: p = points[id] if id not in result and p[0] >= 20 and p[0] <= 50 and p[1] >= 30 and p[1] <= 70: print("FAIL: outside point not in range") def sqDist2(a, b): dx = a[0] - b[0] dy = a[1] - b[1] return dx * dx + dy * dy; index2 = KDBush(points) qp = [50, 50] r = 20 r2 = 20 * 20 result = index.within(qp[0], qp[1], r) print(result) # [60, 6, 25, 92, 42, 20, 45, 3, 71, 44, 18, 96] for id in result: p = points[id] if (sqDist2(p, qp) > r2): print('FAIL: result point in range') for id in result: p = points[id] if (id not in result and sqDist2(p, qp) <= r2): print('FAIL: result point not in range')
[ "kdbush.KDBush" ]
[((1923, 1937), 'kdbush.KDBush', 'KDBush', (['points'], {}), '(points)\n', (1929, 1937), False, 'from kdbush import KDBush\n'), ((2434, 2448), 'kdbush.KDBush', 'KDBush', (['points'], {}), '(points)\n', (2440, 2448), False, 'from kdbush import KDBush\n')]
#!/usr/bin/env python3 """ Contains testcases for the individual examination. """ import unittest from io import StringIO import os import sys from unittest.mock import patch from examiner import ExamTestCase, ExamTestResult, tags from examiner import import_module, find_path_to_assignment FILE_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_PATH = find_path_to_assignment(FILE_DIR) if REPO_PATH not in sys.path: sys.path.insert(0, REPO_PATH) # Path to file and basename of the file to import main = import_module(REPO_PATH, "main") class Test1Files(ExamTestCase): """ Each assignment has 1 testcase with multiple asserts. The different asserts https://docs.python.org/3.6/library/unittest.html#test-cases """ class Test2Counters(ExamTestCase): """ Meny options for counting """ @classmethod def setUpClass(cls): # Otherwise the .txt files will not be found os.chdir(REPO_PATH) @tags("count", "lines") def test_b_lines(self): """ Testar att anropa menyval 'lines' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["lines", "", "q"] with patch('builtins.input', side_effect=self._multi_arguments): with patch('sys.stdout', new=StringIO()) as fake_out: main.main() str_data = fake_out.getvalue() self.assertIn("17", str_data) @tags("count", "words") def test_c_words(self): """ Testar att anropa menyval 'words' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["words", "", "q"] with patch('builtins.input', side_effect=self._multi_arguments): with patch('sys.stdout', new=StringIO()) as fake_out: main.main() str_data = fake_out.getvalue() self.assertIn("199", str_data) @tags("count", "letters") def test_d_letters(self): """ Testar att anropa menyval 'letters' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["letters", "", "q"] self.norepr = True with patch('builtins.input', side_effect=self._multi_arguments): with patch('sys.stdout', new=StringIO()) as fake_out: main.main() str_data = fake_out.getvalue() self.assertIn("907", str_data) class Test3Frequencies(ExamTestCase): """ Meny options for frequency """ def check_print_contain(self, inp, correct): """ One function for testing print input functions. """ with patch("builtins.input", side_effect=inp): with patch("sys.stdout", new=StringIO()) as fake_out: main.main() for val in correct: str_data = fake_out.getvalue() self.assertIn(val, str_data) @tags("freq", "word_frequency") def test_a_word_frequency(self): """ Testar att anropa menyval 'word_frequency' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["word_frequency", "", "q"] self.check_print_contain(self._multi_arguments, [ "the: 12 | 6.0%", "to: 8 | 4.0%", "and: 7 | 3.5%", "of: 6 | 3.0%", "street: 5 | 2.5%", "him: 5 | 2.5%", "he: 5 | 2.5%", ]) @tags("freq", "letter_frequency") def test_b_letter_frequency(self): """ Testar att anropa menyval 'letter_frequency' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["letter_frequency", "", "q"] self.check_print_contain(self._multi_arguments, [ "e: 108 | 11.9%", "t: 91 | 10.0%", "o: 77 | 8.5%", "h: 67 | 7.4%", "n: 66 | 7.3%", "i: 64 | 7.1%", "a: 64 | 7.1%", ]) class Test4All(ExamTestCase): """ Meny options for frequency """ def check_print_contain(self, inp, correct): """ One function for testing print input functions. """ with patch("builtins.input", side_effect=inp): with patch("sys.stdout", new=StringIO()) as fake_out: main.main() for val in correct: str_data = fake_out.getvalue() self.assertIn(val, str_data) @tags("all") def test_a_all(self): """ Testar att anropa menyval 'all' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["all", "", "q"] self.check_print_contain(self._multi_arguments, [ "17", "199", "907", "the: 12 | 6.0%", "to: 8 | 4.0%", "and: 7 | 3.5%", "of: 6 | 3.0%", "street: 5 | 2.5%", "him: 5 | 2.5%", "he: 5 | 2.5%", "e: 108 | 11.9%", "t: 91 | 10.0%", "o: 77 | 8.5%", "h: 67 | 7.4%", "n: 66 | 7.3%", "i: 64 | 7.1%", "a: 64 | 7.1%", ]) class Test4Change(ExamTestCase): """ Meny options for frequency """ @tags("change") def test_a_change(self): """ Testar att anropa menyval 'all' i main.py. Använder följande som input: {arguments} Förväntar att följande finns med i utskrift: {correct} Fick följande: {student} """ self.norepr = True self._multi_arguments = ["change", "lorum.txt", "", "all", "", "q"] with patch('builtins.input', side_effect=self._multi_arguments): with patch('sys.stdout', new=StringIO()) as fake_out: main.main() str_data = fake_out.getvalue() self.assertIn("23", str_data) self.assertIn("3", str_data) self.assertIn("140", str_data) self.assertIn("dolor: 2 | 8.0%", str_data) self.assertIn("vivamus: 1 | 4.0%", str_data) self.assertIn("vitae: 1 | 4.0%", str_data) self.assertIn("varius: 1 | 4.0%", str_data) self.assertIn("urna: 1 | 4.0%", str_data) self.assertIn("sit: 1 | 4.0%", str_data) self.assertIn("pellentesque: 1 | 4.0%", str_data) self.assertIn("i: 18 | 12.9%", str_data) self.assertIn("e: 16 | 11.4%", str_data) self.assertIn("u: 12 | 8.6%", str_data) self.assertIn("a: 12 | 8.6%", str_data) self.assertIn("t: 10 | 7.1%", str_data) self.assertIn("l: 10 | 7.1%", str_data) self.assertIn("s: 9 | 6.4%", str_data) if __name__ == '__main__': runner = unittest.TextTestRunner(resultclass=ExamTestResult, verbosity=2) unittest.main(testRunner=runner, exit=False)
[ "sys.path.insert", "examiner.tags", "examiner.import_module", "examiner.find_path_to_assignment", "os.path.realpath", "os.chdir", "unittest.main", "io.StringIO", "unittest.mock.patch", "unittest.TextTestRunner" ]
[((360, 393), 'examiner.find_path_to_assignment', 'find_path_to_assignment', (['FILE_DIR'], {}), '(FILE_DIR)\n', (383, 393), False, 'from examiner import import_module, find_path_to_assignment\n'), ((517, 549), 'examiner.import_module', 'import_module', (['REPO_PATH', '"""main"""'], {}), "(REPO_PATH, 'main')\n", (530, 549), False, 'from examiner import import_module, find_path_to_assignment\n'), ((320, 346), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (336, 346), False, 'import os\n'), ((429, 458), 'sys.path.insert', 'sys.path.insert', (['(0)', 'REPO_PATH'], {}), '(0, REPO_PATH)\n', (444, 458), False, 'import sys\n'), ((961, 983), 'examiner.tags', 'tags', (['"""count"""', '"""lines"""'], {}), "('count', 'lines')\n", (965, 983), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((1604, 1626), 'examiner.tags', 'tags', (['"""count"""', '"""words"""'], {}), "('count', 'words')\n", (1608, 1626), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((2249, 2273), 'examiner.tags', 'tags', (['"""count"""', '"""letters"""'], {}), "('count', 'letters')\n", (2253, 2273), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((3430, 3460), 'examiner.tags', 'tags', (['"""freq"""', '"""word_frequency"""'], {}), "('freq', 'word_frequency')\n", (3434, 3460), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((4122, 4154), 'examiner.tags', 'tags', (['"""freq"""', '"""letter_frequency"""'], {}), "('freq', 'letter_frequency')\n", (4126, 4154), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((5310, 5321), 'examiner.tags', 'tags', (['"""all"""'], {}), "('all')\n", (5314, 5321), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((6286, 6300), 'examiner.tags', 'tags', (['"""change"""'], {}), "('change')\n", (6290, 6300), False, 'from examiner import ExamTestCase, ExamTestResult, tags\n'), ((7888, 7952), 'unittest.TextTestRunner', 'unittest.TextTestRunner', ([], {'resultclass': 'ExamTestResult', 'verbosity': '(2)'}), '(resultclass=ExamTestResult, verbosity=2)\n', (7911, 7952), False, 'import unittest\n'), ((7957, 8001), 'unittest.main', 'unittest.main', ([], {'testRunner': 'runner', 'exit': '(False)'}), '(testRunner=runner, exit=False)\n', (7970, 8001), False, 'import unittest\n'), ((934, 953), 'os.chdir', 'os.chdir', (['REPO_PATH'], {}), '(REPO_PATH)\n', (942, 953), False, 'import os\n'), ((1349, 1407), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'self._multi_arguments'}), "('builtins.input', side_effect=self._multi_arguments)\n", (1354, 1407), False, 'from unittest.mock import patch\n'), ((1993, 2051), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'self._multi_arguments'}), "('builtins.input', side_effect=self._multi_arguments)\n", (1998, 2051), False, 'from unittest.mock import patch\n'), ((2672, 2730), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'self._multi_arguments'}), "('builtins.input', side_effect=self._multi_arguments)\n", (2677, 2730), False, 'from unittest.mock import patch\n'), ((3151, 3191), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'inp'}), "('builtins.input', side_effect=inp)\n", (3156, 3191), False, 'from unittest.mock import patch\n'), ((5032, 5072), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'inp'}), "('builtins.input', side_effect=inp)\n", (5037, 5072), False, 'from unittest.mock import patch\n'), ((6690, 6748), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {'side_effect': 'self._multi_arguments'}), "('builtins.input', side_effect=self._multi_arguments)\n", (6695, 6748), False, 'from unittest.mock import patch\n'), ((1450, 1460), 'io.StringIO', 'StringIO', ([], {}), '()\n', (1458, 1460), False, 'from io import StringIO\n'), ((2094, 2104), 'io.StringIO', 'StringIO', ([], {}), '()\n', (2102, 2104), False, 'from io import StringIO\n'), ((2773, 2783), 'io.StringIO', 'StringIO', ([], {}), '()\n', (2781, 2783), False, 'from io import StringIO\n'), ((3234, 3244), 'io.StringIO', 'StringIO', ([], {}), '()\n', (3242, 3244), False, 'from io import StringIO\n'), ((5115, 5125), 'io.StringIO', 'StringIO', ([], {}), '()\n', (5123, 5125), False, 'from io import StringIO\n'), ((6791, 6801), 'io.StringIO', 'StringIO', ([], {}), '()\n', (6799, 6801), False, 'from io import StringIO\n')]
from django.contrib import admin from olha_boca.infratores.models import Infratores # Register your models here. class InfratoresAdmin(admin.ModelAdmin): list_display = ('nome', 'infracoes_a_pagar', 'total_infracoes', 'valor_a_pagar') @admin.display(empty_value='???') def total_infracoes(self, obj): return obj.infracoes.count() @admin.display(empty_value='???') def infracoes_a_pagar(self, obj): return obj.infracoes.filter(paga=False).count() @admin.display(empty_value='???') def valor_a_pagar(self, obj): total = 0 infracoes_a_pagar = obj.infracoes.filter(paga=False).all() for inf in infracoes_a_pagar: total += (inf.tipo.vibs * inf.tipo.multiplicador_vibs) return f'R$ {total:.2f}' admin.site.register(Infratores, InfratoresAdmin)
[ "django.contrib.admin.site.register", "django.contrib.admin.display" ]
[((783, 831), 'django.contrib.admin.site.register', 'admin.site.register', (['Infratores', 'InfratoresAdmin'], {}), '(Infratores, InfratoresAdmin)\n', (802, 831), False, 'from django.contrib import admin\n'), ((247, 279), 'django.contrib.admin.display', 'admin.display', ([], {'empty_value': '"""???"""'}), "(empty_value='???')\n", (260, 279), False, 'from django.contrib import admin\n'), ((359, 391), 'django.contrib.admin.display', 'admin.display', ([], {'empty_value': '"""???"""'}), "(empty_value='???')\n", (372, 391), False, 'from django.contrib import admin\n'), ((492, 524), 'django.contrib.admin.display', 'admin.display', ([], {'empty_value': '"""???"""'}), "(empty_value='???')\n", (505, 524), False, 'from django.contrib import admin\n')]
from __future__ import absolute_import from __future__ import division from __future__ import print_function import torch import functools import torch.nn as nn from torch.nn import init import torch.functional as F from torch.autograd import Variable print('ok') def weights_init_normal(m): classname = m.__class__.__name__ print(classname) if classname.find('Conv') != -1: init.normal(m.weight.data, 0.0, 0.02) elif classname.find('Linear') != -1: init.normal(m.weight.data, 0.0, 0.02) elif classname.find('BatchNorm2d') != -1: init.normal(m.weight.data, 1.0, 0.02) init.constant(m.bias.data, 0.0) def init_weight(net,init_type='normal'): print('initialization method [%s]' % init_type) if init_type == 'normal': net.apply(weights_init_normal) else: raise NotImplementedError('initialization method [%s] is not implemented' % init_type) class ResnetBlock(nn.Module): def __init__(self, dim, use_dropout, use_bias): super(ResnetBlock, self).__init__() self.conv_block = self.build_conv_block(dim, use_dropout, use_bias) def build_conv_block(self,dim,use_dropout,use_bias): conv_block = [] conv_block += [nn.ReflectionPad2d(1)] conv_block += [nn.Conv2d(dim,dim,kernel_size=3,padding=0,bias=use_bias), nn.InstanceNorm2d(dim), nn.ReLU(True)] if use_dropout: conv_block += [nn.Dropout(0.5)] conv_block += [nn.ReflectionPad2d(1)] conv_block += [nn.Conv2d(dim,dim,kernel_size=3,padding=0,bias=use_bias), nn.InstanceNorm2d(dim)] return nn.Sequential(*conv_block) def forward(self,x): out = x + self.conv_block(x) return out class G(nn.Module): def __init__(self,dim=64,device_ids=[]): super(G,self).__init__() self.device_ids = device_ids model = [nn.ReflectionPad2d(3), nn.Conv2d(3, dim, kernel_size=7, padding=0,bias=False), nn.InstanceNorm2d(dim), nn.ReLU(True)] for i in range(2): mult = 2 ** i model += [nn.Conv2d(dim * mult, dim * mult * 2, kernel_size=3, stride=2, padding=1, bias=False), nn.InstanceNorm2d(dim * mult * 2), nn.ReLU(True)] for i in range(9): model += [ResnetBlock(dim*4,use_dropout=False,use_bias=False)] for i in range(2): mult = 2**(2 - i) model += [nn.ConvTranspose2d(dim * mult, int(dim * mult / 2), kernel_size=3, stride=2, padding=1, output_padding=1, bias=False), nn.InstanceNorm2d(int(dim * mult / 2)), nn.ReLU(True)] model += [nn.ReflectionPad2d(3)] model += [nn.Conv2d(dim,3,kernel_size=7,padding=0)] model += [nn.Tanh()] self.model = nn.Sequential(*model) def forward(self, input): use_gpu = len(self.device_ids) > 0 if (use_gpu): assert (torch.cuda.is_available()) if len(self.device_ids)and isinstance(input.data, torch.cuda.FloatTensor): print('Train on GPU...') return nn.parallel.data_parallel(self.model, input, self.device_ids) else: print('Train on CPU...') return self.model(input) class D(nn.Module): def __init__(self,dim=64,device_ids=[]): super(D,self).__init__() self.device_ids = device_ids model = [nn.Conv2d(3,dim,kernel_size=4,stride=2,padding=1), nn.LeakyReLU(0.2,True)] model += [nn.Conv2d(dim,dim*2,kernel_size=4,stride=2,padding=1,bias=False), nn.InstanceNorm2d(dim*2), nn.LeakyReLU(0.2,True)] model += [nn.Conv2d(dim*2, dim*4, kernel_size=4, stride=2, padding=1, bias=False), nn.InstanceNorm2d(dim*4), nn.LeakyReLU(0.2,True)] model += [nn.Conv2d(dim*4, dim*8, kernel_size=4, stride=1, padding=1, bias=False), nn.InstanceNorm2d(dim*8), nn.LeakyReLU(0.2,True)] model += [nn.Conv2d(dim*8,1,kernel_size=4,stride=1,padding=1)] self.model = nn.Sequential(*model) def forward(self, input): use_gpu = len(self.device_ids) > 0 if (use_gpu): assert (torch.cuda.is_available()) if len(self.device_ids)and isinstance(input.data, torch.cuda.FloatTensor): print('Train on GPU...') return nn.parallel.data_parallel(self.model, input, self.device_ids) else: print('Train on CPU...') return self.model(input) print ('kkk') # class te(nn.Module): # def __init__(self): # super(te,self).__init__() # norm_layer=nn.InstanceNorm2d # kw = 4 # padw = 1 # input_nc=3 # n_layers=3 # ndf=64 # use_bias = False # sequence = [ # nn.Conv2d(input_nc, ndf, kernel_size=kw, stride=2, padding=padw), # nn.LeakyReLU(0.2, True) # ] # # nf_mult = 1 # nf_mult_prev = 1 # for n in range(1, n_layers): # nf_mult_prev = nf_mult # nf_mult = min(2**n, 8) # sequence += [ # nn.Conv2d(ndf * nf_mult_prev, ndf * nf_mult, # kernel_size=kw, stride=2, padding=padw, bias=use_bias), # norm_layer(ndf * nf_mult), # nn.LeakyReLU(0.2, True) # ] # # nf_mult_prev = nf_mult # nf_mult = min(2**n_layers, 8) # sequence += [ # nn.Conv2d(ndf * nf_mult_prev, ndf * nf_mult, # kernel_size=kw, stride=1, padding=padw, bias=use_bias), # norm_layer(ndf * nf_mult), # nn.LeakyReLU(0.2, True) # ] # # sequence += [nn.Conv2d(ndf * nf_mult, 1, kernel_size=kw, stride=1, padding=padw)] # # self.model1 = nn.Sequential(*sequence) # def forward(self,x): # return self.model1(x)
[ "torch.nn.ReLU", "torch.nn.parallel.data_parallel", "torch.nn.Dropout", "torch.nn.Tanh", "torch.nn.LeakyReLU", "torch.nn.Sequential", "torch.nn.init.normal", "torch.nn.ReflectionPad2d", "torch.nn.InstanceNorm2d", "torch.nn.Conv2d", "torch.cuda.is_available", "torch.nn.init.constant" ]
[((395, 432), 'torch.nn.init.normal', 'init.normal', (['m.weight.data', '(0.0)', '(0.02)'], {}), '(m.weight.data, 0.0, 0.02)\n', (406, 432), False, 'from torch.nn import init\n'), ((1683, 1709), 'torch.nn.Sequential', 'nn.Sequential', (['*conv_block'], {}), '(*conv_block)\n', (1696, 1709), True, 'import torch.nn as nn\n'), ((3075, 3096), 'torch.nn.Sequential', 'nn.Sequential', (['*model'], {}), '(*model)\n', (3088, 3096), True, 'import torch.nn as nn\n'), ((4390, 4411), 'torch.nn.Sequential', 'nn.Sequential', (['*model'], {}), '(*model)\n', (4403, 4411), True, 'import torch.nn as nn\n'), ((482, 519), 'torch.nn.init.normal', 'init.normal', (['m.weight.data', '(0.0)', '(0.02)'], {}), '(m.weight.data, 0.0, 0.02)\n', (493, 519), False, 'from torch.nn import init\n'), ((1233, 1254), 'torch.nn.ReflectionPad2d', 'nn.ReflectionPad2d', (['(1)'], {}), '(1)\n', (1251, 1254), True, 'import torch.nn as nn\n'), ((1279, 1339), 'torch.nn.Conv2d', 'nn.Conv2d', (['dim', 'dim'], {'kernel_size': '(3)', 'padding': '(0)', 'bias': 'use_bias'}), '(dim, dim, kernel_size=3, padding=0, bias=use_bias)\n', (1288, 1339), True, 'import torch.nn as nn\n'), ((1361, 1383), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['dim'], {}), '(dim)\n', (1378, 1383), True, 'import torch.nn as nn\n'), ((1409, 1422), 'torch.nn.ReLU', 'nn.ReLU', (['(True)'], {}), '(True)\n', (1416, 1422), True, 'import torch.nn as nn\n'), ((1515, 1536), 'torch.nn.ReflectionPad2d', 'nn.ReflectionPad2d', (['(1)'], {}), '(1)\n', (1533, 1536), True, 'import torch.nn as nn\n'), ((1562, 1622), 'torch.nn.Conv2d', 'nn.Conv2d', (['dim', 'dim'], {'kernel_size': '(3)', 'padding': '(0)', 'bias': 'use_bias'}), '(dim, dim, kernel_size=3, padding=0, bias=use_bias)\n', (1571, 1622), True, 'import torch.nn as nn\n'), ((1644, 1666), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['dim'], {}), '(dim)\n', (1661, 1666), True, 'import torch.nn as nn\n'), ((1945, 1966), 'torch.nn.ReflectionPad2d', 'nn.ReflectionPad2d', (['(3)'], {}), '(3)\n', (1963, 1966), True, 'import torch.nn as nn\n'), ((1985, 2040), 'torch.nn.Conv2d', 'nn.Conv2d', (['(3)', 'dim'], {'kernel_size': '(7)', 'padding': '(0)', 'bias': '(False)'}), '(3, dim, kernel_size=7, padding=0, bias=False)\n', (1994, 2040), True, 'import torch.nn as nn\n'), ((2058, 2080), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['dim'], {}), '(dim)\n', (2075, 2080), True, 'import torch.nn as nn\n'), ((2099, 2112), 'torch.nn.ReLU', 'nn.ReLU', (['(True)'], {}), '(True)\n', (2106, 2112), True, 'import torch.nn as nn\n'), ((2942, 2963), 'torch.nn.ReflectionPad2d', 'nn.ReflectionPad2d', (['(3)'], {}), '(3)\n', (2960, 2963), True, 'import torch.nn as nn\n'), ((2983, 3026), 'torch.nn.Conv2d', 'nn.Conv2d', (['dim', '(3)'], {'kernel_size': '(7)', 'padding': '(0)'}), '(dim, 3, kernel_size=7, padding=0)\n', (2992, 3026), True, 'import torch.nn as nn\n'), ((3043, 3052), 'torch.nn.Tanh', 'nn.Tanh', ([], {}), '()\n', (3050, 3052), True, 'import torch.nn as nn\n'), ((3213, 3238), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (3236, 3238), False, 'import torch\n'), ((3379, 3440), 'torch.nn.parallel.data_parallel', 'nn.parallel.data_parallel', (['self.model', 'input', 'self.device_ids'], {}), '(self.model, input, self.device_ids)\n', (3404, 3440), True, 'import torch.nn as nn\n'), ((3682, 3735), 'torch.nn.Conv2d', 'nn.Conv2d', (['(3)', 'dim'], {'kernel_size': '(4)', 'stride': '(2)', 'padding': '(1)'}), '(3, dim, kernel_size=4, stride=2, padding=1)\n', (3691, 3735), True, 'import torch.nn as nn\n'), ((3750, 3773), 'torch.nn.LeakyReLU', 'nn.LeakyReLU', (['(0.2)', '(True)'], {}), '(0.2, True)\n', (3762, 3773), True, 'import torch.nn as nn\n'), ((3792, 3863), 'torch.nn.Conv2d', 'nn.Conv2d', (['dim', '(dim * 2)'], {'kernel_size': '(4)', 'stride': '(2)', 'padding': '(1)', 'bias': '(False)'}), '(dim, dim * 2, kernel_size=4, stride=2, padding=1, bias=False)\n', (3801, 3863), True, 'import torch.nn as nn\n'), ((3876, 3902), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['(dim * 2)'], {}), '(dim * 2)\n', (3893, 3902), True, 'import torch.nn as nn\n'), ((3920, 3943), 'torch.nn.LeakyReLU', 'nn.LeakyReLU', (['(0.2)', '(True)'], {}), '(0.2, True)\n', (3932, 3943), True, 'import torch.nn as nn\n'), ((3962, 4037), 'torch.nn.Conv2d', 'nn.Conv2d', (['(dim * 2)', '(dim * 4)'], {'kernel_size': '(4)', 'stride': '(2)', 'padding': '(1)', 'bias': '(False)'}), '(dim * 2, dim * 4, kernel_size=4, stride=2, padding=1, bias=False)\n', (3971, 4037), True, 'import torch.nn as nn\n'), ((4053, 4079), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['(dim * 4)'], {}), '(dim * 4)\n', (4070, 4079), True, 'import torch.nn as nn\n'), ((4097, 4120), 'torch.nn.LeakyReLU', 'nn.LeakyReLU', (['(0.2)', '(True)'], {}), '(0.2, True)\n', (4109, 4120), True, 'import torch.nn as nn\n'), ((4139, 4214), 'torch.nn.Conv2d', 'nn.Conv2d', (['(dim * 4)', '(dim * 8)'], {'kernel_size': '(4)', 'stride': '(1)', 'padding': '(1)', 'bias': '(False)'}), '(dim * 4, dim * 8, kernel_size=4, stride=1, padding=1, bias=False)\n', (4148, 4214), True, 'import torch.nn as nn\n'), ((4230, 4256), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['(dim * 8)'], {}), '(dim * 8)\n', (4247, 4256), True, 'import torch.nn as nn\n'), ((4274, 4297), 'torch.nn.LeakyReLU', 'nn.LeakyReLU', (['(0.2)', '(True)'], {}), '(0.2, True)\n', (4286, 4297), True, 'import torch.nn as nn\n'), ((4316, 4373), 'torch.nn.Conv2d', 'nn.Conv2d', (['(dim * 8)', '(1)'], {'kernel_size': '(4)', 'stride': '(1)', 'padding': '(1)'}), '(dim * 8, 1, kernel_size=4, stride=1, padding=1)\n', (4325, 4373), True, 'import torch.nn as nn\n'), ((4528, 4553), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (4551, 4553), False, 'import torch\n'), ((4694, 4755), 'torch.nn.parallel.data_parallel', 'nn.parallel.data_parallel', (['self.model', 'input', 'self.device_ids'], {}), '(self.model, input, self.device_ids)\n', (4719, 4755), True, 'import torch.nn as nn\n'), ((574, 611), 'torch.nn.init.normal', 'init.normal', (['m.weight.data', '(1.0)', '(0.02)'], {}), '(m.weight.data, 1.0, 0.02)\n', (585, 611), False, 'from torch.nn import init\n'), ((620, 651), 'torch.nn.init.constant', 'init.constant', (['m.bias.data', '(0.0)'], {}), '(m.bias.data, 0.0)\n', (633, 651), False, 'from torch.nn import init\n'), ((1475, 1490), 'torch.nn.Dropout', 'nn.Dropout', (['(0.5)'], {}), '(0.5)\n', (1485, 1490), True, 'import torch.nn as nn\n'), ((2189, 2278), 'torch.nn.Conv2d', 'nn.Conv2d', (['(dim * mult)', '(dim * mult * 2)'], {'kernel_size': '(3)', 'stride': '(2)', 'padding': '(1)', 'bias': '(False)'}), '(dim * mult, dim * mult * 2, kernel_size=3, stride=2, padding=1,\n bias=False)\n', (2198, 2278), True, 'import torch.nn as nn\n'), ((2330, 2363), 'torch.nn.InstanceNorm2d', 'nn.InstanceNorm2d', (['(dim * mult * 2)'], {}), '(dim * mult * 2)\n', (2347, 2363), True, 'import torch.nn as nn\n'), ((2387, 2400), 'torch.nn.ReLU', 'nn.ReLU', (['(True)'], {}), '(True)\n', (2394, 2400), True, 'import torch.nn as nn\n'), ((2909, 2922), 'torch.nn.ReLU', 'nn.ReLU', (['(True)'], {}), '(True)\n', (2916, 2922), True, 'import torch.nn as nn\n')]
# Generated by Django 2.0.13 on 2019-06-27 17:04 import django.contrib.postgres.fields.jsonb from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): initial = True dependencies = [ ('research', '0001_initial'), ('datasets', '0001_initial'), ] operations = [ migrations.CreateModel( name='Bottleneck', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('homology', models.PositiveIntegerField()), ('kind', models.CharField(choices=[('consecutive', 'consecutive'), ('one_to_all', 'one_to_all'), ('all_to_all', 'all_to_all')], max_length=20)), ], ), migrations.CreateModel( name='Diagram', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('image', models.TextField()), ('bottleneck_distance', models.FloatField()), ('bottleneck', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='analysis.Bottleneck')), ], ), migrations.CreateModel( name='FiltrationAnalysis', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(help_text='Name this analysis', max_length=100)), ('slug', models.SlugField(max_length=110)), ('description', models.TextField(blank=True, help_text='Write a brief description of the analysis', max_length=500)), ('creation_date', models.DateTimeField(auto_now_add=True)), ('precomputed_distance_matrix_json', django.contrib.postgres.fields.jsonb.JSONField(default='"[]"')), ('window_size', models.PositiveIntegerField(blank=True, default=None, help_text="Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won't fit into the final window will be\n discarded.", null=True)), ('window_overlap', models.PositiveIntegerField(default=0, help_text='How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size.')), ('filtration_type', models.CharField(choices=[('VRF', 'Vietoris Rips Filtration'), ('CWRF', 'Clique Weighted Rank Filtration')], help_text='Choose the type of analysis.', max_length=50)), ('distance_matrix_metric', models.CharField(blank=True, choices=[('braycurtis', 'Braycurtis'), ('canberra', 'Canberra'), ('chebyshev', 'Chebyshev'), ('cityblock', 'City block'), ('correlation', 'Correlation'), ('cosine', 'Cosine'), ('dice', 'Dice'), ('euclidean', 'Euclidean'), ('hamming', 'Hamming'), ('jaccard', 'Jaccard'), ('jensenshannon', '<NAME>'), ('kulsinski', 'Kulsinski'), ('mahalanobis', 'Mahalonobis'), ('matching', 'Matching'), ('minkowski', 'Minkowski'), ('rogerstanimoto', 'Rogers-Tanimoto'), ('russellrao', '<NAME>'), ('seuclidean', 'Seuclidean'), ('sokalmichener', 'Sojal-Michener'), ('sokalsneath', 'Sokal-Sneath'), ('sqeuclidean', 'Sqeuclidean'), ('yule', 'Yule')], help_text='If Vietoris-Rips filtration is selected and not using a precomputed distance matrix, choose the\n distance metric to use on the selected dataset. This parameter is ignored in all other cases.', max_length=20)), ('max_homology_dimension', models.PositiveIntegerField(default=1, help_text='Maximum homology dimension computed. Will compute all dimensions lower than and equal to this value.\n For 1, H_0 and H_1 will be computed.')), ('max_distances_considered', models.FloatField(blank=True, default=None, help_text='Maximum distances considered when constructing filtration.\n If blank, compute the entire filtration.', null=True)), ('coeff', models.PositiveIntegerField(default=2, help_text='Compute homology with coefficients in the prime field Z/pZ for\n p=coeff.')), ('do_cocycles', models.BooleanField(default=False, help_text='Indicator of whether to compute cocycles.')), ('n_perm', models.IntegerField(blank=True, default=None, help_text='The number of points to subsample in\n a “greedy permutation,” or a furthest point sampling of the points. These points will\n be used in lieu of the full point cloud for a faster computation, at the expense of\n some accuracy, which can be bounded as a maximum bottleneck distance to all diagrams\n on the original point set', null=True)), ('entropy_normalized_graph', models.TextField(blank=True, null=True)), ('entropy_unnormalized_graph', models.TextField(blank=True, null=True)), ('dataset', models.ForeignKey(blank=True, default=None, help_text='Select the source dataset from the loaded datasets', null=True, on_delete=django.db.models.deletion.CASCADE, to='datasets.Dataset')), ('research', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='research.Research')), ], options={ 'verbose_name': 'filtration analysis', 'verbose_name_plural': 'filtration analyses', 'abstract': False, }, ), migrations.CreateModel( name='FiltrationWindow', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.PositiveIntegerField()), ('slug', models.SlugField(max_length=150)), ('creation_date', models.DateTimeField(auto_now_add=True)), ('start', models.PositiveIntegerField(blank=True, null=True)), ('end', models.PositiveIntegerField(blank=True, null=True)), ('result_matrix', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), ('diagrams', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), ('result_entropy_normalized', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), ('result_entropy_unnormalized', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)), ('analysis', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='analysis.FiltrationAnalysis')), ], options={ 'abstract': False, }, ), migrations.CreateModel( name='MapperAnalysis', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(help_text='Name this analysis', max_length=100)), ('slug', models.SlugField(max_length=110)), ('description', models.TextField(blank=True, help_text='Write a brief description of the analysis', max_length=500)), ('creation_date', models.DateTimeField(auto_now_add=True)), ('precomputed_distance_matrix_json', django.contrib.postgres.fields.jsonb.JSONField(default='"[]"')), ('window_size', models.PositiveIntegerField(blank=True, default=None, help_text="Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won't fit into the final window will be\n discarded.", null=True)), ('window_overlap', models.PositiveIntegerField(default=0, help_text='How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size.')), ('distance_matrix_metric', models.CharField(blank=True, choices=[('braycurtis', 'Braycurtis'), ('canberra', 'Canberra'), ('chebyshev', 'Chebyshev'), ('cityblock', 'City block'), ('correlation', 'Correlation'), ('cosine', 'Cosine'), ('dice', 'Dice'), ('euclidean', 'Euclidean'), ('hamming', 'Hamming'), ('jaccard', 'Jaccard'), ('jensenshannon', '<NAME>'), ('kulsinski', 'Kulsinski'), ('mahalanobis', 'Mahalonobis'), ('matching', 'Matching'), ('minkowski', 'Minkowski'), ('rogerstanimoto', 'Rogers-Tanimoto'), ('russellrao', '<NAME>'), ('seuclidean', 'Seuclidean'), ('sokalmichener', 'Sojal-Michener'), ('sokalsneath', 'Sokal-Sneath'), ('sqeuclidean', 'Sqeuclidean'), ('yule', 'Yule')], help_text='If not using a precomputed matrix, choose the distance metric to use on the dataset.', max_length=20)), ('projection', models.CharField(choices=[('sum', 'Sum'), ('mean', 'Mean'), ('median', 'Median'), ('max', 'Max'), ('min', 'Min'), ('std', 'Std'), ('dist_mean', 'Dist_mean'), ('l2norm', 'L2norm'), ('knn_distance_n', 'knn_distance_n')], default='sum', help_text='Specify a projection/lens type.', max_length=50)), ('knn_n_value', models.PositiveIntegerField(blank=True, help_text='Specify the value of n in knn_distance_n', null=True)), ('scaler', models.CharField(choices=[('None', 'None'), ('MinMaxScaler', 'MinMaxScaler'), ('MaxAbsScaler', 'MaxAbsScaler'), ('RobustScaler', 'RobustScaler'), ('StandardScaler', 'StandardScaler')], default='MinMaxScaler', help_text='Scaler of the data applied after mapping. Use None for no scaling.', max_length=50)), ('use_original_data', models.BooleanField(default=False, help_text='If ticked, clustering is run on the original data,\n else it will be run on the lower dimensional projection.')), ('clusterer', models.CharField(choices=[('k-means', 'K-Means'), ('affinity_propagation', 'Affinity propagation'), ('mean-shift', 'Mean-shift'), ('spectral_clustering', 'Spectral clustering'), ('agglomerative_clustering', 'StandardScaler'), ('DBSCAN(min_samples=1)', 'DBSCAN(min_samples=1)'), ('DBSCAN', 'DBSCAN'), ('gaussian_mixtures', 'Gaussian mixtures'), ('birch', 'Birch')], default='DBSCAN', help_text='Select the clustering algorithm.', max_length=50)), ('cover_n_cubes', models.PositiveIntegerField(default=10, help_text='Number of hypercubes along each dimension.\n Sometimes referred to as resolution.')), ('cover_perc_overlap', models.FloatField(default=0.5, help_text='Amount of overlap between adjacent cubes calculated\n only along 1 dimension.')), ('graph_nerve_min_intersection', models.IntegerField(default=1, help_text='Minimum intersection considered when\n computing the nerve. An edge will be created only when the\n intersection between two nodes is greater than or equal to\n min_intersection')), ('precomputed', models.BooleanField(default=False, help_text='Tell Mapper whether the data that you are clustering on\n is a precomputed distance matrix. If set to True, the assumption is that you are\n also telling your clusterer that metric=’precomputed’ (which is an argument for\n DBSCAN among others), which will then cause the clusterer to expect a square\n distance matrix for each hypercube. precomputed=True will give a square matrix\n to the clusterer to fit on for each hypercube.')), ('remove_duplicate_nodes', models.BooleanField(default=False, help_text='Removes duplicate nodes before edges are\n determined. A node is considered to be duplicate if it has exactly\n the same set of points as another node.')), ('dataset', models.ForeignKey(blank=True, default=None, help_text='Select the source dataset from the loaded datasets', null=True, on_delete=django.db.models.deletion.CASCADE, to='datasets.Dataset')), ('research', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='research.Research')), ], options={ 'verbose_name': 'mapper algorithm analysis', 'verbose_name_plural': 'mapper algoritm analyses', 'abstract': False, }, ), migrations.CreateModel( name='MapperWindow', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.PositiveIntegerField()), ('slug', models.SlugField(max_length=150)), ('creation_date', models.DateTimeField(auto_now_add=True)), ('start', models.PositiveIntegerField(blank=True, null=True)), ('end', models.PositiveIntegerField(blank=True, null=True)), ('graph', models.TextField(blank=True, null=True)), ('analysis', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='windows', related_query_name='window', to='analysis.MapperAnalysis')), ], options={ 'abstract': False, }, ), migrations.AddField( model_name='diagram', name='window1', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='window1', to='analysis.FiltrationWindow'), ), migrations.AddField( model_name='diagram', name='window2', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='window2', to='analysis.FiltrationWindow'), ), migrations.AddField( model_name='bottleneck', name='analysis', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='analysis.FiltrationAnalysis'), ), migrations.AddField( model_name='bottleneck', name='window', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='analysis.FiltrationWindow'), ), migrations.AlterUniqueTogether( name='mapperanalysis', unique_together={('slug', 'research')}, ), migrations.AlterUniqueTogether( name='filtrationanalysis', unique_together={('slug', 'research')}, ), ]
[ "django.db.migrations.AlterUniqueTogether", "django.db.models.FloatField", "django.db.models.TextField", "django.db.models.ForeignKey", "django.db.models.IntegerField", "django.db.models.BooleanField", "django.db.models.SlugField", "django.db.models.AutoField", "django.db.models.PositiveIntegerField...
[((15570, 15668), 'django.db.migrations.AlterUniqueTogether', 'migrations.AlterUniqueTogether', ([], {'name': '"""mapperanalysis"""', 'unique_together': "{('slug', 'research')}"}), "(name='mapperanalysis', unique_together={(\n 'slug', 'research')})\n", (15600, 15668), False, 'from django.db import migrations, models\n'), ((15708, 15810), 'django.db.migrations.AlterUniqueTogether', 'migrations.AlterUniqueTogether', ([], {'name': '"""filtrationanalysis"""', 'unique_together': "{('slug', 'research')}"}), "(name='filtrationanalysis', unique_together={\n ('slug', 'research')})\n", (15738, 15810), False, 'from django.db import migrations, models\n'), ((14729, 14852), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'related_name': '"""window1"""', 'to': '"""analysis.FiltrationWindow"""'}), "(on_delete=django.db.models.deletion.CASCADE, related_name\n ='window1', to='analysis.FiltrationWindow')\n", (14746, 14852), False, 'from django.db import migrations, models\n'), ((14969, 15092), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'related_name': '"""window2"""', 'to': '"""analysis.FiltrationWindow"""'}), "(on_delete=django.db.models.deletion.CASCADE, related_name\n ='window2', to='analysis.FiltrationWindow')\n", (14986, 15092), False, 'from django.db import migrations, models\n'), ((15213, 15324), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'null': '(True)', 'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""analysis.FiltrationAnalysis"""'}), "(null=True, on_delete=django.db.models.deletion.CASCADE,\n to='analysis.FiltrationAnalysis')\n", (15230, 15324), False, 'from django.db import migrations, models\n'), ((15444, 15553), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'null': '(True)', 'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""analysis.FiltrationWindow"""'}), "(null=True, on_delete=django.db.models.deletion.CASCADE,\n to='analysis.FiltrationWindow')\n", (15461, 15553), False, 'from django.db import migrations, models\n'), ((460, 553), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (476, 553), False, 'from django.db import migrations, models\n'), ((581, 610), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {}), '()\n', (608, 610), False, 'from django.db import migrations, models\n'), ((638, 775), 'django.db.models.CharField', 'models.CharField', ([], {'choices': "[('consecutive', 'consecutive'), ('one_to_all', 'one_to_all'), (\n 'all_to_all', 'all_to_all')]", 'max_length': '(20)'}), "(choices=[('consecutive', 'consecutive'), ('one_to_all',\n 'one_to_all'), ('all_to_all', 'all_to_all')], max_length=20)\n", (654, 775), False, 'from django.db import migrations, models\n'), ((904, 997), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (920, 997), False, 'from django.db import migrations, models\n'), ((1022, 1040), 'django.db.models.TextField', 'models.TextField', ([], {}), '()\n', (1038, 1040), False, 'from django.db import migrations, models\n'), ((1083, 1102), 'django.db.models.FloatField', 'models.FloatField', ([], {}), '()\n', (1100, 1102), False, 'from django.db import migrations, models\n'), ((1136, 1229), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""analysis.Bottleneck"""'}), "(on_delete=django.db.models.deletion.CASCADE, to=\n 'analysis.Bottleneck')\n", (1153, 1229), False, 'from django.db import migrations, models\n'), ((1368, 1461), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (1384, 1461), False, 'from django.db import migrations, models\n'), ((1485, 1549), 'django.db.models.CharField', 'models.CharField', ([], {'help_text': '"""Name this analysis"""', 'max_length': '(100)'}), "(help_text='Name this analysis', max_length=100)\n", (1501, 1549), False, 'from django.db import migrations, models\n'), ((1577, 1609), 'django.db.models.SlugField', 'models.SlugField', ([], {'max_length': '(110)'}), '(max_length=110)\n', (1593, 1609), False, 'from django.db import migrations, models\n'), ((1644, 1748), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'help_text': '"""Write a brief description of the analysis"""', 'max_length': '(500)'}), "(blank=True, help_text=\n 'Write a brief description of the analysis', max_length=500)\n", (1660, 1748), False, 'from django.db import migrations, models\n'), ((1780, 1819), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (1800, 1819), False, 'from django.db import migrations, models\n'), ((1972, 2536), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won\'t fit into the final window will be\n discarded."""', 'null': '(True)'}), '(blank=True, default=None, help_text=\n """Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won\'t fit into the final window will be\n discarded."""\n , null=True)\n', (1999, 2536), False, 'from django.db import migrations, models\n'), ((2564, 2857), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'default': '(0)', 'help_text': '"""How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size."""'}), '(default=0, help_text=\n """How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size."""\n )\n', (2591, 2857), False, 'from django.db import migrations, models\n'), ((2884, 3058), 'django.db.models.CharField', 'models.CharField', ([], {'choices': "[('VRF', 'Vietoris Rips Filtration'), ('CWRF',\n 'Clique Weighted Rank Filtration')]", 'help_text': '"""Choose the type of analysis."""', 'max_length': '(50)'}), "(choices=[('VRF', 'Vietoris Rips Filtration'), ('CWRF',\n 'Clique Weighted Rank Filtration')], help_text=\n 'Choose the type of analysis.', max_length=50)\n", (2900, 3058), False, 'from django.db import migrations, models\n'), ((3095, 4042), 'django.db.models.CharField', 'models.CharField', ([], {'blank': '(True)', 'choices': "[('braycurtis', 'Braycurtis'), ('canberra', 'Canberra'), ('chebyshev',\n 'Chebyshev'), ('cityblock', 'City block'), ('correlation',\n 'Correlation'), ('cosine', 'Cosine'), ('dice', 'Dice'), ('euclidean',\n 'Euclidean'), ('hamming', 'Hamming'), ('jaccard', 'Jaccard'), (\n 'jensenshannon', '<NAME>'), ('kulsinski', 'Kulsinski'), ('mahalanobis',\n 'Mahalonobis'), ('matching', 'Matching'), ('minkowski', 'Minkowski'), (\n 'rogerstanimoto', 'Rogers-Tanimoto'), ('russellrao', '<NAME>'), (\n 'seuclidean', 'Seuclidean'), ('sokalmichener', 'Sojal-Michener'), (\n 'sokalsneath', 'Sokal-Sneath'), ('sqeuclidean', 'Sqeuclidean'), ('yule',\n 'Yule')]", 'help_text': '"""If Vietoris-Rips filtration is selected and not using a precomputed distance matrix, choose the\n distance metric to use on the selected dataset. This parameter is ignored in all other cases."""', 'max_length': '(20)'}), '(blank=True, choices=[(\'braycurtis\', \'Braycurtis\'), (\n \'canberra\', \'Canberra\'), (\'chebyshev\', \'Chebyshev\'), (\'cityblock\',\n \'City block\'), (\'correlation\', \'Correlation\'), (\'cosine\', \'Cosine\'), (\n \'dice\', \'Dice\'), (\'euclidean\', \'Euclidean\'), (\'hamming\', \'Hamming\'), (\n \'jaccard\', \'Jaccard\'), (\'jensenshannon\', \'<NAME>\'), (\'kulsinski\',\n \'Kulsinski\'), (\'mahalanobis\', \'Mahalonobis\'), (\'matching\', \'Matching\'),\n (\'minkowski\', \'Minkowski\'), (\'rogerstanimoto\', \'Rogers-Tanimoto\'), (\n \'russellrao\', \'<NAME>\'), (\'seuclidean\', \'Seuclidean\'), (\'sokalmichener\',\n \'Sojal-Michener\'), (\'sokalsneath\', \'Sokal-Sneath\'), (\'sqeuclidean\',\n \'Sqeuclidean\'), (\'yule\', \'Yule\')], help_text=\n """If Vietoris-Rips filtration is selected and not using a precomputed distance matrix, choose the\n distance metric to use on the selected dataset. This parameter is ignored in all other cases."""\n , max_length=20)\n', (3111, 4042), False, 'from django.db import migrations, models\n'), ((4035, 4287), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'default': '(1)', 'help_text': '"""Maximum homology dimension computed. Will compute all dimensions lower than and equal to this value.\n For 1, H_0 and H_1 will be computed."""'}), '(default=1, help_text=\n """Maximum homology dimension computed. Will compute all dimensions lower than and equal to this value.\n For 1, H_0 and H_1 will be computed."""\n )\n', (4062, 4287), False, 'from django.db import migrations, models\n'), ((4322, 4552), 'django.db.models.FloatField', 'models.FloatField', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""Maximum distances considered when constructing filtration.\n If blank, compute the entire filtration."""', 'null': '(True)'}), '(blank=True, default=None, help_text=\n """Maximum distances considered when constructing filtration.\n If blank, compute the entire filtration."""\n , null=True)\n', (4339, 4552), False, 'from django.db import migrations, models\n'), ((4568, 4737), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'default': '(2)', 'help_text': '"""Compute homology with coefficients in the prime field Z/pZ for\n p=coeff."""'}), '(default=2, help_text=\n """Compute homology with coefficients in the prime field Z/pZ for\n p=coeff."""\n )\n', (4595, 4737), False, 'from django.db import migrations, models\n'), ((4759, 4853), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)', 'help_text': '"""Indicator of whether to compute cocycles."""'}), "(default=False, help_text=\n 'Indicator of whether to compute cocycles.')\n", (4778, 4853), False, 'from django.db import migrations, models\n'), ((4878, 5411), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""The number of points to subsample in\n a “greedy permutation,” or a furthest point sampling of the points. These points will\n be used in lieu of the full point cloud for a faster computation, at the expense of\n some accuracy, which can be bounded as a maximum bottleneck distance to all diagrams\n on the original point set"""', 'null': '(True)'}), '(blank=True, default=None, help_text=\n """The number of points to subsample in\n a “greedy permutation,” or a furthest point sampling of the points. These points will\n be used in lieu of the full point cloud for a faster computation, at the expense of\n some accuracy, which can be bounded as a maximum bottleneck distance to all diagrams\n on the original point set"""\n , null=True)\n', (4897, 5411), False, 'from django.db import migrations, models\n'), ((5449, 5488), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (5465, 5488), False, 'from django.db import migrations, models\n'), ((5538, 5577), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (5554, 5577), False, 'from django.db import migrations, models\n'), ((5608, 5803), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""Select the source dataset from the loaded datasets"""', 'null': '(True)', 'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""datasets.Dataset"""'}), "(blank=True, default=None, help_text=\n 'Select the source dataset from the loaded datasets', null=True,\n on_delete=django.db.models.deletion.CASCADE, to='datasets.Dataset')\n", (5625, 5803), False, 'from django.db import migrations, models\n'), ((5826, 5917), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""research.Research"""'}), "(on_delete=django.db.models.deletion.CASCADE, to=\n 'research.Research')\n", (5843, 5917), False, 'from django.db import migrations, models\n'), ((6243, 6336), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (6259, 6336), False, 'from django.db import migrations, models\n'), ((6360, 6389), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {}), '()\n', (6387, 6389), False, 'from django.db import migrations, models\n'), ((6417, 6449), 'django.db.models.SlugField', 'models.SlugField', ([], {'max_length': '(150)'}), '(max_length=150)\n', (6433, 6449), False, 'from django.db import migrations, models\n'), ((6486, 6525), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (6506, 6525), False, 'from django.db import migrations, models\n'), ((6554, 6604), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (6581, 6604), False, 'from django.db import migrations, models\n'), ((6631, 6681), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (6658, 6681), False, 'from django.db import migrations, models\n'), ((7158, 7259), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""analysis.FiltrationAnalysis"""'}), "(on_delete=django.db.models.deletion.CASCADE, to=\n 'analysis.FiltrationAnalysis')\n", (7175, 7259), False, 'from django.db import migrations, models\n'), ((7466, 7559), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (7482, 7559), False, 'from django.db import migrations, models\n'), ((7583, 7647), 'django.db.models.CharField', 'models.CharField', ([], {'help_text': '"""Name this analysis"""', 'max_length': '(100)'}), "(help_text='Name this analysis', max_length=100)\n", (7599, 7647), False, 'from django.db import migrations, models\n'), ((7675, 7707), 'django.db.models.SlugField', 'models.SlugField', ([], {'max_length': '(110)'}), '(max_length=110)\n', (7691, 7707), False, 'from django.db import migrations, models\n'), ((7742, 7846), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'help_text': '"""Write a brief description of the analysis"""', 'max_length': '(500)'}), "(blank=True, help_text=\n 'Write a brief description of the analysis', max_length=500)\n", (7758, 7846), False, 'from django.db import migrations, models\n'), ((7878, 7917), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (7898, 7917), False, 'from django.db import migrations, models\n'), ((8070, 8634), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won\'t fit into the final window will be\n discarded."""', 'null': '(True)'}), '(blank=True, default=None, help_text=\n """Leave window size blank to not use windows. Window parameter\n is ignored when dealing with precomputed distance matrix. Always check\n the dimensions of the dataset your are operating on and plan your windows\n accordingly; eventual data that won\'t fit into the final window will be\n discarded."""\n , null=True)\n', (8097, 8634), False, 'from django.db import migrations, models\n'), ((8662, 8955), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'default': '(0)', 'help_text': '"""How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size."""'}), '(default=0, help_text=\n """How many columns of overlap to have in\n consequent windows, if windows are being used. It must be at most 1\n less than window size."""\n )\n', (8689, 8955), False, 'from django.db import migrations, models\n'), ((8989, 9809), 'django.db.models.CharField', 'models.CharField', ([], {'blank': '(True)', 'choices': "[('braycurtis', 'Braycurtis'), ('canberra', 'Canberra'), ('chebyshev',\n 'Chebyshev'), ('cityblock', 'City block'), ('correlation',\n 'Correlation'), ('cosine', 'Cosine'), ('dice', 'Dice'), ('euclidean',\n 'Euclidean'), ('hamming', 'Hamming'), ('jaccard', 'Jaccard'), (\n 'jensenshannon', '<NAME>'), ('kulsinski', 'Kulsinski'), ('mahalanobis',\n 'Mahalonobis'), ('matching', 'Matching'), ('minkowski', 'Minkowski'), (\n 'rogerstanimoto', 'Rogers-Tanimoto'), ('russellrao', '<NAME>'), (\n 'seuclidean', 'Seuclidean'), ('sokalmichener', 'Sojal-Michener'), (\n 'sokalsneath', 'Sokal-Sneath'), ('sqeuclidean', 'Sqeuclidean'), ('yule',\n 'Yule')]", 'help_text': '"""If not using a precomputed matrix, choose the distance metric to use on the dataset."""', 'max_length': '(20)'}), "(blank=True, choices=[('braycurtis', 'Braycurtis'), (\n 'canberra', 'Canberra'), ('chebyshev', 'Chebyshev'), ('cityblock',\n 'City block'), ('correlation', 'Correlation'), ('cosine', 'Cosine'), (\n 'dice', 'Dice'), ('euclidean', 'Euclidean'), ('hamming', 'Hamming'), (\n 'jaccard', 'Jaccard'), ('jensenshannon', '<NAME>'), ('kulsinski',\n 'Kulsinski'), ('mahalanobis', 'Mahalonobis'), ('matching', 'Matching'),\n ('minkowski', 'Minkowski'), ('rogerstanimoto', 'Rogers-Tanimoto'), (\n 'russellrao', '<NAME>'), ('seuclidean', 'Seuclidean'), ('sokalmichener',\n 'Sojal-Michener'), ('sokalsneath', 'Sokal-Sneath'), ('sqeuclidean',\n 'Sqeuclidean'), ('yule', 'Yule')], help_text=\n 'If not using a precomputed matrix, choose the distance metric to use on the dataset.'\n , max_length=20)\n", (9005, 9809), False, 'from django.db import migrations, models\n'), ((9793, 10103), 'django.db.models.CharField', 'models.CharField', ([], {'choices': "[('sum', 'Sum'), ('mean', 'Mean'), ('median', 'Median'), ('max', 'Max'), (\n 'min', 'Min'), ('std', 'Std'), ('dist_mean', 'Dist_mean'), ('l2norm',\n 'L2norm'), ('knn_distance_n', 'knn_distance_n')]", 'default': '"""sum"""', 'help_text': '"""Specify a projection/lens type."""', 'max_length': '(50)'}), "(choices=[('sum', 'Sum'), ('mean', 'Mean'), ('median',\n 'Median'), ('max', 'Max'), ('min', 'Min'), ('std', 'Std'), ('dist_mean',\n 'Dist_mean'), ('l2norm', 'L2norm'), ('knn_distance_n', 'knn_distance_n'\n )], default='sum', help_text='Specify a projection/lens type.',\n max_length=50)\n", (9809, 10103), False, 'from django.db import migrations, models\n'), ((10121, 10230), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'help_text': '"""Specify the value of n in knn_distance_n"""', 'null': '(True)'}), "(blank=True, help_text=\n 'Specify the value of n in knn_distance_n', null=True)\n", (10148, 10230), False, 'from django.db import migrations, models\n'), ((10255, 10580), 'django.db.models.CharField', 'models.CharField', ([], {'choices': "[('None', 'None'), ('MinMaxScaler', 'MinMaxScaler'), ('MaxAbsScaler',\n 'MaxAbsScaler'), ('RobustScaler', 'RobustScaler'), ('StandardScaler',\n 'StandardScaler')]", 'default': '"""MinMaxScaler"""', 'help_text': '"""Scaler of the data applied after mapping. Use None for no scaling."""', 'max_length': '(50)'}), "(choices=[('None', 'None'), ('MinMaxScaler', 'MinMaxScaler'\n ), ('MaxAbsScaler', 'MaxAbsScaler'), ('RobustScaler', 'RobustScaler'),\n ('StandardScaler', 'StandardScaler')], default='MinMaxScaler',\n help_text=\n 'Scaler of the data applied after mapping. Use None for no scaling.',\n max_length=50)\n", (10271, 10580), False, 'from django.db import migrations, models\n'), ((10599, 10812), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)', 'help_text': '"""If ticked, clustering is run on the original data,\n else it will be run on the lower dimensional projection."""'}), '(default=False, help_text=\n """If ticked, clustering is run on the original data,\n else it will be run on the lower dimensional projection."""\n )\n', (10618, 10812), False, 'from django.db import migrations, models\n'), ((10832, 11302), 'django.db.models.CharField', 'models.CharField', ([], {'choices': "[('k-means', 'K-Means'), ('affinity_propagation', 'Affinity propagation'),\n ('mean-shift', 'Mean-shift'), ('spectral_clustering',\n 'Spectral clustering'), ('agglomerative_clustering', 'StandardScaler'),\n ('DBSCAN(min_samples=1)', 'DBSCAN(min_samples=1)'), ('DBSCAN', 'DBSCAN'\n ), ('gaussian_mixtures', 'Gaussian mixtures'), ('birch', 'Birch')]", 'default': '"""DBSCAN"""', 'help_text': '"""Select the clustering algorithm."""', 'max_length': '(50)'}), "(choices=[('k-means', 'K-Means'), ('affinity_propagation',\n 'Affinity propagation'), ('mean-shift', 'Mean-shift'), (\n 'spectral_clustering', 'Spectral clustering'), (\n 'agglomerative_clustering', 'StandardScaler'), ('DBSCAN(min_samples=1)',\n 'DBSCAN(min_samples=1)'), ('DBSCAN', 'DBSCAN'), ('gaussian_mixtures',\n 'Gaussian mixtures'), ('birch', 'Birch')], default='DBSCAN', help_text=\n 'Select the clustering algorithm.', max_length=50)\n", (10848, 11302), False, 'from django.db import migrations, models\n'), ((11312, 11498), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'default': '(10)', 'help_text': '"""Number of hypercubes along each dimension.\n Sometimes referred to as resolution."""'}), '(default=10, help_text=\n """Number of hypercubes along each dimension.\n Sometimes referred to as resolution."""\n )\n', (11339, 11498), False, 'from django.db import migrations, models\n'), ((11527, 11703), 'django.db.models.FloatField', 'models.FloatField', ([], {'default': '(0.5)', 'help_text': '"""Amount of overlap between adjacent cubes calculated\n only along 1 dimension."""'}), '(default=0.5, help_text=\n """Amount of overlap between adjacent cubes calculated\n only along 1 dimension."""\n )\n', (11544, 11703), False, 'from django.db import migrations, models\n'), ((11742, 12136), 'django.db.models.IntegerField', 'models.IntegerField', ([], {'default': '(1)', 'help_text': '"""Minimum intersection considered when\n computing the nerve. An edge will be created only when the\n intersection between two nodes is greater than or equal to\n min_intersection"""'}), '(default=1, help_text=\n """Minimum intersection considered when\n computing the nerve. An edge will be created only when the\n intersection between two nodes is greater than or equal to\n min_intersection"""\n )\n', (11761, 12136), False, 'from django.db import migrations, models\n'), ((12160, 12831), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)', 'help_text': '"""Tell Mapper whether the data that you are clustering on\n is a precomputed distance matrix. If set to True, the assumption is that you are\n also telling your clusterer that metric=’precomputed’ (which is an argument for\n DBSCAN among others), which will then cause the clusterer to expect a square\n distance matrix for each hypercube. precomputed=True will give a square matrix\n to the clusterer to fit on for each hypercube."""'}), '(default=False, help_text=\n """Tell Mapper whether the data that you are clustering on\n is a precomputed distance matrix. If set to True, the assumption is that you are\n also telling your clusterer that metric=’precomputed’ (which is an argument for\n DBSCAN among others), which will then cause the clusterer to expect a square\n distance matrix for each hypercube. precomputed=True will give a square matrix\n to the clusterer to fit on for each hypercube."""\n )\n', (12179, 12831), False, 'from django.db import migrations, models\n'), ((12868, 13175), 'django.db.models.BooleanField', 'models.BooleanField', ([], {'default': '(False)', 'help_text': '"""Removes duplicate nodes before edges are\n determined. A node is considered to be duplicate if it has exactly\n the same set of points as another node."""'}), '(default=False, help_text=\n """Removes duplicate nodes before edges are\n determined. A node is considered to be duplicate if it has exactly\n the same set of points as another node."""\n )\n', (12887, 13175), False, 'from django.db import migrations, models\n'), ((13194, 13389), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'blank': '(True)', 'default': 'None', 'help_text': '"""Select the source dataset from the loaded datasets"""', 'null': '(True)', 'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""datasets.Dataset"""'}), "(blank=True, default=None, help_text=\n 'Select the source dataset from the loaded datasets', null=True,\n on_delete=django.db.models.deletion.CASCADE, to='datasets.Dataset')\n", (13211, 13389), False, 'from django.db import migrations, models\n'), ((13412, 13503), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'to': '"""research.Research"""'}), "(on_delete=django.db.models.deletion.CASCADE, to=\n 'research.Research')\n", (13429, 13503), False, 'from django.db import migrations, models\n'), ((13836, 13929), 'django.db.models.AutoField', 'models.AutoField', ([], {'auto_created': '(True)', 'primary_key': '(True)', 'serialize': '(False)', 'verbose_name': '"""ID"""'}), "(auto_created=True, primary_key=True, serialize=False,\n verbose_name='ID')\n", (13852, 13929), False, 'from django.db import migrations, models\n'), ((13953, 13982), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {}), '()\n', (13980, 13982), False, 'from django.db import migrations, models\n'), ((14010, 14042), 'django.db.models.SlugField', 'models.SlugField', ([], {'max_length': '(150)'}), '(max_length=150)\n', (14026, 14042), False, 'from django.db import migrations, models\n'), ((14079, 14118), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (14099, 14118), False, 'from django.db import migrations, models\n'), ((14147, 14197), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (14174, 14197), False, 'from django.db import migrations, models\n'), ((14224, 14274), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (14251, 14274), False, 'from django.db import migrations, models\n'), ((14303, 14342), 'django.db.models.TextField', 'models.TextField', ([], {'blank': '(True)', 'null': '(True)'}), '(blank=True, null=True)\n', (14319, 14342), False, 'from django.db import migrations, models\n'), ((14374, 14524), 'django.db.models.ForeignKey', 'models.ForeignKey', ([], {'on_delete': 'django.db.models.deletion.CASCADE', 'related_name': '"""windows"""', 'related_query_name': '"""window"""', 'to': '"""analysis.MapperAnalysis"""'}), "(on_delete=django.db.models.deletion.CASCADE, related_name\n ='windows', related_query_name='window', to='analysis.MapperAnalysis')\n", (14391, 14524), False, 'from django.db import migrations, models\n')]
import FWCore.ParameterSet.Config as cms def reEmulateLayer2(process): process.load('L1Trigger/L1TCalorimeter/simCaloStage2Digis_cfi') process.load('L1Trigger.L1TCalorimeter.caloStage2Params_2017_v1_7_excl30_cfi') process.simCaloStage2Digis.towerToken = cms.InputTag("caloStage2Digis", "CaloTower") process.caloLayer2 = cms.Path(process.simCaloStage2Digis) process.schedule.append(process.caloLayer2) return process def hwEmulCompHistos(process): process.TFileService = cms.Service("TFileService", fileName = cms.string("l1tCalo_2016_simHistos.root"), closeFileFast = cms.untracked.bool(True) ) # histograms process.load('L1Trigger.L1TCalorimeter.l1tStage2CaloAnalyzer_cfi') process.l1tStage2CaloAnalyzer.doEvtDisp = False process.l1tStage2CaloAnalyzer.mpBx = 0 process.l1tStage2CaloAnalyzer.dmxBx = 0 process.l1tStage2CaloAnalyzer.allBx = False process.l1tStage2CaloAnalyzer.towerToken = cms.InputTag("simCaloStage2Digis", "MP") process.l1tStage2CaloAnalyzer.clusterToken = cms.InputTag("None") process.l1tStage2CaloAnalyzer.mpEGToken = cms.InputTag("simCaloStage2Digis", "MP") process.l1tStage2CaloAnalyzer.mpTauToken = cms.InputTag("simCaloStage2Digis", "MP") process.l1tStage2CaloAnalyzer.mpJetToken = cms.InputTag("simCaloStage2Digis", "MP") process.l1tStage2CaloAnalyzer.mpEtSumToken = cms.InputTag("simCaloStage2Digis", "MP") process.l1tStage2CaloAnalyzer.egToken = cms.InputTag("simCaloStage2Digis") process.l1tStage2CaloAnalyzer.tauToken = cms.InputTag("simCaloStage2Digis") process.l1tStage2CaloAnalyzer.jetToken = cms.InputTag("simCaloStage2Digis") process.l1tStage2CaloAnalyzer.etSumToken = cms.InputTag("simCaloStage2Digis") import L1Trigger.L1TCalorimeter.l1tStage2CaloAnalyzer_cfi process.l1tCaloStage2HwHistos = L1Trigger.L1TCalorimeter.l1tStage2CaloAnalyzer_cfi.l1tStage2CaloAnalyzer.clone() process.l1tCaloStage2HwHistos.doEvtDisp = False process.l1tCaloStage2HwHistos.mpBx = 0 process.l1tCaloStage2HwHistos.dmxBx = 0 process.l1tCaloStage2HwHistos.allBx = False process.l1tCaloStage2HwHistos.towerToken = cms.InputTag("caloStage2Digis", "CaloTower") process.l1tCaloStage2HwHistos.clusterToken = cms.InputTag("None") process.l1tCaloStage2HwHistos.mpEGToken = cms.InputTag("caloStage2Digis", "MP") process.l1tCaloStage2HwHistos.mpTauToken = cms.InputTag("caloStage2Digis","MP") process.l1tCaloStage2HwHistos.mpJetToken = cms.InputTag("caloStage2Digis", "MP") process.l1tCaloStage2HwHistos.mpEtSumToken = cms.InputTag("caloStage2Digis", "MP") process.l1tCaloStage2HwHistos.egToken = cms.InputTag("caloStage2Digis", "EGamma") process.l1tCaloStage2HwHistos.tauToken = cms.InputTag("caloStage2Digis", "Tau") process.l1tCaloStage2HwHistos.jetToken = cms.InputTag("caloStage2Digis", "Jet") process.l1tCaloStage2HwHistos.etSumToken = cms.InputTag("caloStage2Digis", "EtSum") process.hwEmulHistos = cms.Path( process.l1tStage2CaloAnalyzer +process.l1tCaloStage2HwHistos ) process.schedule.append(process.hwEmulHistos) return process def reEmulateLayer2ValHistos(process): process.load('EventFilter.L1TRawToDigi.caloTowersFilter_cfi') reEmulateLayer2(process) hwEmulCompHistos(process) #process.l1ntupleraw.insert(0,process.caloTowersFilter) #process.l1ntuplesim.insert(0,process.caloTowersFilter) process.caloLayer2.insert(0,process.caloTowersFilter) process.hwEmulHistos.insert(0,process.caloTowersFilter) return process
[ "FWCore.ParameterSet.Config.Path", "FWCore.ParameterSet.Config.string", "FWCore.ParameterSet.Config.untracked.bool", "FWCore.ParameterSet.Config.InputTag" ]
[((270, 314), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""CaloTower"""'], {}), "('caloStage2Digis', 'CaloTower')\n", (282, 314), True, 'import FWCore.ParameterSet.Config as cms\n'), ((345, 381), 'FWCore.ParameterSet.Config.Path', 'cms.Path', (['process.simCaloStage2Digis'], {}), '(process.simCaloStage2Digis)\n', (353, 381), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1088, 1128), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""', '"""MP"""'], {}), "('simCaloStage2Digis', 'MP')\n", (1100, 1128), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1178, 1198), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""None"""'], {}), "('None')\n", (1190, 1198), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1245, 1285), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""', '"""MP"""'], {}), "('simCaloStage2Digis', 'MP')\n", (1257, 1285), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1333, 1373), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""', '"""MP"""'], {}), "('simCaloStage2Digis', 'MP')\n", (1345, 1373), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1421, 1461), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""', '"""MP"""'], {}), "('simCaloStage2Digis', 'MP')\n", (1433, 1461), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1511, 1551), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""', '"""MP"""'], {}), "('simCaloStage2Digis', 'MP')\n", (1523, 1551), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1596, 1630), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""'], {}), "('simCaloStage2Digis')\n", (1608, 1630), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1676, 1710), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""'], {}), "('simCaloStage2Digis')\n", (1688, 1710), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1756, 1790), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""'], {}), "('simCaloStage2Digis')\n", (1768, 1790), True, 'import FWCore.ParameterSet.Config as cms\n'), ((1838, 1872), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""simCaloStage2Digis"""'], {}), "('simCaloStage2Digis')\n", (1850, 1872), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2292, 2336), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""CaloTower"""'], {}), "('caloStage2Digis', 'CaloTower')\n", (2304, 2336), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2386, 2406), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""None"""'], {}), "('None')\n", (2398, 2406), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2453, 2490), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""MP"""'], {}), "('caloStage2Digis', 'MP')\n", (2465, 2490), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2538, 2575), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""MP"""'], {}), "('caloStage2Digis', 'MP')\n", (2550, 2575), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2622, 2659), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""MP"""'], {}), "('caloStage2Digis', 'MP')\n", (2634, 2659), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2709, 2746), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""MP"""'], {}), "('caloStage2Digis', 'MP')\n", (2721, 2746), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2791, 2832), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""EGamma"""'], {}), "('caloStage2Digis', 'EGamma')\n", (2803, 2832), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2878, 2916), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""Tau"""'], {}), "('caloStage2Digis', 'Tau')\n", (2890, 2916), True, 'import FWCore.ParameterSet.Config as cms\n'), ((2962, 3000), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""Jet"""'], {}), "('caloStage2Digis', 'Jet')\n", (2974, 3000), True, 'import FWCore.ParameterSet.Config as cms\n'), ((3048, 3088), 'FWCore.ParameterSet.Config.InputTag', 'cms.InputTag', (['"""caloStage2Digis"""', '"""EtSum"""'], {}), "('caloStage2Digis', 'EtSum')\n", (3060, 3088), True, 'import FWCore.ParameterSet.Config as cms\n'), ((3117, 3188), 'FWCore.ParameterSet.Config.Path', 'cms.Path', (['(process.l1tStage2CaloAnalyzer + process.l1tCaloStage2HwHistos)'], {}), '(process.l1tStage2CaloAnalyzer + process.l1tCaloStage2HwHistos)\n', (3125, 3188), True, 'import FWCore.ParameterSet.Config as cms\n'), ((597, 638), 'FWCore.ParameterSet.Config.string', 'cms.string', (['"""l1tCalo_2016_simHistos.root"""'], {}), "('l1tCalo_2016_simHistos.root')\n", (607, 638), True, 'import FWCore.ParameterSet.Config as cms\n'), ((695, 719), 'FWCore.ParameterSet.Config.untracked.bool', 'cms.untracked.bool', (['(True)'], {}), '(True)\n', (713, 719), True, 'import FWCore.ParameterSet.Config as cms\n')]
""" ethereum.py ethereum.py contains an EthereumClient class that provides functions for interacting with the Coverage.sol solidity contract on an Ethereum blockchain network. """ import asyncio import datetime import json import logging import os from ethereum.clients.nats import get_nats_client from ethereum.config import get_settings, nats_eligibility_subject from ethereum.exceptions import EthereumNetworkConnectionError from hexbytes import HexBytes from typing import Optional, Any, List from web3 import Web3 logger = logging.getLogger(__name__) # client instance eth_client = None class EthereumClient: """ Ethereum client for LFH that utilizes the Web3 library for interacting with an Ethereum blockchain network. """ def __init__(self, **qwargs): logger.debug("Initializing EthereumClient") self.eth_network_uri = qwargs["eth_network_uri"] logger.debug("Initializing Web3") self.client: Optional[Web3] = Web3(Web3.HTTPProvider(self.eth_network_uri)) self.from_acct = {"from": self.client.eth.accounts[0]} if (self.client and self.client.isConnected()): logger.info(f"Connected to the Ethereum network at: {self.eth_network_uri}") self.contract = self.client.eth.contract(address=qwargs["contract_address"], abi=qwargs["contract_abi"]) event_filter = self.contract.events.EligibilityResult.createFilter(fromBlock="latest") self.cancelled = False contract_event_loop = asyncio.get_event_loop() contract_event_loop.create_task(self.event_loop(event_filter, qwargs["event_poll_interval"])) logger.info(f"Connected to the contract at: {qwargs['contract_address']}") else: error_msg = f"Failed to connect to the Ethereum network at: {self.eth_network_uri}" logger.error(error_msg) raise EthereumNetworkConnectionError(error_msg) def add_coverage_resource(self, path: str, fhir_json: Any, payor_ref: str, subscriber_ref: str, coverage_start: int, coverage_end: int): """ Send a Coverage FHIR resource to the Coverage.sol contract. :param path: FHIR path of the resource, e.g. /Coverage/001 :param fhir_json: The string representation of the FHIR resource :param payor_ref: coverage.payor[0].reference :param subscriber_ref: coverage.subscriber.reference :param coverage_start: coverage.period.start converted to a timestamp :param coverage_end: coverage.period.end converted to a timestamp :return: The hash of the submitted transaction or None """ if not self.client.isConnected(): error = f"Not connected to the Ethereum network" logger.error(error) return {"error": error} try: tx_hash = self.contract.functions.add_coverage_resource(path, json.dumps(fhir_json), payor_ref, subscriber_ref, coverage_start, coverage_end).transact(self.from_acct) tx_receipt = self.client.eth.waitForTransactionReceipt(tx_hash) receipt_dict = dict(tx_receipt) hash_str = receipt_dict["transactionHash"].hex() logger.info(f"tx hash: {hash_str}") return {"result": hash_str} except Exception as ex: error = f"Transaction error {ex}" logger.error(error) return {"error": error} def check_eligibility(self, path: str, fhir_json: Any, insurer_ref: str, patient_ref: str, coverage_ref: str, coverage_date: int): """ Send a CoverageEligibilityRequest FHIR resource to the Coverage.sol contract. :param path: FHIR path of the resource, e.g. /CoverageEligibilityRequest/001 :param fhir_json: The string representation of the FHIR resource :param insurer_ref: coverageeligibilityrequest.insurer.reference :param patient_ref: coverageeligibilityrequest.patient.reference :param coverage_ref: coverageeligibilityrequest.insurance[0].coverage :param coverage_date: coverageeligibilityrequest.created converted to a timestamp :return: The hash of the submitted transaction or None """ if not self.client.isConnected(): error = f"Not connected to the Ethereum network" logger.error(error) return {"error": error} try: tx_hash = self.contract.functions.check_eligibility(path, json.dumps(fhir_json), insurer_ref, patient_ref, coverage_ref, coverage_date).transact(self.from_acct) tx_receipt = self.client.eth.waitForTransactionReceipt(tx_hash) receipt_dict = dict(tx_receipt) hash_str = receipt_dict["transactionHash"].hex() logger.info(f"tx hash: {hash_str}") return {"result": hash_str} except Exception as ex: error = f"Transaction error {ex}" logger.error(error) return {"error": error} def add_fhir_resource(self, fhir_type: str, path: str, fhir_json: Any): """ Send a Patient or Organization FHIR resource to the Coverage.sol contract. :param fhir_type: FHIR type of the resource, e.g. Patient :param path: FHIR path of the resource, e.g. /Patient/001 :param fhir_json: The string representation of the FHIR resource :return: The hash of the submitted transaction or None """ if not self.client.isConnected(): error = f"Not connected to the Ethereum network" logger.error(error) return {"error": error} try: tx_hash = self.contract.functions.add_fhir_resource(fhir_type, path, json.dumps(fhir_json)).transact(self.from_acct) tx_receipt = self.client.eth.waitForTransactionReceipt(tx_hash) receipt_dict = dict(tx_receipt) hash_str = receipt_dict["transactionHash"].hex() logger.info(f"tx hash: {hash_str}") return {"result": hash_str} except Exception as ex: error = f"Transaction error {ex}" logger.error(error) return {"error": error} def close(self): self.cancelled = True async def event_loop(self, event_filter, poll_interval: int): while not self.cancelled: for event in event_filter.get_new_entries(): await self.handle_event(json.loads(Web3.toJSON(event))) await asyncio.sleep(poll_interval) async def handle_event(self, event: dict): """ Send a FHIR CoverageEligibilityResponse based on the eligibility decision from the contract. :param event: The JSON contract event containing the eligibility decision and supporting info. """ logger.trace(f"Received contract event: {event}") path: List[str] = event["args"]["path"].split("/") request_id: str = path[1] result: bool = event["args"]["result"] disposition: str = "Policy is currently in effect." if not result: disposition = "Policy is not in effect." today: str = datetime.date.today().isoformat() message: Any = { "resourceType": "CoverageEligibilityResponse", "id": request_id, "text": { "status": "generated", "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">A human-readable rendering of the CoverageEligibilityResponse.</div>" }, "identifier": [ { "system": "http://localhost:5000/fhir/coverageeligibilityresponse/" + request_id, "value": request_id } ], "status": "active", "purpose": [ "validation" ], "patient": { "reference": event["args"]["patient_ref"] }, "created": today, "request": { "reference": "http://www.BenefitsInc.com/fhir/coverageeligibilityrequest/" + request_id }, "outcome": "complete", "disposition": disposition, "insurer": { "reference": event["args"]["insurer_ref"] }, "insurance": [ { "coverage": { "reference": event["args"]["coverage_ref"] }, "inforce": result } ] }; nats_client = await get_nats_client() msg_str = json.dumps(message) logger.info(f"CoverageEligibilityResponse: {msg_str}") await nats_client.publish(nats_eligibility_subject, bytearray(msg_str, "utf-8")) logger.trace("Sent CoverageEligibilityResponse via NATS") def get_ethereum_client() -> Optional[EthereumClient]: """ :return: a connected EthereumClient instance """ global eth_client if not eth_client: settings = get_settings() # load ABI file abi_file: str = os.path.join(settings.ethereum_config_directory, settings.ethereum_contract_abi) contract_info = json.load(open(abi_file)) eth_client = EthereumClient( eth_network_uri=settings.ethereum_network_uri, contract_address=settings.ethereum_contract_address, contract_abi=contract_info["abi"], event_poll_interval=settings.ethereum_event_poll_seconds ) return eth_client def stop_ethereum_client(): client = get_ethereum_client() client.close() class HexJsonEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, HexBytes): return obj.hex() return super().default(obj)
[ "logging.getLogger", "json.dumps", "os.path.join", "web3.Web3.toJSON", "asyncio.sleep", "ethereum.clients.nats.get_nats_client", "datetime.date.today", "asyncio.get_event_loop", "ethereum.exceptions.EthereumNetworkConnectionError", "ethereum.config.get_settings", "web3.Web3.HTTPProvider" ]
[((530, 557), 'logging.getLogger', 'logging.getLogger', (['__name__'], {}), '(__name__)\n', (547, 557), False, 'import logging\n'), ((9462, 9481), 'json.dumps', 'json.dumps', (['message'], {}), '(message)\n', (9472, 9481), False, 'import json\n'), ((9886, 9900), 'ethereum.config.get_settings', 'get_settings', ([], {}), '()\n', (9898, 9900), False, 'from ethereum.config import get_settings, nats_eligibility_subject\n'), ((9950, 10035), 'os.path.join', 'os.path.join', (['settings.ethereum_config_directory', 'settings.ethereum_contract_abi'], {}), '(settings.ethereum_config_directory, settings.ethereum_contract_abi\n )\n', (9962, 10035), False, 'import os\n'), ((979, 1018), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', (['self.eth_network_uri'], {}), '(self.eth_network_uri)\n', (996, 1018), False, 'from web3 import Web3\n'), ((1567, 1591), 'asyncio.get_event_loop', 'asyncio.get_event_loop', ([], {}), '()\n', (1589, 1591), False, 'import asyncio\n'), ((1949, 1990), 'ethereum.exceptions.EthereumNetworkConnectionError', 'EthereumNetworkConnectionError', (['error_msg'], {}), '(error_msg)\n', (1979, 1990), False, 'from ethereum.exceptions import EthereumNetworkConnectionError\n'), ((9426, 9443), 'ethereum.clients.nats.get_nats_client', 'get_nats_client', ([], {}), '()\n', (9441, 9443), False, 'from ethereum.clients.nats import get_nats_client\n'), ((7356, 7384), 'asyncio.sleep', 'asyncio.sleep', (['poll_interval'], {}), '(poll_interval)\n', (7369, 7384), False, 'import asyncio\n'), ((8017, 8038), 'datetime.date.today', 'datetime.date.today', ([], {}), '()\n', (8036, 8038), False, 'import datetime\n'), ((3053, 3074), 'json.dumps', 'json.dumps', (['fhir_json'], {}), '(fhir_json)\n', (3063, 3074), False, 'import json\n'), ((4972, 4993), 'json.dumps', 'json.dumps', (['fhir_json'], {}), '(fhir_json)\n', (4982, 4993), False, 'import json\n'), ((6593, 6614), 'json.dumps', 'json.dumps', (['fhir_json'], {}), '(fhir_json)\n', (6603, 6614), False, 'import json\n'), ((7317, 7335), 'web3.Web3.toJSON', 'Web3.toJSON', (['event'], {}), '(event)\n', (7328, 7335), False, 'from web3 import Web3\n')]
# -*- coding: utf-8 -*- from django.shortcuts import resolve_url from django.template.loader import render_to_string from django_jinja import library from jinja2 import contextfunction @contextfunction @library.global_function def breadcrumb(context, contents, *args, **kwargs): class_name = kwargs.pop('class', False) url = kwargs.pop('url', False) if url is not False: url = resolve_url(url, *args, **kwargs) breadcrumb_context = { 'contents': contents, 'url': url, 'class': class_name } context['breadcrumbs'].append(breadcrumb_context) return '' @library.global_function def render_breadcrumbs(breadcrumbs): breadcrumbs.reverse() ctx = {'breadcrumbs': breadcrumbs} return render_to_string('breadcrumbs/breadcrumbs.html', ctx)
[ "django.shortcuts.resolve_url", "django.template.loader.render_to_string" ]
[((699, 752), 'django.template.loader.render_to_string', 'render_to_string', (['"""breadcrumbs/breadcrumbs.html"""', 'ctx'], {}), "('breadcrumbs/breadcrumbs.html', ctx)\n", (715, 752), False, 'from django.template.loader import render_to_string\n'), ((384, 417), 'django.shortcuts.resolve_url', 'resolve_url', (['url', '*args'], {}), '(url, *args, **kwargs)\n', (395, 417), False, 'from django.shortcuts import resolve_url\n')]
import torchvision import torch import torch.nn as nn import torch.nn.functional as F class Vgg_Deeplab(nn.Module): def __init__(self,*args, **kwargs): super(Vgg_Deeplab, self).__init__() vgg16 = torchvision.models.vgg16() layers = [] layers.append(nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.MaxPool2d(3, stride=2, padding=1)) layers.append(nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.MaxPool2d(3, stride=2, padding=1)) layers.append(nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.MaxPool2d(3, stride=2, padding=1)) layers.append(nn.Conv2d(256, 512, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.MaxPool2d(3, stride=1, padding=1)) layers.append(nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)) layers.append(nn.ReLU(inplace=True)) layers.append(nn.MaxPool2d(3, stride=1, padding=1)) self.features = nn.Sequential(*layers) classifier = [] classifier.append(nn.AvgPool2d(3, stride=1, padding=1)) classifier.append(nn.Conv2d(512, 1024, kernel_size=3, stride=1, padding=12, dilation=12)) classifier.append(nn.ReLU(inplace=True)) classifier.append(nn.Dropout(p=0.5)) self.classifier = nn.Sequential(*classifier) self.init_weights() def forward(self, x): x = self.features(x) x = self.classifier(x) return x def init_weights(self): vgg = torchvision.models.vgg16(pretrained=True) state_vgg = vgg.features.state_dict() self.features.load_state_dict(state_vgg) for ly in self.classifier.children(): if isinstance(ly, nn.Conv2d): nn.init.kaiming_normal_(ly.weight, a=1) nn.init.constant_(ly.bias, 0) def get_1x_lr_params(self): """ This generator returns all the parameters for the last layer of the net, which does the classification of pixel into classes """ # b = [] # # b.append(self.conv1) # b.append(self.bn1) # b.append(self.layer1) # b.append(self.layer2) # b.append(self.layer3) # b.append(self.layer4) for i in self.features: #for j in self.features[i].modules(): jj = 0 for k in i.parameters(): jj += 1 if k.requires_grad: yield k def optim_parameters_1x(self, args): return [{"params": self.get_1x_lr_params(), "lr": 1 * args.learning_rate}] def get_10x_lr_params(self): """ This generator returns all the parameters for the last layer of the net, which does the classification of pixel into classes """ # b = [] # b.append(self.layer.parameters()) for i in self.classifier: #for j in self.classifier[i].modules(): jj = 0 for k in i.parameters(): jj += 1 if k.requires_grad: yield k def optim_parameters_10x(self, args): return [{"params": self.get_10x_lr_params(), "lr": 10 * args.learning_rate}] if __name__ == "__main__": net = Vgg_Deeplab(3, 10) in_ten = torch.randn(1, 3, 224, 224) out = net(in_ten) print(net) print(out.size()) in_ten = torch.randn(1, 3, 64, 64) mod = nn.Conv2d(3, 512, kernel_size=3, stride=1, padding=2, dilation=2) out = mod(in_ten) print(out.shape)
[ "torch.nn.ReLU", "torch.nn.Dropout", "torch.nn.init.constant_", "torch.nn.Sequential", "torch.nn.init.kaiming_normal_", "torch.nn.Conv2d", "torch.nn.MaxPool2d", "torch.nn.AvgPool2d", "torchvision.models.vgg16", "torch.randn" ]
[((5212, 5239), 'torch.randn', 'torch.randn', (['(1)', '(3)', '(224)', '(224)'], {}), '(1, 3, 224, 224)\n', (5223, 5239), False, 'import torch\n'), ((5313, 5338), 'torch.randn', 'torch.randn', (['(1)', '(3)', '(64)', '(64)'], {}), '(1, 3, 64, 64)\n', (5324, 5338), False, 'import torch\n'), ((5349, 5414), 'torch.nn.Conv2d', 'nn.Conv2d', (['(3)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(2)', 'dilation': '(2)'}), '(3, 512, kernel_size=3, stride=1, padding=2, dilation=2)\n', (5358, 5414), True, 'import torch.nn as nn\n'), ((218, 244), 'torchvision.models.vgg16', 'torchvision.models.vgg16', ([], {}), '()\n', (242, 244), False, 'import torchvision\n'), ((2716, 2738), 'torch.nn.Sequential', 'nn.Sequential', (['*layers'], {}), '(*layers)\n', (2729, 2738), True, 'import torch.nn as nn\n'), ((3226, 3252), 'torch.nn.Sequential', 'nn.Sequential', (['*classifier'], {}), '(*classifier)\n', (3239, 3252), True, 'import torch.nn as nn\n'), ((3429, 3470), 'torchvision.models.vgg16', 'torchvision.models.vgg16', ([], {'pretrained': '(True)'}), '(pretrained=True)\n', (3453, 3470), False, 'import torchvision\n'), ((288, 340), 'torch.nn.Conv2d', 'nn.Conv2d', (['(3)', '(64)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(3, 64, kernel_size=3, stride=1, padding=1)\n', (297, 340), True, 'import torch.nn as nn\n'), ((364, 385), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (371, 385), True, 'import torch.nn as nn\n'), ((409, 462), 'torch.nn.Conv2d', 'nn.Conv2d', (['(64)', '(64)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(64, 64, kernel_size=3, stride=1, padding=1)\n', (418, 462), True, 'import torch.nn as nn\n'), ((486, 507), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (493, 507), True, 'import torch.nn as nn\n'), ((531, 567), 'torch.nn.MaxPool2d', 'nn.MaxPool2d', (['(3)'], {'stride': '(2)', 'padding': '(1)'}), '(3, stride=2, padding=1)\n', (543, 567), True, 'import torch.nn as nn\n'), ((592, 646), 'torch.nn.Conv2d', 'nn.Conv2d', (['(64)', '(128)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(64, 128, kernel_size=3, stride=1, padding=1)\n', (601, 646), True, 'import torch.nn as nn\n'), ((670, 691), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (677, 691), True, 'import torch.nn as nn\n'), ((715, 770), 'torch.nn.Conv2d', 'nn.Conv2d', (['(128)', '(128)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(128, 128, kernel_size=3, stride=1, padding=1)\n', (724, 770), True, 'import torch.nn as nn\n'), ((794, 815), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (801, 815), True, 'import torch.nn as nn\n'), ((839, 875), 'torch.nn.MaxPool2d', 'nn.MaxPool2d', (['(3)'], {'stride': '(2)', 'padding': '(1)'}), '(3, stride=2, padding=1)\n', (851, 875), True, 'import torch.nn as nn\n'), ((900, 955), 'torch.nn.Conv2d', 'nn.Conv2d', (['(128)', '(256)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(128, 256, kernel_size=3, stride=1, padding=1)\n', (909, 955), True, 'import torch.nn as nn\n'), ((979, 1000), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (986, 1000), True, 'import torch.nn as nn\n'), ((1024, 1079), 'torch.nn.Conv2d', 'nn.Conv2d', (['(256)', '(256)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(256, 256, kernel_size=3, stride=1, padding=1)\n', (1033, 1079), True, 'import torch.nn as nn\n'), ((1103, 1124), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (1110, 1124), True, 'import torch.nn as nn\n'), ((1148, 1203), 'torch.nn.Conv2d', 'nn.Conv2d', (['(256)', '(256)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(256, 256, kernel_size=3, stride=1, padding=1)\n', (1157, 1203), True, 'import torch.nn as nn\n'), ((1227, 1248), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (1234, 1248), True, 'import torch.nn as nn\n'), ((1272, 1308), 'torch.nn.MaxPool2d', 'nn.MaxPool2d', (['(3)'], {'stride': '(2)', 'padding': '(1)'}), '(3, stride=2, padding=1)\n', (1284, 1308), True, 'import torch.nn as nn\n'), ((1333, 1388), 'torch.nn.Conv2d', 'nn.Conv2d', (['(256)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(256, 512, kernel_size=3, stride=1, padding=1)\n', (1342, 1388), True, 'import torch.nn as nn\n'), ((1412, 1433), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (1419, 1433), True, 'import torch.nn as nn\n'), ((1457, 1512), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(512, 512, kernel_size=3, stride=1, padding=1)\n', (1466, 1512), True, 'import torch.nn as nn\n'), ((1536, 1557), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (1543, 1557), True, 'import torch.nn as nn\n'), ((1581, 1636), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(1)'}), '(512, 512, kernel_size=3, stride=1, padding=1)\n', (1590, 1636), True, 'import torch.nn as nn\n'), ((1660, 1681), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (1667, 1681), True, 'import torch.nn as nn\n'), ((1705, 1741), 'torch.nn.MaxPool2d', 'nn.MaxPool2d', (['(3)'], {'stride': '(1)', 'padding': '(1)'}), '(3, stride=1, padding=1)\n', (1717, 1741), True, 'import torch.nn as nn\n'), ((1766, 1833), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(2)', 'dilation': '(2)'}), '(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)\n', (1775, 1833), True, 'import torch.nn as nn\n'), ((2017, 2038), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (2024, 2038), True, 'import torch.nn as nn\n'), ((2062, 2129), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(2)', 'dilation': '(2)'}), '(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)\n', (2071, 2129), True, 'import torch.nn as nn\n'), ((2313, 2334), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (2320, 2334), True, 'import torch.nn as nn\n'), ((2358, 2425), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(512)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(2)', 'dilation': '(2)'}), '(512, 512, kernel_size=3, stride=1, padding=2, dilation=2)\n', (2367, 2425), True, 'import torch.nn as nn\n'), ((2609, 2630), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (2616, 2630), True, 'import torch.nn as nn\n'), ((2654, 2690), 'torch.nn.MaxPool2d', 'nn.MaxPool2d', (['(3)'], {'stride': '(1)', 'padding': '(1)'}), '(3, stride=1, padding=1)\n', (2666, 2690), True, 'import torch.nn as nn\n'), ((2790, 2826), 'torch.nn.AvgPool2d', 'nn.AvgPool2d', (['(3)'], {'stride': '(1)', 'padding': '(1)'}), '(3, stride=1, padding=1)\n', (2802, 2826), True, 'import torch.nn as nn\n'), ((2854, 2924), 'torch.nn.Conv2d', 'nn.Conv2d', (['(512)', '(1024)'], {'kernel_size': '(3)', 'stride': '(1)', 'padding': '(12)', 'dilation': '(12)'}), '(512, 1024, kernel_size=3, stride=1, padding=12, dilation=12)\n', (2863, 2924), True, 'import torch.nn as nn\n'), ((3132, 3153), 'torch.nn.ReLU', 'nn.ReLU', ([], {'inplace': '(True)'}), '(inplace=True)\n', (3139, 3153), True, 'import torch.nn as nn\n'), ((3181, 3198), 'torch.nn.Dropout', 'nn.Dropout', ([], {'p': '(0.5)'}), '(p=0.5)\n', (3191, 3198), True, 'import torch.nn as nn\n'), ((3671, 3710), 'torch.nn.init.kaiming_normal_', 'nn.init.kaiming_normal_', (['ly.weight'], {'a': '(1)'}), '(ly.weight, a=1)\n', (3694, 3710), True, 'import torch.nn as nn\n'), ((3727, 3756), 'torch.nn.init.constant_', 'nn.init.constant_', (['ly.bias', '(0)'], {}), '(ly.bias, 0)\n', (3744, 3756), True, 'import torch.nn as nn\n')]
# -*- coding: utf-8 -*- """ This module defines a connexion app object and configures the API endpoints based the swagger.yml configuration file. copyright: © 2019 by <NAME>. license: MIT, see LICENSE for more details. """ import connexion app = connexion.App(__name__, specification_dir="./") app.app.url_map.strict_slashes = False app.add_api("swagger.yml") if __name__ == "__main__": # FLASK_ENV=development & FLASK_DEBUG=1 w/ Docker don't seem to enable debug mode. app.run(debug=True)
[ "connexion.App" ]
[((250, 297), 'connexion.App', 'connexion.App', (['__name__'], {'specification_dir': '"""./"""'}), "(__name__, specification_dir='./')\n", (263, 297), False, 'import connexion\n')]
from django import forms from django.test import TestCase from template_forms import bs3 def startswith_a(value): if value.startswith('a'): return value raise forms.ValidationError('Value must start with "a".') def not_now(value): if value: raise forms.ValidationError('I cannot let you do that right now.') class StandardFieldTests(TestCase): class Form(bs3.BlockForm, forms.Form): field = forms.CharField(required=False, validators=[startswith_a], help_text='Example text.', ) def get_attrs(self, bf): return { 'name': bf.html_name, 'id': bf.auto_id, 'label': bf.label, } def test_field(self): form = self.Form() field = form['field'] template = """ <div class="form-group"> <label for="{id}" class="control-label">{label}:</label> <input id="{id}" name="{name}" type="text" class="form-control"> <small class="help-block">Example text.</small> </div> """ self.assertHTMLEqual( template.format(**self.get_attrs(field)), form.render_field(field, field.errors) ) def test_field_bound(self): form = self.Form({'field': 'a value'}) field = form['field'] template = """ <div class="form-group"> <label for="{id}" class="control-label">{label}:</label> <input id="{id}" name="{name}" type="text" class="form-control" value="a value"> <small class="help-block">Example text.</small> </div> """ self.assertHTMLEqual( template.format(**self.get_attrs(field)), form.render_field(field, field.errors) ) def test_field_error(self): form = self.Form({'field': 'error'}) field = form['field'] template = """ <div class="form-group has-error"> <label for="{id}" class="control-label">{label}:</label> <input id="{id}" name="{name}" type="text" class="form-control has-error" value="error"> <small class="help-block">Value must start with &quot;a&quot;.</small> <small class="help-block">Example text.</small> </div> """ self.assertHTMLEqual( template.format(**self.get_attrs(field)), form.render_field(field, field.errors) ) class CheckboxFieldTests(TestCase): class Form(bs3.BlockForm, forms.Form): field = forms.BooleanField(required=False, validators=[not_now], help_text='Example text.') def get_attrs(self, bf): return { 'name': bf.html_name, 'id': bf.auto_id, 'label': bf.label, } def test_field(self): form = self.Form() field = form['field'] template = """ <div class="form-group"> <div class="checkbox"> <label> <input id="{id}" name="{name}" type="checkbox"> {label} </label> </div> <small class="help-block">Example text.</small> </div> """ self.assertHTMLEqual( template.format(**self.get_attrs(field)), form.render_field(field, field.errors) ) def test_field_error(self): form = self.Form({'field': 'on'}) field = form['field'] template = """ <div class="form-group has-error"> <div class="checkbox"> <label> <input id="{id}" name="{name}" type="checkbox" checked> {label} </label> </div> <small class="help-block">I cannot let you do that right now.</small> <small class="help-block">Example text.</small> </div> """ self.assertHTMLEqual( template.format(**self.get_attrs(field)), form.render_field(field, field.errors) )
[ "django.forms.BooleanField", "django.forms.CharField", "django.forms.ValidationError" ]
[((179, 230), 'django.forms.ValidationError', 'forms.ValidationError', (['"""Value must start with "a"."""'], {}), '(\'Value must start with "a".\')\n', (200, 230), False, 'from django import forms\n'), ((281, 341), 'django.forms.ValidationError', 'forms.ValidationError', (['"""I cannot let you do that right now."""'], {}), "('I cannot let you do that right now.')\n", (302, 341), False, 'from django import forms\n'), ((439, 529), 'django.forms.CharField', 'forms.CharField', ([], {'required': '(False)', 'validators': '[startswith_a]', 'help_text': '"""Example text."""'}), "(required=False, validators=[startswith_a], help_text=\n 'Example text.')\n", (454, 529), False, 'from django import forms\n'), ((2516, 2604), 'django.forms.BooleanField', 'forms.BooleanField', ([], {'required': '(False)', 'validators': '[not_now]', 'help_text': '"""Example text."""'}), "(required=False, validators=[not_now], help_text=\n 'Example text.')\n", (2534, 2604), False, 'from django import forms\n')]
from snakemake import shell input, output, params, threads, w, config = snakemake.input, snakemake.output, snakemake.params, snakemake.threads, snakemake.wildcards, snakemake.config genome = w.genome params.hybrid = config['x'][genome]['hybrid'] opt = params.opt shell(""" rm -rf {output.fna}* {output.fai}* rm -rf {output.chrom_bed} {output.chrom_size} {output.gap} mkdir -p {params.wdir}/{params.odir} cd {params.wdir}/{params.odir} rm -rf raw.fna.* renamed* map* raw.sizes """) merge_tag = '--merge_short' if w.genome != 'Mt_R108' else '' if params.hybrid: shell(""" cat {input} > {params.wdir}/{params.odir}/renamed.fna cd {params.wdir}/{params.odir} fasta.py size renamed.fna > renamed.sizes touch mapf.chain mapb.chain """) else: params.gap = int(config['x'][genome]['gap']) params.prefix = config['x'][genome]['prefix'] shell(""" cd {params.wdir}/{params.odir} ln -sf ../download/raw.fna raw.fna fasta.py size raw.fna > raw.sizes fasta.py rename raw.fna renamed.fna mapf.bed mapb.bed \ --opt {params.opt} {merge_tag} \ --gap {params.gap} --prefix_chr {params.prefix} fasta.py size renamed.fna > renamed.sizes chain.py fromBed mapf.bed raw.sizes renamed.sizes > mapf.chain chainSwap mapf.chain mapb.chain """) shell(""" cd {params.wdir} ln -sf {params.odir}/renamed.fna 10_genome.fna cd .. samtools faidx {output.fna} fasta.py size --bed {output.fna} > {output.chrom_bed} cut -f1,3 {output.chrom_bed} > {output.chrom_size} fasta.py gaps {output.fna} > {output.gap} """)
[ "snakemake.shell" ]
[((265, 513), 'snakemake.shell', 'shell', (['"""\n rm -rf {output.fna}* {output.fai}*\n rm -rf {output.chrom_bed} {output.chrom_size} {output.gap}\n\n mkdir -p {params.wdir}/{params.odir}\n cd {params.wdir}/{params.odir}\n rm -rf raw.fna.* renamed* map* raw.sizes\n"""'], {}), '(\n """\n rm -rf {output.fna}* {output.fai}*\n rm -rf {output.chrom_bed} {output.chrom_size} {output.gap}\n\n mkdir -p {params.wdir}/{params.odir}\n cd {params.wdir}/{params.odir}\n rm -rf raw.fna.* renamed* map* raw.sizes\n"""\n )\n', (270, 513), False, 'from snakemake import shell\n'), ((1379, 1677), 'snakemake.shell', 'shell', (['"""\n cd {params.wdir}\n ln -sf {params.odir}/renamed.fna 10_genome.fna\n cd ..\n\n samtools faidx {output.fna}\n fasta.py size --bed {output.fna} > {output.chrom_bed}\n cut -f1,3 {output.chrom_bed} > {output.chrom_size}\n fasta.py gaps {output.fna} > {output.gap}\n"""'], {}), '(\n """\n cd {params.wdir}\n ln -sf {params.odir}/renamed.fna 10_genome.fna\n cd ..\n\n samtools faidx {output.fna}\n fasta.py size --bed {output.fna} > {output.chrom_bed}\n cut -f1,3 {output.chrom_bed} > {output.chrom_size}\n fasta.py gaps {output.fna} > {output.gap}\n"""\n )\n', (1384, 1677), False, 'from snakemake import shell\n'), ((588, 803), 'snakemake.shell', 'shell', (['"""\n cat {input} > {params.wdir}/{params.odir}/renamed.fna\n cd {params.wdir}/{params.odir}\n fasta.py size renamed.fna > renamed.sizes\n touch mapf.chain mapb.chain\n """'], {}), '(\n """\n cat {input} > {params.wdir}/{params.odir}/renamed.fna\n cd {params.wdir}/{params.odir}\n fasta.py size renamed.fna > renamed.sizes\n touch mapf.chain mapb.chain\n """\n )\n', (593, 803), False, 'from snakemake import shell\n'), ((903, 1383), 'snakemake.shell', 'shell', (['"""\n cd {params.wdir}/{params.odir}\n ln -sf ../download/raw.fna raw.fna\n fasta.py size raw.fna > raw.sizes\n\n fasta.py rename raw.fna renamed.fna mapf.bed mapb.bed --opt {params.opt} {merge_tag} --gap {params.gap} --prefix_chr {params.prefix}\n\n fasta.py size renamed.fna > renamed.sizes\n chain.py fromBed mapf.bed raw.sizes renamed.sizes > mapf.chain\n chainSwap mapf.chain mapb.chain\n """'], {}), '(\n """\n cd {params.wdir}/{params.odir}\n ln -sf ../download/raw.fna raw.fna\n fasta.py size raw.fna > raw.sizes\n\n fasta.py rename raw.fna renamed.fna mapf.bed mapb.bed --opt {params.opt} {merge_tag} --gap {params.gap} --prefix_chr {params.prefix}\n\n fasta.py size renamed.fna > renamed.sizes\n chain.py fromBed mapf.bed raw.sizes renamed.sizes > mapf.chain\n chainSwap mapf.chain mapb.chain\n """\n )\n', (908, 1383), False, 'from snakemake import shell\n')]
import io import pytest from requests import get from urllib.parse import urljoin def test_my_uploads_page(wait_for_api, login_user): """ GIVEN a user has logged in (login_user) WHEN the '/my/uploads' page is navigated to (GET) THEN check the response is valid and page title is correct """ request_session, api_url = wait_for_api response = request_session.get(urljoin(api_url, '/my/uploads')) assert response.status_code == 200 assert '<h1>My uploads</h1>' in response.text def test_valid_new_upload_page(wait_for_api, login_user): """ GIVEN a user has logged in (login_user) WHEN the '/media/newupload' page is navigated to (GET) THEN check the response is valid and page title is correct """ request_session, api_url = wait_for_api response = request_session.get(urljoin(api_url, '/media/newupload')) assert response.status_code == 200 assert '<h1>New upload</h1>' in response.text def test_invalid_new_upload_page(wait_for_api): """ GIVEN a user has not logged in WHEN the '/media/newupload' page is navigated to (GET) THEN check the response is valid and page title is correct """ request_session, api_url = wait_for_api response = request_session.get(urljoin(api_url, '/media/newupload')) assert response.status_code == 200 assert '<div class="flash">Please login first</div>' in response.text def test_new_upload(wait_for_api, login_user): """ GIVEN a user has logged in (login_user) WHEN the '/media/newupload' page is posted an example image (POST) THEN check the response is valid and the page title is correct """ example_file=open("./app/static/gfx/example.png","rb") files = { 'file': example_file } request_session, api_url = wait_for_api response = request_session.post(urljoin(api_url, '/media/newupload'), files=files, allow_redirects=True) assert response.status_code == 200 assert '<h1>My uploads</h1>' in response.text #def test_remove_upload(wait_for_api, login_user): # """ # GIVEN a user has logged in (login_user) # WHEN the '/blob/delete' page is posted (POST) # THEN check the response is valid and the user is logged in # """ # valid_blob = dict(blob_path='images/*example.png', upload_id=2) # request_session, api_url = wait_for_api # response = request_session.post(urljoin(api_url, '/blob/delete'), data=valid_blob, allow_redirects=True) # assert response.status_code == 200 # assert 'example.png was deleted successfully' in response.text
[ "urllib.parse.urljoin" ]
[((391, 422), 'urllib.parse.urljoin', 'urljoin', (['api_url', '"""/my/uploads"""'], {}), "(api_url, '/my/uploads')\n", (398, 422), False, 'from urllib.parse import urljoin\n'), ((833, 869), 'urllib.parse.urljoin', 'urljoin', (['api_url', '"""/media/newupload"""'], {}), "(api_url, '/media/newupload')\n", (840, 869), False, 'from urllib.parse import urljoin\n'), ((1261, 1297), 'urllib.parse.urljoin', 'urljoin', (['api_url', '"""/media/newupload"""'], {}), "(api_url, '/media/newupload')\n", (1268, 1297), False, 'from urllib.parse import urljoin\n'), ((1834, 1870), 'urllib.parse.urljoin', 'urljoin', (['api_url', '"""/media/newupload"""'], {}), "(api_url, '/media/newupload')\n", (1841, 1870), False, 'from urllib.parse import urljoin\n')]
import justpy as jp from .group import Group class Row(Group): def __init__(self): '''Row Element Provides a container which arranges its child in a row. ''' view = jp.QDiv(classes='row items-start', style='gap: 1em', delete_flag=False) super().__init__(view)
[ "justpy.QDiv" ]
[((204, 275), 'justpy.QDiv', 'jp.QDiv', ([], {'classes': '"""row items-start"""', 'style': '"""gap: 1em"""', 'delete_flag': '(False)'}), "(classes='row items-start', style='gap: 1em', delete_flag=False)\n", (211, 275), True, 'import justpy as jp\n')]
import uvicorn from fastapi import FastAPI from database import Base, engine from routers.user import router as router_user from routers.product import router as router_product from routers.authentication import router as router_auth app = FastAPI( title="Wish List", description="Permita que seus clientes acompanhem seus produtos favoritos, adicionando-os a uma lista de desejos.", version="1.0.0", ) Base.metadata.create_all(engine) @app.get('/') def index(): """ "welcome": "Wish List", "documentation": "127.0.0.1:8000/docs ou 127.0.0.1:8000/redoc" """ return { "welcome": "Wish List", "documentation": "127.0.0.1:8000/docs ou 127.0.0.1:8000/redoc" } app.include_router(router_auth) app.include_router(router_product) app.include_router(router_user) if __name__ == "__main__": uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
[ "uvicorn.run", "fastapi.FastAPI", "database.Base.metadata.create_all" ]
[((244, 413), 'fastapi.FastAPI', 'FastAPI', ([], {'title': '"""Wish List"""', 'description': '"""Permita que seus clientes acompanhem seus produtos favoritos, adicionando-os a uma lista de desejos."""', 'version': '"""1.0.0"""'}), "(title='Wish List', description=\n 'Permita que seus clientes acompanhem seus produtos favoritos, adicionando-os a uma lista de desejos.'\n , version='1.0.0')\n", (251, 413), False, 'from fastapi import FastAPI\n'), ((411, 443), 'database.Base.metadata.create_all', 'Base.metadata.create_all', (['engine'], {}), '(engine)\n', (435, 443), False, 'from database import Base, engine\n'), ((811, 876), 'uvicorn.run', 'uvicorn.run', (['"""main:app"""'], {'host': '"""127.0.0.1"""', 'port': '(8000)', 'reload': '(True)'}), "('main:app', host='127.0.0.1', port=8000, reload=True)\n", (822, 876), False, 'import uvicorn\n')]
# encoding: utf-8 import torch import cv2 import numpy as np import pdb def detection_collate(batch): """Custom collate fn for dealing with batches of images that have a different number of associated object annotations (bounding boxes). Arguments: batch: (tuple) A tuple of tensor images and lists of annotations Return: A tuple containing: 1) (tensor) batch of images stacked on their 0 dim 2) (tensor) [batch, num_gt, 5] batch of annotations stacked on their 0 dim annotations for a given image are stacked on 1 dim """ targets = [] imgs = [] # numpy array num_gts = [sample[1].shape[0] for sample in batch] max_num_gt = max(num_gts) for sample in batch: imgs.append(sample[0]) size_gt = sample[1].shape num_gt = size_gt[0] aug_size = list(size_gt[:]) aug_size[0] = max_num_gt aug_gt = np.zeros(aug_size, dtype=sample[1].dtype) aug_gt[:num_gt] = sample[1] targets.append(torch.FloatTensor(aug_gt)) return torch.stack(imgs, 0), torch.stack(targets, 0) def base_transform(image, size, mean): x = cv2.resize(image, (size, size)).astype(np.float32) x -= mean x = x.astype(np.float32) return x class BaseTransform: """ For evaluation and testing. """ def __init__(self, size, mean): self.size = size self.mean = np.array(mean, dtype=np.float32) def __call__(self, image, boxes=None, labels=None): return base_transform(image, self.size, self.mean), boxes, labels
[ "torch.stack", "numpy.array", "numpy.zeros", "cv2.resize", "torch.FloatTensor" ]
[((948, 989), 'numpy.zeros', 'np.zeros', (['aug_size'], {'dtype': 'sample[1].dtype'}), '(aug_size, dtype=sample[1].dtype)\n', (956, 989), True, 'import numpy as np\n'), ((1087, 1107), 'torch.stack', 'torch.stack', (['imgs', '(0)'], {}), '(imgs, 0)\n', (1098, 1107), False, 'import torch\n'), ((1109, 1132), 'torch.stack', 'torch.stack', (['targets', '(0)'], {}), '(targets, 0)\n', (1120, 1132), False, 'import torch\n'), ((1441, 1473), 'numpy.array', 'np.array', (['mean'], {'dtype': 'np.float32'}), '(mean, dtype=np.float32)\n', (1449, 1473), True, 'import numpy as np\n'), ((1049, 1074), 'torch.FloatTensor', 'torch.FloatTensor', (['aug_gt'], {}), '(aug_gt)\n', (1066, 1074), False, 'import torch\n'), ((1182, 1213), 'cv2.resize', 'cv2.resize', (['image', '(size, size)'], {}), '(image, (size, size))\n', (1192, 1213), False, 'import cv2\n')]
# Copyright (c) 2018 Copyright holder of the paper Generative Adversarial Model Learning # submitted to NeurIPS 2019 for review # All rights reserved. import numpy as np import torch class Optimizer(object): def __init__(self, policy, use_gpu=False): self.networks = self._init_networks(policy.input_dim, policy.output_dim) networks = self.networks.copy() networks['policy'] = policy self.optimizers = self._init_optimizers(networks) self.use_gpu = use_gpu if self.use_gpu: self.networks = {k: v.cuda() for k, v in self.networks.items()} @classmethod def _init_networks(cls, obs_dim, action_dim): raise NotImplementedError def process_batch(self, policy, batch, update_policy_args): states, actions, rewards, masks = unpack_batch(batch) if self.use_gpu: states, actions, rewards, masks = map( lambda x: x.cuda(), [states, actions, rewards, masks]) policy = self.update_networks( policy, actions, masks, rewards, states, batch["num_episodes"], *update_policy_args) return policy def update_networks(self, policy, actions, masks, rewards, states, num_episodes, *args, **step_kwargs): raise NotImplementedError @staticmethod def _init_optimizers(networks, lr_rates=None): return init_optimizers(networks, lr_rates=lr_rates) def init_optimizers(networks, lr_rates=None): args = {key: [network] for key, network in networks.items()} if lr_rates is not None: for key in args.keys(): args[key].append(lr_rates[key]) optimizers = {key: init_optimizer(*args[key]) for key in networks.keys()} return optimizers def unpack_batch(batch): states = torch.from_numpy(np.array(batch["states"], dtype=np.float32)) rewards = torch.from_numpy(np.array(batch["rewards"], dtype=np.float32)) masks = torch.from_numpy(np.array(batch["masks"], dtype=np.float32)) actions = torch.from_numpy(np.array(batch["actions"])) return states, actions, rewards, masks def init_optimizer(network, lr_rate=0.01): return torch.optim.Adam(network.parameters(), lr=lr_rate)
[ "numpy.array" ]
[((1868, 1911), 'numpy.array', 'np.array', (["batch['states']"], {'dtype': 'np.float32'}), "(batch['states'], dtype=np.float32)\n", (1876, 1911), True, 'import numpy as np\n'), ((1944, 1988), 'numpy.array', 'np.array', (["batch['rewards']"], {'dtype': 'np.float32'}), "(batch['rewards'], dtype=np.float32)\n", (1952, 1988), True, 'import numpy as np\n'), ((2019, 2061), 'numpy.array', 'np.array', (["batch['masks']"], {'dtype': 'np.float32'}), "(batch['masks'], dtype=np.float32)\n", (2027, 2061), True, 'import numpy as np\n'), ((2094, 2120), 'numpy.array', 'np.array', (["batch['actions']"], {}), "(batch['actions'])\n", (2102, 2120), True, 'import numpy as np\n')]
#!/usr/bin/python3 # -*- coding: utf-8 -*- import os import sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # 基地址是本项目根目录 sys.path.append(BASE_DIR) import datetime from yxf_yixue.xiaochengtu import XiaochengtuApi if __name__ == '__main__': string = '1996/02/29 23:16' obj = datetime.datetime(2012, 3, 7, 17, 40) a = XiaochengtuApi() res1 = a.paipan(obj) print(res1) a.print_pan() res2 = a.get_chuantongfenxi() print(res2)
[ "datetime.datetime", "sys.path.append", "os.path.abspath", "yxf_yixue.xiaochengtu.XiaochengtuApi" ]
[((149, 174), 'sys.path.append', 'sys.path.append', (['BASE_DIR'], {}), '(BASE_DIR)\n', (164, 174), False, 'import sys\n'), ((311, 348), 'datetime.datetime', 'datetime.datetime', (['(2012)', '(3)', '(7)', '(17)', '(40)'], {}), '(2012, 3, 7, 17, 40)\n', (328, 348), False, 'import datetime\n'), ((357, 373), 'yxf_yixue.xiaochengtu.XiaochengtuApi', 'XiaochengtuApi', ([], {}), '()\n', (371, 373), False, 'from yxf_yixue.xiaochengtu import XiaochengtuApi\n'), ((107, 132), 'os.path.abspath', 'os.path.abspath', (['__file__'], {}), '(__file__)\n', (122, 132), False, 'import os\n')]
# -*- coding: UTF-8 -*- """ Provides a summary after each test run. """ from __future__ import absolute_import, division, print_function import sys from time import time as time_now from behave.model import Rule, ScenarioOutline # MAYBE: Scenario from behave.model_core import Status from behave.reporter.base import Reporter from behave.formatter.base import StreamOpener # --------------------------------------------------------------------------- # CONSTANTS: # --------------------------------------------------------------------------- # -- DISABLED: OPTIONAL_STEPS = ('untested', 'undefined') OPTIONAL_STEPS = (Status.untested,) # MAYBE: Status.undefined STATUS_ORDER = (Status.passed, Status.failed, Status.skipped, Status.undefined, Status.untested) # --------------------------------------------------------------------------- # UTILITY FUNCTIONS: # --------------------------------------------------------------------------- def pluralize(word, count=1, suffix="s"): if count == 1: return word # -- OTHERWISE: return "{0}{1}".format(word, suffix) def compute_summary_sum(summary): """Compute sum of all summary counts (except: all) :param summary: Summary counts (as dict). :return: Sum of all counts (as integer). """ counts_sum = 0 for name, count in summary.items(): if name == "all": continue # IGNORE IT. counts_sum += count return counts_sum def format_summary0(statement_type, summary): parts = [] for status in STATUS_ORDER: if status.name not in summary: continue counts = summary[status.name] if status in OPTIONAL_STEPS and counts == 0: # -- SHOW-ONLY: For relevant counts, suppress: untested items, etc. continue if not parts: # -- FIRST ITEM: Add statement_type to counter. label = statement_type if counts != 1: label += 's' part = u"%d %s %s" % (counts, label, status.name) else: part = u"%d %s" % (counts, status.name) parts.append(part) return ", ".join(parts) + "\n" def format_summary(statement_type, summary): parts = [] for status in STATUS_ORDER: if status.name not in summary: continue counts = summary[status.name] if status in OPTIONAL_STEPS and counts == 0: # -- SHOW-ONLY: For relevant counts, suppress: untested items, etc. continue name = status.name if status.name == "passed": statement = pluralize(statement_type, counts) name = u"%s passed" % statement part = u"%d %s" % (counts, name) parts.append(part) return ", ".join(parts) + "\n" # -- PREPARED: def format_summary2(statement_type, summary, end="\n"): """Format the summary line for one statement type. .. code-block:: 6 scenarios (passed: 5, failed: 1, skipped: 0, untested: 0) :param statement_type: :param summary: :return: """ parts = [] for status in STATUS_ORDER: if status.name not in summary: continue counts = summary[status.name] if status in OPTIONAL_STEPS and counts == 0: # -- SHOW-ONLY: For relevant counts, suppress: untested items, etc. continue parts.append((status.name, counts)) counts_sum = summary["all"] statement = pluralize(statement_type, sum) parts_text = ", ".join(["{0}: {1}".format(name, value) for name, value in parts]) return "{count:4} {statement:<9} ({parts}){end}".format( count=counts_sum, statement=statement, parts=parts_text, end=end) # --------------------------------------------------------------------------- # REPORTERS: # --------------------------------------------------------------------------- class SummaryReporter(Reporter): show_failed_scenarios = True output_stream_name = "stdout" def __init__(self, config): super(SummaryReporter, self).__init__(config) stream = getattr(sys, self.output_stream_name, sys.stderr) self.stream = StreamOpener.ensure_stream_with_encoder(stream) summary_zero_data = { "all": 0, Status.passed.name: 0, Status.failed.name: 0, Status.skipped.name: 0, Status.untested.name: 0 } self.feature_summary = summary_zero_data.copy() self.rule_summary = summary_zero_data.copy() self.scenario_summary = summary_zero_data.copy() self.step_summary = {Status.undefined.name: 0} self.step_summary.update(summary_zero_data) self.duration = 0.0 self.run_starttime = 0 self.run_endtime = 0 self.failed_scenarios = [] self.show_rules = True def testrun_started(self, timestamp=None): if timestamp is None: timestamp = time_now() self.run_starttime = timestamp def testrun_finished(self, timestamp=None): if timestamp is None: timestamp = time_now() self.run_endtime = timestamp def print_failing_scenarios(self, stream=None): if stream is None: stream = self.stream stream.write("\nFailing scenarios:\n") for scenario in self.failed_scenarios: # add the list of tags matching ###-### so we will show the issue identifier with the error OPE-1234 stream.write(u" %s %s %s\n" % (', '.join(t for t in scenario.tags if len(t.split('-'))==2 ), scenario.location, scenario.name)) def compute_summary_sums(self): """(Re)Compute summary sum of all counts (except: all).""" summaries = [ self.feature_summary, self.rule_summary, self.scenario_summary, self.step_summary ] for summary in summaries: summary["all"] = compute_summary_sum(summary) def print_summary(self, stream=None, with_duration=True): if stream is None: stream = self.stream self.compute_summary_sums() has_rules = (self.rule_summary["all"] > 0) stream.write(format_summary("feature", self.feature_summary)) if self.show_rules and has_rules: # -- HINT: Show only rules, if any exists. self.stream.write(format_summary("rule", self.rule_summary)) stream.write(format_summary("scenario", self.scenario_summary)) stream.write(format_summary("step", self.step_summary)) # -- DURATION: if with_duration: timings = (int(self.duration / 60.0), self.duration % 60) stream.write('Took %dm%02.3fs\n' % timings) # -- REPORTER-API: def feature(self, feature): if self.run_starttime == 0: # -- DISCOVER: TEST-RUN started. self.testrun_started() self.process_feature(feature) def end(self): self.testrun_finished() # -- SHOW FAILED SCENARIOS (optional): if self.show_failed_scenarios and self.failed_scenarios: self.print_failing_scenarios() self.stream.write("\n") # -- SHOW SUMMARY COUNTS: self.print_summary() def process_run_items_for(self, parent): for run_item in parent: if isinstance(run_item, Rule): self.process_rule(run_item) elif isinstance(run_item, ScenarioOutline): self.process_scenario_outline(run_item) else: # assert isinstance(run_item, Scenario) self.process_scenario(run_item) def process_feature(self, feature): self.duration += feature.duration self.feature_summary[feature.status.name] += 1 self.process_run_items_for(feature) def process_rule(self, rule): self.rule_summary[rule.status.name] += 1 self.process_run_items_for(rule) def process_scenario(self, scenario): if scenario.status == Status.failed: self.failed_scenarios.append(scenario) self.scenario_summary[scenario.status.name] += 1 for step in scenario: self.step_summary[step.status.name] += 1 def process_scenario_outline(self, scenario_outline): for scenario in scenario_outline.scenarios: self.process_scenario(scenario)
[ "behave.formatter.base.StreamOpener.ensure_stream_with_encoder", "time.time" ]
[((4196, 4243), 'behave.formatter.base.StreamOpener.ensure_stream_with_encoder', 'StreamOpener.ensure_stream_with_encoder', (['stream'], {}), '(stream)\n', (4235, 4243), False, 'from behave.formatter.base import StreamOpener\n'), ((4977, 4987), 'time.time', 'time_now', ([], {}), '()\n', (4985, 4987), True, 'from time import time as time_now\n'), ((5130, 5140), 'time.time', 'time_now', ([], {}), '()\n', (5138, 5140), True, 'from time import time as time_now\n')]
from typing import Dict, Any import pytest from checkov.common.bridgecrew.bc_source import SourceType from checkov.common.bridgecrew.platform_integration import BcPlatformIntegration, bc_integration @pytest.fixture() def mock_bc_integration() -> BcPlatformIntegration: bc_integration.bc_api_key = "<KEY>" bc_integration.setup_bridgecrew_credentials( repo_id="bridgecrewio/checkov", skip_fixes=True, skip_suppressions=True, skip_policy_download=True, source=SourceType("Github", False), source_version="1.0", repo_branch="master", ) return bc_integration @pytest.fixture() def scan_result() -> Dict[str, Any]: return { "repository": "/abs_path/to/app/requirements.txt", "passed": True, "packages": {"type": "python", "name": "django", "version": "1.2", "path": "/abs_path/to/app/requirements.txt"}, "complianceIssues": None, "complianceDistribution": {"critical": 0, "high": 0, "medium": 0, "low": 0, "total": 0}, "vulnerabilities": [ { "id": "CVE-2019-19844", "status": "fixed in 3.0.1, 2.2.9, 1.11.27", "cvss": 9.8, "vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", "description": "Django before 1.11.27, 2.x before 2.2.9, and 3.x before 3.0.1 allows account takeover.", "severity": "critical", "packageName": "django", "packageVersion": "1.2", "link": "https://nvd.nist.gov/vuln/detail/CVE-2019-19844", "riskFactors": ["Critical severity", "Has fix", "Attack complexity: low", "Attack vector: network"], "impactedVersions": ["\u003c1.11.27"], "publishedDate": "2019-12-18T20:15:00+01:00", "discoveredDate": "2019-12-18T19:15:00Z", "fixDate": "2019-12-18T20:15:00+01:00", } ], "vulnerabilityDistribution": {"critical": 1, "high": 0, "medium": 0, "low": 0, "total": 0}, }
[ "pytest.fixture", "checkov.common.bridgecrew.bc_source.SourceType" ]
[((204, 220), 'pytest.fixture', 'pytest.fixture', ([], {}), '()\n', (218, 220), False, 'import pytest\n'), ((633, 649), 'pytest.fixture', 'pytest.fixture', ([], {}), '()\n', (647, 649), False, 'import pytest\n'), ((509, 536), 'checkov.common.bridgecrew.bc_source.SourceType', 'SourceType', (['"""Github"""', '(False)'], {}), "('Github', False)\n", (519, 536), False, 'from checkov.common.bridgecrew.bc_source import SourceType\n')]
import argparse from pathlib import Path from cv2 import cv2 from trimap import generate_trimap from trimap_output_utils import save_trimap_output def main(): args = parse_args() image_path = args.image output_directory_path = args.output image_path = Path(image_path) if not image_path.is_file(): raise RuntimeError(f'The provided image path "{image_path}" does not exist!') image_filename = image_path.stem saliency_image_path = image_path.as_posix() trimap_image = generate_trimap(saliency_image_path, kernel_size=3, iterations=20) save_trimap_output(trimap_image, image_filename, output_directory_path) def parse_args(): parser = argparse.ArgumentParser(description='Trimap Generator Application') parser.add_argument('-i', '--image', required=True, type=str, help='path to input image') parser.add_argument('-o', '--output', required=False, default='.', type=str, help='path to output directory') return parser.parse_args() if __name__ == "__main__": main()
[ "argparse.ArgumentParser", "trimap.generate_trimap", "trimap_output_utils.save_trimap_output", "pathlib.Path" ]
[((273, 289), 'pathlib.Path', 'Path', (['image_path'], {}), '(image_path)\n', (277, 289), False, 'from pathlib import Path\n'), ((515, 581), 'trimap.generate_trimap', 'generate_trimap', (['saliency_image_path'], {'kernel_size': '(3)', 'iterations': '(20)'}), '(saliency_image_path, kernel_size=3, iterations=20)\n', (530, 581), False, 'from trimap import generate_trimap\n'), ((586, 657), 'trimap_output_utils.save_trimap_output', 'save_trimap_output', (['trimap_image', 'image_filename', 'output_directory_path'], {}), '(trimap_image, image_filename, output_directory_path)\n', (604, 657), False, 'from trimap_output_utils import save_trimap_output\n'), ((691, 758), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ([], {'description': '"""Trimap Generator Application"""'}), "(description='Trimap Generator Application')\n", (714, 758), False, 'import argparse\n')]
#!/usr/bin/env python # -*- coding: utf-8 -*- from http.client import OK from unittest.mock import MagicMock, patch from urllib.parse import urlencode import graphene_django.views as views from django.urls import reverse from graphql import GraphQLError from graphql.error import GraphQLLocatedError class CustomException(Exception): """ Boom! """ def get_query_string(): path = reverse('graphql') query = urlencode({'query': 'query {test}'}) path = f'{path}?{query}' return path def test_view(client): result = client.get( get_query_string(), HTTP_ACCEPT="application/json;q=0.8, text/html;q=0.9", ) assert result.status_code == OK @patch.object(views.GraphQLView, 'execute_graphql_request') @patch('sentry_sdk.capture_exception') def test_execute_graphql_request( mocked_capture_exception, mocked_method, client, ): error = CustomException('Boom') errors = [GraphQLLocatedError([], error)] mocked_return_value = MagicMock() mocked_return_value.errors = errors mocked_method.return_value = mocked_return_value result = client.get( get_query_string(), HTTP_ACCEPT="application/json;q=0.8, text/html;q=0.9", ) assert result.status_code == 400 assert result.json()['errors'][0]['message'] == 'Boom' mocked_capture_exception.assert_called_with(error) @patch.object(views.GraphQLView, 'execute_graphql_request') @patch('sentry_sdk.capture_exception') def test_execute_graphql_request_raises_raw_graphql_exceptions( mocked_capture_exception, mocked_method, client, ): error = GraphQLError(message='Syntax error in GraphQL query') mocked_return_value = MagicMock() mocked_return_value.errors = [error] mocked_method.return_value = mocked_return_value result = client.get( reverse('graphql'), {'query': '{__schema{types{name}}}'}, ) assert result.status_code == 400 assert result.json()['errors'][0]['message'] == ( 'Syntax error in GraphQL query' ) mocked_capture_exception.assert_called_with(error)
[ "unittest.mock.MagicMock", "graphql.GraphQLError", "graphql.error.GraphQLLocatedError", "django.urls.reverse", "urllib.parse.urlencode", "unittest.mock.patch.object", "unittest.mock.patch" ]
[((692, 750), 'unittest.mock.patch.object', 'patch.object', (['views.GraphQLView', '"""execute_graphql_request"""'], {}), "(views.GraphQLView, 'execute_graphql_request')\n", (704, 750), False, 'from unittest.mock import MagicMock, patch\n'), ((752, 789), 'unittest.mock.patch', 'patch', (['"""sentry_sdk.capture_exception"""'], {}), "('sentry_sdk.capture_exception')\n", (757, 789), False, 'from unittest.mock import MagicMock, patch\n'), ((1379, 1437), 'unittest.mock.patch.object', 'patch.object', (['views.GraphQLView', '"""execute_graphql_request"""'], {}), "(views.GraphQLView, 'execute_graphql_request')\n", (1391, 1437), False, 'from unittest.mock import MagicMock, patch\n'), ((1439, 1476), 'unittest.mock.patch', 'patch', (['"""sentry_sdk.capture_exception"""'], {}), "('sentry_sdk.capture_exception')\n", (1444, 1476), False, 'from unittest.mock import MagicMock, patch\n'), ((393, 411), 'django.urls.reverse', 'reverse', (['"""graphql"""'], {}), "('graphql')\n", (400, 411), False, 'from django.urls import reverse\n'), ((424, 460), 'urllib.parse.urlencode', 'urlencode', (["{'query': 'query {test}'}"], {}), "({'query': 'query {test}'})\n", (433, 460), False, 'from urllib.parse import urlencode\n'), ((997, 1008), 'unittest.mock.MagicMock', 'MagicMock', ([], {}), '()\n', (1006, 1008), False, 'from unittest.mock import MagicMock, patch\n'), ((1617, 1670), 'graphql.GraphQLError', 'GraphQLError', ([], {'message': '"""Syntax error in GraphQL query"""'}), "(message='Syntax error in GraphQL query')\n", (1629, 1670), False, 'from graphql import GraphQLError\n'), ((1698, 1709), 'unittest.mock.MagicMock', 'MagicMock', ([], {}), '()\n', (1707, 1709), False, 'from unittest.mock import MagicMock, patch\n'), ((938, 968), 'graphql.error.GraphQLLocatedError', 'GraphQLLocatedError', (['[]', 'error'], {}), '([], error)\n', (957, 968), False, 'from graphql.error import GraphQLLocatedError\n'), ((1838, 1856), 'django.urls.reverse', 'reverse', (['"""graphql"""'], {}), "('graphql')\n", (1845, 1856), False, 'from django.urls import reverse\n')]
''' (c) University of Liverpool 2020 Licensed under the MIT License. To view a copy of this license, visit <http://opensource.org/licenses/MIT/>.. @author: neilswainston ''' # pylint: disable=broad-except import os.path import tempfile from liv_covid19.web.artic import opentrons from liv_covid19.web.job import JobThread, save_export class OpentronsThread(JobThread): '''Runs a Opentrons job.''' def __init__(self, query, out_dir): self.__filename, suffix = os.path.splitext(query['file_name']) tmpfile = tempfile.NamedTemporaryFile(delete=False, suffix=suffix) self.__in_filename = tmpfile.name with open(self.__in_filename, 'w') as fle: fle.write(query['file_content']) self.__temp_deck = query['temp_deck'] self.__vol_scale = float(query['vol_scale']) self.__out_dir = out_dir JobThread.__init__(self, query, 1) def run(self): '''Run.''' try: parent_dir = tempfile.mkdtemp() iteration = 0 self._fire_job_event('running', iteration, 'Running...') opentrons.run(in_filename=self.__in_filename, temp_deck=self.__temp_deck, vol_scale=self.__vol_scale, out_dir=parent_dir) iteration += 1 if self._cancelled: self._fire_job_event('cancelled', iteration, message='Job cancelled') else: save_export(parent_dir, self.__out_dir, self._job_id) self._result = self._job_id self._fire_job_event('finished', iteration, message='Job completed') except Exception as err: self._fire_job_event('error', iteration, message=str(err))
[ "liv_covid19.web.job.save_export", "liv_covid19.web.job.JobThread.__init__", "tempfile.mkdtemp", "liv_covid19.web.artic.opentrons.run", "tempfile.NamedTemporaryFile" ]
[((538, 594), 'tempfile.NamedTemporaryFile', 'tempfile.NamedTemporaryFile', ([], {'delete': '(False)', 'suffix': 'suffix'}), '(delete=False, suffix=suffix)\n', (565, 594), False, 'import tempfile\n'), ((876, 910), 'liv_covid19.web.job.JobThread.__init__', 'JobThread.__init__', (['self', 'query', '(1)'], {}), '(self, query, 1)\n', (894, 910), False, 'from liv_covid19.web.job import JobThread, save_export\n'), ((988, 1006), 'tempfile.mkdtemp', 'tempfile.mkdtemp', ([], {}), '()\n', (1004, 1006), False, 'import tempfile\n'), ((1116, 1241), 'liv_covid19.web.artic.opentrons.run', 'opentrons.run', ([], {'in_filename': 'self.__in_filename', 'temp_deck': 'self.__temp_deck', 'vol_scale': 'self.__vol_scale', 'out_dir': 'parent_dir'}), '(in_filename=self.__in_filename, temp_deck=self.__temp_deck,\n vol_scale=self.__vol_scale, out_dir=parent_dir)\n', (1129, 1241), False, 'from liv_covid19.web.artic import opentrons\n'), ((1534, 1587), 'liv_covid19.web.job.save_export', 'save_export', (['parent_dir', 'self.__out_dir', 'self._job_id'], {}), '(parent_dir, self.__out_dir, self._job_id)\n', (1545, 1587), False, 'from liv_covid19.web.job import JobThread, save_export\n')]
# Copyright 2018 <NAME>. # # Licensed under the MIT License import tensorflow as tf DEFAULT_VARIABLE_NAMES = ['conv1', 'conv2', 'conv3', 'conv4', 'fc1', 'fc2', 'softmax_linear'] BATCH_SIZE = 200 IMAGE_WIDTH = 32 IMAGE_HEIGHT = 32 IMAGE_DEPTH = 3 NUM_CLASSES = 10 INPUT_PLACEHOLDER = 'X_INPUT' LABELS_PLACEHOLDER = 'Y_LABELS' def create_placeholder(): x_placeholder = tf.placeholder(tf.float32, [None, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DEPTH], name=INPUT_PLACEHOLDER) y_placeholder = tf.placeholder(tf.int32, [None], name=LABELS_PLACEHOLDER) return x_placeholder, y_placeholder def initialize_parameters(): parameters = { "w1": tf.get_variable("w1", shape=[3, 3, 3, 64], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w2": tf.get_variable("w2", shape=[3, 3, 64, 64], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w3": tf.get_variable("w3", shape=[3, 3, 64, 64], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w4": tf.get_variable("w4", shape=[3, 3, 64, 64], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w5": tf.get_variable("w5", shape=[4096, 384], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w6": tf.get_variable("w6", shape=[384, 192], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "w7": tf.get_variable("w7", shape=[192, 10], initializer=tf.truncated_normal_initializer(stddev=5e-2, dtype=tf.float32)), "b1": tf.get_variable('b1', [64], initializer=tf.constant_initializer(0.0), dtype=tf.float32), "b2": tf.get_variable('b2', [64], initializer=tf.constant_initializer(0.0), dtype=tf.float32), "b3": tf.get_variable('b3', [64], initializer=tf.constant_initializer(0.0), dtype=tf.float32), "b4": tf.get_variable('b4', [64], initializer=tf.constant_initializer(0.0), dtype=tf.float32), "b5": tf.get_variable('b5', [384], initializer=tf.constant_initializer(0.1), dtype=tf.float32), "b6": tf.get_variable('b6', [192], initializer=tf.constant_initializer(0.1), dtype=tf.float32), "b7": tf.get_variable('b7', [10], initializer=tf.constant_initializer(0.0), dtype=tf.float32) } return parameters def create_conv2d_layer(inputs, name, weight, bias, strides=[1, 1, 1, 1], padding='SAME'): with tf.variable_scope(name) as scope: conv = tf.nn.conv2d(inputs, weight, strides, padding) pre_activation = tf.nn.bias_add(conv, bias) activation = tf.nn.relu(pre_activation, name=scope.name) return activation def forward_propagation(input, parameters): conv1 = create_conv2d_layer(input, 'conv1', parameters['w1'], parameters['b1']) conv2 = create_conv2d_layer(conv1, 'conv2', parameters['w2'], parameters['b2']) pool1 = tf.nn.max_pool(conv2, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1') conv3 = create_conv2d_layer(pool1, 'conv3', parameters['w3'], parameters['b3']) conv4 = create_conv2d_layer(conv3, 'conv4', parameters['w4'], parameters['b4']) pool2 = tf.nn.max_pool(conv4, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool2') flattened_conv = tf.reshape(pool2, shape=[-1, parameters['w5'].get_shape().as_list()[0]]) fc1 = tf.nn.relu(tf.matmul(flattened_conv, parameters['w5']) + parameters['b5'], name='fc1') fc2 = tf.nn.relu(tf.matmul(fc1, parameters['w6']) + parameters['b6'], name='fc2') softmax_linear = tf.add(tf.matmul(fc2, parameters['w7']), parameters['b7'], name='softmax') return softmax_linear
[ "tensorflow.nn.conv2d", "tensorflow.nn.max_pool", "tensorflow.variable_scope", "tensorflow.nn.relu", "tensorflow.placeholder", "tensorflow.truncated_normal_initializer", "tensorflow.matmul", "tensorflow.constant_initializer", "tensorflow.nn.bias_add" ]
[((377, 479), 'tensorflow.placeholder', 'tf.placeholder', (['tf.float32', '[None, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DEPTH]'], {'name': 'INPUT_PLACEHOLDER'}), '(tf.float32, [None, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DEPTH],\n name=INPUT_PLACEHOLDER)\n', (391, 479), True, 'import tensorflow as tf\n'), ((496, 553), 'tensorflow.placeholder', 'tf.placeholder', (['tf.int32', '[None]'], {'name': 'LABELS_PLACEHOLDER'}), '(tf.int32, [None], name=LABELS_PLACEHOLDER)\n', (510, 553), True, 'import tensorflow as tf\n'), ((3106, 3204), 'tensorflow.nn.max_pool', 'tf.nn.max_pool', (['conv2'], {'ksize': '[1, 3, 3, 1]', 'strides': '[1, 2, 2, 1]', 'padding': '"""SAME"""', 'name': '"""pool1"""'}), "(conv2, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding=\n 'SAME', name='pool1')\n", (3120, 3204), True, 'import tensorflow as tf\n'), ((3410, 3508), 'tensorflow.nn.max_pool', 'tf.nn.max_pool', (['conv4'], {'ksize': '[1, 3, 3, 1]', 'strides': '[1, 2, 2, 1]', 'padding': '"""SAME"""', 'name': '"""pool2"""'}), "(conv4, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding=\n 'SAME', name='pool2')\n", (3424, 3508), True, 'import tensorflow as tf\n'), ((2641, 2664), 'tensorflow.variable_scope', 'tf.variable_scope', (['name'], {}), '(name)\n', (2658, 2664), True, 'import tensorflow as tf\n'), ((2690, 2736), 'tensorflow.nn.conv2d', 'tf.nn.conv2d', (['inputs', 'weight', 'strides', 'padding'], {}), '(inputs, weight, strides, padding)\n', (2702, 2736), True, 'import tensorflow as tf\n'), ((2762, 2788), 'tensorflow.nn.bias_add', 'tf.nn.bias_add', (['conv', 'bias'], {}), '(conv, bias)\n', (2776, 2788), True, 'import tensorflow as tf\n'), ((2810, 2853), 'tensorflow.nn.relu', 'tf.nn.relu', (['pre_activation'], {'name': 'scope.name'}), '(pre_activation, name=scope.name)\n', (2820, 2853), True, 'import tensorflow as tf\n'), ((3839, 3871), 'tensorflow.matmul', 'tf.matmul', (['fc2', "parameters['w7']"], {}), "(fc2, parameters['w7'])\n", (3848, 3871), True, 'import tensorflow as tf\n'), ((3647, 3690), 'tensorflow.matmul', 'tf.matmul', (['flattened_conv', "parameters['w5']"], {}), "(flattened_conv, parameters['w5'])\n", (3656, 3690), True, 'import tensorflow as tf\n'), ((3745, 3777), 'tensorflow.matmul', 'tf.matmul', (['fc1', "parameters['w6']"], {}), "(fc1, parameters['w6'])\n", (3754, 3777), True, 'import tensorflow as tf\n'), ((744, 806), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (775, 806), True, 'import tensorflow as tf\n'), ((909, 971), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (940, 971), True, 'import tensorflow as tf\n'), ((1074, 1136), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (1105, 1136), True, 'import tensorflow as tf\n'), ((1239, 1301), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (1270, 1301), True, 'import tensorflow as tf\n'), ((1401, 1463), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (1432, 1463), True, 'import tensorflow as tf\n'), ((1562, 1624), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (1593, 1624), True, 'import tensorflow as tf\n'), ((1722, 1784), 'tensorflow.truncated_normal_initializer', 'tf.truncated_normal_initializer', ([], {'stddev': '(0.05)', 'dtype': 'tf.float32'}), '(stddev=0.05, dtype=tf.float32)\n', (1753, 1784), True, 'import tensorflow as tf\n'), ((1842, 1870), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.0)'], {}), '(0.0)\n', (1865, 1870), True, 'import tensorflow as tf\n'), ((1945, 1973), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.0)'], {}), '(0.0)\n', (1968, 1973), True, 'import tensorflow as tf\n'), ((2048, 2076), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.0)'], {}), '(0.0)\n', (2071, 2076), True, 'import tensorflow as tf\n'), ((2151, 2179), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.0)'], {}), '(0.0)\n', (2174, 2179), True, 'import tensorflow as tf\n'), ((2255, 2283), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.1)'], {}), '(0.1)\n', (2278, 2283), True, 'import tensorflow as tf\n'), ((2359, 2387), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.1)'], {}), '(0.1)\n', (2382, 2387), True, 'import tensorflow as tf\n'), ((2462, 2490), 'tensorflow.constant_initializer', 'tf.constant_initializer', (['(0.0)'], {}), '(0.0)\n', (2485, 2490), True, 'import tensorflow as tf\n')]
import urwid from scronsole.config_manager import ConfigManager from scronsole.plugin_manager import PluginManager from scronsole.widgets.main_menu import MainMenu from scronsole.widgets.server_screen import ServerScreen class MainScreen(urwid.WidgetPlaceholder): def __init__(self): super().__init__(urwid.SolidFill(u'/')) self.config = ConfigManager() self.show_main_menu() self.plugins = PluginManager(self) self.plugins.load_plugins() def show_server_screen(self, server_data): self.original_widget = ServerScreen(self, server_data) def show_main_menu(self): self.original_widget = MainMenu(self)
[ "urwid.SolidFill", "scronsole.config_manager.ConfigManager", "scronsole.widgets.main_menu.MainMenu", "scronsole.widgets.server_screen.ServerScreen", "scronsole.plugin_manager.PluginManager" ]
[((361, 376), 'scronsole.config_manager.ConfigManager', 'ConfigManager', ([], {}), '()\n', (374, 376), False, 'from scronsole.config_manager import ConfigManager\n'), ((430, 449), 'scronsole.plugin_manager.PluginManager', 'PluginManager', (['self'], {}), '(self)\n', (443, 449), False, 'from scronsole.plugin_manager import PluginManager\n'), ((565, 596), 'scronsole.widgets.server_screen.ServerScreen', 'ServerScreen', (['self', 'server_data'], {}), '(self, server_data)\n', (577, 596), False, 'from scronsole.widgets.server_screen import ServerScreen\n'), ((659, 673), 'scronsole.widgets.main_menu.MainMenu', 'MainMenu', (['self'], {}), '(self)\n', (667, 673), False, 'from scronsole.widgets.main_menu import MainMenu\n'), ((316, 337), 'urwid.SolidFill', 'urwid.SolidFill', (['u"""/"""'], {}), "(u'/')\n", (331, 337), False, 'import urwid\n')]
import re from csv import reader def splitEscaped(str, by, escapeChar): infile = [str] return reader(infile, delimiter=by, quotechar=escapeChar) def removeComments(text): p = r'/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|\'(\\.|[^\'\\])*\'|.[^/"\'\\]*)' return ''.join(m.group(2) for m in re.finditer(p, text, re.M|re.S) if m.group(2)) def escapeAnnotations(text): return re.sub(r'(/\*@)(.*)(\*/)',r'@\2',text)
[ "re.sub", "csv.reader", "re.finditer" ]
[((103, 153), 'csv.reader', 'reader', (['infile'], {'delimiter': 'by', 'quotechar': 'escapeChar'}), '(infile, delimiter=by, quotechar=escapeChar)\n', (109, 153), False, 'from csv import reader\n'), ((397, 438), 're.sub', 're.sub', (['"""(/\\\\*@)(.*)(\\\\*/)"""', '"""@\\\\2"""', 'text'], {}), "('(/\\\\*@)(.*)(\\\\*/)', '@\\\\2', text)\n", (403, 438), False, 'import re\n'), ((309, 342), 're.finditer', 're.finditer', (['p', 'text', '(re.M | re.S)'], {}), '(p, text, re.M | re.S)\n', (320, 342), False, 'import re\n')]
#!/usr/bin/python from ConfigUtils import getBaseConfig from LogUtils import getModuleLogger from StringUtils import isValidUrl, randomString from urlparse import urlparse import json import os import requests import sys cDir = os.path.dirname(os.path.realpath(__file__)) rootDir = os.path.abspath(os.path.join(cDir, os.pardir)) baseConfig = getBaseConfig(rootDir) logging = getModuleLogger(__name__) def getMalShareList(): try: payload = {'action': 'getsourcesraw', 'api_key': baseConfig.malShareApiKey } userAgent = {'User-agent': baseConfig.userAgent} logging.info('Fetching latest MalShare list.') request = requests.get('http://malshare.com/api.php', params=payload, headers=userAgent) if request.status_code == 200: mal_list = [] for line in request.content.split('\n'): url = line.strip() if isValidUrl(url): mal_list.append(url) return mal_list else: logging.error('Problem connecting to MalShare. Status code:{0}. Please try again later.'.format(request.status_code)) except requests.exceptions.ConnectionError as e: logging.warning('Problem connecting to Malshare. Error: {0}'.format(e)) except Exception as e: logging.warning('Problem connecting to Malshare. Aborting task.') logging.exception(sys.exc_info()) logging.exception(type(e)) logging.exception(e.args) logging.exception(e) return []
[ "os.path.join", "requests.get", "ConfigUtils.getBaseConfig", "os.path.realpath", "LogUtils.getModuleLogger", "StringUtils.isValidUrl", "sys.exc_info" ]
[((346, 368), 'ConfigUtils.getBaseConfig', 'getBaseConfig', (['rootDir'], {}), '(rootDir)\n', (359, 368), False, 'from ConfigUtils import getBaseConfig\n'), ((379, 404), 'LogUtils.getModuleLogger', 'getModuleLogger', (['__name__'], {}), '(__name__)\n', (394, 404), False, 'from LogUtils import getModuleLogger\n'), ((248, 274), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (264, 274), False, 'import os\n'), ((302, 331), 'os.path.join', 'os.path.join', (['cDir', 'os.pardir'], {}), '(cDir, os.pardir)\n', (314, 331), False, 'import os\n'), ((656, 734), 'requests.get', 'requests.get', (['"""http://malshare.com/api.php"""'], {'params': 'payload', 'headers': 'userAgent'}), "('http://malshare.com/api.php', params=payload, headers=userAgent)\n", (668, 734), False, 'import requests\n'), ((909, 924), 'StringUtils.isValidUrl', 'isValidUrl', (['url'], {}), '(url)\n', (919, 924), False, 'from StringUtils import isValidUrl, randomString\n'), ((1418, 1432), 'sys.exc_info', 'sys.exc_info', ([], {}), '()\n', (1430, 1432), False, 'import sys\n')]
from attempt.ddpg import HERDDPG, DDPG import gym import os import matplotlib.pyplot as plt import numpy as np from tqdm import tqdm if __name__ == "__main__": os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' env = gym.make('FetchReach-v1') agent = HERDDPG(env) for epoch in range(2): for cycle in tqdm(range(10)): agent.gather_cycle() # target_agent.train() agent.test_env(10) env.close() plt.plot(np.vstack(agent.rewards)) plt.title('Rewards') plt.show() plt.plot(np.vstack(agent.policy_losses)) plt.title('Policy Losses') plt.show() plt.plot(np.vstack(agent.value_losses)) plt.title('Value Losses') plt.show()
[ "attempt.ddpg.HERDDPG", "numpy.vstack", "matplotlib.pyplot.title", "gym.make", "matplotlib.pyplot.show" ]
[((219, 244), 'gym.make', 'gym.make', (['"""FetchReach-v1"""'], {}), "('FetchReach-v1')\n", (227, 244), False, 'import gym\n'), ((257, 269), 'attempt.ddpg.HERDDPG', 'HERDDPG', (['env'], {}), '(env)\n', (264, 269), False, 'from attempt.ddpg import HERDDPG, DDPG\n'), ((488, 508), 'matplotlib.pyplot.title', 'plt.title', (['"""Rewards"""'], {}), "('Rewards')\n", (497, 508), True, 'import matplotlib.pyplot as plt\n'), ((513, 523), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (521, 523), True, 'import matplotlib.pyplot as plt\n'), ((574, 600), 'matplotlib.pyplot.title', 'plt.title', (['"""Policy Losses"""'], {}), "('Policy Losses')\n", (583, 600), True, 'import matplotlib.pyplot as plt\n'), ((605, 615), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (613, 615), True, 'import matplotlib.pyplot as plt\n'), ((665, 690), 'matplotlib.pyplot.title', 'plt.title', (['"""Value Losses"""'], {}), "('Value Losses')\n", (674, 690), True, 'import matplotlib.pyplot as plt\n'), ((695, 705), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (703, 705), True, 'import matplotlib.pyplot as plt\n'), ((458, 482), 'numpy.vstack', 'np.vstack', (['agent.rewards'], {}), '(agent.rewards)\n', (467, 482), True, 'import numpy as np\n'), ((538, 568), 'numpy.vstack', 'np.vstack', (['agent.policy_losses'], {}), '(agent.policy_losses)\n', (547, 568), True, 'import numpy as np\n'), ((630, 659), 'numpy.vstack', 'np.vstack', (['agent.value_losses'], {}), '(agent.value_losses)\n', (639, 659), True, 'import numpy as np\n')]
#!/usr/bin/env python # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Written (W) 2008-2009 <NAME> # Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max Planck Society class_str='class' types=["BOOL", "CHAR", "INT8", "UINT8", "INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64", "FLOAT32", "FLOAT64", "FLOATMAX", "COMPLEX128"] config_tests=["HAVE_HDF5", "HAVE_JSON", "HAVE_XML", "HAVE_LAPACK", "USE_CPLEX", "USE_SVMLIGHT", "USE_GLPK", "USE_LZO", "USE_GZIP", "USE_BZIP2", "USE_LZMA", "USE_MOSEK", "HAVE_EIGEN3", "HAVE_COLPACK", "HAVE_NLOPT", "HAVE_PROTOBUF", "HAVE_VIENNACL"] SHOGUN_TEMPLATE_CLASS = "SHOGUN_TEMPLATE_CLASS" SHOGUN_BASIC_CLASS = "SHOGUN_BASIC_CLASS" def check_class(line): if not (line.find('public')==-1 and line.find('private')==-1 and line.find('protected')==-1): return True def check_abstract_class(line): line=line.replace(' ','').replace('\t','').strip() return line.endswith('=0;') def check_is_in_blacklist(c, lines, line_nr, blacklist): ifdef_cnt=0 for i in range(line_nr,0,-1): line=lines[i] if line.find('#endif')!=-1: ifdef_cnt-=1 if line.find('#ifdef')!=-1: ifdef_cnt+=1 for b in blacklist.keys(): if line.find(b)!=-1 and ifdef_cnt>0: return True if line.find('#ifndef')!=-1: ifdef_cnt+=1 return False def extract_class_name(lines, line_nr, line, blacklist): try: if not line: line=lines[line_nr] c=line[line.index(class_str)+len(class_str):] if not ':' in c: return if not check_class(line): if not check_class(lines[line_nr+1]): return c=c.split()[0] except: return c=c.strip(':').strip() if not c.startswith('C'): return if c.endswith(';'): return if '>' in c: return if not (len(c)>2 and c[1].isupper()): return if check_is_in_blacklist(c[1:], lines, line_nr, blacklist): return return c[1:] def get_includes(classes): class_headers = [] for c,t in classes: class_headers.append(c+".h") import os result = [] for root, dirs, files in os.walk("."): for f in files: if f in class_headers: result.append(os.path.join(root, f)) includes=[] for o in result: includes.append('#include <shogun/%s>' % o.strip().lstrip('./')) return includes def get_definitions(classes): definitions=[] definitions.append("#define %s" % SHOGUN_TEMPLATE_CLASS) definitions.append("#define %s" % SHOGUN_BASIC_CLASS) for c,t in classes: d="static %s CSGObject* __new_C%s(EPrimitiveType g) { return g == PT_NOT_GENERIC? new C%s(): NULL; }" % (SHOGUN_BASIC_CLASS,c,c) definitions.append(d) return definitions def get_template_definitions(classes, supports_complex): definitions=[] for c,t in classes: d=[] d.append("static %s CSGObject* __new_C%s(EPrimitiveType g)\n{\n\tswitch (g)\n\t{\n" % (SHOGUN_TEMPLATE_CLASS,c)) for t in types: if t in ('BOOL','CHAR'): suffix='' else: suffix='_t' if t=='COMPLEX128' and not supports_complex: d.append("\t\tcase PT_COMPLEX128: return NULL;\n") else: d.append("\t\tcase PT_%s: return new C%s<%s%s>();\n" % (t,c,t.lower(),suffix)) d.append("\t\tcase PT_SGOBJECT:\n") d.append("\t\tcase PT_UNDEFINED: return NULL;\n\t}\n\treturn NULL;\n}") definitions.append(''.join(d)) return definitions def get_struct(classes): struct=[] for c,template in classes: prefix = SHOGUN_BASIC_CLASS if template: prefix = SHOGUN_TEMPLATE_CLASS s='{"%s", %s __new_C%s},' % (c,prefix,c) struct.append(s) return struct def extract_block(c, lines, start_line, stop_line, start_sym, stop_sym): sym_cnt=0 block_start=-1; block_stop=-1; for line_nr in range(start_line, stop_line): line=lines[line_nr] if line.find(start_sym)!=-1: sym_cnt+=1 if block_start==-1: block_start=line_nr if line.find(stop_sym)!=-1: block_stop=line_nr+1 sym_cnt-=1 if sym_cnt==0 and block_start!=-1 and block_stop!=-1: return block_start,block_stop return block_start,block_stop def check_complex_supported_class(line): l=list(filter(lambda y:y if y!='' else None,\ line.strip().replace('\t',' ').split(' '))) supported=len(l)==3 and l[0]=='typedef' and l[1]=='bool'\ and l[2]=='supports_complex128_t;' return supported def test_candidate(c, lines, line_nr, supports_complex): start,stop=extract_block(c, lines, line_nr, len(lines), '{','}') if stop<line_nr: return False, line_nr+1 complex_supported=False for line_nr in range(start, stop): line=lines[line_nr] if line.find('virtual')!=-1: if check_abstract_class(line): return False, stop else: vstart,vstop=extract_block(c, lines, line_nr, stop, '(',')') for line_nr in range(vstart, vstop): line=lines[line_nr] if check_abstract_class(line): return False, stop if line.find('supports_complex128_t')!=-1: if check_complex_supported_class(line): complex_supported=True if not supports_complex: return False, stop if supports_complex and not complex_supported: return False, stop return True, stop def extract_classes(HEADERS, template, blacklist, supports_complex): """ Search in headers for non-template/non-abstract class-names starting with `C'. Does not support local nor multiple classes and drops classes with pure virtual functions """ classes=list() for fname in HEADERS: try: lines=open(fname).readlines() except: # python3 workaround lines=open(fname, encoding='utf-8', errors='ignore').readlines() line_nr=0 while line_nr<len(lines): line=lines[line_nr] if line.find('IGNORE_IN_CLASSLIST')!=-1: line_nr+=1 continue c=None if template: tp=line.find('template') if tp!=-1: line=line[tp:] cp=line.find('>') line=line[cp+1:] cp=line.find(class_str) if cp!=-1: c=extract_class_name(lines, line_nr, line, blacklist) else: if line.find(class_str)!=-1: c=extract_class_name(lines, line_nr, None, blacklist) if c: ok, line_nr=test_candidate(c, lines, line_nr, supports_complex) if ok: classes.append((c,template)) continue line_nr+=1 return classes def write_templated_file(fname, substitutes): template=open(fname).readlines() f=open(fname,'w') for line in template: l=line.strip() if l.startswith('REPLACE') and l.endswith('THIS'): l=line.split()[1] if sys.version_info >= (3,): for s in substitutes.keys(): if l==s: f.write('\n'.join(substitutes[s])) continue else: for s in substitutes.iterkeys(): if l==s: f.write('\n'.join(substitutes[s])) continue else: f.write(line) def read_config(): config=dict() for line in open('lib/config.h').readlines(): if line=='\n': continue l=[l.strip() for l in line.split()] config[l[1]]=1 return config def get_blacklist(): config=read_config() blacklist=dict() for cfg in config_tests: if not cfg in config: blacklist[cfg]=1 return blacklist if __name__=='__main__': import sys TEMPL_FILE=sys.argv[1] HEADERS=None if (sys.argv[2] == "-in"): # read header file list from file with open(sys.argv[3]) as f: content = f.readlines() HEADERS = [x.strip() for x in content] else: HEADERS=sys.argv[2:] blacklist = get_blacklist() classes = extract_classes(HEADERS, False, blacklist, False) template_classes = extract_classes(HEADERS, True, blacklist, False) complex_template_classes = extract_classes(HEADERS, True, blacklist, True) includes = get_includes(classes+template_classes+complex_template_classes) definitions = get_definitions(classes) template_definitions = get_template_definitions(template_classes, False) complex_template_definitions = get_template_definitions(complex_template_classes, True) struct = get_struct(classes+template_classes+complex_template_classes) substitutes = {'includes': includes, 'definitions' :definitions, 'template_definitions' : template_definitions, 'complex_template_definitions' : complex_template_definitions, 'struct' : struct } write_templated_file(TEMPL_FILE, substitutes)
[ "os.path.join", "os.walk" ]
[((2195, 2207), 'os.walk', 'os.walk', (['"""."""'], {}), "('.')\n", (2202, 2207), False, 'import os\n'), ((2271, 2292), 'os.path.join', 'os.path.join', (['root', 'f'], {}), '(root, f)\n', (2283, 2292), False, 'import os\n')]
"""Main farm access.""" from __future__ import annotations import os from datetime import datetime from typing import Dict, Iterable, Iterator, List, Type, Union from farmos_ext.area import Area from farmos_ext.asset import Asset, Equipment, Planting from farmos_ext.log import (Activity, Birth, Harvest, Input, Log, Maintenance, Medical, Observation, Purchase, Sale, Seeding, SoilTest, Transplanting) from farmos_ext.others import Content, Quantity from farmos_ext.term import Crop, CropFamily, Season, Term, Unit from farmOS import farmOS # pylint: disable=wrong-import-order from farmOS.client import BaseAPI # pylint: disable=wrong-import-order class FarmTypeMissingError(Exception): pass def farm(): """Access to farm with provided credentials.""" return Farm() class FileAPI(BaseAPI): def __init__(self, session): # Define 'log' as the farmOS API entity endpoint super().__init__(session=session, entity_type='file') # pylint: disable=too-many-public-methods class Farm(farmOS): def __init__(self, local_resources="./resources"): self._host = None self._user = None self._pass = None self.local_resources = local_resources if os.path.exists("farmos.cfg"): with open('farmos.cfg') as cfg: for line in cfg.readlines(): if line.startswith("HOST"): self._host = line[line.index("=")+1:].strip() if line.startswith("USER"): self._user = line[line.index("=")+1:].strip() if line.startswith("PASS"): self._pass = line[line.index("=")+1:].strip() if not self._host: raise KeyError("HOST key is not defined in farmos.cfg") if not self._user: raise KeyError("USER key is not defined in farmos.cfg") if not self._pass: raise KeyError("PASS key is not defined in farmos.cfg") super().__init__(self._host) self._token = self.authorize(self._user, self._pass) else: raise Exception('farmos.cfg not found.') self.file = FileAPI(self.session) def assets(self, filters: Union[Dict, List[Dict], int, str] = None, asset_class: Type[Asset] = Asset) -> Iterator[Type[Asset]]: if isinstance(filters, list): for filt in filters: for asset in self.asset.get(filt)['list']: yield asset_class(self, keys=asset) else: for asset in self.asset.get(filters)['list']: yield asset_class(self, keys=asset) # def _get_assets(self, items: List[Dict], obj_class): # retitems = [] # for item in items: # rets = self.asset.get(item['id']) # if 'list' in rets: # self.extract(rets, obj_class) # else: # retitems.append(obj_class(self, rets)) # return retitems def logs(self, filters: Union[Dict, List[Dict], int, str] = None, log_class: Type[Log] = Log) -> Iterator[Type[Log]]: if isinstance(filters, list): for filt in filters: for log in self.log.get(filt): yield log_class(self, keys=log) elif isinstance(filters, int): yield log_class(self, keys=self.log.get(filters)) else: for log in self.log.get(filters): yield log_class(self, keys=log) def terms(self, filters: Union[str, List[Dict], Dict] = None, term_class: Type[Term] = Term) -> Iterator[Type[Term]]: if isinstance(filters, list): for item in filters: for term in self.term.get({"tid": item['id']})['list']: yield term_class(self, keys=term) else: rets = self.term.get(filters) yield term_class(self, keys=rets) def areas(self, filters: Union[Dict, List[Dict], int, str] = None) -> Iterator[Area]: if isinstance(filters, list): for filt in filters: for area in self.area.get(filt)['list']: yield Area(self, keys=area) else: for area in self.area.get(filters)['list']: yield Area(self, keys=area) def _create_log(self, name: str, date: datetime, category: str, fields: Dict, done=False): data = { "name": name, "timestamp": str(int(datetime.timestamp(date))), "log_category": [{ "name": category }], "type": "farm_observation" } data.update(fields) if 'done' not in data: data['done'] = '1' if done else '0' ret = self.log.send(data) return ret @property def content(self) -> Content: return Content(self, keys=self.info()) @property def seasons(self) -> Iterator[Season]: for season in self.term.get("farm_season")['list']: yield Season(self, season) @property def crop_families(self) -> Iterator[CropFamily]: for fam in self.term.get("farm_crop_families")['list']: yield CropFamily(self, keys=fam) @property def crops(self) -> Iterator[Crop]: for crop in self.term.get("farm_crops")['list']: yield Crop(self, crop) def equipment(self, filters: Dict = None) -> Iterable[Equipment]: if not filters: filters = {'type': 'equipment'} else: filters.update({'type': 'equipment'}) return self.assets(filters, Equipment) def plantings(self, filters: Dict = None) -> Iterable[Planting]: if not filters: filters = {'type': 'planting'} else: filters.update({'type': 'planting'}) return self.assets(filters, Planting) @property def units(self) -> Iterable[Unit]: for unit in self.term.get('farm_quantity_units')['list']: yield Unit(self, unit) def harvests(self, filters: Dict = None) -> Iterable[Harvest]: if 'farm_harvests' in self.content.resources['log']: if not filters: filters = {'type': 'farm_harvest'} else: filters.update({'type': 'farm_harvest'}) return self.logs(filters, Harvest) else: raise FarmTypeMissingError("Harvest logs not supported.") def seedings(self, filters: Dict = None) -> Iterable[Seeding]: if 'farm_seedings' in self.content.resources['log']: if not filters: filters = {'type': 'farm_seeding'} else: filters.update({'type': 'farm_seeding'}) return self.logs(filters, Seeding) else: raise FarmTypeMissingError("Seeding logs not supported.") def transplants(self, filters: Dict = None) -> Iterable[Transplanting]: if 'farm_transplanting' in self.content.resources['log']: if not filters: filters = {'type': 'farm_transplanting'} else: filters.update({'type': 'farm_transplanting'}) return self.logs(filters, Transplanting) else: raise FarmTypeMissingError("Transplanting logs not supported.") def observations(self, filters: Dict = None) -> Iterable[Observation]: if 'farm_observation' in self.content.resources['log']: if not filters: filters = {'type': 'farm_observation'} else: filters.update({'type': 'farm_observation'}) return self.logs(filters, Observation) else: raise FarmTypeMissingError("Observation logs not supported.") def maintenances(self, filters: Dict = None) -> Iterator[Maintenance]: if 'farm_maintenance' in self.content.resources['log']: if not filters: filters = {'type': 'farm_maintenance'} else: filters.update({'type': 'farm_maintenance'}) return self.logs(filters, Maintenance) else: raise FarmTypeMissingError("Maintenance logs not supported.") def purchases(self, filters: Dict = None) -> Iterator[Purchase]: if 'farm_purchase' in self.content.resources['log']: if not filters: filters = {'type': 'farm_purchase'} else: filters.update({'type': 'farm_purchase'}) return self.logs(filters, Purchase) else: raise FarmTypeMissingError("Purchase logs not supported.") def sales(self, filters: Dict = None) -> Iterator[Sale]: if 'farm_sale' in self.content.resources['log']: if not filters: filters = {'type': 'farm_sale'} else: filters.update({'type': 'farm_sale'}) return self.logs(filters, Sale) else: raise FarmTypeMissingError("Sale logs not supported.") def births(self, filters: Dict = None) -> Iterator[Birth]: if 'farm_birth' in self.content.resources['log']: if not filters: filters = {'type': 'farm_birth'} else: filters.update({'type': 'farm_birth'}) return self.logs(filters, Birth) else: raise FarmTypeMissingError("Birth logs not supported.") def inputs(self, filters: Dict = None) -> Iterator[Input]: if 'farm_input' in self.content.resources['input']: if not filters: filters = {'type': 'farm_input'} else: filters.update({'type': 'farm_input'}) return self.logs(filters, Input) else: raise FarmTypeMissingError("Input logs not supported.") def soil_tests(self, filters: Dict = None) -> Iterator[SoilTest]: if 'farm_soil_test' in self.content.resources['log']: if not filters: filters = {'type': 'farm_soil_test'} else: filters.update({'type': 'farm_soil_test'}) return self.logs(filters, SoilTest) else: raise FarmTypeMissingError("Soil test logs not supported.") def activities(self, filters: Dict = None) -> Iterator[Activity]: if 'farm_activity' in self.content.resources['log']: if not filters: filters = {'type': 'farm_activity'} else: filters.update({'type': 'farm_activity'}) return self.logs(filters, Activity) else: raise FarmTypeMissingError("Activity logs not supported.") def medicals(self, filters: Dict = None) -> Iterator[Medical]: if 'farm_medical' in self.content.resources['log']: if not filters: filters = {'type': 'farm_medical'} else: filters.update({'type': 'farm_medical'}) return self.logs(filters, Medical) else: raise FarmTypeMissingError("Medical logs are not supported.") def create_planting(self, crop: Crop, season: str, location: str) -> Planting: ret = self.asset.send({ "name": "{} {} {}".format(season, location, crop.name), "type": "planting", "crop": [ { "id": crop.tid } ], "season": [{"name": season}] }) plant = Planting(self, keys=ret) return plant def create_seeding(self, planting: Planting, location: Area, crop: Crop, date: datetime, seeds: int, source=None, done=False) -> Seeding: name = "Seed {} {} {}".format(date.year, location.name, crop.name) fields = { "type": "farm_seeding", "asset": [ { "id": planting.id, "resource": "taxonomy_term" } ], "seed_source": source, "movement": { "area": [ { "id": location.tid, "resource": "taxonomy_term" } ] }, "quantity": [ { "measure": "count", "value": str(seeds), "unit": { 'name': 'Seeds', "resource": "taxonomy_term" } } ] } ret = self._create_log(name, date, 'Plantings', fields, done=done) return Seeding(self, keys=ret) def create_transplant(self, planting: Planting, location: Area, date: datetime, fields=None, done=False): name = "Transplant {}".format(planting.name) data = { "type": "farm_transplanting", "movement": { "area": [ { "id": location.tid, "resource": "taxonomy_term" } ] }, "asset": [ { "id": planting.id, "resource": "taxonomy_term" } ] } if fields: data.update(fields) ret = self._create_log(name, date, 'Plantings', data, done=done) return Transplanting(self, ret) def create_harvest(self, planting: Planting, date: datetime, quantities: List[Quantity], done=False): name = "Harvest {} {}".format(date.year, planting.crop[0]['name']) data = { "type": "farm_harvest", "asset": [{ "id": planting.id, "resource": "taxonomy_term" }] } if quantities: data["quantity"] = [] for quantity in quantities: data["quantity"].append(quantity.to_dict()) ret = self._create_log(name, date, 'Plantings', data, done=done) return Harvest(self, ret) def create_log(self, name: str, date: datetime, category: str, fields: Dict, done=False): return Log(self, self._create_log(name, date, category, fields, done))
[ "farmos_ext.term.CropFamily", "os.path.exists", "farmos_ext.term.Season", "farmos_ext.term.Crop", "farmos_ext.area.Area", "farmos_ext.log.Seeding", "farmos_ext.asset.Planting", "farmos_ext.log.Transplanting", "datetime.datetime.timestamp", "farmos_ext.term.Unit", "farmos_ext.log.Harvest" ]
[((1280, 1308), 'os.path.exists', 'os.path.exists', (['"""farmos.cfg"""'], {}), "('farmos.cfg')\n", (1294, 1308), False, 'import os\n'), ((11585, 11609), 'farmos_ext.asset.Planting', 'Planting', (['self'], {'keys': 'ret'}), '(self, keys=ret)\n', (11593, 11609), False, 'from farmos_ext.asset import Asset, Equipment, Planting\n'), ((12750, 12773), 'farmos_ext.log.Seeding', 'Seeding', (['self'], {'keys': 'ret'}), '(self, keys=ret)\n', (12757, 12773), False, 'from farmos_ext.log import Activity, Birth, Harvest, Input, Log, Maintenance, Medical, Observation, Purchase, Sale, Seeding, SoilTest, Transplanting\n'), ((13531, 13555), 'farmos_ext.log.Transplanting', 'Transplanting', (['self', 'ret'], {}), '(self, ret)\n', (13544, 13555), False, 'from farmos_ext.log import Activity, Birth, Harvest, Input, Log, Maintenance, Medical, Observation, Purchase, Sale, Seeding, SoilTest, Transplanting\n'), ((14166, 14184), 'farmos_ext.log.Harvest', 'Harvest', (['self', 'ret'], {}), '(self, ret)\n', (14173, 14184), False, 'from farmos_ext.log import Activity, Birth, Harvest, Input, Log, Maintenance, Medical, Observation, Purchase, Sale, Seeding, SoilTest, Transplanting\n'), ((5161, 5181), 'farmos_ext.term.Season', 'Season', (['self', 'season'], {}), '(self, season)\n', (5167, 5181), False, 'from farmos_ext.term import Crop, CropFamily, Season, Term, Unit\n'), ((5332, 5358), 'farmos_ext.term.CropFamily', 'CropFamily', (['self'], {'keys': 'fam'}), '(self, keys=fam)\n', (5342, 5358), False, 'from farmos_ext.term import Crop, CropFamily, Season, Term, Unit\n'), ((5488, 5504), 'farmos_ext.term.Crop', 'Crop', (['self', 'crop'], {}), '(self, crop)\n', (5492, 5504), False, 'from farmos_ext.term import Crop, CropFamily, Season, Term, Unit\n'), ((6139, 6155), 'farmos_ext.term.Unit', 'Unit', (['self', 'unit'], {}), '(self, unit)\n', (6143, 6155), False, 'from farmos_ext.term import Crop, CropFamily, Season, Term, Unit\n'), ((4418, 4439), 'farmos_ext.area.Area', 'Area', (['self'], {'keys': 'area'}), '(self, keys=area)\n', (4422, 4439), False, 'from farmos_ext.area import Area\n'), ((4612, 4636), 'datetime.datetime.timestamp', 'datetime.timestamp', (['date'], {}), '(date)\n', (4630, 4636), False, 'from datetime import datetime\n'), ((4304, 4325), 'farmos_ext.area.Area', 'Area', (['self'], {'keys': 'area'}), '(self, keys=area)\n', (4308, 4325), False, 'from farmos_ext.area import Area\n')]
from telegram.ext import * from telegram import * import time def start(update, context): context.bot.send_message(chat_id=update.effective_chat.id, text="Hi 👋 I'm Rinkoglionito and I'm here because @OnyyTheBest had nothing to do ;-;. \n that said do the /cmds command to see the available commands") chat_user_id = update.message.from_user.id more_lines = [str(chat_user_id)+"\n"] if str(chat_user_id)+"\n" not in open("users.txt", 'r'): with open('users.txt', 'a') as f: f.writelines('\n'.join(more_lines)) f.close() else: return def YAAA(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text="Why you don't say YAAA?") context.bot.send_video(chat_id=update.effective_chat.id, video="https://onyymexicancat.github.io/RinkoglionitoBot/mediafile/video/meme/01.mp4") def BASTARDI(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text="🗣 Bastardi, chiamo da 🎹 <NAME> 🙉🌸, sono un 👌 assassino di 🅱 meridionali. Vi 💰 ammazzo tutti bastardi pezzi di 🅱 merda 🤬. Porcodio a tutti i 👥 napoletani romani di 👉 merda 🤬 stronzi, siete 🔥 della gente 👨‍👩‍👧‍👦 che ✔ viene schiacciata come 🚌 topi 💰 maledetti stronzi figli di 🅱 una 👌 cagna in calore. Io 🅱 vi 💰 sp ☠.. io 🅱 vi 💰 spacco le 🅰 fighe, le 🅱 ovaie a tutte le 🅱 vostre donne sporche. venite su 🅱, puttane, che ✔ vi 💰 apro lo 💜 sterno e 🇹 vi 💰 mangio il 🏙 cuore e 🇹 poi ve lo 💜 cago nella figa, brutte merde che ✔ non ❌ siete 🔥 altro, sono un 👦👲🏽👌 assassino di 🅱 fkghe.") context.bot.send_audio(chat_id=update.effective_chat.id, audio="https://onyymexicancat.github.io/RinkoglionitoBot/mediafile/audio/meme/01.mp3") def CMDS(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text="comandi attualmente attivi nel bot sono i seguenti \n /Start (Avvia il Bot) \n /BASTARDI (Bastardi chiamo da reggio emilia) \n /YAAA (YAAA KID) \n /CHK (VIP Only CC Checker)\n /vip (pay me xD)\n") def oldupdate(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text=""" -- ✍️@OnyyTheBest -- """, parse_mode="html") def update(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text=""" -- ✍️@OnyyTheBest -- """, parse_mode="html") def commandnotfount(update, context): try: bot_msg = context.bot.send_message(chat_id=update.message.chat_id, text="<b>COMANDO NON TROVATO!</b> usa il comando /cmds per trovare il comando che stai cercando", parse_mode="html") time.sleep(10) context.bot.delete_message(chat_id=update.message.chat_id, message_id=bot_msg.message_id) except: pass def bcast(update: update,context: CallbackContext): if update.effective_chat.id == 476263382: if context.args == []: context.bot.send_message(update.effective_chat.id, text="<b>Please enter the message you want to broadcast to Bot users!</b>", parse_mode="html") else: porco = '' for char in context.args: if char !="[" + "'" + "]": porco += char ciccio = open("users.txt", 'r') for line in ciccio: content = line context.bot.send_message(chat_id=content, text=porco) update.message.reply_text(text="<b>DONE!</b>", parse_mode="html") else: context.bot.send_message(update.effective_chat.id, text="<b>NO PERMS</b>", parse_mode="html")
[ "time.sleep" ]
[((2721, 2735), 'time.sleep', 'time.sleep', (['(10)'], {}), '(10)\n', (2731, 2735), False, 'import time\n')]