content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
""" Django settings for api project. Generated by 'django-admin startproject' using Django 1.8. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ import os from urlparse import urlparse from website import settings as osf_settings BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ DATABASES = { 'default': { 'CONN_MAX_AGE': 0, 'ENGINE': 'osf.db.backends.postgresql', # django.db.backends.postgresql 'NAME': os.environ.get('OSF_DB_NAME', 'osf'), 'USER': os.environ.get('OSF_DB_USER', 'postgres'), 'PASSWORD': os.environ.get('OSF_DB_PASSWORD', ''), 'HOST': os.environ.get('OSF_DB_HOST', '127.0.0.1'), 'PORT': os.environ.get('OSF_DB_PORT', '5432'), 'ATOMIC_REQUESTS': True, 'TEST': { 'SERIALIZE': False, }, }, } DATABASE_ROUTERS = ['osf.db.router.PostgreSQLFailoverRouter', ] PASSWORD_HASHERS = [ 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', ] AUTH_USER_MODEL = 'osf.OSFUser' # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = osf_settings.SECRET_KEY AUTHENTICATION_BACKENDS = ( 'api.base.authentication.backends.ODMBackend', 'guardian.backends.ObjectPermissionBackend', ) # SECURITY WARNING: don't run with debug turned on in production! DEV_MODE = osf_settings.DEV_MODE DEBUG = osf_settings.DEBUG_MODE DEBUG_PROPAGATE_EXCEPTIONS = True # session: SESSION_COOKIE_NAME = 'api' SESSION_COOKIE_SECURE = osf_settings.SECURE_MODE SESSION_COOKIE_HTTPONLY = osf_settings.SESSION_COOKIE_HTTPONLY # csrf: CSRF_COOKIE_NAME = 'api-csrf' CSRF_COOKIE_SECURE = osf_settings.SECURE_MODE CSRF_COOKIE_HTTPONLY = osf_settings.SECURE_MODE ALLOWED_HOSTS = [ '.osf.io', ] # Application definition INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.messages', 'django.contrib.sessions', 'django.contrib.staticfiles', 'django.contrib.admin', # 3rd party 'django_celery_beat', 'django_celery_results', 'rest_framework', 'corsheaders', 'raven.contrib.django.raven_compat', 'django_extensions', 'guardian', 'storages', 'waffle', 'elasticsearch_metrics', # OSF 'osf', # Addons 'addons.osfstorage', 'addons.bitbucket', 'addons.box', 'addons.dataverse', 'addons.dropbox', 'addons.figshare', 'addons.forward', 'addons.github', 'addons.gitlab', 'addons.googledrive', 'addons.mendeley', 'addons.onedrive', 'addons.owncloud', 'addons.s3', 'addons.twofactor', 'addons.wiki', 'addons.zotero', ) # local development using https if osf_settings.SECURE_MODE and DEBUG: INSTALLED_APPS += ('sslserver',) # TODO: Are there more granular ways to configure reporting specifically related to the API? RAVEN_CONFIG = { 'tags': {'App': 'api'}, 'dsn': osf_settings.SENTRY_DSN, 'release': osf_settings.VERSION, } BULK_SETTINGS = { 'DEFAULT_BULK_LIMIT': 100, } MAX_PAGE_SIZE = 100 REST_FRAMEWORK = { 'PAGE_SIZE': 10, 'DEFAULT_RENDERER_CLASSES': ( 'api.base.renderers.JSONAPIRenderer', 'api.base.renderers.JSONRendererWithESISupport', 'api.base.renderers.BrowsableAPIRendererNoForms', ), 'DEFAULT_PARSER_CLASSES': ( 'api.base.parsers.JSONAPIParser', 'api.base.parsers.JSONAPIParserForRegularJSON', 'rest_framework.parsers.FormParser', 'rest_framework.parsers.MultiPartParser', ), 'EXCEPTION_HANDLER': 'api.base.exceptions.json_api_exception_handler', 'DEFAULT_CONTENT_NEGOTIATION_CLASS': 'api.base.content_negotiation.JSONAPIContentNegotiation', 'DEFAULT_VERSIONING_CLASS': 'api.base.versioning.BaseVersioning', 'DEFAULT_VERSION': '2.0', 'ALLOWED_VERSIONS': ( '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9', '2.10', '2.11', '2.12', '2.13', '2.14', '2.15', '2.16', '2.17', ), 'DEFAULT_FILTER_BACKENDS': ('api.base.filters.OSFOrderingFilter',), 'DEFAULT_PAGINATION_CLASS': 'api.base.pagination.JSONAPIPagination', 'ORDERING_PARAM': 'sort', 'DEFAULT_AUTHENTICATION_CLASSES': ( # Custom auth classes 'api.base.authentication.drf.OSFBasicAuthentication', 'api.base.authentication.drf.OSFSessionAuthentication', 'api.base.authentication.drf.OSFCASAuthentication', ), 'DEFAULT_THROTTLE_CLASSES': ( 'rest_framework.throttling.UserRateThrottle', 'api.base.throttling.NonCookieAuthThrottle', ), 'DEFAULT_THROTTLE_RATES': { 'user': '10000/day', 'non-cookie-auth': '100/hour', 'add-contributor': '10/second', 'create-guid': '1000/hour', 'root-anon-throttle': '1000/hour', 'test-user': '2/hour', 'test-anon': '1/hour', 'send-email': '2/minute', }, } # Settings related to CORS Headers addon: allow API to receive authenticated requests from OSF # CORS plugin only matches based on "netloc" part of URL, so as workaround we add that to the list CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_WHITELIST = ( urlparse(osf_settings.DOMAIN).netloc, osf_settings.DOMAIN, ) # This needs to remain True to allow cross origin requests that are in CORS_ORIGIN_WHITELIST to # use cookies. CORS_ALLOW_CREDENTIALS = True # Set dynamically on app init ORIGINS_WHITELIST = () MIDDLEWARE = ( 'api.base.middleware.DjangoGlobalMiddleware', 'api.base.middleware.CeleryTaskMiddleware', 'api.base.middleware.PostcommitTaskMiddleware', # A profiling middleware. ONLY FOR DEV USE # Uncomment and add "prof" to url params to recieve a profile for that url # 'api.base.middleware.ProfileMiddleware', # 'django.contrib.sessions.middleware.SessionMiddleware', 'api.base.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', # 'django.contrib.auth.middleware.AuthenticationMiddleware', # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', # 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'waffle.middleware.WaffleMiddleware', ) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, }, ] ROOT_URLCONF = 'api.base.urls' WSGI_APPLICATION = 'api.base.wsgi.application' LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # https://django-storages.readthedocs.io/en/latest/backends/gcloud.html if os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', False): # Required to interact with Google Cloud Storage DEFAULT_FILE_STORAGE = 'api.base.storage.RequestlessURLGoogleCloudStorage' GS_BUCKET_NAME = os.environ.get('GS_BUCKET_NAME', 'cos-osf-stage-cdn-us') GS_FILE_OVERWRITE = os.environ.get('GS_FILE_OVERWRITE', False) elif osf_settings.DEV_MODE or osf_settings.DEBUG_MODE: DEFAULT_FILE_STORAGE = 'api.base.storage.DevFileSystemStorage' # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_ROOT = os.path.join(BASE_DIR, 'static/vendor') API_BASE = 'v2/' API_PRIVATE_BASE = '_/' STATIC_URL = '/static/' NODE_CATEGORY_MAP = osf_settings.NODE_CATEGORY_MAP DEBUG_TRANSACTIONS = DEBUG JWT_SECRET = 'osf_api_cas_login_jwt_secret_32b' JWE_SECRET = 'osf_api_cas_login_jwe_secret_32b' ENABLE_VARNISH = osf_settings.ENABLE_VARNISH ENABLE_ESI = osf_settings.ENABLE_ESI VARNISH_SERVERS = osf_settings.VARNISH_SERVERS ESI_MEDIA_TYPES = osf_settings.ESI_MEDIA_TYPES ADDONS_FOLDER_CONFIGURABLE = ['box', 'dropbox', 's3', 'googledrive', 'figshare', 'owncloud', 'onedrive'] ADDONS_OAUTH = ADDONS_FOLDER_CONFIGURABLE + ['dataverse', 'github', 'bitbucket', 'gitlab', 'mendeley', 'zotero', 'forward'] BYPASS_THROTTLE_TOKEN = 'test-token' OSF_SHELL_USER_IMPORTS = None # Settings for use in the admin OSF_URL = 'https://osf.io' SELECT_FOR_UPDATE_ENABLED = True # Disable anonymous user permissions in django-guardian ANONYMOUS_USER_NAME = None # If set to True, automated tests with extra queries will fail. NPLUSONE_RAISE = False # salt used for generating hashids HASHIDS_SALT = 'pinkhimalayan' # django-elasticsearch-metrics ELASTICSEARCH_DSL = { 'default': { 'hosts': os.environ.get('ELASTIC6_URI', '127.0.0.1:9201'), 'retry_on_timeout': True, }, } # Store yearly indices for time-series metrics ELASTICSEARCH_METRICS_DATE_FORMAT = '%Y' WAFFLE_CACHE_NAME = 'waffle_cache' STORAGE_USAGE_CACHE_NAME = 'storage_usage' CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', }, STORAGE_USAGE_CACHE_NAME: { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'osf_cache_table', }, WAFFLE_CACHE_NAME: { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', }, }
[ 37811, 198, 35, 73, 14208, 6460, 329, 40391, 1628, 13, 198, 198, 8645, 515, 416, 705, 28241, 14208, 12, 28482, 923, 16302, 6, 1262, 37770, 352, 13, 23, 13, 198, 198, 1890, 517, 1321, 319, 428, 2393, 11, 766, 198, 5450, 1378, 31628, ...
2.273659
4,195
# -*- coding: utf-8 -*- """Unit test package for gblackboard."""
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 37811, 26453, 1332, 5301, 329, 308, 13424, 3526, 526, 15931, 198 ]
2.538462
26
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc import fibcapi_pb2 as fibcapi__pb2 import fibcapis_pb2 as fibcapis__pb2 def add_FIBCApApiServicer_to_server(servicer, server): rpc_method_handlers = { 'Monitor': grpc.unary_stream_rpc_method_handler( servicer.Monitor, request_deserializer=fibcapis__pb2.ApMonitorRequest.FromString, response_serializer=fibcapis__pb2.ApMonitorReply.SerializeToString, ), 'GetPortStats': grpc.unary_stream_rpc_method_handler( servicer.GetPortStats, request_deserializer=fibcapis__pb2.ApGetPortStatsRequest.FromString, response_serializer=fibcapi__pb2.FFPortStats.SerializeToString, ), 'ModPortStats': grpc.unary_unary_rpc_method_handler( servicer.ModPortStats, request_deserializer=fibcapis__pb2.ApModPortStatsRequest.FromString, response_serializer=fibcapis__pb2.ApModPortStatsReply.SerializeToString, ), 'GetPortEntries': grpc.unary_stream_rpc_method_handler( servicer.GetPortEntries, request_deserializer=fibcapis__pb2.ApGetPortEntriesRequest.FromString, response_serializer=fibcapis__pb2.DbPortEntry.SerializeToString, ), 'GetIDEntries': grpc.unary_stream_rpc_method_handler( servicer.GetIDEntries, request_deserializer=fibcapis__pb2.ApGetIdEntriesRequest.FromString, response_serializer=fibcapis__pb2.DbIdEntry.SerializeToString, ), 'GetDpEntries': grpc.unary_stream_rpc_method_handler( servicer.GetDpEntries, request_deserializer=fibcapis__pb2.ApGetDpEntriesRequest.FromString, response_serializer=fibcapis__pb2.DbDpEntry.SerializeToString, ), 'AddPortEntry': grpc.unary_unary_rpc_method_handler( servicer.AddPortEntry, request_deserializer=fibcapis__pb2.DbPortEntry.FromString, response_serializer=fibcapis__pb2.ApAddPortEntryReply.SerializeToString, ), 'AddIDEntry': grpc.unary_unary_rpc_method_handler( servicer.AddIDEntry, request_deserializer=fibcapis__pb2.DbIdEntry.FromString, response_serializer=fibcapis__pb2.ApAddIdEntryReply.SerializeToString, ), 'DelPortEntry': grpc.unary_unary_rpc_method_handler( servicer.DelPortEntry, request_deserializer=fibcapis__pb2.DbPortKey.FromString, response_serializer=fibcapis__pb2.ApDelPortEntryReply.SerializeToString, ), 'DelIDEntry': grpc.unary_unary_rpc_method_handler( servicer.DelIDEntry, request_deserializer=fibcapis__pb2.DbIdEntry.FromString, response_serializer=fibcapis__pb2.ApDelIdEntryReply.SerializeToString, ), 'GetStats': grpc.unary_stream_rpc_method_handler( servicer.GetStats, request_deserializer=fibcapis__pb2.ApGetStatsRequest.FromString, response_serializer=fibcapis__pb2.StatsEntry.SerializeToString, ), 'RunOAM': grpc.unary_unary_rpc_method_handler( servicer.RunOAM, request_deserializer=fibcapi__pb2.OAM.Request.FromString, response_serializer=fibcapis__pb2.OAMReplyAck.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'fibcapi.FIBCApApi', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) def add_FIBCVmApiServicer_to_server(servicer, server): rpc_method_handlers = { 'SendHello': grpc.unary_unary_rpc_method_handler( servicer.SendHello, request_deserializer=fibcapi__pb2.Hello.FromString, response_serializer=fibcapis__pb2.HelloReply.SerializeToString, ), 'SendPortConfig': grpc.unary_unary_rpc_method_handler( servicer.SendPortConfig, request_deserializer=fibcapi__pb2.PortConfig.FromString, response_serializer=fibcapis__pb2.PortConfigReply.SerializeToString, ), 'SendFlowMod': grpc.unary_unary_rpc_method_handler( servicer.SendFlowMod, request_deserializer=fibcapi__pb2.FlowMod.FromString, response_serializer=fibcapis__pb2.FlowModReply.SerializeToString, ), 'SendGroupMod': grpc.unary_unary_rpc_method_handler( servicer.SendGroupMod, request_deserializer=fibcapi__pb2.GroupMod.FromString, response_serializer=fibcapis__pb2.GroupModReply.SerializeToString, ), 'SendOAMReply': grpc.unary_unary_rpc_method_handler( servicer.SendOAMReply, request_deserializer=fibcapis__pb2.OAMReply.FromString, response_serializer=fibcapis__pb2.OAMReplyAck.SerializeToString, ), 'Monitor': grpc.unary_stream_rpc_method_handler( servicer.Monitor, request_deserializer=fibcapis__pb2.VmMonitorRequest.FromString, response_serializer=fibcapis__pb2.VmMonitorReply.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'fibcapi.FIBCVmApi', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) def add_FIBCVsApiServicer_to_server(servicer, server): rpc_method_handlers = { 'SendHello': grpc.unary_unary_rpc_method_handler( servicer.SendHello, request_deserializer=fibcapi__pb2.FFHello.FromString, response_serializer=fibcapis__pb2.FFHelloReply.SerializeToString, ), 'SendFFPacket': grpc.unary_unary_rpc_method_handler( servicer.SendFFPacket, request_deserializer=fibcapi__pb2.FFPacket.FromString, response_serializer=fibcapis__pb2.FFPacketReply.SerializeToString, ), 'SendPacketIn': grpc.unary_unary_rpc_method_handler( servicer.SendPacketIn, request_deserializer=fibcapi__pb2.FFPacketIn.FromString, response_serializer=fibcapis__pb2.FFPacketInReply.SerializeToString, ), 'SendOAMReply': grpc.unary_unary_rpc_method_handler( servicer.SendOAMReply, request_deserializer=fibcapis__pb2.OAMReply.FromString, response_serializer=fibcapis__pb2.OAMReplyAck.SerializeToString, ), 'Monitor': grpc.unary_stream_rpc_method_handler( servicer.Monitor, request_deserializer=fibcapis__pb2.VsMonitorRequest.FromString, response_serializer=fibcapis__pb2.VsMonitorReply.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'fibcapi.FIBCVsApi', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) def add_FIBCDpApiServicer_to_server(servicer, server): rpc_method_handlers = { 'SendHello': grpc.unary_unary_rpc_method_handler( servicer.SendHello, request_deserializer=fibcapi__pb2.FFHello.FromString, response_serializer=fibcapis__pb2.FFHelloReply.SerializeToString, ), 'SendPacketIn': grpc.unary_unary_rpc_method_handler( servicer.SendPacketIn, request_deserializer=fibcapi__pb2.FFPacketIn.FromString, response_serializer=fibcapis__pb2.FFPacketInReply.SerializeToString, ), 'SendPortStatus': grpc.unary_unary_rpc_method_handler( servicer.SendPortStatus, request_deserializer=fibcapi__pb2.FFPortStatus.FromString, response_serializer=fibcapis__pb2.FFPortStatusReply.SerializeToString, ), 'SendL2AddrStatus': grpc.unary_unary_rpc_method_handler( servicer.SendL2AddrStatus, request_deserializer=fibcapi__pb2.FFL2AddrStatus.FromString, response_serializer=fibcapis__pb2.L2AddrStatusReply.SerializeToString, ), 'SendMultipartReply': grpc.unary_unary_rpc_method_handler( servicer.SendMultipartReply, request_deserializer=fibcapis__pb2.DpMultipartReply.FromString, response_serializer=fibcapis__pb2.DpMultipartReplyAck.SerializeToString, ), 'SendOAMReply': grpc.unary_unary_rpc_method_handler( servicer.SendOAMReply, request_deserializer=fibcapis__pb2.OAMReply.FromString, response_serializer=fibcapis__pb2.OAMReplyAck.SerializeToString, ), 'Monitor': grpc.unary_stream_rpc_method_handler( servicer.Monitor, request_deserializer=fibcapis__pb2.DpMonitorRequest.FromString, response_serializer=fibcapis__pb2.DpMonitorReply.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'fibcapi.FIBCDpApi', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,))
[ 2, 2980, 515, 416, 262, 308, 49, 5662, 11361, 8435, 17050, 13877, 13, 8410, 5626, 48483, 0, 198, 11748, 1036, 14751, 198, 198, 11748, 12900, 11128, 72, 62, 40842, 17, 355, 12900, 11128, 72, 834, 40842, 17, 198, 11748, 12900, 11128, 27...
2.181008
3,928
from cymbology.identifiers.sedol import Sedol from cymbology.identifiers.cusip import Cusip, cusip_from_isin from cymbology.identifiers.isin import Isin __all__ = ('Sedol', 'Cusip', 'cusip_from_isin', 'Isin')
[ 6738, 3075, 2022, 1435, 13, 738, 13350, 13, 36622, 349, 1330, 22710, 349, 198, 6738, 3075, 2022, 1435, 13, 738, 13350, 13, 9042, 541, 1330, 327, 385, 541, 11, 269, 385, 541, 62, 6738, 62, 45763, 198, 6738, 3075, 2022, 1435, 13, 738,...
2.692308
78
from marshmallow import Schema, fields from marshmallow.validate import Range, Length from sqlalchemy import Column, Integer, Boolean, DateTime from ..db import Base from ..shared.models import StringTypes # ---- Error-report
[ 6738, 22397, 42725, 1330, 10011, 2611, 11, 7032, 198, 6738, 22397, 42725, 13, 12102, 378, 1330, 13667, 11, 22313, 198, 6738, 44161, 282, 26599, 1330, 29201, 11, 34142, 11, 41146, 11, 7536, 7575, 198, 198, 6738, 11485, 9945, 1330, 7308, ...
3.982759
58
#!/bin/python3 import math import os import random import re import sys # # Complete the 'findSubstring' function below. # # The function is expected to return a STRING. # The function accepts following parameters: # 1. STRING s # 2. INTEGER k #
[ 2, 48443, 8800, 14, 29412, 18, 198, 198, 11748, 10688, 198, 11748, 28686, 198, 11748, 4738, 198, 11748, 302, 198, 11748, 25064, 628, 198, 198, 2, 198, 2, 13248, 262, 705, 19796, 7004, 8841, 6, 2163, 2174, 13, 198, 2, 198, 2, 383, ...
3.035294
85
COLLECTION = 'productos'
[ 25154, 16779, 2849, 796, 705, 11167, 418, 6 ]
3
8
"""Evaluation metrics.""" import numpy as np from sklearn.metrics import matthews_corrcoef # noqa from sklearn.metrics import recall_score # noqa from sklearn.metrics import cohen_kappa_score from sklearn.metrics import r2_score # noqa from sklearn.metrics import mean_squared_error from sklearn.metrics import mean_absolute_error from sklearn.metrics import precision_score # noqa from sklearn.metrics import precision_recall_curve from sklearn.metrics import auc from sklearn.metrics import jaccard_score from sklearn.metrics import f1_score from sklearn.metrics import roc_auc_score # noqa from sklearn.metrics import accuracy_score # noqa from sklearn.metrics import balanced_accuracy_score # noqa from scipy.stats import pearsonr # kappa_score is an alias for `sklearn.metrics.cohen_kappa_score` kappa_score = cohen_kappa_score def pearson_r2_score(y: np.ndarray, y_pred: np.ndarray) -> float: """Computes Pearson R^2 (square of Pearson correlation). Parameters ---------- y: np.ndarray ground truth array y_pred: np.ndarray predicted array Returns ------- float The Pearson-R^2 score. """ return pearsonr(y, y_pred)[0]**2 def jaccard_index(y: np.ndarray, y_pred: np.ndarray) -> float: """Computes Jaccard Index which is the Intersection Over Union metric which is commonly used in image segmentation tasks. DEPRECATED: WILL BE REMOVED IN A FUTURE VERSION OF DEEEPCHEM. USE `jaccard_score` instead. Parameters ---------- y: np.ndarray ground truth array y_pred: np.ndarray predicted array Returns ------- score: float The jaccard index. A number between 0 and 1. """ return jaccard_score(y, y_pred) def pixel_error(y: np.ndarray, y_pred: np.ndarray) -> float: """An error metric in case y, y_pred are images. Defined as 1 - the maximal F-score of pixel similarity, or squared Euclidean distance between the original and the result labels. Parameters ---------- y: np.ndarray ground truth array y_pred: np.ndarray predicted array Returns ------- score: float The pixel-error. A number between 0 and 1. """ return 1 - f1_score(y, y_pred) def prc_auc_score(y: np.ndarray, y_pred: np.ndarray) -> float: """Compute area under precision-recall curve Parameters ---------- y: np.ndarray A numpy array of shape `(N, n_classes)` or `(N,)` with true labels y_pred: np.ndarray Of shape `(N, n_classes)` with class probabilities. Returns ------- float The area under the precision-recall curve. A number between 0 and 1. """ precision, recall, _ = precision_recall_curve(y[:, 1], y_pred[:, 1]) return auc(recall, precision) def rms_score(y_true: np.ndarray, y_pred: np.ndarray) -> float: """Computes RMS error.""" return np.sqrt(mean_squared_error(y_true, y_pred)) def mae_score(y_true: np.ndarray, y_pred: np.ndarray) -> float: """Computes MAE.""" return mean_absolute_error(y_true, y_pred) def bedroc_score(y_true: np.ndarray, y_pred: np.ndarray, alpha: float = 20.0): """Compute BEDROC metric. BEDROC metric implemented according to Truchon and Bayley that modifies the ROC score by allowing for a factor of early recognition. Please confirm details from [1]_. Parameters ---------- y_true: np.ndarray Binary class labels. 1 for positive class, 0 otherwise y_pred: np.ndarray Predicted labels alpha: float, default 20.0 Early recognition parameter Returns ------- float Value in [0, 1] that indicates the degree of early recognition Notes ----- This function requires RDKit to be installed. References ---------- .. [1] Truchon et al. "Evaluating virtual screening methods: good and bad metrics for the early recognition problem." Journal of chemical information and modeling 47.2 (2007): 488-508. """ try: from rdkit.ML.Scoring.Scoring import CalcBEDROC except ModuleNotFoundError: raise ValueError("This function requires RDKit to be installed.") # validation assert len(y_true) == len(y_pred), 'Number of examples do not match' assert np.array_equal( np.unique(y_true).astype(int), [0, 1]), ('Class labels must be binary: %s' % np.unique(y_true)) yt = np.asarray(y_true) yp = np.asarray(y_pred) yt = yt.flatten() yp = yp[:, 1].flatten() # Index 1 because one_hot predictions scores = list(zip(yt, yp)) scores = sorted(scores, key=lambda pair: pair[1], reverse=True) return CalcBEDROC(scores, 0, alpha)
[ 37811, 36, 2100, 2288, 20731, 526, 15931, 198, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 1341, 35720, 13, 4164, 10466, 1330, 23963, 40645, 62, 10215, 81, 1073, 891, 220, 1303, 645, 20402, 198, 6738, 1341, 35720, 13, 4164, 10466, 13...
2.900709
1,551
from __future__ import absolute_import import operator from collections import deque import functools from abc import ( ABCMeta, abstractmethod ) import rlp_cython as rlp import time import math from uuid import UUID from typing import ( # noqa: F401 Any, Optional, Callable, cast, Dict, Generator, Iterator, Tuple, Type, TYPE_CHECKING, Union, List, Iterable, ) import logging from itertools import groupby from hvm.rlp.receipts import Receipt from hvm.types import Timestamp from eth_typing import ( Address, BlockNumber, Hash32, ) from eth_utils import ( to_tuple, to_set, ) from hvm.db.backends.base import BaseDB from hvm.db.backends.memory import MemoryDB from hvm.db.chain import ( BaseChainDB, ChainDB, ) from hvm.db.journal import ( JournalDB, ) from hvm.db.read_only import ReadOnlyDB from hvm.constants import ( BLOCK_GAS_LIMIT, BLANK_ROOT_HASH, NUMBER_OF_HEAD_HASH_TO_SAVE, TIME_BETWEEN_HEAD_HASH_SAVE, GENESIS_PARENT_HASH, ) from hvm.db.trie import make_trie_root_and_nodes from hvm import constants from hvm.estimators import ( get_gas_estimator, ) from hvm.exceptions import ( HeaderNotFound, TransactionNotFound, ValidationError, VMNotFound, BlockOnWrongChain, CanonicalHeadNotFound, CannotCalculateStake, NotEnoughTimeBetweenBlocks, ReceivableTransactionNotFound, TriedImportingGenesisBlock, JournalDbNotActivated, ReplacingBlocksNotAllowed, UnprocessedBlockNotAllowed, AppendHistoricalRootHashTooOld, HistoricalNetworkTPCMissing, HistoricalMinGasPriceError, UnprocessedBlockChildIsProcessed, ParentNotFound, NoChronologicalBlocks, RewardProofSenderBlockMissing, InvalidHeadRootTimestamp, RewardAmountRoundsToZero, TriedDeletingGenesisBlock, NoGenesisBlockPresent) from eth_keys.exceptions import ( BadSignature, ) from hvm.utils.blocks import reorganize_chronological_block_list_for_correct_chronological_order_at_index from hvm.validation import ( validate_block_number, validate_uint256, validate_word, validate_vm_configuration, validate_canonical_address, validate_is_queue_block, validate_centisecond_timestamp, ) from hvm.rlp.blocks import ( BaseBlock, BaseQueueBlock, ) from hvm.rlp.headers import ( BlockHeader, HeaderParams, ) from hvm.rlp.transactions import ( BaseTransaction, BaseReceiveTransaction ) from hvm.utils.db import ( apply_state_dict, ) from hvm.utils.datatypes import ( Configurable, ) from hvm.utils.headers import ( compute_gas_limit_bounds, ) from hvm.utils.hexadecimal import ( encode_hex, decode_hex ) from hvm.utils.rlp import ( ensure_imported_block_unchanged, ) from hvm.db.chain_head import ChainHeadDB from hvm.db.consensus import ConsensusDB from eth_keys import keys from eth_keys.datatypes import( BaseKey, PublicKey, PrivateKey ) from hvm.utils.numeric import ( effecient_diff, are_items_in_list_equal, ) from sortedcontainers import ( SortedList, SortedDict, ) from hvm.rlp.consensus import NodeStakingScore, PeerNodeHealth from hvm.rlp.accounts import TransactionKey if TYPE_CHECKING: from hvm.vm.base import BaseVM # noqa: F401 from functools import partial import asyncio # Mapping from address to account state. # 'balance', 'nonce' -> int # 'code' -> bytes # 'storage' -> Dict[int, int] AccountState = Dict[Address, Dict[str, Union[int, bytes, Dict[int, int]]]] # # Global Record and discard API # def enable_read_only_db(self) -> None: if not isinstance(self.db, ReadOnlyDB): self.base_db = self.db self.db = ReadOnlyDB(self.base_db) self.reinitialize() # # Helpers # # # Chain API # def get_chain_at_block_parent(self, block: BaseBlock) -> BaseChain: """ Returns a `Chain` instance with the given block's parent at the chain head. """ try: parent_header = self.get_block_header_by_hash(block.header.parent_hash) except HeaderNotFound: raise ValidationError("Parent ({0}) of block {1} not found".format( block.header.parent_hash, block.header.hash )) init_header = self.create_header_from_parent(parent_header) return type(self)(self.chaindb.db, self.wallet_address, self.private_key, init_header) # # VM API # def get_vm(self, header: BlockHeader=None, timestamp: Timestamp = None) -> 'BaseVM': """ Returns the VM instance for the given block timestamp. Or if timestamp is given, gets the vm for that timestamp """ if header is not None and timestamp is not None: raise ValueError("Cannot specify header and timestamp for get_vm(). Only one is allowed.") if header is None or header == self.header: header = self.header if timestamp is not None: header = header.copy(timestamp = timestamp) vm_class = self.get_vm_class_for_block_timestamp(header.timestamp) return vm_class(header=header, chaindb=self.chaindb, network_id=self.network_id) else: vm_class = self.get_vm_class_for_block_timestamp(header.timestamp) return vm_class(header=header, chaindb=self.chaindb, network_id=self.network_id) # # Header API # def create_header_from_parent(self, parent_header, **header_params): """ Passthrough helper to the VM class of the block descending from the given header. """ return self.get_vm_class_for_block_timestamp().create_header_from_parent(parent_header, **header_params) def get_block_header_by_hash(self, block_hash: Hash32) -> BlockHeader: """ Returns the requested block header as specified by block hash. Raises BlockNotFound if there's no block header with the given hash in the db. """ validate_word(block_hash, title="Block Hash") return self.chaindb.get_block_header_by_hash(block_hash) def get_canonical_head(self, chain_address = None): """ Returns the block header at the canonical chain head. Raises CanonicalHeadNotFound if there's no head defined for the canonical chain. """ if chain_address is not None: return self.chaindb.get_canonical_head(chain_address) else: return self.chaindb.get_canonical_head(self.wallet_address) # # Block API # def get_block_by_header(self, block_header: BlockHeader) -> BaseBlock: """ Returns the requested block as specified by the block header. """ block_class = self.get_vm_class_for_block_timestamp(block_header.timestamp).get_block_class() send_transactions = self.chaindb.get_block_transactions(block_header, block_class.transaction_class) receive_transactions = self.chaindb.get_block_receive_transactions(block_header,block_class.receive_transaction_class) reward_bundle = self.chaindb.get_reward_bundle(block_header.reward_hash, block_class.reward_bundle_class) output_block = block_class(block_header, send_transactions, receive_transactions, reward_bundle) return output_block def get_block(self) -> BaseBlock: """ Returns the current TIP block. """ return self.get_vm().block def get_queue_block(self) -> BaseBlock: """ Returns the current TIP block. """ return self.get_vm().queue_block # def get_block_by_hash(self, block_hash: Hash32) -> BaseBlock: # """ # Returns the requested block as specified by block hash. # """ # validate_word(block_hash, title="Block Hash") # block_header = self.get_block_header_by_hash(block_hash) # return self.get_block_by_header(block_header) # def get_canonical_block_by_number(self, block_number: BlockNumber) -> BaseBlock: # """ # Returns the block with the given number in the canonical chain. # # Raises BlockNotFound if there's no block with the given number in the # canonical chain. # """ # validate_uint256(block_number, title="Block Number") # return self.get_block_by_hash(self.chaindb.get_canonical_block_hash(block_number)) # # def get_canonical_block_hash(self, block_number: BlockNumber) -> Hash32: # """ # Returns the block hash with the given number in the canonical chain. # # Raises BlockNotFound if there's no block with the given number in the # canonical chain. # """ # return self.chaindb.get_canonical_block_hash(block_number) # # Blockchain Database API # # else: # self.chain_head_db.add_block_hash_to_timestamp_without_propogating_to_present(self.wallet_address, block_header.hash, window_for_this_block) # # Queueblock API # def sign_queue_block(self, *args: Any, **kwargs: Any) -> BaseQueueBlock: """ Passthrough helper to the current VM class. """ return self.get_vm().sign_queue_block(*args, **kwargs) def sign_header(self, *args: Any, **kwargs: Any) -> BlockHeader: """ Passthrough helper to the current VM class. """ return self.get_vm().sign_header(*args, **kwargs) # # Transaction API # def get_canonical_transaction(self, transaction_hash: Hash32) -> BaseTransaction: """ Returns the requested transaction as specified by the transaction hash from the canonical chain. Raises TransactionNotFound if no transaction with the specified hash is found in the main chain. """ (block_hash, index, is_receive) = self.chaindb.get_transaction_index(transaction_hash) block_header = self.get_block_header_by_hash(block_hash) VM = self.get_vm_class_for_block_timestamp(block_header.timestamp) if is_receive == False: transaction = self.chaindb.get_transaction_by_index_and_block_hash( block_hash, index, VM.get_transaction_class(), ) else: transaction = self.chaindb.get_receive_transaction_by_index_and_block_hash( block_hash, index, VM.get_receive_transaction_class(), ) if transaction.hash == transaction_hash: return transaction else: raise TransactionNotFound("Found transaction {} instead of {} in block {} at {}".format( encode_hex(transaction.hash), encode_hex(transaction_hash), block_hash, index, )) def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction: """ Passthrough helper to the current VM class. """ return self.get_vm().create_transaction(*args, **kwargs) def create_receive_transaction(self, *args: Any, **kwargs: Any) -> BaseReceiveTransaction: """ Passthrough helper to the current VM class. """ return self.get_vm().create_receive_transaction(*args, **kwargs) # # Chronological Chain api # def get_block_hashes_that_are_new_for_this_historical_root_hash_timestamp(self, historical_root_hash_timestamp: Timestamp) -> List[Tuple[Timestamp, Hash32]]: ''' This is a time consuming function that gets all of the blocks that are new in this root hash that didn't exist in the base root hash. :param timestamp: :return: ''' block_window_start = historical_root_hash_timestamp - TIME_BETWEEN_HEAD_HASH_SAVE base_root_hash = self.chain_head_db.get_historical_root_hash(block_window_start) new_root_hash = self.chain_head_db.get_historical_root_hash(historical_root_hash_timestamp) if base_root_hash == new_root_hash: return None if base_root_hash is None or new_root_hash is None: raise InvalidHeadRootTimestamp( "Could not load block hashes for this historical_root_hash_timestamp because we don't have a root hash for this window or the previous window.") base_head_block_hashes = set(self.chain_head_db.get_head_block_hashes(base_root_hash)) new_head_block_hashes = set(self.chain_head_db.get_head_block_hashes(new_root_hash)) diff_head_block_hashes = new_head_block_hashes - base_head_block_hashes chronological_block_hash_timestamps = [] # now we have to run down each chain until we get to a block that is older than block_window_start for head_block_hash in diff_head_block_hashes: header = self.chaindb.get_block_header_by_hash(head_block_hash) chronological_block_hash_timestamps.append([header.timestamp, head_block_hash]) while True: if header.parent_hash == GENESIS_PARENT_HASH: break try: header = self.chaindb.get_block_header_by_hash(header.parent_hash) except HeaderNotFound: break if header.timestamp < block_window_start: break chronological_block_hash_timestamps.append([header.timestamp, header.hash]) assert len(chronological_block_hash_timestamps) > 0 chronological_block_hash_timestamps.sort() return chronological_block_hash_timestamps # def initialize_historical_root_hashes_and_chronological_blocks(self) -> None: # ''' # This function rebuilds all historical root hashes, and chronological blocks, from the blockchain database. It starts with the saved root hash and works backwards. # This function needs to be run from chain because it requires chain_head_db and chaindb. # :return: # ''' # # self.chain_head_db.load_saved_root_hash() # current_window = self.chain_head_db.current_window # earliest_root_hash = self.chain_head_db.earliest_window # #TIME_BETWEEN_HEAD_HASH_SAVE # # # 1) iterate down the root hash times # # 2) create new chain_head_db with memorydb # # 3) go through each chain and any blocks newer than the timestamp, save to chronological window. # # 4) when you reach a block less than the timestamp, set it as chain head in the new memory based chain_head_db # # 5) get the root hash # # 6) set this root hash in the real chain_head_db at the correct timestamp. # # # A chronological block window holds all of the blocks starting at its timestamp, going to timestamp + TIME_BETWEEN_HEAD_HASH_SAVE # # A historical root hash is the root hash at the given timestamp, so it includes all blocks earlier than that timestamp. # # # us a journaldb so that it doesnt write changes to the database. # temp_chain_head_db = self.get_chain_head_db_class()(MemoryDB()) # #temp_chain_head_db = self.get_chain_head_db_class().load_from_saved_root_hash(JournalDB(self.db)) # for current_timestamp in range(current_window, earliest_root_hash-TIME_BETWEEN_HEAD_HASH_SAVE, -TIME_BETWEEN_HEAD_HASH_SAVE): # self.logger.debug("Rebuilding chronological block window {}".format(current_timestamp)) # if current_timestamp < self.genesis_block_timestamp: # break # # if current_timestamp == current_window: # head_block_hashes = self.chain_head_db.get_head_block_hashes_list() # else: # head_block_hashes = temp_chain_head_db.get_head_block_hashes_list() # # # iterate over all chains # for head_block_hash in head_block_hashes: # current_block_hash = head_block_hash # # now iterate over blocks in chain # while True: # current_header = self.chaindb.get_block_header_by_hash(current_block_hash) # if current_header.timestamp >= current_timestamp: # # add it to chronological block window in the real chain head db # self.chain_head_db.add_block_hash_to_chronological_window(current_header.hash, current_header.timestamp) # else: # # The block is older than the timestamp. Set it as the chain head block hash in our temp chain head db # temp_chain_head_db.set_chain_head_hash(current_header.chain_address, current_header.hash) # break # if current_header.parent_hash == GENESIS_PARENT_HASH: # # we reached the end of the chain # temp_chain_head_db.delete_chain_head_hash(current_header.chain_address) # break # # set the current block to the parent so we move down the chain # current_block_hash = current_header.parent_hash # # # Now that we have gone through all chains, and removed any blocks newer than this timestamp, the root hash in the # # temp chain head db is the correct one for this historical root hash timestamp. # self.chain_head_db.save_single_historical_root_hash(temp_chain_head_db.root_hash, Timestamp(current_timestamp)) def initialize_historical_root_hashes_and_chronological_blocks(self) -> None: ''' This function rebuilds all historical root hashes, and chronological blocks, from the blockchain database. It starts with the saved root hash and works backwards. This function needs to be run from chain because it requires chain_head_db and chaindb. :return: ''' self.chain_head_db.load_saved_root_hash() current_window = self.chain_head_db.current_window earliest_root_hash = self.chain_head_db.earliest_window #TIME_BETWEEN_HEAD_HASH_SAVE # the saved # 1) iterate down the root hash times # 2) create new chain_head_db with memorydb # 3) go through each chain and any blocks newer than the timestamp, save to chronological window. # 4) when you reach a block less than the timestamp, set it as chain head in the new memory based chain_head_db # 5) get the root hash # 6) set this root hash in the real chain_head_db at the correct timestamp. # A chronological block window holds all of the blocks starting at its timestamp, going to timestamp + TIME_BETWEEN_HEAD_HASH_SAVE # A historical root hash is the root hash at the given timestamp, so it includes all blocks earlier than that timestamp. self.logger.debug("Rebuilding chronological block windows") # us a journaldb so that it doesnt write changes to the database. temp_chain_head_db = self.get_chain_head_db_class()(MemoryDB()) #temp_chain_head_db = self.get_chain_head_db_class().load_from_saved_root_hash(JournalDB(self.db)) for current_timestamp in range(current_window, earliest_root_hash-TIME_BETWEEN_HEAD_HASH_SAVE, -TIME_BETWEEN_HEAD_HASH_SAVE): if current_timestamp < self.genesis_block_timestamp: break head_block_hashes = self.chain_head_db.get_head_block_hashes_list() # iterate over all chains for head_block_hash in head_block_hashes: current_block_hash = head_block_hash # now iterate over blocks in chain while True: current_header = self.chaindb.get_block_header_by_hash(current_block_hash) if current_header.timestamp >= current_timestamp: # add it to chronological block window in the real chain head db self.chain_head_db.add_block_hash_to_chronological_window(current_header.hash, current_header.timestamp) else: # The block is older than the timestamp. Set it as the chain head block hash in our temp chain head db self.chain_head_db.set_chain_head_hash(current_header.chain_address, current_header.hash) break if current_header.parent_hash == GENESIS_PARENT_HASH: # we reached the end of the chain self.chain_head_db.delete_chain_head_hash(current_header.chain_address) break # set the current block to the parent so we move down the chain current_block_hash = current_header.parent_hash # Now that we have gone through all chains, and removed any blocks newer than this timestamp, the root hash in the # temp chain head db is the correct one for this historical root hash timestamp. self.chain_head_db.save_single_historical_root_hash(self.chain_head_db.root_hash, Timestamp(current_timestamp)) self.chain_head_db.persist() # finally, lets load the saved root hash again so we are up to date. self.chain_head_db.load_saved_root_hash() # # Execution API # def estimate_gas(self, transaction: BaseTransaction, at_header: BlockHeader=None) -> int: """ Returns an estimation of the amount of gas the given transaction will use if executed on top of the block specified by the given header. """ if at_header is None: at_header = self.get_canonical_head() with self.get_vm(at_header).state_in_temp_block() as state: return self.gas_estimator(state, transaction) # # Reverting block functions # def purge_unprocessed_block(self, block_hash, purge_children_too = True): ''' Deletes all unprocessed block lookups, and unprocessed children lookups for this block and all children blocks. Todo: delete saved block header, and saved transaction tries for each block as well ''' self.logger.debug("purging unprocessed block") if purge_children_too: self.logger.debug("purging unprocessed children") if self.chaindb.has_unprocessed_children(block_hash): self.logger.debug("HAS UNPROCESSED CHILDREN BLOCKS") children_block_hashes = self.chaindb.get_block_children(block_hash) if children_block_hashes != None: for child_block_hash in children_block_hashes: #this includes the child in this actual chain as well as children from send transactions. if not self.chaindb.is_block_unprocessed(child_block_hash): raise UnprocessedBlockChildIsProcessed("In process of deleting children of unprocessed block, and found one that is processed. This should never happen") else: self.purge_unprocessed_block(child_block_hash) try: block = self.get_block_by_hash(block_hash) chain = encode_hex(block.header.chain_address) self.logger.debug("deleting unprocessed child block number {} on chain {}".format(block.number, chain)) self.chaindb.remove_block_from_unprocessed(block) except HeaderNotFound: pass from hvm.utils.profile import profile def _import_block(self, block: BaseBlock, perform_validation: bool=True, save_block_head_hash_timestamp = True, allow_unprocessed = True, ensure_block_unchanged: bool = True, microblock_origin: bool = False) -> BaseBlock: """ Imports a complete block. """ self.logger.debug("importing block {} with number {}".format(block.__repr__(), block.number)) self.validate_time_from_genesis_block(block) if isinstance(block, self.get_vm(timestamp = block.header.timestamp).get_queue_block_class()): # If it was a queueblock, then the header will have changed after importing perform_validation = False ensure_block_unchanged = False queue_block = True else: queue_block = False if not self.chaindb.is_block_unprocessed(block.header.parent_hash): #this part checks to make sure the parent exists try: vm = self.get_vm(timestamp = block.header.timestamp) self.logger.debug("importing block with vm {}".format(vm.__repr__())) if queue_block: imported_block = vm.import_block(block, private_key = self.private_key) else: imported_block = vm.import_block(block) # Validate the imported block. if ensure_block_unchanged: if microblock_origin: # this started out as a microblock. So we only ensure the microblock fields are unchanged. self.logger.debug('ensuring block unchanged. microblock correction') corrected_micro_block = block.copy(header = block.header.copy( receipt_root = imported_block.header.receipt_root, bloom = imported_block.header.bloom, gas_limit = imported_block.header.gas_limit, gas_used = imported_block.header.gas_used, account_hash = imported_block.header.account_hash, account_balance = imported_block.header.account_balance, )) ensure_imported_block_unchanged(imported_block, corrected_micro_block) else: self.logger.debug('ensuring block unchanged') ensure_imported_block_unchanged(imported_block, block) else: self.logger.debug('Not checking block for changes.') if perform_validation: self.validate_block(imported_block) #self.chain_head_db.set_chain_head_hash(self.wallet_address, imported_block.header.hash) if save_block_head_hash_timestamp: self.chain_head_db.add_block_hash_to_chronological_window(imported_block.header.hash, imported_block.header.timestamp) self.save_chain_head_hash_to_trie_for_time_period(imported_block.header) self.chain_head_db.set_chain_head_hash(imported_block.header.chain_address, imported_block.header.hash) self.chain_head_db.persist(True) self.chaindb.persist_block(imported_block) vm.state.account_db.persist(save_account_hash = True, wallet_address = self.wallet_address) #here we must delete the unprocessed lookup before importing children #because the children cannot be imported if their chain parent is unprocessed. #but we cannot delete the lookup for unprocessed children yet. self.chaindb.remove_block_from_unprocessed(imported_block) # Add chronological consistency lookups self.save_block_chronological_consistency_lookups(imported_block) try: self.header = self.create_header_from_parent(self.get_canonical_head()) except CanonicalHeadNotFound: self.header = self.get_vm_class_for_block_timestamp().create_genesis_block(self.wallet_address).header self.queue_block = None self.logger.debug( 'IMPORTED_BLOCK: number %s | hash %s', imported_block.number, encode_hex(imported_block.hash), ) # Make sure our wallet address hasn't magically changed if self.wallet_address != imported_block.header.chain_address: raise ValidationError("Attempted to import a block onto the wrong chain.") return_block = imported_block except ReceivableTransactionNotFound as e: if not allow_unprocessed: raise UnprocessedBlockNotAllowed() self.logger.debug("Saving block as unprocessed because of ReceivableTransactionNotFound error: {}".format(e)) return_block = self.save_block_as_unprocessed(block) if self.raise_errors: raise e except RewardProofSenderBlockMissing as e: if not allow_unprocessed: raise UnprocessedBlockNotAllowed() self.logger.debug("Saving block as unprocessed because of RewardProofSenderBlockMissing error: {}".format(e)) return_block = self.save_block_as_unprocessed(block) else: if not allow_unprocessed: raise UnprocessedBlockNotAllowed() self.logger.debug("Saving block as unprocessed because parent on this chain is unprocessed") return_block = self.save_block_as_unprocessed(block) return return_block def save_block_chronological_consistency_lookups(self, block: BaseBlock) -> None: ''' We need to require that the proof sender chain doesn't add a block after their claimed chain_head_hash, and the timestamp of this block being imported. :param block: :return: ''' block_header = block.header reward_bundle = self.chaindb.get_reward_bundle(block_header.reward_hash, block.reward_bundle_class) chronological_consistency_key = [block_header.timestamp, block_header.hash] for proof in reward_bundle.reward_type_2.proof: # timestamp, block hash of block responsible sender_chain_header = self.chaindb.get_block_header_by_hash(proof.head_hash_of_sender_chain) # The chronological consistency restrictions are placed on the block on top of the one giving the proof. block_number_with_restrictions = sender_chain_header.block_number + 1 self.logger.debug("saving chronological consistency lookup for chain {}, block {}, timestamp {}".format(encode_hex(sender_chain_header.chain_address), block_number_with_restrictions, block_header.timestamp)) self.chaindb.add_block_consistency_key(sender_chain_header.chain_address, block_number_with_restrictions, chronological_consistency_key) # # Chronologically consistent blockchain db API # def check_block_chronological_consistency(self, block: BaseBlock) -> List[Hash32]: ''' Checks to see if the block breaks any chronological consistency. If it does, it will return a list of blocks that need to be reverted for this block to be imported returns list of block hashes that have to be reverted :param block: :return: ''' consistency_keys = self.chaindb.get_block_chronological_consistency_keys(block.header.chain_address, block.header.block_number) block_hashes_to_revert = list() for consistency_key in consistency_keys: if consistency_key[0] > block.header.timestamp: block_hashes_to_revert.append(consistency_key[1]) return block_hashes_to_revert # # Validation API # def validate_block(self, block: BaseBlock) -> None: """ Performs validation on a block that is either being mined or imported. Since block validation (specifically the uncle validation must have access to the ancestor blocks, this validation must occur at the Chain level. """ self.validate_gaslimit(block.header) def validate_gaslimit(self, header: BlockHeader) -> None: """ Validate the gas limit on the given header. """ #parent_header = self.get_block_header_by_hash(header.parent_hash) #low_bound, high_bound = compute_gas_limit_bounds(parent_header) #if header.gas_limit < low_bound: # raise ValidationError( # "The gas limit on block {0} is too low: {1}. It must be at least {2}".format( # encode_hex(header.hash), header.gas_limit, low_bound)) if header.gas_limit > BLOCK_GAS_LIMIT: raise ValidationError( "The gas limit on block {0} is too high: {1}. It must be at most {2}".format( encode_hex(header.hash), header.gas_limit, BLOCK_GAS_LIMIT)) def validate_block_specification(self, block) -> bool: ''' This validates everything we can without looking at the blockchain database. It doesnt need to assume that we have the block that sent the transactions. This that this can check: block signature send transaction signatures receive transaction signatures - dont need to check this. it doesnt add any security signatures of send transaction within receive transactions send transaction root matches transactions receive transaction root matches transactions ''' if not isinstance(block, self.get_vm(timestamp = block.header.timestamp).get_block_class()): self.logger.debug("converting block to correct class") block = self.get_vm(timestamp = block.header.timestamp).convert_block_to_correct_class(block) block.header.check_signature_validity() for transaction in block.transactions: transaction.validate() for transaction in block.receive_transactions: transaction.validate() send_tx_root_hash, _ = make_trie_root_and_nodes(block.transactions) if block.header.transaction_root != send_tx_root_hash: raise ValidationError("Block has invalid transaction root") receive_tx_root_hash, _ = make_trie_root_and_nodes(block.receive_transactions) if block.header.receive_transaction_root != receive_tx_root_hash: raise ValidationError("Block has invalid receive transaction root") return True # # Stake API # # gets the stake for the timestamp corresponding to teh chronological block window, so it is all blocks for the next 1000 seconds. def get_new_block_hash_to_test_peer_node_health(self) -> Hash32: ''' returns one of the newest blocks we have seen. :return: ''' before_this_timestamp = int(time.time()) - 60 # ask the peer for a block that was received at before 1 minute ago current_historical_window = int(time.time() / TIME_BETWEEN_HEAD_HASH_SAVE) * TIME_BETWEEN_HEAD_HASH_SAVE for timestamp in range(current_historical_window, current_historical_window-NUMBER_OF_HEAD_HASH_TO_SAVE*TIME_BETWEEN_HEAD_HASH_SAVE, -1* TIME_BETWEEN_HEAD_HASH_SAVE): chronological_window = self.chain_head_db.load_chronological_block_window(timestamp) if chronological_window is not None: chronological_window.sort(key=lambda x: -1*x[0]) for timestamp_hash in chronological_window: if timestamp_hash[0] < before_this_timestamp: return timestamp_hash[1] #if we get to here then we don't have any blocks within all chronological block windows... raise NoChronologicalBlocks() # # Min Block Gas API used for throttling the network # def re_initialize_historical_minimum_gas_price_at_genesis(self) -> None: ''' re-initializes system with last set min gas price and net tpc cap ''' hist_min_gas_price = self.chaindb.load_historical_minimum_gas_price() hist_tpc_cap = self.chaindb.load_historical_network_tpc_capability() hist_tx_per_centisecond = self.chaindb.load_historical_tx_per_centisecond() if hist_min_gas_price is not None: init_min_gas_price = hist_min_gas_price[-1][1] else: init_min_gas_price = 1 if hist_tpc_cap is not None: init_tpc_cap = hist_tpc_cap[-1][1] else: init_tpc_cap = self.get_local_tpc_cap() if hist_tx_per_centisecond is not None: init_tpc = hist_tx_per_centisecond[-1][1] else: init_tpc = None self.chaindb.initialize_historical_minimum_gas_price_at_genesis(init_min_gas_price, init_tpc_cap, init_tpc) def _update_tpc_from_chronological(self, new_hist_tpc_dict): ''' returns True if they are all the same as what we already had in the database, otherwise it returns False ''' if not isinstance(new_hist_tpc_dict, dict): raise ValidationError("Expected a dict. Didn't get a dict.") hist_tpc = self.chaindb.load_historical_tx_per_centisecond() difference_found = False if hist_tpc is None: hist_tpc = list(new_hist_tpc_dict.items()) else: hist_tpc_dict = dict(hist_tpc) for timestamp, tpc in new_hist_tpc_dict.items(): if timestamp not in hist_tpc_dict or hist_tpc_dict[timestamp] != tpc: #if tpc != 0: difference_found = True hist_tpc_dict[timestamp] = tpc hist_tpc = list(hist_tpc_dict.items()) #print(hist_tpc) #save it to db self.chaindb.save_historical_tx_per_centisecond(hist_tpc, de_sparse = False) return not difference_found # # Consensus DB passthrough's that depend on block timestamp #
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 11748, 10088, 198, 6738, 17268, 1330, 390, 4188, 198, 198, 11748, 1257, 310, 10141, 198, 198, 6738, 450, 66, 1330, 357, 198, 220, 220, 220, 9738, 48526, 11, 198, 220, 220, 220, 1253...
2.34894
16,275
""" This module includes functions related to the regions API endpoint. """ from django.http import JsonResponse from ...cms.models import Region from ...cms.constants import region_status from ..decorators import json_response def transform_region(region): """ Function to create a JSON from a single region object, including information if region is live/active. :param region: The region object which should be converted :type region: ~integreat_cms.cms.models.regions.region.Region :return: data necessary for API :rtype: dict """ return { "id": region.id, "name": region.full_name, "path": region.slug, "live": region.status == region_status.ACTIVE, "prefix": region.prefix, "name_without_prefix": region.name, "plz": region.postal_code, "extras": region.offers.exists(), "events": region.events_enabled, "pois": region.locations_enabled, "push_notifications": region.push_notifications_enabled, "longitude": region.longitude, "latitude": region.latitude, "bounding_box": region.bounding_box.api_representation, "aliases": region.aliases, "tunews": region.tunews_enabled, } def transform_region_by_status(region): """ Function to create a JSON from a single "active" region object. :param region: The region object which should be converted :type region: ~integreat_cms.cms.models.regions.region.Region :return: data necessary for API :rtype: dict """ result = transform_region(region) # Remove status del result["live"] return result
[ 37811, 198, 1212, 8265, 3407, 5499, 3519, 284, 262, 7652, 7824, 36123, 13, 198, 37811, 198, 6738, 42625, 14208, 13, 4023, 1330, 449, 1559, 31077, 198, 198, 6738, 2644, 46406, 13, 27530, 1330, 17718, 198, 6738, 2644, 46406, 13, 9979, 118...
2.757475
602
import copy import os from cli.src.Config import Config from cli.src.helpers.build_io import (get_ansible_path, get_ansible_path_for_build, get_ansible_vault_path) from cli.src.helpers.data_loader import (load_all_schema_objs_from_directory, load_schema_obj, types) from cli.src.helpers.doc_list_helpers import (ExpectedSingleResultException, select_first, select_single) from cli.src.helpers.naming_helpers import to_feature_name, to_role_name from cli.src.helpers.ObjDict import ObjDict from cli.src.helpers.yaml_helpers import dump from cli.src.schema.DefaultMerger import DefaultMerger from cli.src.Step import Step from cli.version import VERSION
[ 11748, 4866, 198, 11748, 28686, 198, 198, 6738, 537, 72, 13, 10677, 13, 16934, 1330, 17056, 198, 6738, 537, 72, 13, 10677, 13, 16794, 364, 13, 11249, 62, 952, 1330, 357, 1136, 62, 504, 856, 62, 6978, 11, 198, 220, 220, 220, 220, 2...
2.094872
390
from unittest import TestCase from snail import snail
[ 6738, 555, 715, 395, 1330, 6208, 20448, 198, 198, 6738, 47374, 1330, 47374, 628 ]
4
14
# Copyright 2021 Google LLC # # 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 """The raw JSON Web Token (JWT).""" import copy import datetime import json from typing import cast, Mapping, Set, List, Dict, Optional, Text, Union, Any from tink import core from tink.jwt import _jwt_error from tink.jwt import _jwt_format _REGISTERED_NAMES = frozenset({'iss', 'sub', 'jti', 'aud', 'exp', 'nbf', 'iat'}) _MAX_TIMESTAMP_VALUE = 253402300799 # 31 Dec 9999, 23:59:59 GMT Claim = Union[None, bool, int, float, Text, List[Any], Dict[Text, Any]]
[ 2, 15069, 33448, 3012, 11419, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, 2, 921, 743, 733...
3.199367
316
import pytest from plenum.server.view_change.view_changer import ViewChanger from stp_core.common.log import getlogger from plenum.test.pool_transactions.helper import start_not_added_node, add_started_node logger = getlogger() def test_no_instance_change_on_primary_disconnection_for_not_ready_node( looper, txnPoolNodeSet, tdir, tconf, allPluginsPath, sdk_pool_handle, sdk_wallet_steward): """ Test steps: 1. create a new node, but don't add it to the pool (so not send NODE txn), so that the node is not ready. 2. wait for more than VIEW_CHANGE_TIMEOUT (a timeout for initial check for disconnected primary) 3. make sure no InstanceChange sent by the new node 4. add the node to the pool (send NODE txn) and make sure that the node is ready now. 5. wait for more than VIEW_CHANGE_TIMEOUT (a timeout for initial check for disconnected primary) 6. make sure no InstanceChange sent by the new node """ # 1. create a new node, but don't add it to the pool (so not send NODE txn), so that the node is not ready. sigseed, bls_key, new_node, node_ha, client_ha = \ start_not_added_node(looper, tdir, tconf, allPluginsPath, "TestTheta") # 2. wait for more than VIEW_CHANGE_TIMEOUT (a timeout for initial check for disconnected primary) looper.runFor(tconf.VIEW_CHANGE_TIMEOUT + 2) # 3. make sure no InstanceChange sent by the new node assert 0 == new_node.view_changer.spylog.count(ViewChanger.sendInstanceChange.__name__) logger.info("Start added node {}".format(new_node)) # 4. add the node to the pool (send NODE txn) and make sure that the node is ready now. add_started_node(looper, new_node, node_ha, client_ha, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, bls_key) # 5. wait for more than VIEW_CHANGE_TIMEOUT (a timeout for initial check for disconnected primary) looper.runFor(tconf.VIEW_CHANGE_TIMEOUT + 2) # 6. make sure no InstanceChange sent by the new node assert 0 == new_node.view_changer.spylog.count(ViewChanger.sendInstanceChange.__name__)
[ 11748, 12972, 9288, 198, 198, 6738, 458, 44709, 13, 15388, 13, 1177, 62, 3803, 13, 1177, 62, 354, 2564, 1330, 3582, 1925, 2564, 198, 198, 6738, 336, 79, 62, 7295, 13, 11321, 13, 6404, 1330, 651, 6404, 1362, 198, 6738, 458, 44709, 13...
2.452891
934
from abc import ABC, abstractclassmethod from model.response import ResponseModel
[ 6738, 450, 66, 1330, 9738, 11, 12531, 4871, 24396, 198, 198, 6738, 2746, 13, 26209, 1330, 18261, 17633, 628, 198 ]
4.25
20
""" Copyright (c) 2020 COTOBA DESIGN, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os from programy.config.file.json_file import JSONConfigurationFile from programy.clients.events.console.config import ConsoleConfiguration from programy.utils.substitutions.substitues import Substitutions from programytest.config.file.base_file_tests import ConfigurationBaseFileTests
[ 37811, 198, 15269, 357, 66, 8, 12131, 327, 26631, 4339, 22196, 16284, 11, 3457, 13, 198, 198, 5990, 3411, 318, 29376, 7520, 11, 1479, 286, 3877, 11, 284, 597, 1048, 16727, 257, 4866, 286, 428, 3788, 290, 3917, 198, 22897, 341, 3696, ...
3.950867
346
import math from typing import List def jump_search(array: List[int], value: int) -> int: """ Performs a jump search on a list of integers. :param array: is the array to search. :param value: is the value to search. :return: the index of the value, or -1 if it doesn't exist.' """ if len(array) == 0: return -1 block_size = get_block_size(array) # Pointers for traversing the array start_pointer = 0 next_pointer = block_size while (start_pointer < len(array)) and (array[next_pointer - 1] < value): start_pointer = next_pointer next_pointer += block_size # Prevent next from going out of bounds if next_pointer > len(array): next_pointer = len(array) # Linear search through the relevant block for i in range(start_pointer, next_pointer): if array[i] == value: return i return -1 def get_block_size(array: List[int]) -> int: """ Gets the block size of an array for jump search. The block size is the square root of the length of the array. We then calculate the absolute value of this block size, because we're using the value as index pointer, and negative values do not make sense here. This value is then floored to act as index pointer in the array. :param array: is the array to search. :return: the block size to be used in jump search. """ return math.floor(abs(math.sqrt(len(array)))) if __name__ == '__main__': # Array must be sorted in order for binary search to work array = [3, 5, 6, 9, 11, 18, 20, 21, 24, 30] print(array) index = jump_search(array, 31) print(index)
[ 11748, 10688, 198, 6738, 19720, 1330, 7343, 628, 198, 4299, 4391, 62, 12947, 7, 18747, 25, 7343, 58, 600, 4357, 1988, 25, 493, 8, 4613, 493, 25, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 2448, 23914, 257, 4391, 2989, 319, 257, ...
2.799337
603
# Copyright Pincer 2021-Present # Full MIT License can be found in `LICENSE` at the project root. from __future__ import annotations from dataclasses import dataclass from enum import IntEnum from typing import List, Optional, TYPE_CHECKING from ...utils.api_object import APIObject from ...utils.types import MISSING if TYPE_CHECKING: from ..user import User from ...utils import APINullable, Snowflake
[ 2, 15069, 350, 1939, 263, 33448, 12, 34695, 198, 2, 6462, 17168, 13789, 460, 307, 1043, 287, 4600, 43, 2149, 24290, 63, 379, 262, 1628, 6808, 13, 198, 198, 6738, 11593, 37443, 834, 1330, 37647, 198, 198, 6738, 4818, 330, 28958, 1330, ...
3.508333
120
from django.views.generic import \ UpdateView as BaseUpdateView
[ 6738, 42625, 14208, 13, 33571, 13, 41357, 1330, 3467, 198, 220, 220, 220, 10133, 7680, 355, 7308, 10260, 7680, 628, 198 ]
3.333333
21
import torch import lib.modeling.resnet as resnet import lib.modeling.semseg_heads as snet import torch.nn as nn import torch.optim as optim import utils.resnet_weights_helper as resnet_utils from torch.autograd import Variable from roi_data.loader import RoiDataLoader, MinibatchSampler, collate_minibatch, collate_minibatch_semseg from datasets.roidb import combined_roidb_for_training, combined_roidb_for_training_semseg import os import numpy as np import nn as mynn import cv2 from modeling.model_builder_3DSD import Generalized_3DSD from modeling.model_builder_PSP3D import DispSeg from core.config import cfg, cfg_from_file, cfg_from_list, assert_and_infer_cfg #load net cfg_file = 'e2e_segdisp-R-50_3Dpool_1x.yaml' cfg_from_file(cfg_file) print (cfg.SEM) print (cfg.DISP) #cfg_from_list(cfg_file) #assert_and_infer_cfg() devices_ids=[5] os.environ["CUDA_VISIBLE_DEVICES"] = ','.join([str(ids) for ids in devices_ids]) torch.backends.cudnn.benchmark=True #torch.cuda.set_device(3) len_gpus = len(devices_ids) batch_size = 2 * len_gpus #net = mynn.DataParallel(load_net().to('cuda'), minibatch=True) net = mynn.DataParallel(DispSeg().to('cuda'), minibatch=True) optimizer = optim.SGD(net.parameters(), lr=0.000875, momentum=0.9) criterion = nn.NLLLoss(ignore_index=255) #dataloader= dataloader(batch_size, len_gpus) for i in range(10): #for i, inputs in zip(range(1000), dataloader): inputs = dataloader(batch_size, len_gpus) for key in inputs: inputs[key] = torch.chunk(inputs[key], chunks=len_gpus, dim=0) optimizer.zero_grad() loss=net(**inputs) optimizer.step() for k in loss['losses'].keys(): print (loss['losses'][k].item())
[ 11748, 28034, 198, 11748, 9195, 13, 4666, 10809, 13, 411, 3262, 355, 581, 3262, 198, 11748, 9195, 13, 4666, 10809, 13, 43616, 325, 70, 62, 16600, 355, 3013, 316, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 28034, 13, 40085...
2.5
672
import json from regenesis.queries import get_cubes, get_all_dimensions, get_dimensions from pprint import pprint if __name__ == '__main__': with open('model.json', 'wb') as fh: model = generate_model() json.dump(model, fh, indent=2)
[ 11748, 33918, 198, 6738, 842, 268, 9339, 13, 421, 10640, 1330, 651, 62, 66, 29080, 11, 651, 62, 439, 62, 27740, 5736, 11, 651, 62, 27740, 5736, 198, 6738, 279, 4798, 1330, 279, 4798, 628, 628, 220, 220, 220, 220, 198, 198, 361, 11...
2.490566
106
"""Test Evil Genius Labs light.""" from unittest.mock import patch import pytest from homeassistant.components.light import ( ATTR_COLOR_MODE, ATTR_SUPPORTED_COLOR_MODES, ColorMode, LightEntityFeature, ) from homeassistant.const import ATTR_SUPPORTED_FEATURES
[ 37811, 14402, 10461, 32562, 23500, 1657, 526, 15931, 198, 6738, 555, 715, 395, 13, 76, 735, 1330, 8529, 198, 198, 11748, 12972, 9288, 198, 198, 6738, 1363, 562, 10167, 13, 5589, 3906, 13, 2971, 1330, 357, 198, 220, 220, 220, 5161, 544...
2.82
100
import platform import shutil import tempfile import warnings from pathlib import Path import requests from tqdm import tqdm DOCKER_VERSION = "20.10.5" BUILDX_VERSION = "0.5.1" CACHE_DIR = Path.home() / ".cache" / "python-on-whales" TEMPLATE_CLI = ( "https://download.docker.com/{os}/static/stable/{arch}/docker-{version}.tgz" ) WINDOWS_CLI_URL = "https://github.com/StefanScherer/docker-cli-builder/releases/download/{version}/docker.exe"
[ 11748, 3859, 198, 11748, 4423, 346, 198, 11748, 20218, 7753, 198, 11748, 14601, 198, 6738, 3108, 8019, 1330, 10644, 198, 198, 11748, 7007, 198, 6738, 256, 80, 36020, 1330, 256, 80, 36020, 198, 198, 35, 11290, 1137, 62, 43717, 796, 366, ...
2.6
175
import boto3 import json import os import logging from contextlib import closing from boto3.dynamodb.conditions import Key, Attr from botocore.exceptions import ClientError from random import shuffle import time import pyqrcode import png __BUCKET_NAME__ = "project-cerebro" dynamo = boto3.client('dynamodb') logger = None print("In initialize fn ...") logger = logging.getLogger() if int(os.environ['DEBUG_MODE']): logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) logger.info("Initialize: Just a test") logger.debug("Initialize: debug a test") def create_presigned_url(bucket_name, object_name, expiration=3600): """Generate a presigned URL to share an S3 object :param bucket_name: string :param object_name: string :param expiration: Time in seconds for the presigned URL to remain valid :return: Presigned URL as string. If error, returns None. """ # Generate a presigned URL for the S3 object s3_client = boto3.client('s3') try: response = s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_name}, ExpiresIn=expiration) except ClientError as e: logging.error(e) return None # The response contains the presigned URL return response # input parameters are: # 1. image ID # output parameters are: # 1. generated QRCode # workflow: # 1. first get the image_id # 2. confirm this exists in s3 # 3. generate a presigned URL with this s3 path # 4. create a QR Code image with this url embedded # 5. return the QR code stored in S3 temp.
[ 11748, 275, 2069, 18, 198, 11748, 33918, 198, 11748, 28686, 198, 11748, 18931, 198, 198, 6738, 4732, 8019, 1330, 9605, 198, 198, 6738, 275, 2069, 18, 13, 67, 4989, 375, 65, 13, 17561, 1756, 1330, 7383, 11, 3460, 81, 198, 6738, 10214, ...
2.454039
718
#!/usr/bin/env python #coding:utf-8 # Author: mozman --<mozman@gmx.at> # Purpose: test drawing module # Created: 11.09.2010 # Copyright (C) 2010, Manfred Moitzi # License: GPLv3 from __future__ import unicode_literals import os import unittest from io import StringIO from svgwrite.drawing import Drawing from svgwrite.container import Group if __name__=='__main__': unittest.main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 201, 198, 2, 66, 7656, 25, 40477, 12, 23, 201, 198, 2, 6434, 25, 220, 6941, 32054, 1377, 27, 5908, 32054, 31, 70, 36802, 13, 265, 29, 201, 198, 2, 32039, 25, 1332, 8263, 8265, 201, 19...
2.601266
158
from django.shortcuts import render from django.utils.translation import ugettext as _ # pylint: disable=unused-argument
[ 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 198, 6738, 42625, 14208, 13, 26791, 13, 41519, 1330, 334, 1136, 5239, 355, 4808, 628, 198, 2, 279, 2645, 600, 25, 15560, 28, 403, 1484, 12, 49140, 198 ]
3.416667
36
from typing import NamedTuple from django.contrib.auth.models import AbstractUser from django.db import models from msg.models import Msg
[ 6738, 19720, 1330, 34441, 51, 29291, 198, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 13, 27530, 1330, 27741, 12982, 198, 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 198, 6738, 31456, 13, 27530, 1330, 6997, 70, 628 ]
3.615385
39
matrix = [list(map(int, input().split())) for _ in range(6)] max_sum = None for i in range(4): for j in range(4): s = sum(matrix[i][j:j+3]) + matrix[i+1][j+1] + sum(matrix[i+2][j:j+3]) if max_sum is None or s > max_sum: max_sum = s print(max_sum)
[ 6759, 8609, 796, 685, 4868, 7, 8899, 7, 600, 11, 5128, 22446, 35312, 3419, 4008, 329, 4808, 287, 2837, 7, 21, 15437, 198, 9806, 62, 16345, 796, 6045, 198, 1640, 1312, 287, 2837, 7, 19, 2599, 198, 220, 220, 220, 329, 474, 287, 2837...
1.944444
144
# Lint as: python2, python3 # Copyright 2019 Google LLC. 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 # # https://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. """A client for the chicago_taxi demo.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import argparse import base64 import json import os import subprocess import tempfile import requests from tensorflow_transform import coders as tft_coders from tensorflow_transform.tf_metadata import dataset_schema from tensorflow_transform.tf_metadata import schema_utils from google.protobuf import text_format from tensorflow.python.lib.io import file_io # pylint: disable=g-direct-tensorflow-import from tensorflow.python.platform import app # pylint: disable=g-direct-tensorflow-import from tensorflow_metadata.proto.v0 import schema_pb2 from tfx.utils import io_utils _LOCAL_INFERENCE_TIMEOUT_SECONDS = 5.0 _LABEL_KEY = 'tips' # Tf.Transform considers these features as "raw" def _make_csv_coder(schema, column_names): """Return a coder for tf.transform to read csv files.""" raw_feature_spec = _get_raw_feature_spec(schema) parsing_schema = dataset_schema.from_feature_spec(raw_feature_spec) return tft_coders.CsvCoder(column_names, parsing_schema) def _read_schema(path): """Reads a schema from the provided location. Args: path: The location of the file holding a serialized Schema proto. Returns: An instance of Schema or None if the input argument is None """ result = schema_pb2.Schema() contents = file_io.read_file_to_string(path) text_format.Parse(contents, result) return result def _do_local_inference(host, port, serialized_examples): """Performs inference on a model hosted by the host:port server.""" json_examples = [] for serialized_example in serialized_examples: # The encoding follows the guidelines in: # https://www.tensorflow.org/tfx/serving/api_rest example_bytes = base64.b64encode(serialized_example).decode('utf-8') predict_request = '{ "b64": "%s" }' % example_bytes json_examples.append(predict_request) json_request = '{ "instances": [' + ','.join(map(str, json_examples)) + ']}' server_url = 'http://' + host + ':' + port + '/v1/models/chicago_taxi:predict' response = requests.post( server_url, data=json_request, timeout=_LOCAL_INFERENCE_TIMEOUT_SECONDS) response.raise_for_status() prediction = response.json() print(json.dumps(prediction, indent=4)) def _do_aiplatform_inference(model, version, serialized_examples): """Performs inference on the model:version in AI Platform.""" working_dir = tempfile.mkdtemp() instances_file = os.path.join(working_dir, 'test.json') json_examples = [] for serialized_example in serialized_examples: # The encoding follows the example in: # https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/quests/tpu/invoke_model.py json_examples.append('{ "inputs": { "b64": "%s" } }' % base64.b64encode(serialized_example).decode('utf-8')) file_io.write_string_to_file(instances_file, '\n'.join(json_examples)) gcloud_command = [ 'gcloud', 'ai-platform', 'predict', '--model', model, '--version', version, '--json-instances', instances_file ] print(subprocess.check_output(gcloud_command)) def _do_inference(model_handle, examples_file, num_examples, schema): """Sends requests to the model and prints the results. Args: model_handle: handle to the model. This can be either "aiplatform:model:version" or "host:port" examples_file: path to csv file containing examples, with the first line assumed to have the column headers num_examples: number of requests to send to the server schema: a Schema describing the input data Returns: Response from model server """ filtered_features = [ feature for feature in schema.feature if feature.name != _LABEL_KEY ] del schema.feature[:] schema.feature.extend(filtered_features) column_names = io_utils.load_csv_column_names(examples_file) csv_coder = _make_csv_coder(schema, column_names) proto_coder = _make_proto_coder(schema) input_file = open(examples_file, 'r') input_file.readline() # skip header line serialized_examples = [] for _ in range(num_examples): one_line = input_file.readline() if not one_line: print('End of example file reached') break one_example = csv_coder.decode(one_line) serialized_example = proto_coder.encode(one_example) serialized_examples.append(serialized_example) parsed_model_handle = model_handle.split(':') if parsed_model_handle[0] == 'aiplatform': _do_aiplatform_inference( model=parsed_model_handle[1], version=parsed_model_handle[2], serialized_examples=serialized_examples) else: _do_local_inference( host=parsed_model_handle[0], port=parsed_model_handle[1], serialized_examples=serialized_examples) if __name__ == '__main__': app.run(main)
[ 2, 406, 600, 355, 25, 21015, 17, 11, 21015, 18, 198, 2, 15069, 13130, 3012, 11419, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, ...
2.89979
1,906
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Q_ARG, QAbstractItemModel, QFileInfo, qFuzzyCompare, QMetaObject, QModelIndex, QObject, Qt, QThread, QTime, QUrl) from PyQt5.QtGui import QColor, qGray, QImage, QPainter, QPalette from PyQt5.QtMultimedia import (QAbstractVideoBuffer, QMediaContent, QMediaMetaData, QMediaPlayer, QMediaPlaylist, QVideoFrame, QVideoProbe) from PyQt5.QtMultimediaWidgets import QVideoWidget from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog, QFileDialog, QFormLayout, QHBoxLayout, QLabel, QListView, QMessageBox, QPushButton, QSizePolicy, QSlider, QStyle, QToolButton, QVBoxLayout, QWidget) if __name__ == '__main__': import sys app = QApplication(sys.argv) player = Player(sys.argv[1:]) player.show() sys.exit(app.exec_())
[ 6738, 9485, 48, 83, 20, 13, 48, 83, 14055, 1330, 357, 9078, 39568, 11712, 282, 11, 12972, 39568, 38963, 11, 1195, 62, 1503, 38, 11, 1195, 23839, 7449, 17633, 11, 198, 220, 220, 220, 220, 220, 220, 220, 1195, 8979, 12360, 11, 10662, ...
2.447368
342
#!/usr/bin/env python """Test checkpoint-like periodic snapshots. We test that there are that many folders and that the currentStep changes. """ import mirheo as mir u = mir.Mirheo(nranks=(1, 1, 1), domain=(4, 6, 8), debug_level=3, log_filename='log', no_splash=True, checkpoint_every=10, checkpoint_mode='Incremental', checkpoint_folder='periodic_snapshots/snapshot_', checkpoint_mechanism='Snapshot') pv = mir.ParticleVectors.ParticleVector('pv', mass=1) ic = mir.InitialConditions.Uniform(number_density=2) u.registerParticleVector(pv, ic) dpd = mir.Interactions.Pairwise('dpd', rc=1.0, kind='DPD', a=10.0, gamma=10.0, kBT=1.0, power=0.5) lj = mir.Interactions.Pairwise('lj', rc=1.0, kind='LJ', epsilon=1.25, sigma=0.75) u.registerInteraction(dpd) u.registerInteraction(lj) u.setInteraction(dpd, pv, pv) minimize = mir.Integrators.Minimize('minimize', max_displacement=1. / 1024) u.registerIntegrator(minimize) u.run(45, dt=0.125) # TEST: snapshot.periodic # cd snapshot # rm -rf periodic_snapshots/ # mir.run --runargs "-n 2" ./periodic.py # ls periodic_snapshots | cat > snapshot.out.txt # grep -rH --include=*.json currentStep periodic_snapshots/ | sort >> snapshot.out.txt
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 37811, 14402, 26954, 12, 2339, 27458, 47787, 13, 198, 198, 1135, 1332, 326, 612, 389, 326, 867, 24512, 290, 326, 262, 1459, 8600, 2458, 13, 198, 37811, 198, 198, 11748, 5720, 258,...
2.50813
492
#!/usr/bin/python # # Copyright 2016 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Loads a set of web pages several times on a device, and extracts the predictor database. """ import argparse import logging import os import sys _SRC_PATH = os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir, os.pardir)) sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) from devil.android import device_utils sys.path.append(os.path.join(_SRC_PATH, 'build', 'android')) import devil_chromium sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) import controller from options import OPTIONS import page_track _PAGE_LOAD_TIMEOUT = 20 def _CreateArgumentParser(): """Creates and returns the argument parser.""" parser = argparse.ArgumentParser( description=('Loads a set of web pages several times on a device, and ' 'extracts the predictor database.'), parents=[OPTIONS.GetParentParser()]) parser.add_argument('--device', help='Device ID') parser.add_argument('--urls_filename', help='File containing a list of URLs ' '(one per line). URLs can be repeated.') parser.add_argument('--output_filename', help='File to store the database in.') parser.add_argument('--url_repeat', help=('Number of times each URL in the input ' 'file is loaded.'), default=3) return parser def _FindDevice(device_id): """Returns a device matching |device_id| or the first one if None, or None.""" devices = device_utils.DeviceUtils.HealthyDevices() if device_id is None: return devices[0] matching_devices = [d for d in devices if str(d) == device_id] if not matching_devices: return None return matching_devices[0] def _Setup(device): """Sets up a device and returns an instance of RemoteChromeController.""" chrome_controller = controller.RemoteChromeController(device) device.ForceStop(OPTIONS.ChromePackage().package) chrome_controller.AddChromeArguments( ['--speculative-resource-prefetching=learning']) chrome_controller.ResetBrowserState() return chrome_controller if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 198, 2, 15069, 1584, 383, 18255, 1505, 46665, 13, 1439, 2489, 10395, 13, 198, 2, 5765, 286, 428, 2723, 2438, 318, 21825, 416, 257, 347, 10305, 12, 7635, 5964, 326, 460, 307, 198, 2, 10...
2.809069
838
from abc import ABC, abstractmethod from typing import Optional from xml import dom import numpy as np import pandas as pd from .utils import get_factors_rev def setup_domain(cfg): domain_x, domain_y = cfg["domain"]["x"], (round(cfg["domain"]["y"] * cfg["domain"]["urban_ratio"])) plot_footprint, plot_ratio, dx, dy = ( cfg["plot"]["plot_footprint"], cfg["plot"]["plot_ratio"], cfg["domain"]["dx"], cfg["domain"]["dy"], ) plots = calc_plot_sizes( domain_x, domain_y, plot_footprint, cfg["house"]["footprint"], plot_ratio, dx, dy, cfg["domain"]["y"], ) tplot_x, tplot_y, tdomain_x, tdomain_y, trimmed_y = get_best_plot_size(plots, plot_footprint, plot_ratio, dx, dy) house_x, house_y = calc_house_size(tplot_x, tplot_y, cfg["house"]["footprint"], dx, dy) house = House(house_x, house_y, cfg["house"]["height"]) return Domain.from_plot_size(house, cfg, tplot_x, tplot_y, tdomain_x, tdomain_y, trimmed_y, plot_ratio, cfg["domain"]["stack_height"]) if __name__ == "__main__": from .load_wrapper_config import get_wrapper_config config = get_wrapper_config() domain = setup_domain(config) domain
[ 6738, 450, 66, 1330, 9738, 11, 12531, 24396, 198, 6738, 19720, 1330, 32233, 198, 6738, 35555, 1330, 2401, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 6738, 764, 26791, 1330, 651, 62, 22584, ...
2.230906
563
#!/usr/bin/env python3 # -*- config: utf-8 -*- from tkinter import * from random import random root = Tk() root['bg'] = 'white' root.title('crown') img = PhotoImage(file='crown.png') bt1 = Button(image=img, command=on_click) bt1.place(relx=0.5, rely=0.5, anchor=CENTER) root.mainloop()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 4566, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 6738, 256, 74, 3849, 1330, 1635, 198, 6738, 4738, 1330, 4738, 628, 198, 198, 15763, 796, 309, 74, 3419, 198, ...
2.373984
123
from openpyxl import Workbook
[ 6738, 1280, 9078, 87, 75, 1330, 5521, 2070, 628 ]
3.444444
9
import subprocess import sys import unittest import pathlib from torch.testing._internal.common_utils import TestCase, run_tests, IS_LINUX, IS_IN_CI REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent try: # Just in case PyTorch was not built in 'develop' mode sys.path.append(str(REPO_ROOT)) from tools.stats.scribe import rds_write, register_rds_schema except ImportError: register_rds_schema = None rds_write = None # these tests could eventually be changed to fail if the import/init # time is greater than a certain threshold, but for now we just use them # as a way to track the duration of `import torch` in our ossci-metrics # S3 bucket (see tools/stats/print_test_stats.py) if __name__ == "__main__": if register_rds_schema and IS_IN_CI: register_rds_schema( "import_stats", { "test_name": "string", "peak_memory_bytes": "int", "time_ms": "int", }, ) run_tests()
[ 11748, 850, 14681, 198, 11748, 25064, 198, 11748, 555, 715, 395, 198, 11748, 3108, 8019, 198, 198, 6738, 28034, 13, 33407, 13557, 32538, 13, 11321, 62, 26791, 1330, 6208, 20448, 11, 1057, 62, 41989, 11, 3180, 62, 34509, 31235, 11, 3180,...
2.442308
416
from django.core.exceptions import ValidationError from django.core.validators import validate_email from django.template import Template, TemplateSyntaxError, TemplateDoesNotExist from django.utils.encoding import force_str def validate_email_with_name(value): """ Validate email address. Both "Recipient Name <email@example.com>" and "email@example.com" are valid. """ value = force_str(value) recipient = value if '<' in value and '>' in value: start = value.find('<') + 1 end = value.find('>') if start < end: recipient = value[start:end] validate_email(recipient) def validate_comma_separated_emails(value): """ Validate every email address in a comma separated list of emails. """ if not isinstance(value, (tuple, list)): raise ValidationError('Email list must be a list/tuple.') for email in value: try: validate_email_with_name(email) except ValidationError: raise ValidationError('Invalid email: %s' % email, code='invalid') def validate_template_syntax(source): """ Basic Django Template syntax validation. This allows for robuster template authoring. """ try: Template(source) except (TemplateSyntaxError, TemplateDoesNotExist) as err: raise ValidationError(str(err))
[ 6738, 42625, 14208, 13, 7295, 13, 1069, 11755, 1330, 3254, 24765, 12331, 198, 6738, 42625, 14208, 13, 7295, 13, 12102, 2024, 1330, 26571, 62, 12888, 198, 6738, 42625, 14208, 13, 28243, 1330, 37350, 11, 37350, 13940, 41641, 12331, 11, 3735...
2.724551
501
# Input DOI / URL import re import sys # Pyperclip is not built-in, check and download if needed try: import pyperclip except (ImportError, ModuleNotFoundError): print('Pyperclip module not found. Please download it.') sys.exit(0) # Regex for links link_regex = re.compile(r'''( http[s]?:// (?:[a-zA-Z]| [0-9]| [$-_@.&+]| [!*\(\),]| (?:%[0-9a-fA-F][0-9a-fA-F]))+ )''', re.IGNORECASE | re.VERBOSE) # Get DOI / URL using different methods # Method 1: argument try: input_link = sys.argv[1] # Method 2: clipboard except IndexError: input_link = pyperclip.paste() # Method 3: manual input def regex_check(regex, link): """ Check using regex. If DOI/URL are not in the right format, require manual input until correct or Enter to quit. """ while True: match = re.match(regex, link) if match == None: link = str(input('''Enter valid DOI / URL or press Enter to quit: > ''')) if link == '': exit() else: continue else: return link url = regex_check(link_regex, input_link)
[ 2, 23412, 40722, 1220, 10289, 198, 198, 11748, 302, 198, 11748, 25064, 198, 198, 2, 9485, 525, 15036, 318, 407, 3170, 12, 259, 11, 2198, 290, 4321, 611, 2622, 198, 28311, 25, 198, 220, 220, 220, 1330, 12972, 525, 15036, 198, 16341, ...
2.221359
515
import argparse import csv import os import torch import tqdm from torch import distributed from torch.utils import data from torchvision import datasets from torchvision import transforms from nets import nn from utils import util data_dir = os.path.join('..', 'Dataset', 'IMAGENET') if __name__ == '__main__': main()
[ 11748, 1822, 29572, 198, 11748, 269, 21370, 198, 11748, 28686, 198, 198, 11748, 28034, 198, 11748, 256, 80, 36020, 198, 6738, 28034, 1330, 9387, 198, 6738, 28034, 13, 26791, 1330, 1366, 198, 6738, 28034, 10178, 1330, 40522, 198, 6738, 280...
3.242718
103
import numpy as np from time import time from cgbind.atoms import get_atomic_number from cgbind.log import logger from cgbind.constants import Constants from cgbind.exceptions import CgbindCritical def get_esp_cube_lines(charges, atoms): """ From a list of charges and a set of xyzs create the electrostatic potential map grid-ed uniformly between the most negative x, y, z values -5 and the largest x, y, z +5 :param charges: (list(float)) :param atoms: (list(autode.atoms.Atom)) :return: (list(str)), (min ESP value, max ESP value) """ logger.info('Calculating the ESP and generating a .cube file') start_time = time() try: from esp_gen import get_cube_lines except ModuleNotFoundError: raise CgbindCritical('esp_gen not available. cgbind must be ' 'installed with the --esp_gen flag') if charges is None: logger.error('Could not generate an .cube file, charges were None') return [], (None, None) coords = np.array([atom.coord for atom in atoms]) charges = np.array(charges) # Get the max and min points from the coordinates max_cart_values = np.max(coords, axis=0) min_cat_values = np.min(coords, axis=0) # The grid needs to be slightly larger than the smallest/largest Cartesian # coordinate # NOTE: All distances from here are in Bohr (a0) i.e. atomic units min_carts = Constants.ang2a0 * (min_cat_values - 5 * np.ones(3)) max_carts = Constants.ang2a0 * (max_cart_values + 5 * np.ones(3)) coords = np.array([Constants.ang2a0 * np.array(coord) for coord in coords]) # Number of voxels will be nx * ny * nz nx, ny, nz = 50, 50, 50 vox_size = max_carts - min_carts rx, ry, rz = vox_size[0] / nx, vox_size[1] / ny, vox_size[2] / nz # Write the .cube file lines cube_file_lines = ['Generated by cgbind\n', 'ESP\n'] n_atoms = len(coords) min_x, min_y, min_z = min_carts cube_file_lines.append(f'{n_atoms:>5d}{min_x:>12f}{min_y:>12f}{min_z:>12f}\n') # n_atoms origin(x y z) cube_file_lines.append(f'{nx:>5d}{rx:>12f}{0.0:>12f}{0.0:>12f}\n') # Number of voxels and their size cube_file_lines.append(f'{ny:>5d}{0.0:>12f}{ry:>12f}{0.0:>12f}\n') cube_file_lines.append(f'{nz:>5d}{0.0:>12f}{0.0:>12f}{rz:>12f}\n') for atom in atoms: x, y, z = atom.coord cube_file_lines.append(f'{get_atomic_number(atom):>5d}{0.0:>12f}' f'{Constants.ang2a0*x:>12f}{Constants.ang2a0*y:>12f}{Constants.ang2a0*z:>12f}\n') # Looping over x, y, z is slow in python so use Cython extension cube_val_lines, min_val, max_val = get_cube_lines(nx, ny, nz, coords, min_carts, charges, vox_size) cube_file_lines += cube_val_lines logger.info(f'ESP generated in {time()-start_time:.3f} s') return cube_file_lines, (min_val, max_val)
[ 11748, 299, 32152, 355, 45941, 198, 6738, 640, 1330, 640, 198, 6738, 269, 70, 21653, 13, 265, 3150, 1330, 651, 62, 47116, 62, 17618, 198, 6738, 269, 70, 21653, 13, 6404, 1330, 49706, 198, 6738, 269, 70, 21653, 13, 9979, 1187, 1330, ...
2.292162
1,263
import os import sys import logging import time import argparse import numpy as np from collections import OrderedDict import scripts.options as option import utils.util as util from data.util import bgr2ycbcr from data import create_dataset, create_dataloader from models import create_model # options parser = argparse.ArgumentParser() parser.add_argument('-opt', type=str, required=True, help='Path to options JSON file.') opt = option.parse(parser.parse_args().opt, is_train=False) util.mkdirs((path for key, path in opt['path'].items() if not key == 'pretrain_model_G')) opt = option.dict_to_nonedict(opt) util.setup_logger(None, opt['path']['log'], 'test.log', level=logging.INFO, screen=True) logger = logging.getLogger('base') logger.info(option.dict2str(opt)) # Create test dataset and dataloader test_loaders = [] for phase, dataset_opt in sorted(opt['datasets'].items()): test_set = create_dataset(dataset_opt) test_loader = create_dataloader(test_set, dataset_opt) logger.info('Number of test images in [{:s}]: {:d}'.format(dataset_opt['name'], len(test_set))) test_loaders.append(test_loader) # Create model model = create_model(opt) for test_loader in test_loaders: test_set_name = test_loader.dataset.opt['name'] logger.info('\nTesting [{:s}]...'.format(test_set_name)) test_start_time = time.time() dataset_dir = os.path.join(opt['path']['results_root'], test_set_name) util.mkdir(dataset_dir) test_results = OrderedDict() test_results['psnr'] = [] test_results['ssim'] = [] test_results['psnr_y'] = [] test_results['ssim_y'] = [] for data in test_loader: need_GT = False if test_loader.dataset.opt['dataroot_GT'] is None else True # need_GT = True model.feed_data_specular(data, need_GT=need_GT) if opt["image_type"] == "exr": y = data["x_offset"] x = data["y_offset"] img_path = data['NOISY_path'][0] img_name = os.path.splitext(os.path.basename(img_path))[0] start = time.time() model.test() # test end = time.time() print("Time elapsed... %f "%(end - start)) visuals = model.get_current_visuals(need_GT=need_GT) denoised_img = util.tensor2img(visuals['DENOISED']) # uint8 noisy_img = util.tensor2img(visuals['NOISY']) gt_img = util.tensor2img(visuals['GT']) # uint8 # save images suffix = opt['suffix'] if suffix ==None: suffix = "" save_DENOISED_img_path = os.path.join(dataset_dir, img_name + suffix + '_1denoised.png') save_NOISY_img_path = os.path.join(dataset_dir, img_name + suffix + '_0noisy.png') save_GT_img_path = os.path.join(dataset_dir, img_name + suffix + '_2gt.png') # calculate PSNR and SSIM if need_GT: # gt_img = util.tensor2img(visuals['GT']) gt_img = gt_img / 255. denoised_img = denoised_img / 255. crop_border = test_loader.dataset.opt['scale'] cropped_denoised_img = denoised_img#[crop_border:-crop_border, crop_border:-crop_border, :] cropped_gt_img = gt_img#[crop_border:-crop_border, crop_border:-crop_border, :] psnr = util.calculate_psnr(cropped_denoised_img * 255, cropped_gt_img * 255) ssim = util.calculate_ssim(cropped_denoised_img * 255, cropped_gt_img * 255) test_results['psnr'].append(psnr) test_results['ssim'].append(ssim) if gt_img.shape[2] == 3: # RGB image denoised_img_y = bgr2ycbcr(denoised_img, only_y=True) gt_img_y = bgr2ycbcr(gt_img, only_y=True) cropped_denoised_img_y = denoised_img_y[crop_border:-crop_border, crop_border:-crop_border] cropped_gt_img_y = gt_img_y[crop_border:-crop_border, crop_border:-crop_border] psnr_y = util.calculate_psnr(cropped_denoised_img_y * 255, cropped_gt_img_y * 255) ssim_y = util.calculate_ssim(cropped_denoised_img_y * 255, cropped_gt_img_y * 255) test_results['psnr_y'].append(psnr_y) test_results['ssim_y'].append(ssim_y) logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}; PSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}.'\ .format(img_name, psnr, ssim, psnr_y, ssim_y)) else: logger.info('{:20s} - PSNR: {:.6f} dB; SSIM: {:.6f}.'.format(img_name, psnr, ssim)) else: logger.info(img_name) if opt["image_type"] == "exr": denoised_exr = util.tensor2exr(visuals['DENOISED']) # uint8 noisy_exr = util.tensor2exr(visuals['NOISY']) gt_exr = util.tensor2exr(visuals['GT']) # uint8 save_DENOISED_img_path = os.path.join(dataset_dir, img_name + suffix + '_1denoised.exr') save_NOISY_img_path = os.path.join(dataset_dir, img_name + suffix + '_0noisy.exr') save_GT_img_path = os.path.join(dataset_dir, img_name + suffix + '_2gt.exr') util.saveEXRfromMatrix(save_DENOISED_img_path, denoised_exr, (x, y)) util.saveEXRfromMatrix(save_NOISY_img_path, noisy_exr, (x, y)) util.saveEXRfromMatrix(save_GT_img_path, gt_exr, (x, y)) if need_GT: # metrics # Average PSNR/SSIM results ave_psnr = sum(test_results['psnr']) / len(test_results['psnr']) ave_ssim = sum(test_results['ssim']) / len(test_results['ssim']) logger.info('----Average PSNR/SSIM results for {}----\n\tPSNR: {:.6f} dB; SSIM: {:.6f}\n'\ .format(test_set_name, ave_psnr, ave_ssim)) # if test_results['psnr_y'] and test_results['ssim_y']: # ave_psnr_y = sum(test_results['psnr_y']) / len(test_results['psnr_y']) # ave_ssim_y = sum(test_results['ssim_y']) / len(test_results['ssim_y']) # logger.info('----Y channel, average PSNR/SSIM----\n\tPSNR_Y: {:.6f} dB; SSIM_Y: {:.6f}\n'\ # .format(ave_psnr_y, ave_ssim_y))
[ 11748, 28686, 198, 11748, 25064, 198, 11748, 18931, 198, 11748, 640, 198, 11748, 1822, 29572, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 17268, 1330, 14230, 1068, 35, 713, 198, 198, 11748, 14750, 13, 25811, 355, 3038, 198, 11748, 3384...
2.052578
2,948
# coding:utf-8 import time import matplotlib.pyplot as plt import numpy as np import sklearn import sklearn.datasets import sklearn.linear_model import matplotlib matplotlib.rcParams['figure.figsize'] = (10.0, 8.0) np.random.seed(0) X, y = sklearn.datasets.make_moons(200, noise=0.20) plt.scatter(X[:,0], X[:,1], s=40, c=y, cmap=plt.cm.Spectral) # plt.show() clf = sklearn.linear_model.LogisticRegressionCV() clf.fit(X, y) # Helper function to plot a decision boundary. # If you don't fully understand this function don't worry, it just generates # the contour plot below. plot_decision_boundary(lambda x: clf.predict(x)) plt.title("Logistic Regression") #plt.show() num_examples = len(X) # training set size nn_input_dim = 2 # input layer dimensionality nn_output_dim = 2 # output layer dimensionality # Gradient descent parameters (I picked these by hand) epsilon = 0.01 # learning rate for gradient descent reg_lambda = 0.01 # regularization strength # Helper function to evaluate the total loss on the dataset # This function learns parameters for the neural network and returns the model. # - nn_hdim: Number of nodes in the hidden layer # - num_passes: Number of passes through the training data for gradient descent # - print_loss: If True, print the loss every 1000 iterations if __name__ == '__main__': #print(y) #print(12121) #print(X) test_1()
[ 2, 19617, 25, 40477, 12, 23, 198, 198, 11748, 640, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 1341, 35720, 198, 11748, 1341, 35720, 13, 19608, 292, 1039, 198, 11748, 1...
2.944798
471
#!/usr/bin/env python # coding=utf-8 from manage import db import app.domain.model db.create_all()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 19617, 28, 40477, 12, 23, 198, 198, 6738, 6687, 1330, 20613, 198, 11748, 598, 13, 27830, 13, 19849, 198, 198, 9945, 13, 17953, 62, 439, 3419, 198 ]
2.72973
37
import asyncio import json from aiodocker import Docker, DockerError from jupyterhub.tests.utils import api_request
[ 11748, 30351, 952, 198, 11748, 33918, 198, 198, 6738, 257, 2101, 12721, 1330, 25716, 11, 25716, 12331, 198, 6738, 474, 929, 88, 353, 40140, 13, 41989, 13, 26791, 1330, 40391, 62, 25927, 628, 628 ]
3.529412
34
from api import db from uuid import uuid4 from ariadne import MutationType from api.models import Post from api.store import queues mutation = MutationType()
[ 198, 6738, 40391, 1330, 20613, 198, 6738, 334, 27112, 1330, 334, 27112, 19, 198, 6738, 257, 21244, 710, 1330, 337, 7094, 6030, 198, 198, 6738, 40391, 13, 27530, 1330, 2947, 198, 6738, 40391, 13, 8095, 1330, 43359, 198, 76, 7094, 796, ...
3.533333
45
from async_sched.client import quit_server as module_quit from async_sched.client import request_schedules as module_request from async_sched.client import run_command as module_run from async_sched.client import schedule_command as module_schedule from async_sched.client import stop_schedule as module_stop from async_sched.client import update_server as module_update from .client import Client, \ quit_server_async, quit_server, update_server_async, update_server, request_schedules_async, \ request_schedules, run_command_async, run_command, schedule_command_async, schedule_command, \ stop_schedule_async, stop_schedule # The other modules in this package exist for the "-m" python flag # `python -m async_sched.client.request_schedules --host "12.0.0.1" --port 8000` __all__ = ['Client', 'quit_server_async', 'quit_server', 'update_server_async', 'update_server', 'request_schedules_async', 'request_schedules', 'run_command_async', 'run_command', 'schedule_command_async', 'schedule_command', 'stop_schedule_async', 'stop_schedule', 'module_quit', 'module_request', 'module_run', 'module_schedule', 'module_stop', 'module_update']
[ 6738, 30351, 62, 1416, 704, 13, 16366, 1330, 11238, 62, 15388, 355, 8265, 62, 47391, 198, 6738, 30351, 62, 1416, 704, 13, 16366, 1330, 2581, 62, 1416, 704, 5028, 355, 8265, 62, 25927, 198, 6738, 30351, 62, 1416, 704, 13, 16366, 1330, ...
2.898551
414
import abc from typing import TypeVar, Generic, List, Dict T = TypeVar('T')
[ 11748, 450, 66, 198, 6738, 19720, 1330, 5994, 19852, 11, 42044, 11, 7343, 11, 360, 713, 198, 198, 51, 796, 5994, 19852, 10786, 51, 11537, 628 ]
3
26
from pathlib import Path import pytest import git import json from conftest import TEST_DIR
[ 198, 6738, 3108, 8019, 1330, 10644, 198, 11748, 12972, 9288, 198, 11748, 17606, 198, 11748, 33918, 198, 198, 6738, 369, 701, 395, 1330, 43001, 62, 34720, 628, 198 ]
3.428571
28
# Copyright 2015 Huawei Technologies Co., Ltd. # # 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 oslo_config import cfg from oslo_log import log as logging from pecan import rest import six import tooz.coordination import wsmeext.pecan as wsme_pecan from mistral.api import access_control as acl from mistral.api.controllers.v2 import resources # TODO(rakhmerov): invalid dependency, a REST controller must not depend on # a launch script. from mistral.cmd import launch from mistral import context from mistral import exceptions as exc from mistral.service import coordination from mistral.utils import rest_utils LOG = logging.getLogger(__name__)
[ 2, 15069, 1853, 43208, 21852, 1766, 1539, 12052, 13, 198, 2, 198, 2, 220, 220, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 220, 220, 220, 345, 743, 407, 779, 428, 2393, 2845, 2...
3.486726
339
from setuptools import setup setup( name="greek-utils", version="0.2", description="various utilities for processing Ancient Greek", license="MIT", url="http://github.com/jtauber/greek-utils", author="James Tauber", author_email="jtauber@jtauber.com", packages=["greekutils"], classifiers=[ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Text Processing", "Topic :: Text Processing :: Linguistic", "Topic :: Utilities", ], )
[ 6738, 900, 37623, 10141, 1330, 9058, 198, 198, 40406, 7, 198, 220, 220, 220, 1438, 2625, 70, 10316, 12, 26791, 1600, 198, 220, 220, 220, 2196, 2625, 15, 13, 17, 1600, 198, 220, 220, 220, 6764, 2625, 7785, 699, 20081, 329, 7587, 1340...
2.585366
287
""" tweet stuff in intervals """ import time import datetime import twitter from markov_chains import german_text from config import config_no, config_yes MAX_TWEET_LENGTH = 280 greeting = ' Sehr geehrte/r Anstragssteller/in.' ending = ' MfG' num_tweets = 3 # if __name__ == '__main__': # main()
[ 37811, 198, 83, 7277, 3404, 287, 20016, 198, 37811, 198, 198, 11748, 640, 198, 11748, 4818, 8079, 198, 198, 11748, 17044, 198, 198, 6738, 1317, 709, 62, 38861, 1330, 308, 2224, 62, 5239, 198, 6738, 4566, 1330, 4566, 62, 3919, 11, 4566...
2.618644
118
from selenium.webdriver import Firefox from selenium.webdriver.firefox.options import Options import getpass import time from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from utils import *
[ 6738, 384, 11925, 1505, 13, 12384, 26230, 1330, 16802, 198, 6738, 384, 11925, 1505, 13, 12384, 26230, 13, 6495, 12792, 13, 25811, 1330, 18634, 198, 11748, 651, 6603, 198, 11748, 640, 198, 6738, 384, 11925, 1505, 13, 12384, 26230, 13, 11...
3.575342
73
pessoas = {'nomes': "Rafael","sexo":"macho alfa","idade":19} print(f"o {pessoas['nomes']} que se considera um {pessoas['sexo']} possui {pessoas['idade']}") print(pessoas.keys()) print(pessoas.values()) print(pessoas.items()) for c in pessoas.keys(): print(c) for c in pessoas.values(): print(c) for c, j in pessoas.items(): print(f"o {c} pertence ao {j}") del pessoas['sexo'] print(pessoas) pessoas["sexo"] = "macho alfa" print(pessoas) print("outro codida daqui pra frente \n\n\n\n\n\n") estado1 = {'estado': 'minas gerais', 'cidade':'capela nova' } estado2 = {'estado':'rio de janeiro', 'cidade':"rossinha"} brasil = [] brasil.append(estado1) brasil.append(estado2) print(brasil) print(f"o brasil possui um estado chamado {brasil[0]['estado']} e a prorpia possui uma cidade chamada {brasil[0]['cidade']}") print("-"*45) es = {} br = [] for c in range(0,3): es['estado'] = str(input("informe o seu estado:")) es['cidade'] = str(input("informe a sua cidade:")) br.append(es.copy()) for c in br: for i,j in c.items(): print(f"o campo {i} tem valor {j}")
[ 79, 408, 78, 292, 796, 1391, 6, 77, 2586, 10354, 366, 49, 1878, 3010, 2430, 8044, 78, 2404, 76, 43703, 435, 13331, 2430, 312, 671, 1298, 1129, 92, 198, 4798, 7, 69, 1, 78, 1391, 79, 408, 78, 292, 17816, 77, 2586, 20520, 92, 8358...
2.059701
536
# RSA Key Generator 2. # http://inventwithpython.com/hacking (BSD Licensed) 3. 4. import random, sys, os, rabinMiller, cryptomath The program imports the rabinMiller and cryptomath modules that we created in the last chapter, along with a few others. Chapter 24 Public Key Cryptography and the RSA Cipher 387 makeRsaKeys.py
[ 2, 42319, 7383, 35986, 198, 220, 362, 13, 1303, 2638, 1378, 259, 1151, 4480, 29412, 13, 785, 14, 71, 5430, 357, 21800, 49962, 8, 220, 513, 13, 220, 220, 604, 13, 1330, 4738, 11, 25064, 11, 28686, 11, 374, 6014, 33253, 11, 8194, 29...
3.393939
99
config = { "Luminosity": 1000, "InputDirectory": "results", "Histograms" : { "WtMass" : {}, "etmiss" : {}, "lep_n" : {}, "lep_pt" : {}, "lep_eta" : {}, "lep_E" : {}, "lep_phi" : {"y_margin" : 0.6}, "lep_charge" : {"y_margin" : 0.6}, "lep_type" : {"y_margin" : 0.5}, "lep_ptconerel30" : {}, "lep_etconerel20" : {}, "lep_d0" : {}, "lep_z0" : {}, "n_jets" : {}, "jet_pt" : {}, "jet_m" : {}, "jet_jvf" : {"y_margin" : 0.4}, "jet_eta" : {}, "jet_MV1" : {"y_margin" : 0.3}, "vxp_z" : {}, "pvxp_n" : {}, }, "Paintables": { "Stack": { "Order" : ["Diboson", "DrellYan", "W", "Z", "stop", "ttbar"], "Processes" : { "Diboson" : { "Color" : "#fa7921", "Contributions" : ["WW", "WZ", "ZZ"]}, "DrellYan": { "Color" : "#5bc0eb", "Contributions" : ["DYeeM08to15", "DYeeM15to40", "DYmumuM08to15", "DYmumuM15to40", "DYtautauM08to15", "DYtautauM15to40"]}, "W": { "Color" : "#e55934", "Contributions" : ["WenuJetsBVeto", "WenuWithB", "WenuNoJetsBVeto", "WmunuJetsBVeto", "WmunuWithB", "WmunuNoJetsBVeto", "WtaunuJetsBVeto", "WtaunuWithB", "WtaunuNoJetsBVeto"]}, "Z": { "Color" : "#086788", "Contributions" : ["Zee", "Zmumu", "Ztautau"]}, "stop": { "Color" : "#fde74c", "Contributions" : ["stop_tchan_top", "stop_tchan_antitop", "stop_schan", "stop_wtchan"]}, "ttbar": { "Color" : "#9bc53d", "Contributions" : ["ttbar_lep", "ttbar_had"]} } }, "data" : { "Contributions": ["data_Egamma", "data_Muons"]} }, "Depictions": { "Order": ["Main", "Data/MC"], "Definitions" : { "Data/MC": { "type" : "Agreement", "Paintables" : ["data", "Stack"] }, "Main": { "type" : "Main", "Paintables": ["Stack", "data"] }, } }, }
[ 11250, 796, 1391, 198, 1, 43, 7230, 16579, 1298, 8576, 11, 198, 1, 20560, 43055, 1298, 366, 43420, 1600, 198, 198, 1, 13749, 26836, 1, 1058, 1391, 198, 220, 220, 220, 366, 54, 83, 20273, 1, 220, 220, 220, 220, 220, 220, 220, 220, ...
1.489724
1,703
# coding=utf-8 from ..logger import log_debug from ..utils import parent_map, replace_node, is_prefixed_var, get_used_vars
[ 2, 19617, 28, 40477, 12, 23, 198, 6738, 11485, 6404, 1362, 1330, 2604, 62, 24442, 198, 6738, 11485, 26791, 1330, 2560, 62, 8899, 11, 6330, 62, 17440, 11, 318, 62, 3866, 34021, 62, 7785, 11, 651, 62, 1484, 62, 85, 945, 628, 198 ]
2.906977
43
""" Determine the number of bits required to convert integer A to integer B Example Given n = 31, m = 14,return 2 (31)10=(11111)2 (14)10=(01110)2 """ __author__ = 'Danyang' if __name__=="__main__": assert Solution().bitSwapRequired(1, -1)==31 assert Solution().bitSwapRequired(31, 14)==2
[ 37811, 198, 35, 2357, 3810, 262, 1271, 286, 10340, 2672, 284, 10385, 18253, 317, 284, 18253, 347, 198, 198, 16281, 198, 15056, 299, 796, 3261, 11, 285, 796, 1478, 11, 7783, 362, 198, 198, 7, 3132, 8, 940, 16193, 1157, 16243, 8, 17, ...
2.603448
116
from pyLMS7002M import * print("Searching for QSpark...") try: QSpark = QSpark() except: print("QSpark not found") exit(1) print("\QSpark info:") QSpark.printInfo() # print the QSpark board info # QSpark.LMS7002_Reset() # reset the LMS7002M lms7002 = QSpark.getLMS7002() # get the LMS7002M object ver, rev, mask = lms7002.chipInfo # get the chip info print("\nLMS7002M info:") print("VER : "+str(ver)) print("REV : "+str(rev)) print("MASK : "+str(mask))
[ 6738, 12972, 43, 5653, 9879, 17, 44, 1330, 1635, 198, 198, 4798, 7203, 18243, 278, 329, 1195, 4561, 668, 9313, 8, 198, 28311, 25, 198, 220, 220, 220, 1195, 4561, 668, 796, 1195, 4561, 668, 3419, 198, 16341, 25, 198, 220, 220, 220, ...
1.811377
334
from django.conf import settings from netaddr import mac_unix, mac_eui48 import importlib import warnings from pkg_resources import get_distribution, DistributionNotFound import os.path try: _dist = get_distribution('django-macaddress') except DistributionNotFound: __version__ = 'Please install this project with setup.py' else: __version__ = _dist.version VERSION = __version__ # synonym
[ 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 198, 6738, 2010, 29851, 1330, 8352, 62, 403, 844, 11, 8352, 62, 68, 9019, 2780, 198, 198, 11748, 1330, 8019, 198, 11748, 14601, 628, 198, 6738, 279, 10025, 62, 37540, 1330, 651, 62, 1708...
3.272
125
import time from textmagic.test import ONE_TEST_NUMBER from textmagic.test import THREE_TEST_NUMBERS from textmagic.test import TextMagicTestsBase from textmagic.test import LiveUnsafeTests
[ 11748, 640, 198, 198, 6738, 2420, 32707, 13, 9288, 1330, 16329, 62, 51, 6465, 62, 41359, 13246, 198, 6738, 2420, 32707, 13, 9288, 1330, 48697, 62, 51, 6465, 62, 41359, 33, 4877, 198, 198, 6738, 2420, 32707, 13, 9288, 1330, 8255, 22975...
3.305085
59
from django.db import models from utils.models import BaseModel from users.models import User, Address from goods.models import GoodsSKU # Create your models here.
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 6738, 3384, 4487, 13, 27530, 1330, 7308, 17633, 198, 6738, 2985, 13, 27530, 1330, 11787, 11, 17917, 198, 6738, 7017, 13, 27530, 1330, 38360, 18831, 52, 198, 198, 2, 13610, 534, 4981, 994, ...
3.755556
45
from collections import defaultdict, Counter import os import gzip import json import pickle from json.decoder import JSONDecodeError import logging from typing import Dict import pdb from event import util from event.arguments.prepare.slot_processor import get_simple_dep, is_propbank_dep logger = logging.getLogger(__name__) def get_arg_rep(self, dep, entity_rep): if dep.startswith("prep"): dep = self.get_vocab_word(dep, "preposition") arg_rep = self.make_arg(entity_rep, dep) return arg_rep def get_pred_rep(self, event): """ Take the predicates, and get the vocab index for it. This will first use the predicate itself, if not found, it will try to use the verb form. :param event: :return: """ pred = self.get_vocab_word(event["predicate"], "predicate") if pred == self.oovs["predicate"]: # Try to see if the verb form help. if "verb_form" in event: pred = self.get_vocab_word(event["verb_form"], "predicate") return self.make_predicate(pred) def get_fe_rep(self, frame_name, fe_role): # return self.make_fe(frame_name, fe_role) return self.get_vocab_word(self.make_fe(frame_name, fe_role), "fe") class EmbbedingVocab: def __init__(self, vocab_file, with_padding=False, extras=None): self.vocab_file = vocab_file self.vocab = {} self.tf = [] self.extras = [] self.pad = "__PADDING__" self.padded = False if with_padding: # Paddings should be at 0. self.padded = True self.vocab[self.pad] = 0 self.tf.append(0) if extras: for name in extras: self.add_extra(name) self.__read_vocab() def add_extra(self, name): """Add extra dimensions into the embedding vocab, used for special tokens. Args: name: Returns: """ if name in self.extras: logger.info( f"Extra {name} already exist in vocabulary " f"at index {self.vocab[name]}" ) return self.vocab[name] else: self.extras.append(name) extra_index = len(self.vocab) self.vocab[name] = extra_index self.tf.append(0) logger.info( f"Adding {name} as extra dimension {extra_index} " f"to {self.vocab_file}" ) return extra_index def create_sentences( doc, event_vocab, output_path, include_frame=False, use_simple_dep=False, prop_arg_only=False, ): if include_frame: print("Adding frames to sentences.") doc_count = 0 event_count = 0 with gzip.open(doc) as data, gzip.open(output_path, "w") as out: for line in data: try: doc_info = json.loads(line) except JSONDecodeError: continue sentence = [] represent_by_id = {} for entity in doc_info["entities"]: eid = entity["entityId"] represent = entity["representEntityHead"] represent_by_id[eid] = represent for event in doc_info["events"]: event_count += 1 sentence.append(event_vocab.get_pred_rep(event)) if include_frame and not event["frame"] == "NA": frame = event_vocab.get_vocab_word(event["frame"], "frame") sentence.append(frame) for arg in event["arguments"]: dep = arg["dep"] if ( arg["argStart"] == event["predicateStart"] and arg["argEnd"] == event["predicateEnd"] ): dep = "root" if use_simple_dep: dep = get_simple_dep(dep) if prop_arg_only and not is_propbank_dep(dep): continue sentence.append( event_vocab.get_arg_rep( dep, event_vocab.get_arg_entity_rep(arg, None) ) ) if include_frame and not arg["feName"] == "NA": fe = event_vocab.get_fe_rep(frame, arg["feName"]) if not fe == event_vocab.oovs["fe"]: sentence.append(fe) if "NA" in sentence: pdb.set_trace() doc_count += 1 out.write(str.encode(" ".join(sentence) + "\n")) if event_count % 1000 == 0: print( "\rCreated sentences for {} documents, " "{} events.".format(doc_count, event_count), end="", ) print( "\rCreated sentences for {} documents, " "{} events.\n".format(doc_count, event_count), end="", ) def write_sentences( sent_out, event_data, event_vocab, include_frame, simple_dep, prop_arg ): if not os.path.exists(sent_out): os.makedirs(sent_out) fname = "sent_with_frames.gz" if include_frame else "sent_pred_only.gz" out = os.path.join(sent_out, fname) if not os.path.exists(out): create_sentences( event_data, event_vocab, out, include_frame=include_frame, use_simple_dep=simple_dep, prop_arg_only=prop_arg, ) else: logger.info(f"Will not overwrite {out}") def main(event_data, vocab_dir, sent_out, prop_arg): if not os.path.exists(vocab_dir): os.makedirs(vocab_dir) event_vocab = TypedEventVocab(vocab_dir, event_data=event_data) logger.info("Done loading vocabulary.") # The 3 boolean are : include_frame,simple_dep, prop_arg if prop_arg: # For propbank style training. logger.info("Creating event sentences in propbank style") # Include frame or not version for propbank, but always use simple dep # and propbank style arguments. write_sentences(sent_out, event_data, event_vocab, False, True, True) write_sentences(sent_out, event_data, event_vocab, True, True, True) else: # For framenet style training. logger.info("Creating event sentences in FrameNet style") # Include frame or not version for framenet, but always use complex dep # and framenet style arguments. write_sentences(sent_out, event_data, event_vocab, True, False, False) write_sentences(sent_out, event_data, event_vocab, False, False, False) if __name__ == "__main__": parser = util.OptionPerLineParser( description="Event Vocabulary.", fromfile_prefix_chars="@" ) parser.add_argument("--vocab_dir", type=str, help="Vocabulary directory.") parser.add_argument("--input_data", type=str, help="Input data.") parser.add_argument("--sent_out", type=str, help="Sentence out dir.") parser.add_argument( "--prop_arg", action="store_true", help="Propbank arg only.", default=False ) util.set_basic_log() args = parser.parse_args() main(args.input_data, args.vocab_dir, args.sent_out, args.prop_arg)
[ 6738, 17268, 1330, 4277, 11600, 11, 15034, 198, 11748, 28686, 198, 11748, 308, 13344, 198, 11748, 33918, 198, 11748, 2298, 293, 198, 6738, 33918, 13, 12501, 12342, 1330, 19449, 10707, 1098, 12331, 198, 11748, 18931, 198, 6738, 19720, 1330, ...
2.039441
3,651
#!/usr/bin/python import random count = 20 test_set = [] while count: a = random.randrange(3,20) b = random.randrange(3,20) if a > b and a - b > 1: if (b, a-b) not in test_set: test_set.append((b, a-b)) count -= 1 elif b > a and b - a > 1: if (a, b-a) not in test_set: test_set.append((a, b-a)) count -= 1 else: continue for (a,b) in test_set: print " %2d + %2d = " % (a,b)
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 198, 11748, 4738, 198, 198, 9127, 796, 1160, 198, 198, 9288, 62, 2617, 796, 17635, 198, 4514, 954, 25, 198, 220, 220, 220, 257, 796, 4738, 13, 25192, 9521, 7, 18, 11, 1238, 8, 198, 220, ...
1.81749
263
from enum import Enum from functools import reduce from math import ceil from typing import Optional, Tuple from autovirt import utils from autovirt.exception import AutovirtError from autovirt.structs import UnitEquipment, RepairOffer logger = utils.get_logger() # maximum allowed equipment price PRICE_MAX = 100000 # value to add and sub from offer quality when filtering QUALITY_DELTA = 3 def quantity_to_repair(units: list[UnitEquipment]) -> int: """Calculate total quantity of equipment to repair on given units""" return sum([unit.wear_quantity for unit in units]) def quantity_total(units: list[UnitEquipment]) -> int: """Calculate total equipment count on given units""" return sum([unit.quantity for unit in units]) def split_by_quality( units: list[UnitEquipment], quality_type: QualityType = QualityType.REQUIRED ) -> dict[float, list[UnitEquipment]]: """Split units by quality (required or installed)""" res: dict[float, list[UnitEquipment]] = {} for unit in units: quality = getattr(unit, quality_type.value) if quality not in res.keys(): res[quality] = [] res[quality].append(unit) return res def split_mismatch_quality_units( units: list[UnitEquipment], ) -> tuple[list[UnitEquipment], list[UnitEquipment]]: """Split units into 'normal' and 'mismatch' groups. Mismatched unit have installed equipment of lower quality then required. We need to treat them in different manner then normal while repairing. """ normal = [] mismatch = [] for unit in units: if unit.quality < unit.quality_required: mismatch.append(unit) else: normal.append(unit) return normal, mismatch
[ 6738, 33829, 1330, 2039, 388, 198, 6738, 1257, 310, 10141, 1330, 4646, 198, 6738, 10688, 1330, 2906, 346, 198, 6738, 19720, 1330, 32233, 11, 309, 29291, 198, 198, 6738, 1960, 709, 2265, 1330, 3384, 4487, 198, 6738, 1960, 709, 2265, 13, ...
2.972743
587
#!/usr/bin/env python3 import re with open("input.txt") as f: content = f.read().strip() print(ulen(content))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 302, 628, 198, 4480, 1280, 7203, 15414, 13, 14116, 4943, 355, 277, 25, 198, 220, 220, 220, 2695, 796, 277, 13, 961, 22446, 36311, 3419, 198, 198, 4798, 7, 377, 268, ...
2.510638
47
# pylint: disable=wrong-or-nonexistent-copyright-notice import itertools import math import numpy as np import pytest import sympy import cirq import cirq.contrib.quimb as ccq import cirq.testing from cirq import value
[ 2, 279, 2645, 600, 25, 15560, 28, 36460, 12, 273, 12, 23108, 87, 7609, 12, 22163, 4766, 12, 42138, 198, 11748, 340, 861, 10141, 198, 11748, 10688, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 198, 11748, 10558, 88...
2.824176
91
import os from pathlib import Path from typing import Any, Dict from determined.common import util MASTER_SCHEME = "http" MASTER_IP = "localhost" MASTER_PORT = "8080" DET_VERSION = None DEFAULT_MAX_WAIT_SECS = 1800 MAX_TASK_SCHEDULED_SECS = 30 MAX_TRIAL_BUILD_SECS = 90 DEFAULT_TF1_CPU_IMAGE = "determinedai/environments:py-3.7-pytorch-1.7-tf-1.15-cpu-08f9c9b" DEFAULT_TF2_CPU_IMAGE = ( "determinedai/environments:py-3.8-pytorch-1.9-lightning-1.3-tf-2.4-cpu-08f9c9b" ) DEFAULT_TF1_GPU_IMAGE = "determinedai/environments:cuda-10.2-pytorch-1.7-tf-1.15-gpu-08f9c9b" DEFAULT_TF2_GPU_IMAGE = ( "determinedai/environments:cuda-11.1-pytorch-1.9-lightning-1.3-tf-2.4-gpu-08f9c9b" ) TF1_CPU_IMAGE = os.environ.get("TF1_CPU_IMAGE") or DEFAULT_TF1_CPU_IMAGE TF2_CPU_IMAGE = os.environ.get("TF2_CPU_IMAGE") or DEFAULT_TF2_CPU_IMAGE TF1_GPU_IMAGE = os.environ.get("TF1_GPU_IMAGE") or DEFAULT_TF1_GPU_IMAGE TF2_GPU_IMAGE = os.environ.get("TF2_GPU_IMAGE") or DEFAULT_TF2_GPU_IMAGE GPU_ENABLED = os.environ.get("DET_TEST_GPU_ENABLED", "1") not in ("0", "false") PROJECT_ROOT_PATH = Path(__file__).resolve().parents[2]
[ 11748, 28686, 198, 6738, 3108, 8019, 1330, 10644, 198, 6738, 19720, 1330, 4377, 11, 360, 713, 198, 198, 6738, 5295, 13, 11321, 1330, 7736, 198, 198, 31180, 5781, 62, 50, 3398, 3620, 36, 796, 366, 4023, 1, 198, 31180, 5781, 62, 4061, ...
2.085455
550
from django.contrib.contenttypes.models import ContentType from rest_framework import serializers, exceptions from greenbudget.lib.rest_framework_utils.fields import ModelChoiceField from greenbudget.lib.rest_framework_utils.serializers import ( EnhancedModelSerializer) from greenbudget.app.budget.models import BaseBudget from greenbudget.app.common.serializers import ( EntitySerializer, AbstractBulkUpdateSerializer, create_bulk_create_serializer ) from greenbudget.app.fringe.models import Fringe from greenbudget.app.group.models import ( BudgetSubAccountGroup, TemplateSubAccountGroup ) from .models import SubAccount, BudgetSubAccount, TemplateSubAccount def create_bulk_create_subaccounts_serializer(model_cls): data_serializer = BudgetSubAccountSerializer if model_cls is TemplateSubAccount: data_serializer = TemplateSubAccountSerializer base_serializer = create_bulk_create_serializer(data_serializer) return BulkCreateSubAccountsSerializer def create_subaccount_bulk_change_serializer(model_cls): base_serializer = BudgetSubAccountSerializer if model_cls is TemplateSubAccount: base_serializer = TemplateSubAccountSerializer return SubAccountBulkChangeSerializer def create_bulk_update_subaccounts_serializer(model_cls): return BulkUpdateSubAccountsSerializer
[ 6738, 42625, 14208, 13, 3642, 822, 13, 11299, 19199, 13, 27530, 1330, 14041, 6030, 198, 6738, 1334, 62, 30604, 1330, 11389, 11341, 11, 13269, 198, 198, 6738, 4077, 37315, 13, 8019, 13, 2118, 62, 30604, 62, 26791, 13, 25747, 1330, 9104, ...
3.303398
412
import contextlib import logging import typing from typing import Any, Dict, Tuple import attr from dbnd._core.configuration import get_dbnd_project_config from dbnd._core.constants import ( RESULT_PARAM, DbndTargetOperationStatus, DbndTargetOperationType, TaskRunState, ) from dbnd._core.current import ( current_task_run, get_databand_run, is_verbose, try_get_current_task, ) from dbnd._core.errors.errors_utils import log_exception from dbnd._core.log.external_exception_logging import log_exception_to_server from dbnd._core.parameter.parameter_definition import ParameterDefinition from dbnd._core.parameter.parameter_value import ParameterFilters from dbnd._core.settings import TrackingConfig from dbnd._core.task.tracking_task import TrackingTask from dbnd._core.task_build.task_context import try_get_current_task from dbnd._core.task_build.task_definition import TaskDefinition from dbnd._core.task_build.task_results import FuncResultParameter from dbnd._core.task_run.task_run import TaskRun from dbnd._core.task_run.task_run_error import TaskRunError from dbnd._core.utils.callable_spec import args_to_kwargs from dbnd._core.utils.timezone import utcnow from targets import InMemoryTarget, Target from targets.value_meta import ValueMetaConf from targets.values import get_value_type_of_obj if typing.TYPE_CHECKING: from dbnd._core.task_build.task_decorator import TaskDecorator logger = logging.getLogger(__name__) def _handle_tracking_error(msg, func_call=None): log_exception_to_server() location = " for %s" % func_call.callable if func_call else "" msg = "Failed during dbnd %s for %s, ignoring, and continue without tracking" % ( msg, location, ) if is_verbose(): logger.warning( msg, exc_info=True, ) else: logger.info(msg) def _do_nothing_decorator(f): return f def _log_inputs(task_run): """ For tracking mode. Logs InMemoryTarget inputs. """ try: params = task_run.task._params for param_value in params.get_param_values(ParameterFilters.INPUTS): param, value = param_value.parameter, param_value.value if isinstance(param_value, InMemoryTarget): try: param = param.modify( value_meta_conf=ValueMetaConf( log_preview=True, log_schema=True, ) ) task_run.tracker.log_parameter_data( parameter=param, target=param_value, value=value, operation_type=DbndTargetOperationType.read, operation_status=DbndTargetOperationStatus.OK, ) except Exception as ex: log_exception( "Failed to log input param to tracking store.", ex=ex, non_critical=True, ) except Exception as ex: log_exception( "Failed to log input params to tracking store.", ex=ex, non_critical=True ) def _log_result(task_run, result): # type: (TaskRun, Any) -> None """ For tracking mode. Logs the task result and adds it to the target_origin map to support relationships between dynamic tasks. """ try: result_param = task_run.task.task_params.get_param_value(RESULT_PARAM) if not result_param: logger.debug( "No result params to log for task {}".format(task_run.task_af_id) ) return # we now the parameter value is a target because this is an output param # the target is created in the task creation result_param_def, result_target = result_param.parameter, result_param.value # spread result into relevant fields. if isinstance(result_param_def, FuncResultParameter): # assign all returned values to relevant band Outputs if result is None: return for result_name, value in result_param_def.named_results(result): # we now the parameter value is a target because this is an output param # the target is created in the task creation parameter_value = task_run.task.task_params.get_param_value(result_name) _log_parameter_value( task_run, parameter_definition=parameter_value.parameter, target=parameter_value.value, value=value, ) else: _log_parameter_value( task_run, parameter_definition=result_param_def, target=result_target, value=result, ) except Exception as ex: log_exception( "Failed to log result to tracking store.", ex=ex, non_critical=True )
[ 11748, 4732, 8019, 198, 11748, 18931, 198, 11748, 19720, 198, 198, 6738, 19720, 1330, 4377, 11, 360, 713, 11, 309, 29291, 198, 198, 11748, 708, 81, 198, 198, 6738, 20613, 358, 13557, 7295, 13, 11250, 3924, 1330, 651, 62, 9945, 358, 62...
2.241578
2,256
import os import logging from json import loads, dumps from datetime import timedelta from argparse import ArgumentParser from redis import Redis from flask import Response, Flask, request app = Flask(__name__) log = logging.getLogger(__name__) parser = ArgumentParser() parser.add_argument("-a", "--address", action="store", dest="address", type=str, required=True, help="Address for api") parser.add_argument("-p", "--port", action="store", dest="port", type=str, required=True, help="Port for api") parser.add_argument("-c", "--crt", action="store", dest="cert", type=str, required=False, help="Path to certificate for this API") parser.add_argument("-k", "--key", action="store", dest="key", type=str, required=False, help="Path to key of certificate used by this API") parser.add_argument("-rp", "--redis-port", action="store", dest="redis-port", type=str, required=True, help="Port for Redis client") args = vars(parser.parse_args()) api_address = args["address"] api_port = args["port"] api_cert = args["cert"] api_key = args["key"] redis_port = args["redis-port"] r = Redis(port=redis_port, charset="utf-8", decode_responses=True) def start_api(address, port, clnt_cert=None, clnt_key=None): if clnt_cert is None or clnt_key is None: app.run(host=address, port=port, debug=False) else: app.run(host=address, port=port, ssl_context=(clnt_cert, clnt_key), debug=False) if api_cert is None or api_key is None: start_api(api_address, api_port) else: start_api(api_address, api_port, api_cert, api_key)
[ 11748, 28686, 198, 11748, 18931, 198, 6738, 33918, 1330, 15989, 11, 45514, 198, 6738, 4818, 8079, 1330, 28805, 12514, 198, 6738, 1822, 29572, 1330, 45751, 46677, 198, 198, 6738, 2266, 271, 1330, 2297, 271, 198, 6738, 42903, 1330, 18261, 1...
2.199058
849
""" spider Chromecmd cd Chrome chrome.exe --remote-debugging-port=9222 http://127.0.0.1:9222/json json spider settings # ROBOTSTXT_OBEY = False # parse # COOKIES_ENABLED = True # Request cookies # USER_AGENT = # DOWNLOADER_MIDDLEWARES user agent """ import re import json import datetime import scrapy from scrapy.loader import ItemLoader from urllib import parse from ZhihuSpider.utils.browsezhihu import get_cookies from ZhihuSpider import settings from ZhihuSpider.items import ZhihuQuestionItem, ZhihuAnswerItem
[ 37811, 198, 19230, 220, 18255, 721, 9132, 220, 198, 10210, 220, 13282, 220, 220, 198, 46659, 13, 13499, 1377, 47960, 12, 24442, 2667, 12, 634, 28, 24, 23148, 198, 4023, 1378, 16799, 13, 15, 13, 15, 13, 16, 25, 24, 23148, 14, 17752, ...
2.924324
185
import nose import angr import logging l = logging.getLogger("angr.tests.test_bindiff") import os test_location = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'binaries', 'tests') # todo make a better test if __name__ == "__main__": logging.getLogger("angr.analyses.bindiff").setLevel(logging.DEBUG) import sys if len(sys.argv) > 1: globals()['test_' + sys.argv[1]]() else: run_all()
[ 11748, 9686, 198, 11748, 281, 2164, 198, 198, 11748, 18931, 198, 75, 796, 18931, 13, 1136, 11187, 1362, 7203, 648, 81, 13, 41989, 13, 9288, 62, 21653, 733, 4943, 198, 198, 11748, 28686, 198, 9288, 62, 24886, 796, 28686, 13, 6978, 13, ...
2.385027
187
from pathlib import Path BASE_DIR = Path(__file__).resolve().parent.parent # def handle_uploaded_file(f): # with open('screenshot.png', 'wb') as destination: # # for chunk in f.chunks(): # # destination.write(chunk) # destination.write(f) with open( BASE_DIR/'media'/'Greater_coat_of_arms_of_the_United_States.png', 'rb' ) as file: flag = file.read() # handle_uploaded_file(flag) print(type(flag)) print(len(flag)) # print(flag) # for place in sys.path: # print(place)
[ 6738, 3108, 8019, 1330, 10644, 628, 198, 33, 11159, 62, 34720, 796, 10644, 7, 834, 7753, 834, 737, 411, 6442, 22446, 8000, 13, 8000, 198, 2, 825, 5412, 62, 25850, 276, 62, 7753, 7, 69, 2599, 198, 2, 220, 220, 220, 220, 351, 1280, ...
2.345291
223
#!/usr/bin/env python3 # # Copyright 2018 Google LLC # # 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 aiohttp import web import capstone import functools from gdbproc import GDBProcess import socketio import asyncio import codecs import os enable_logging = False premium = 'PREMIUM' in os.environ if premium: access_key = os.getenv('PREMIUM_KEY') runnable = ['/home/user/printwebflag'] else: access_key = os.getenv('TRIAL_KEY') runnable = ['/bin/sleep', '20'] MAX_INSN_LEN = 15 capstone_md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64) sio = socketio.AsyncServer() app = web.Application() sio.attach(app) with open('index.html') as f: index_html = f.read() app.add_routes([web.get('/', index), web.get('/{name}', index)]) gdb_sessions = {} stop_queue_readers = {} app.on_shutdown.append(on_shutdown) if __name__ == '__main__': web.run_app(app)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 198, 2, 15069, 2864, 3012, 11419, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393,...
2.862705
488
r""" Piezo-elasticity problem - linear elastic material with piezoelectric effects. Find :math:`\ul{u}`, :math:`\phi` such that: .. math:: - \omega^2 \int_{Y} \rho\ \ul{v} \cdot \ul{u} + \int_{Y} D_{ijkl}\ e_{ij}(\ul{v}) e_{kl}(\ul{u}) - \int_{Y_2} g_{kij}\ e_{ij}(\ul{v}) \nabla_k \phi = 0 \;, \quad \forall \ul{v} \;, \int_{Y_2} g_{kij}\ e_{ij}(\ul{u}) \nabla_k \psi + \int_{Y} K_{ij} \nabla_i \psi \nabla_j \phi = 0 \;, \quad \forall \psi \;, where .. math:: D_{ijkl} = \mu (\delta_{ik} \delta_{jl}+\delta_{il} \delta_{jk}) + \lambda \ \delta_{ij} \delta_{kl} \;. """ from __future__ import absolute_import import os import numpy as nm from sfepy import data_dir from sfepy.discrete.fem import MeshIO from sfepy.mechanics.matcoefs import stiffness_from_lame import six def post_process(out, pb, state, extend=False): """ Calculate and output the strain and stresses for the given state. """ from sfepy.base.base import Struct from sfepy.discrete.fem import extend_cell_data ev = pb.evaluate strain = ev('ev_cauchy_strain.i.Y(u)', mode='el_avg') stress = ev('ev_cauchy_stress.i.Y(inclusion.D, u)', mode='el_avg') piezo = -ev('ev_piezo_stress.i.Y2(inclusion.coupling, phi)', mode='el_avg') piezo = extend_cell_data(piezo, pb.domain, 'Y2', val=0.0) piezo_strain = ev('ev_piezo_strain.i.Y(inclusion.coupling, u)', mode='el_avg') out['cauchy_strain'] = Struct(name='output_data', mode='cell', data=strain, dofs=None) out['elastic_stress'] = Struct(name='output_data', mode='cell', data=stress, dofs=None) out['piezo_stress'] = Struct(name='output_data', mode='cell', data=piezo, dofs=None) out['piezo_strain'] = Struct(name='output_data', mode='cell', data=piezo_strain, dofs=None) out['total_stress'] = Struct(name='output_data', mode='cell', data=stress + piezo, dofs=None) return out filename_mesh = data_dir + '/meshes/2d/special/circle_in_square.mesh' ## filename_mesh = data_dir + '/meshes/2d/special/circle_in_square_small.mesh' ## filename_mesh = data_dir + '/meshes/3d/special/cube_sphere.mesh' ## filename_mesh = data_dir + '/meshes/2d/special/cube_cylinder.mesh' omega = 1 omega_squared = omega**2 conf_dir = os.path.dirname(__file__) io = MeshIO.any_from_filename(filename_mesh, prefix_dir=conf_dir) bbox, dim = io.read_bounding_box(ret_dim=True) geom = {3 : '3_4', 2 : '2_3'}[dim] x_left, x_right = bbox[:,0] options = { 'post_process_hook' : 'post_process', } regions = { 'Y' : 'all', 'Y1' : 'cells of group 1', 'Y2' : 'cells of group 2', 'Y2_Surface': ('r.Y1 *v r.Y2', 'facet'), 'Left' : ('vertices in (x < %f)' % (x_left + 1e-3), 'facet'), 'Right' : ('vertices in (x > %f)' % (x_right - 1e-3), 'facet'), } fields = { 'displacement' : ('real', dim, 'Y', 1), 'potential' : ('real', 1, 'Y', 1), } variables = { 'u' : ('unknown field', 'displacement', 0), 'v' : ('test field', 'displacement', 'u'), 'phi' : ('unknown field', 'potential', 1), 'psi' : ('test field', 'potential', 'phi'), } ebcs = { 'u1' : ('Left', {'u.all' : 0.0}), 'u2' : ('Right', {'u.0' : 0.1}), 'phi' : ('Y2_Surface', {'phi.all' : 0.0}), } def get_inclusion_pars(ts, coor, mode=None, **kwargs): """TODO: implement proper 3D -> 2D transformation of constitutive matrices.""" if mode == 'qp': _, dim = coor.shape sym = (dim + 1) * dim // 2 dielectric = nm.eye(dim, dtype=nm.float64) # !!! coupling = nm.ones((dim, sym), dtype=nm.float64) # coupling[0,1] = 0.2 out = { # Lame coefficients in 1e+10 Pa. 'D' : stiffness_from_lame(dim=2, lam=0.1798, mu=0.148), # dielectric tensor 'dielectric' : dielectric, # piezoelectric coupling 'coupling' : coupling, 'density' : nm.array([[0.1142]]), # in 1e4 kg/m3 } for key, val in six.iteritems(out): out[key] = val[None, ...] return out materials = { 'inclusion' : (None, 'get_inclusion_pars') } functions = { 'get_inclusion_pars' : (get_inclusion_pars,), } integrals = { 'i' : 2, } equations = { '1' : """- %f * dw_volume_dot.i.Y(inclusion.density, v, u) + dw_lin_elastic.i.Y(inclusion.D, v, u) - dw_piezo_coupling.i.Y2(inclusion.coupling, v, phi) = 0""" % omega_squared, '2' : """dw_piezo_coupling.i.Y2(inclusion.coupling, u, psi) + dw_diffusion.i.Y(inclusion.dielectric, psi, phi) = 0""", } solvers = { 'ls' : ('ls.scipy_direct', {}), 'newton' : ('nls.newton', {'i_max' : 1, 'eps_a' : 1e-10, }), }
[ 81, 37811, 198, 48223, 10872, 12, 417, 3477, 414, 1917, 532, 14174, 27468, 2587, 351, 2508, 89, 2577, 801, 1173, 198, 34435, 13, 198, 198, 16742, 1058, 11018, 25, 63, 59, 377, 90, 84, 92, 47671, 1058, 11018, 25, 63, 59, 34846, 63, ...
1.964356
2,525
# Desempacotamento de parametros em funcoes # somando valores de uma tupla # Programa principal print('Resultado: {}\n' .format(soma(1, 2))) print('Resultado: {}\n' .format(soma(1, 2, 3, 4, 5, 6, 7, 8, 9)))
[ 2, 2935, 368, 33587, 313, 3263, 78, 390, 5772, 316, 4951, 795, 1257, 1073, 274, 198, 2, 3870, 25440, 1188, 2850, 390, 334, 2611, 12777, 489, 64, 628, 198, 2, 6118, 64, 10033, 198, 4798, 10786, 23004, 4533, 25, 23884, 59, 77, 6, 76...
2.375
88
import pandas from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import KerasClassifier from keras.utils import np_utils from sklearn.model_selection import cross_val_score from sklearn.model_selection import KFold from sklearn.preprocessing import LabelEncoder from sklearn.pipeline import Pipeline import keras import sys import json import requests import numpy as np # define baseline model model = baseline_model() model.load_weights("../model1.h5") # data = sys.argv[1] # data = '{"pH min":5.7,"pH max":7,"nitrogen min":109,"nitrogen max":146,"phosphorus min":20,"phosphorus max":30,"potasium min":78,"potasium max":115,"calcium min":270,"calcium max":990,"magnesium min":46,"magnesium max":96,"sulphur min":10,"sulphur max":10,"iron min":44,"iron max":46,"zinc min":3.87,"zinc max":5.87,"manganese min":4.81,"manganese max":4.81,"copper min":21,"copper max":26,"boron min":1.25,"boron max":2.25,"temperature min":25,"temperature max":35,"precipitation min":50,"precipitation max":60,"irrigation":"yes ","region":"barshi"}' # data = '{"pH min":7.6,"pH max":7.6,"nitrogen min":150.53,"nitrogen max":150.53,"phosphorus min":55.96,"phosphorus max":55.96,"potasium min":728,"potasium max":728,"calcium min":45.56,"calcium max":45.56,"magnesium min":36.46,"magnesium max":36.46,"sulphur min":44.69,"sulphur max":44.69,"iron min":2.7,"iron max":2.7,"zinc min":0.49,"zinc max":0.49,"manganese min":2.16,"manganese max":2.16,"copper min":3.5,"copper max":3.5,"boron min":0.63,"boron max":0.63,"temperature min":21,"temperature max":31,"precipitation min":60.18,"precipitation max":60.18,"irrigation":"yes ","region":"barshi"}' data= '{"pH min":5.7,"pH max":7,"nitrogen min":109,"nitrogen max":146,"phosphorus min":20,"phosphorus max":30,"potasium min":78,"potasium max":115,"calcium min":270,"calcium max":990,"magnesium min":46,"magnesium max":96,"sulphur min":10,"sulphur max":10,"iron min":44,"iron max":46,"zinc min":3.87,"zinc max":5.87,"manganese min":4.81,"manganese max":4.81,"copper min":21,"copper max":26,"boron min":1.25,"boron max":2.25,"temperature min":25,"temperature max":35,"precipitation min":50,"precipitation max":60,"irrigation":"yes ","region":"barshi"}' data = json.loads(data) dataframe = pandas.DataFrame(data,index=[0]) dataset = dataframe.values X = dataset[:,0:28].astype(float) op=model.predict(X) #op = model.predict_classes(X) #print(op) #classes = np.argmax(op) #print(classes) best_n = np.argsort(op, axis=1)[:,-7:] print(best_n[0])
[ 11748, 19798, 292, 198, 6738, 41927, 292, 13, 27530, 1330, 24604, 1843, 198, 6738, 41927, 292, 13, 75, 6962, 1330, 360, 1072, 198, 6738, 41927, 292, 13, 29988, 11799, 13, 36216, 15813, 62, 35720, 1330, 17337, 292, 9487, 7483, 198, 6738,...
2.641213
956
from django.core.urlresolvers import reverse from sentry.models import Project from sentry.testutils import APITestCase
[ 6738, 42625, 14208, 13, 7295, 13, 6371, 411, 349, 690, 1330, 9575, 198, 6738, 1908, 563, 13, 27530, 1330, 4935, 198, 6738, 1908, 563, 13, 9288, 26791, 1330, 3486, 2043, 395, 20448, 628, 628 ]
3.617647
34
# encoding: utf-8 """Unit-test suite for `pptx.table` module.""" import pytest from pptx.dml.fill import FillFormat from pptx.dml.border import BorderFormat from pptx.enum.text import MSO_ANCHOR from pptx.oxml.ns import qn from pptx.oxml.table import CT_Table, CT_TableCell, TcRange from pptx.shapes.graphfrm import GraphicFrame from pptx.table import ( _Cell, _CellCollection, _Column, _ColumnCollection, _Row, _RowCollection, Table, ) from pptx.text.text import TextFrame from pptx.util import Inches, Length, Pt from .unitutil.cxml import element, xml from .unitutil.mock import call, class_mock, instance_mock, property_mock
[ 2, 21004, 25, 3384, 69, 12, 23, 198, 198, 37811, 26453, 12, 9288, 18389, 329, 4600, 381, 17602, 13, 11487, 63, 8265, 526, 15931, 198, 198, 11748, 12972, 9288, 198, 198, 6738, 279, 457, 87, 13, 67, 4029, 13, 20797, 1330, 27845, 26227...
2.633858
254
import numpy as np from imread import imread from . import file_path
[ 11748, 299, 32152, 355, 45941, 198, 6738, 545, 961, 1330, 545, 961, 198, 6738, 764, 1330, 2393, 62, 6978, 198 ]
3.45
20
from serial import Serial from tqdm import tqdm import binascii import hashlib import struct import time import sys import os if __name__ == "__main__": main()
[ 6738, 11389, 1330, 23283, 201, 198, 6738, 256, 80, 36020, 1330, 256, 80, 36020, 201, 198, 11748, 9874, 292, 979, 72, 201, 198, 11748, 12234, 8019, 201, 198, 11748, 2878, 201, 198, 11748, 640, 201, 198, 11748, 25064, 201, 198, 11748, 2...
2.707692
65
# -*- coding: utf-8 -*- import unittest from avro import avro_builder from avro import schema if __name__ == '__main__': unittest.main()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 555, 715, 395, 198, 198, 6738, 1196, 305, 1330, 1196, 305, 62, 38272, 198, 6738, 1196, 305, 1330, 32815, 628, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 1...
2.5
58
import random # use a unit square
[ 11748, 4738, 198, 198, 2, 779, 257, 4326, 6616, 198 ]
3.5
10
#!/usr/bin/env python3 # # This file is part of the MicroPython project, http://micropython.org/ # # The MIT License (MIT) # # Copyright (c) 2019 Damien P. George # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ Link .o files to .mpy """ import sys, os, struct, re from elftools.elf import elffile sys.path.append(os.path.dirname(__file__) + "/../py") import makeqstrdata as qstrutil # MicroPython constants MPY_VERSION = 5 MP_NATIVE_ARCH_X86 = 1 MP_NATIVE_ARCH_X64 = 2 MP_NATIVE_ARCH_ARMV7M = 5 MP_NATIVE_ARCH_ARMV7EMSP = 7 MP_NATIVE_ARCH_ARMV7EMDP = 8 MP_NATIVE_ARCH_XTENSA = 9 MP_NATIVE_ARCH_XTENSAWIN = 10 MP_CODE_BYTECODE = 2 MP_CODE_NATIVE_VIPER = 4 MP_SCOPE_FLAG_VIPERRELOC = 0x20 MP_SCOPE_FLAG_VIPERRODATA = 0x40 MP_SCOPE_FLAG_VIPERBSS = 0x80 MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE = 1 MICROPY_PY_BUILTINS_STR_UNICODE = 2 MP_SMALL_INT_BITS = 31 QSTR_WINDOW_SIZE = 32 # ELF constants R_386_32 = 1 R_X86_64_64 = 1 R_XTENSA_32 = 1 R_386_PC32 = 2 R_X86_64_PC32 = 2 R_ARM_ABS32 = 2 R_386_GOT32 = 3 R_ARM_REL32 = 3 R_386_PLT32 = 4 R_X86_64_PLT32 = 4 R_XTENSA_PLT = 6 R_386_GOTOFF = 9 R_386_GOTPC = 10 R_ARM_THM_CALL = 10 R_XTENSA_DIFF32 = 19 R_XTENSA_SLOT0_OP = 20 R_ARM_BASE_PREL = 25 # aka R_ARM_GOTPC R_ARM_GOT_BREL = 26 # aka R_ARM_GOT32 R_ARM_THM_JUMP24 = 30 R_X86_64_REX_GOTPCRELX = 42 R_386_GOT32X = 43 ################################################################################ # Architecture configuration ARCH_DATA = { "x86": ArchData( "EM_386", MP_NATIVE_ARCH_X86 << 2 | MICROPY_PY_BUILTINS_STR_UNICODE | MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE, 2, 4, (R_386_PC32, R_386_GOT32, R_386_GOT32X), asm_jump_x86, ), "x64": ArchData( "EM_X86_64", MP_NATIVE_ARCH_X64 << 2 | MICROPY_PY_BUILTINS_STR_UNICODE | MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE, 2, 8, (R_X86_64_REX_GOTPCRELX,), asm_jump_x86, ), "armv7m": ArchData( "EM_ARM", MP_NATIVE_ARCH_ARMV7M << 2 | MICROPY_PY_BUILTINS_STR_UNICODE, 2, 4, (R_ARM_GOT_BREL,), asm_jump_arm, ), "armv7emsp": ArchData( "EM_ARM", MP_NATIVE_ARCH_ARMV7EMSP << 2 | MICROPY_PY_BUILTINS_STR_UNICODE, 2, 4, (R_ARM_GOT_BREL,), asm_jump_arm, ), "armv7emdp": ArchData( "EM_ARM", MP_NATIVE_ARCH_ARMV7EMDP << 2 | MICROPY_PY_BUILTINS_STR_UNICODE, 2, 4, (R_ARM_GOT_BREL,), asm_jump_arm, ), "xtensa": ArchData( "EM_XTENSA", MP_NATIVE_ARCH_XTENSA << 2 | MICROPY_PY_BUILTINS_STR_UNICODE, 2, 4, (R_XTENSA_32, R_XTENSA_PLT), asm_jump_xtensa, ), "xtensawin": ArchData( "EM_XTENSA", MP_NATIVE_ARCH_XTENSAWIN << 2 | MICROPY_PY_BUILTINS_STR_UNICODE, 4, 4, (R_XTENSA_32, R_XTENSA_PLT), asm_jump_xtensa, ), } ################################################################################ # Helper functions # Smaller numbers are enabled first LOG_LEVEL_1 = 1 LOG_LEVEL_2 = 2 LOG_LEVEL_3 = 3 log_level = LOG_LEVEL_1 ################################################################################ # Qstr extraction ################################################################################ # Linker def build_got_generic(env): env.got_entries = {} for sec in env.sections: for r in sec.reloc: s = r.sym if not ( s.entry["st_info"]["bind"] == "STB_GLOBAL" and r["r_info_type"] in env.arch.arch_got ): continue s_type = s.entry["st_info"]["type"] assert s_type in ("STT_NOTYPE", "STT_FUNC", "STT_OBJECT"), s_type assert s.name if s.name in env.got_entries: continue env.got_entries[s.name] = GOTEntry(s.name, s) ################################################################################ # .mpy output ################################################################################ # main if __name__ == "__main__": main()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 198, 2, 770, 2393, 318, 636, 286, 262, 4527, 37906, 1628, 11, 2638, 1378, 9383, 1773, 7535, 13, 2398, 14, 198, 2, 198, 2, 383, 17168, 13789, 357, 36393, 8, 198, 2, 198, 2,...
2.166598
2,413
from PyQt4 import QtGui from ui_mant_libros_new import NewLibrosWindow from ui_mant_libros_edit import EditLibrosWindow from ui_mant_libros_id_edit import GetIdEditWindow # Debug only import inspect if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) mainWin = MenuLibros() mainWin.show() sys.exit(app.exec_())
[ 6738, 9485, 48, 83, 19, 1330, 33734, 8205, 72, 198, 6738, 334, 72, 62, 76, 415, 62, 8019, 4951, 62, 3605, 1330, 968, 25835, 4951, 27703, 198, 6738, 334, 72, 62, 76, 415, 62, 8019, 4951, 62, 19312, 1330, 5312, 25835, 4951, 27703, 1...
2.55
140
import argparse import re import holdem_calc.holdem_functions as holdem_functions # Wrapper class which holds the arguments for library calls # Mocks actual argparse object # Parses arguments passed to holdem_calc as a library call def parse_lib_args(args): error_check_arguments(args) # Parse hole cards and board hole_cards, board = None, None if not args.input: hole_cards, board = parse_cards(args.cards, args.board) return hole_cards, args.n, args.exact, board, args.input # Parses command line arguments to holdem_calc # Parses a line taken from the input file and returns the hole cards and board # Parses hole cards and board # Error check the command line arguments # Error check the command line arguments # Checking that the hole cards + board are formatted properly and unique # Returns tuple of two-tuple hole_cards: e.g. ((As, Ks), (Ad, Kd), (Jh, Th)) # Returns list of board cards: e.g. [As Ks Ad Kd] # Instantiates new cards from the arguments and returns them in a tuple
[ 11748, 1822, 29572, 198, 11748, 302, 198, 11748, 1745, 368, 62, 9948, 66, 13, 2946, 368, 62, 12543, 2733, 355, 1745, 368, 62, 12543, 2733, 628, 198, 2, 27323, 2848, 1398, 543, 6622, 262, 7159, 329, 5888, 3848, 198, 2, 337, 3320, 403...
3.246875
320
from flask import render_template, request, session, redirect from qbay.models import * from datetime import date from qbay import app def authenticate(inner_function): """ :param inner_function: any python function that accepts a user object Wrap any python function and check the current session to see if the user has logged in. If login, it will call the inner_function with the logged in user object. To wrap a function, we can put a decoration on that function. Example: @authenticate def home_page(user): pass """ # return the wrapped version of the inner_function: return wrapped_inner
[ 6738, 42903, 1330, 8543, 62, 28243, 11, 2581, 11, 6246, 11, 18941, 198, 6738, 10662, 24406, 13, 27530, 1330, 1635, 198, 6738, 4818, 8079, 1330, 3128, 198, 198, 6738, 10662, 24406, 1330, 598, 628, 198, 4299, 8323, 5344, 7, 5083, 62, 88...
3.345
200
from datetime import timedelta from django.utils.timezone import now from preferences import preferences from rest_framework import fields, serializers from bikesharing.models import Bike, Station, VehicleType from cykel.serializers import EnumFieldSerializer
[ 6738, 4818, 8079, 1330, 28805, 12514, 198, 198, 6738, 42625, 14208, 13, 26791, 13, 2435, 11340, 1330, 783, 198, 6738, 15387, 1330, 15387, 198, 6738, 1334, 62, 30604, 1330, 7032, 11, 11389, 11341, 198, 198, 6738, 275, 1134, 5069, 1723, 1...
4.060606
66
import logging import re from anime_downloader.extractors.base_extractor import BaseExtractor from anime_downloader.sites import helpers logger = logging.getLogger(__name__)
[ 11748, 18931, 198, 11748, 302, 198, 6738, 11984, 62, 15002, 263, 13, 2302, 974, 669, 13, 8692, 62, 2302, 40450, 1330, 7308, 11627, 40450, 198, 6738, 11984, 62, 15002, 263, 13, 49315, 1330, 49385, 198, 198, 6404, 1362, 796, 18931, 13, ...
3.5
50
import time import os from django.shortcuts import render, redirect from django.http import JsonResponse from django.views import View from django.conf import settings from .forms import File_uploadForm from .models import File_upload, SummaryRes from sim_v1.textsummary import TEXTSummary summary_document_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)),'media','sum_v1','upload') #summary_document_dir = r'C:\Users\ERDIG\Dropbox\Python\nlp_v1\media\sum_v1\upload' summary_extraction_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)),'media','sum_v1','temp') #summary_extraction_dir = r'C:\Users\ERDIG\Dropbox\Python\nlp_v1\media\sum_v1\temp' summary_ratio = 0.01
[ 11748, 640, 198, 11748, 28686, 198, 198, 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 11, 18941, 198, 6738, 42625, 14208, 13, 4023, 1330, 449, 1559, 31077, 198, 6738, 42625, 14208, 13, 33571, 1330, 3582, 198, 6738, 42625, 14208, 13, ...
2.765873
252
""" Websocket based API for Home Assistant. For more details about this component, please refer to the documentation at https://developers.home-assistant.io/docs/external_api_websocket.html """ from homeassistant.core import callback from homeassistant.loader import bind_hass from . import commands, connection, const, decorators, http, messages DOMAIN = const.DOMAIN DEPENDENCIES = ('http',) # Backwards compat / Make it easier to integrate # pylint: disable=invalid-name ActiveConnection = connection.ActiveConnection BASE_COMMAND_MESSAGE_SCHEMA = messages.BASE_COMMAND_MESSAGE_SCHEMA error_message = messages.error_message result_message = messages.result_message async_response = decorators.async_response require_admin = decorators.require_admin ws_require_user = decorators.ws_require_user # pylint: enable=invalid-name async def async_setup(hass, config): """Initialize the websocket API.""" hass.http.register_view(http.WebsocketAPIView) commands.async_register_commands(hass) return True
[ 37811, 198, 1135, 1443, 5459, 1912, 7824, 329, 5995, 15286, 13, 198, 198, 1890, 517, 3307, 546, 428, 7515, 11, 3387, 3522, 284, 262, 10314, 379, 198, 5450, 1378, 16244, 364, 13, 11195, 12, 562, 10167, 13, 952, 14, 31628, 14, 22615, ...
3.183801
321
# # Created on Tue Dec 21 2021 # # Copyright (c) 2021 Lenders Cooperative, a division of Summit Technology Group, Inc. # """ Django settings for test_app project. Generated by 'django-admin startproject' using Django 3.1.7. For more information on this file, see https://docs.djangoproject.com/en/3.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ from pathlib import Path import environ env = environ.Env() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "uhtgm(e2y3@5%0x!wy#re#fn+51h*ck88^ocm7d1=hx^@(&7$7" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "los_docusign.apps.LosDocusignConfig", "test_app.test_organization.apps.TestOrganizationConfig", "django_lc_utils", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "test_app.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] WSGI_APPLICATION = "test_app.wsgi.application" # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "docusign_new_poc", "USER": "postgres", "PASSWORD": "admin", "HOST": "localhost", "PORT": "5432", } } # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = "/static/" BASE_DIR = Path(__file__).resolve().parent DOCUSIGN_API_ACCOUNT_ID = env( "DOCUSIGN_API_ACCOUNT_ID", default="<Docusign API Account Id >" ) DOCUSIGN_CLIENT_ID = env("DOCUSIGN_CLIENT_ID", default="<Docusign Client Id>") DOCUSIGN_API_ENDPOINT = env( "DOCUSIGN_API_ENDPOINT", default="https://demo.docusign.net/restapi/v2.1/accounts/" ) DOCUSIGN_TOKEN_EXPIRY_IN_SECONDS = env("DOCUSIGN_TOKEN_EXPIRY_IN_SECONDS", default=3600) DOCUSIGN_AUTHORIZATION_SERVER = env( "DOCUSIGN_AUTHORIZATION_SERVER", default="account-d.docusign.com" ) DOCUSIGN_PRIVATE_KEY_FILE = env( "DOCUSIGN_PRIVATE_KEY_FILE", default="<Private Key file data>", ) DOCUSIGN_ENABLE_KBA = env("DOCUSIGN_ENABLE_KBA", default=False)
[ 2, 198, 2, 15622, 319, 30030, 4280, 2310, 33448, 198, 2, 198, 2, 15069, 357, 66, 8, 33448, 406, 7338, 43457, 11, 257, 7297, 286, 20014, 8987, 4912, 11, 3457, 13, 198, 2, 198, 37811, 198, 35, 73, 14208, 6460, 329, 1332, 62, 1324, ...
2.374219
1,761
# Copyright 2020 Province of British Columbia # # 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. """Test Suite to ensure the PPR Search Query schema is valid. """ import copy from registry_schemas import validate from registry_schemas.example_data.ppr import SEARCH_QUERY def test_valid_search_query_ind_debtor(): """Assert that the schema is performing as expected for a search by individual debtor.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'INDIVIDUAL_DEBTOR' del query['criteria']['debtorName']['business'] del query['criteria']['value'] del query['clientReferenceId'] del query['startDateTime'] del query['endDateTime'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_valid_search_query_bus_debtor(): """Assert that the schema is performing as expected for a search by business debtor.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'BUSINESS_DEBTOR' del query['criteria']['debtorName']['first'] del query['criteria']['debtorName']['second'] del query['criteria']['debtorName']['last'] del query['criteria']['value'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_valid_search_query_airdot(): """Assert that the schema is performing as expected for a search by aircraft DOT.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'AIRCRAFT_DOT' del query['criteria']['debtorName'] query['criteria']['value'] = 'CFYXW' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_valid_search_query_regnum(): """Assert that the schema is performing as expected for a search by registration number.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'REGISTRATION_NUMBER' del query['criteria']['debtorName'] query['criteria']['value'] = '023001B' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_valid_search_query_mhrnum(): """Assert that the schema is performing as expected for a search by MHR number.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'MHR_NUMBER' del query['criteria']['debtorName'] query['criteria']['value'] = '21324' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_valid_search_query_serialnum(): """Assert that the schema is performing as expected for a search by serial number.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'SERIAL_NUMBER' del query['criteria']['debtorName'] query['criteria']['value'] = 'KM8J3CA46JU622994' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert is_valid def test_invalid_search_query_missing_type(): """Assert that an invalid search query fails - type is missing.""" query = copy.deepcopy(SEARCH_QUERY) del query['type'] del query['criteria']['debtorName']['business'] del query['criteria']['value'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_missing_criteria(): """Assert that an invalid search query fails - criteria is missing.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_type(): """Assert that an invalid search query fails - type is invalid.""" query = copy.deepcopy(SEARCH_QUERY) query['type'] = 'XXXXXXXX' del query['criteria']['debtorName']['business'] del query['criteria']['value'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_criteria(): """Assert that an invalid search query fails - criteria is invalid.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['debtorName']['business'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_busname(): """Assert that an invalid search query fails - business name is too short.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['debtorName']['first'] del query['criteria']['debtorName']['second'] del query['criteria']['debtorName']['last'] del query['criteria']['value'] query['criteria']['debtorName']['business'] = 'XXXX' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_value(): """Assert that an invalid search query fails - value is too long.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['debtorName'] query['criteria']['value'] = 'XxxxxxxxxxxxxxxxxxxxXxxxxxxxxxxxxxxxxxxxXxxxxxxxxxx' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_debtor(): """Assert that an invalid search query fails - debtor name is invalid.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_firstname(): """Assert that an invalid search query fails - debtor first name is too long.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['criteria']['debtorName']['first'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_secondname(): """Assert that an invalid search query fails - debtor second name is too long.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['criteria']['debtorName']['second'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_lastname(): """Assert that an invalid search query fails - debtor last name is too long.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['criteria']['debtorName']['last'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_clientref(): """Assert that an invalid search query fails - client reference id is too long.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['clientReferenceId'] = 'XxxxxxxxxxXxxxxxxxxxX' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_startts(): """Assert that an invalid search query fails - start date time format is invalid.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['startDateTime'] = 'Xxxxxxxxxx' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid def test_invalid_search_query_endts(): """Assert that an invalid search query fails - end date time format is invalid.""" query = copy.deepcopy(SEARCH_QUERY) del query['criteria']['value'] del query['criteria']['debtorName']['business'] query['endDateTime'] = 'Xxxxxxxxxx' is_valid, errors = validate(query, 'searchQuery', 'ppr') if errors: for err in errors: print(err.message) print(errors) assert not is_valid
[ 2, 15069, 220, 12131, 22783, 286, 3517, 9309, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 198, ...
2.671177
3,695
""" Module to contain Pywork decorators """ __author__ = 'sergey kharnam' import re import time import itertools import logging log = logging.getLogger(__name__)
[ 37811, 198, 26796, 284, 3994, 9485, 1818, 11705, 2024, 198, 37811, 198, 198, 834, 9800, 834, 796, 705, 2655, 39608, 44081, 1501, 321, 6, 198, 198, 11748, 302, 198, 11748, 640, 198, 11748, 340, 861, 10141, 198, 198, 11748, 18931, 198, ...
3.055556
54
from __future__ import unicode_literals import pytest from django.test import TestCase from rest_framework import status from rest_framework.authentication import BasicAuthentication from rest_framework.decorators import ( action, api_view, authentication_classes, detail_route, list_route, parser_classes, permission_classes, renderer_classes, schema, throttle_classes ) from rest_framework.parsers import JSONParser from rest_framework.permissions import IsAuthenticated from rest_framework.renderers import JSONRenderer from rest_framework.response import Response from rest_framework.schemas import AutoSchema from rest_framework.test import APIRequestFactory from rest_framework.throttling import UserRateThrottle from rest_framework.views import APIView def test_method_mapping_already_mapped(self): msg = "Method 'get' has already been mapped to '.test_action'." with self.assertRaisesMessage(AssertionError, msg): def test_method_mapping_overwrite(self): msg = ("Method mapping does not behave like the property decorator. You " "cannot use the same method name for each mapping declaration.") with self.assertRaisesMessage(AssertionError, msg): def test_detail_route_deprecation(self): with pytest.warns(DeprecationWarning) as record: assert len(record) == 1 assert str(record[0].message) == ( "`detail_route` is deprecated and will be removed in " "3.10 in favor of `action`, which accepts a `detail` bool. Use " "`@action(detail=True)` instead." ) def test_list_route_deprecation(self): with pytest.warns(DeprecationWarning) as record: assert len(record) == 1 assert str(record[0].message) == ( "`list_route` is deprecated and will be removed in " "3.10 in favor of `action`, which accepts a `detail` bool. Use " "`@action(detail=False)` instead." ) def test_route_url_name_from_path(self): # pre-3.8 behavior was to base the `url_name` off of the `url_path` with pytest.warns(DeprecationWarning): assert view.url_path == 'foo_bar' assert view.url_name == 'foo-bar'
[ 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 198, 11748, 12972, 9288, 198, 6738, 42625, 14208, 13, 9288, 1330, 6208, 20448, 198, 198, 6738, 1334, 62, 30604, 1330, 3722, 198, 6738, 1334, 62, 30604, 13, 41299, 3299, 13...
2.783582
804
## -*- coding: utf-8 -*- #(C) 2018 Muthiah Annamalai # This file is part of Open-Tamil project # You may use or distribute this file under terms of MIT license import codecs import json import tamil import sys import os #e.g. python morse_encode.py CURRDIR = os.path.dirname(os.path.realpath(__file__)) if __name__ == u"__main__": encode(u" ".join([i.decode("utf-8") for i in sys.argv[1:]]))
[ 2235, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 7, 34, 8, 2864, 337, 1071, 9520, 5506, 321, 282, 1872, 198, 2, 770, 2393, 318, 636, 286, 4946, 12, 42061, 346, 1628, 198, 2, 921, 743, 779, 393, 14983, 428, ...
2.580645
155
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next
[ 2, 30396, 329, 1702, 306, 12, 25614, 1351, 13, 198, 2, 1398, 7343, 19667, 25, 198, 2, 220, 220, 220, 220, 825, 11593, 15003, 834, 7, 944, 11, 1188, 28, 15, 11, 1306, 28, 14202, 2599, 198, 2, 220, 220, 220, 220, 220, 220, 220, ...
2.018182
165
""" Warning - this will reset all components back to a blank state before running the simulation Runs node1, electrumx1 and electrumsv1 and loads the default wallet on the daemon (so that newly submitted blocks will be synchronized by ElectrumSV reorged txid: 'a1fa9460ca105c1396cd338f7fa202bf79a9d244d730e91e19f6302a05b2f07a' """ import asyncio import os from pathlib import Path import pytest import pytest_asyncio from electrumsv_node import electrumsv_node from electrumsv_sdk import utils import logging import requests from contrib.functional_tests.websocket_client import TxStateWSClient MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("simulate-fresh-reorg")
[ 37811, 198, 20361, 532, 428, 481, 13259, 477, 6805, 736, 284, 257, 9178, 1181, 878, 2491, 262, 18640, 198, 198, 10987, 82, 10139, 16, 11, 1742, 6582, 87, 16, 290, 30880, 5700, 85, 16, 290, 15989, 262, 4277, 13008, 319, 262, 33386, 3...
3.069672
244
# Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and # Technical University of Darmstadt. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH, # or Technical University of Darmstadt, nor the names of its contributors may # be used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH, # OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. import mujoco_py import numpy as np import os.path as osp from init_args_serializer import Serializable from typing import Optional import pyrado from pyrado.environments.barrett_wam import ( goal_pos_init_sim_4dof, goal_pos_init_sim_7dof, init_qpos_des_4dof, init_qpos_des_7dof, act_space_bic_4dof, act_space_bic_7dof, wam_q_limits_up_7dof, wam_q_limits_lo_7dof, torque_space_wam_4dof, torque_space_wam_7dof, wam_pgains_7dof, wam_dgains_7dof, wam_pgains_4dof, wam_dgains_4dof, ) from pyrado.environments.mujoco.base import MujocoSimEnv from pyrado.spaces.base import Space from pyrado.spaces.box import BoxSpace from pyrado.spaces.singular import SingularStateSpace from pyrado.tasks.base import Task from pyrado.tasks.condition_only import ConditionOnlyTask from pyrado.tasks.desired_state import DesStateTask from pyrado.tasks.final_reward import BestStateFinalRewTask, FinalRewTask, FinalRewMode from pyrado.tasks.goalless import GoallessTask from pyrado.tasks.masked import MaskedTask from pyrado.tasks.parallel import ParallelTasks from pyrado.tasks.reward_functions import ZeroPerStepRewFcn, ExpQuadrErrRewFcn, QuadrErrRewFcn from pyrado.tasks.sequential import SequentialTasks from pyrado.utils.data_types import EnvSpec from pyrado.utils.input_output import print_cbt def check_ball_collisions(self, verbose: bool = False) -> bool: """ Check if an undesired collision with the ball occurs. :param verbose: print messages on collision :return: `True` if the ball collides with something else than the central parts of the cup """ for i in range(self.sim.data.ncon): # Get current contact object contact = self.sim.data.contact[i] # Extract body-id and body-name of both contact geoms body1 = self.model.geom_bodyid[contact.geom1] body1_name = self.model.body_names[body1] body2 = self.model.geom_bodyid[contact.geom2] body2_name = self.model.body_names[body2] # Evaluate if the ball collides with part of the WAM (collision bodies) # or the connection of WAM and cup (geom_ids) c1 = body1_name == "ball" and ( body2_name in self._collision_bodies or contact.geom2 in self._collision_geom_ids ) c2 = body2_name == "ball" and ( body1_name in self._collision_bodies or contact.geom1 in self._collision_geom_ids ) if c1 or c2: if verbose: print_cbt( f"Undesired collision of {body1_name} and {body2_name} detected!", "y", ) return True return False def check_ball_in_cup(self, *args, verbose: bool = False): """ Check if the ball is in the cup. :param verbose: print messages when ball is in the cup :return: `True` if the ball is in the cup """ for i in range(self.sim.data.ncon): # Get current contact object contact = self.sim.data.contact[i] # Extract body-id and body-name of both contact geoms body1 = self.model.geom_bodyid[contact.geom1] body1_name = self.model.body_names[body1] body2 = self.model.geom_bodyid[contact.geom2] body2_name = self.model.body_names[body2] # Evaluate if the ball collides with part of the WAM (collision bodies) # or the connection of WAM and cup (geom_ids) cup_inner_id = self.model._geom_name2id["cup_inner"] c1 = body1_name == "ball" and contact.geom2 == cup_inner_id c2 = body2_name == "ball" and contact.geom1 == cup_inner_id if c1 or c2: if verbose: print_cbt(f"The ball is in the cup at time step {self.curr_step}.", "y") return True return False
[ 2, 15069, 357, 66, 8, 12131, 11, 14236, 952, 5921, 265, 382, 11, 20059, 4992, 5136, 2031, 402, 2022, 39, 11, 290, 198, 2, 20671, 2059, 286, 360, 1670, 38863, 13, 198, 2, 1439, 2489, 10395, 13, 198, 2, 198, 2, 2297, 396, 3890, 29...
2.456753
2,347
# pyRasp # Copyright (c) Tonino Tarsi 2020. Licensed under MIT. # requirement : # Python 3 # pip install pyyaml # pip install request # pip install f90nml from downloadGFSA import downloadGFSA from prepare_wps import prepare_wps from ungrib import ungrib from metgrid import metgrid from prepare_wrf import prepare_wrf from real import real from wrf import wrf result = downloadGFSA(True) prepare_wps(result) ungrib() metgrid() prepare_wrf(result) real() wrf()
[ 2, 12972, 49, 5126, 220, 198, 2, 15069, 357, 66, 8, 16859, 2879, 309, 945, 72, 12131, 13, 49962, 739, 17168, 13, 198, 198, 2, 9079, 1058, 198, 2, 11361, 513, 220, 198, 2, 7347, 2721, 12972, 88, 43695, 198, 2, 7347, 2721, 2581, 1...
2.987261
157