repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
reiinakano/xcessiv | xcessiv/automatedruns.py | start_tpot | def start_tpot(automated_run, session, path):
"""Starts a TPOT automated run that exports directly to base learner setup
Args:
automated_run (xcessiv.models.AutomatedRun): Automated run object
session: Valid SQLAlchemy session
path (str, unicode): Path to project folder
"""
mo... | python | def start_tpot(automated_run, session, path):
"""Starts a TPOT automated run that exports directly to base learner setup
Args:
automated_run (xcessiv.models.AutomatedRun): Automated run object
session: Valid SQLAlchemy session
path (str, unicode): Path to project folder
"""
mo... | [
"def",
"start_tpot",
"(",
"automated_run",
",",
"session",
",",
"path",
")",
":",
"module",
"=",
"functions",
".",
"import_string_code_as_module",
"(",
"automated_run",
".",
"source",
")",
"extraction",
"=",
"session",
".",
"query",
"(",
"models",
".",
"Extrac... | Starts a TPOT automated run that exports directly to base learner setup
Args:
automated_run (xcessiv.models.AutomatedRun): Automated run object
session: Valid SQLAlchemy session
path (str, unicode): Path to project folder | [
"Starts",
"a",
"TPOT",
"automated",
"run",
"that",
"exports",
"directly",
"to",
"base",
"learner",
"setup"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/automatedruns.py#L210-L248 | train |
reiinakano/xcessiv | xcessiv/automatedruns.py | start_greedy_ensemble_search | def start_greedy_ensemble_search(automated_run, session, path):
"""Starts an automated ensemble search using greedy forward model selection.
The steps for this search are adapted from "Ensemble Selection from Libraries of Models" by
Caruana.
1. Start with the empty ensemble
2. Add to the ensemble... | python | def start_greedy_ensemble_search(automated_run, session, path):
"""Starts an automated ensemble search using greedy forward model selection.
The steps for this search are adapted from "Ensemble Selection from Libraries of Models" by
Caruana.
1. Start with the empty ensemble
2. Add to the ensemble... | [
"def",
"start_greedy_ensemble_search",
"(",
"automated_run",
",",
"session",
",",
"path",
")",
":",
"module",
"=",
"functions",
".",
"import_string_code_as_module",
"(",
"automated_run",
".",
"source",
")",
"assert",
"module",
".",
"metric_to_optimize",
"in",
"autom... | Starts an automated ensemble search using greedy forward model selection.
The steps for this search are adapted from "Ensemble Selection from Libraries of Models" by
Caruana.
1. Start with the empty ensemble
2. Add to the ensemble the model in the library that maximizes the ensemmble's
performanc... | [
"Starts",
"an",
"automated",
"ensemble",
"search",
"using",
"greedy",
"forward",
"model",
"selection",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/automatedruns.py#L331-L398 | train |
reiinakano/xcessiv | xcessiv/rqtasks.py | extraction_data_statistics | def extraction_data_statistics(path):
""" Generates data statistics for the given data extraction setup stored
in Xcessiv notebook.
This is in rqtasks.py but not as a job yet. Temporarily call this directly
while I'm figuring out Javascript lel.
Args:
path (str, unicode): Path to xcessiv n... | python | def extraction_data_statistics(path):
""" Generates data statistics for the given data extraction setup stored
in Xcessiv notebook.
This is in rqtasks.py but not as a job yet. Temporarily call this directly
while I'm figuring out Javascript lel.
Args:
path (str, unicode): Path to xcessiv n... | [
"def",
"extraction_data_statistics",
"(",
"path",
")",
":",
"with",
"functions",
".",
"DBContextManager",
"(",
"path",
")",
"as",
"session",
":",
"extraction",
"=",
"session",
".",
"query",
"(",
"models",
".",
"Extraction",
")",
".",
"first",
"(",
")",
"X"... | Generates data statistics for the given data extraction setup stored
in Xcessiv notebook.
This is in rqtasks.py but not as a job yet. Temporarily call this directly
while I'm figuring out Javascript lel.
Args:
path (str, unicode): Path to xcessiv notebook | [
"Generates",
"data",
"statistics",
"for",
"the",
"given",
"data",
"extraction",
"setup",
"stored",
"in",
"Xcessiv",
"notebook",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/rqtasks.py#L17-L95 | train |
reiinakano/xcessiv | xcessiv/rqtasks.py | generate_meta_features | def generate_meta_features(path, base_learner_id):
"""Generates meta-features for specified base learner
After generation of meta-features, the file is saved into the meta-features folder
Args:
path (str): Path to Xcessiv notebook
base_learner_id (str): Base learner ID
"""
with fu... | python | def generate_meta_features(path, base_learner_id):
"""Generates meta-features for specified base learner
After generation of meta-features, the file is saved into the meta-features folder
Args:
path (str): Path to Xcessiv notebook
base_learner_id (str): Base learner ID
"""
with fu... | [
"def",
"generate_meta_features",
"(",
"path",
",",
"base_learner_id",
")",
":",
"with",
"functions",
".",
"DBContextManager",
"(",
"path",
")",
"as",
"session",
":",
"base_learner",
"=",
"session",
".",
"query",
"(",
"models",
".",
"BaseLearner",
")",
".",
"... | Generates meta-features for specified base learner
After generation of meta-features, the file is saved into the meta-features folder
Args:
path (str): Path to Xcessiv notebook
base_learner_id (str): Base learner ID | [
"Generates",
"meta",
"-",
"features",
"for",
"specified",
"base",
"learner"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/rqtasks.py#L99-L171 | train |
reiinakano/xcessiv | xcessiv/rqtasks.py | start_automated_run | def start_automated_run(path, automated_run_id):
"""Starts automated run. This will automatically create
base learners until the run finishes or errors out.
Args:
path (str): Path to Xcessiv notebook
automated_run_id (str): Automated Run ID
"""
with functions.DBContextManager(path)... | python | def start_automated_run(path, automated_run_id):
"""Starts automated run. This will automatically create
base learners until the run finishes or errors out.
Args:
path (str): Path to Xcessiv notebook
automated_run_id (str): Automated Run ID
"""
with functions.DBContextManager(path)... | [
"def",
"start_automated_run",
"(",
"path",
",",
"automated_run_id",
")",
":",
"with",
"functions",
".",
"DBContextManager",
"(",
"path",
")",
"as",
"session",
":",
"automated_run",
"=",
"session",
".",
"query",
"(",
"models",
".",
"AutomatedRun",
")",
".",
"... | Starts automated run. This will automatically create
base learners until the run finishes or errors out.
Args:
path (str): Path to Xcessiv notebook
automated_run_id (str): Automated Run ID | [
"Starts",
"automated",
"run",
".",
"This",
"will",
"automatically",
"create",
"base",
"learners",
"until",
"the",
"run",
"finishes",
"or",
"errors",
"out",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/rqtasks.py#L175-L221 | train |
reiinakano/xcessiv | xcessiv/functions.py | hash_file | def hash_file(path, block_size=65536):
"""Returns SHA256 checksum of a file
Args:
path (string): Absolute file path of file to hash
block_size (int, optional): Number of bytes to read per block
"""
sha256 = hashlib.sha256()
with open(path, 'rb') as f:
for block in iter(lamb... | python | def hash_file(path, block_size=65536):
"""Returns SHA256 checksum of a file
Args:
path (string): Absolute file path of file to hash
block_size (int, optional): Number of bytes to read per block
"""
sha256 = hashlib.sha256()
with open(path, 'rb') as f:
for block in iter(lamb... | [
"def",
"hash_file",
"(",
"path",
",",
"block_size",
"=",
"65536",
")",
":",
"sha256",
"=",
"hashlib",
".",
"sha256",
"(",
")",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"f",
":",
"for",
"block",
"in",
"iter",
"(",
"lambda",
":",
"f",
"... | Returns SHA256 checksum of a file
Args:
path (string): Absolute file path of file to hash
block_size (int, optional): Number of bytes to read per block | [
"Returns",
"SHA256",
"checksum",
"of",
"a",
"file"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L16-L28 | train |
reiinakano/xcessiv | xcessiv/functions.py | import_object_from_path | def import_object_from_path(path, object):
"""Used to import an object from an absolute path.
This function takes an absolute path and imports it as a Python module.
It then returns the object with name `object` from the imported module.
Args:
path (string): Absolute file path of .py file to i... | python | def import_object_from_path(path, object):
"""Used to import an object from an absolute path.
This function takes an absolute path and imports it as a Python module.
It then returns the object with name `object` from the imported module.
Args:
path (string): Absolute file path of .py file to i... | [
"def",
"import_object_from_path",
"(",
"path",
",",
"object",
")",
":",
"with",
"open",
"(",
"path",
")",
"as",
"f",
":",
"return",
"import_object_from_string_code",
"(",
"f",
".",
"read",
"(",
")",
",",
"object",
")"
] | Used to import an object from an absolute path.
This function takes an absolute path and imports it as a Python module.
It then returns the object with name `object` from the imported module.
Args:
path (string): Absolute file path of .py file to import
object (string): Name of object to ... | [
"Used",
"to",
"import",
"an",
"object",
"from",
"an",
"absolute",
"path",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L36-L48 | train |
reiinakano/xcessiv | xcessiv/functions.py | import_object_from_string_code | def import_object_from_string_code(code, object):
"""Used to import an object from arbitrary passed code.
Passed in code is treated as a module and is imported and added
to `sys.modules` with its SHA256 hash as key.
Args:
code (string): Python code to import as module
object (string):... | python | def import_object_from_string_code(code, object):
"""Used to import an object from arbitrary passed code.
Passed in code is treated as a module and is imported and added
to `sys.modules` with its SHA256 hash as key.
Args:
code (string): Python code to import as module
object (string):... | [
"def",
"import_object_from_string_code",
"(",
"code",
",",
"object",
")",
":",
"sha256",
"=",
"hashlib",
".",
"sha256",
"(",
"code",
".",
"encode",
"(",
"'UTF-8'",
")",
")",
".",
"hexdigest",
"(",
")",
"module",
"=",
"imp",
".",
"new_module",
"(",
"sha25... | Used to import an object from arbitrary passed code.
Passed in code is treated as a module and is imported and added
to `sys.modules` with its SHA256 hash as key.
Args:
code (string): Python code to import as module
object (string): Name of object to extract from imported module | [
"Used",
"to",
"import",
"an",
"object",
"from",
"arbitrary",
"passed",
"code",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L51-L72 | train |
reiinakano/xcessiv | xcessiv/functions.py | import_string_code_as_module | def import_string_code_as_module(code):
"""Used to run arbitrary passed code as a module
Args:
code (string): Python code to import as module
Returns:
module: Python module
"""
sha256 = hashlib.sha256(code.encode('UTF-8')).hexdigest()
module = imp.new_module(sha256)
try:
... | python | def import_string_code_as_module(code):
"""Used to run arbitrary passed code as a module
Args:
code (string): Python code to import as module
Returns:
module: Python module
"""
sha256 = hashlib.sha256(code.encode('UTF-8')).hexdigest()
module = imp.new_module(sha256)
try:
... | [
"def",
"import_string_code_as_module",
"(",
"code",
")",
":",
"sha256",
"=",
"hashlib",
".",
"sha256",
"(",
"code",
".",
"encode",
"(",
"'UTF-8'",
")",
")",
".",
"hexdigest",
"(",
")",
"module",
"=",
"imp",
".",
"new_module",
"(",
"sha256",
")",
"try",
... | Used to run arbitrary passed code as a module
Args:
code (string): Python code to import as module
Returns:
module: Python module | [
"Used",
"to",
"run",
"arbitrary",
"passed",
"code",
"as",
"a",
"module"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L75-L91 | train |
reiinakano/xcessiv | xcessiv/functions.py | verify_dataset | def verify_dataset(X, y):
"""Verifies if a dataset is valid for use i.e. scikit-learn format
Used to verify a dataset by returning shape and basic statistics of
returned data. This will also provide quick and dirty check on
capability of host machine to process the data.
Args:
X (array-lik... | python | def verify_dataset(X, y):
"""Verifies if a dataset is valid for use i.e. scikit-learn format
Used to verify a dataset by returning shape and basic statistics of
returned data. This will also provide quick and dirty check on
capability of host machine to process the data.
Args:
X (array-lik... | [
"def",
"verify_dataset",
"(",
"X",
",",
"y",
")",
":",
"X_shape",
",",
"y_shape",
"=",
"np",
".",
"array",
"(",
"X",
")",
".",
"shape",
",",
"np",
".",
"array",
"(",
"y",
")",
".",
"shape",
"if",
"len",
"(",
"X_shape",
")",
"!=",
"2",
":",
"r... | Verifies if a dataset is valid for use i.e. scikit-learn format
Used to verify a dataset by returning shape and basic statistics of
returned data. This will also provide quick and dirty check on
capability of host machine to process the data.
Args:
X (array-like): Features array
y (ar... | [
"Verifies",
"if",
"a",
"dataset",
"is",
"valid",
"for",
"use",
"i",
".",
"e",
".",
"scikit",
"-",
"learn",
"format"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L94-L127 | train |
reiinakano/xcessiv | xcessiv/functions.py | make_serializable | def make_serializable(json):
"""This function ensures that the dictionary is JSON serializable. If not,
keys with non-serializable values are removed from the return value.
Args:
json (dict): Dictionary to convert to serializable
Returns:
new_dict (dict): New dictionary with non JSON s... | python | def make_serializable(json):
"""This function ensures that the dictionary is JSON serializable. If not,
keys with non-serializable values are removed from the return value.
Args:
json (dict): Dictionary to convert to serializable
Returns:
new_dict (dict): New dictionary with non JSON s... | [
"def",
"make_serializable",
"(",
"json",
")",
":",
"new_dict",
"=",
"dict",
"(",
")",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"json",
")",
":",
"if",
"is_valid_json",
"(",
"value",
")",
":",
"new_dict",
"[",
"key",
"]",
"=",
"value",
"ret... | This function ensures that the dictionary is JSON serializable. If not,
keys with non-serializable values are removed from the return value.
Args:
json (dict): Dictionary to convert to serializable
Returns:
new_dict (dict): New dictionary with non JSON serializable values removed | [
"This",
"function",
"ensures",
"that",
"the",
"dictionary",
"is",
"JSON",
"serializable",
".",
"If",
"not",
"keys",
"with",
"non",
"-",
"serializable",
"values",
"are",
"removed",
"from",
"the",
"return",
"value",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L143-L158 | train |
reiinakano/xcessiv | xcessiv/functions.py | get_sample_dataset | def get_sample_dataset(dataset_properties):
"""Returns sample dataset
Args:
dataset_properties (dict): Dictionary corresponding to the properties of the dataset
used to verify the estimator and metric generators.
Returns:
X (array-like): Features array
y (array-like): ... | python | def get_sample_dataset(dataset_properties):
"""Returns sample dataset
Args:
dataset_properties (dict): Dictionary corresponding to the properties of the dataset
used to verify the estimator and metric generators.
Returns:
X (array-like): Features array
y (array-like): ... | [
"def",
"get_sample_dataset",
"(",
"dataset_properties",
")",
":",
"kwargs",
"=",
"dataset_properties",
".",
"copy",
"(",
")",
"data_type",
"=",
"kwargs",
".",
"pop",
"(",
"'type'",
")",
"if",
"data_type",
"==",
"'multiclass'",
":",
"try",
":",
"X",
",",
"y... | Returns sample dataset
Args:
dataset_properties (dict): Dictionary corresponding to the properties of the dataset
used to verify the estimator and metric generators.
Returns:
X (array-like): Features array
y (array-like): Labels array
splits (iterator): This is an... | [
"Returns",
"sample",
"dataset"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L161-L201 | train |
reiinakano/xcessiv | xcessiv/functions.py | verify_estimator_class | def verify_estimator_class(est, meta_feature_generator, metric_generators, dataset_properties):
"""Verify if estimator object is valid for use i.e. scikit-learn format
Verifies if an estimator is fit for use by testing for existence of methods
such as `get_params` and `set_params`. Must also be able to pro... | python | def verify_estimator_class(est, meta_feature_generator, metric_generators, dataset_properties):
"""Verify if estimator object is valid for use i.e. scikit-learn format
Verifies if an estimator is fit for use by testing for existence of methods
such as `get_params` and `set_params`. Must also be able to pro... | [
"def",
"verify_estimator_class",
"(",
"est",
",",
"meta_feature_generator",
",",
"metric_generators",
",",
"dataset_properties",
")",
":",
"X",
",",
"y",
",",
"splits",
"=",
"get_sample_dataset",
"(",
"dataset_properties",
")",
"if",
"not",
"hasattr",
"(",
"est",
... | Verify if estimator object is valid for use i.e. scikit-learn format
Verifies if an estimator is fit for use by testing for existence of methods
such as `get_params` and `set_params`. Must also be able to properly fit on
and predict a sample iris dataset.
Args:
est: Estimator object with `fit`... | [
"Verify",
"if",
"estimator",
"object",
"is",
"valid",
"for",
"use",
"i",
".",
"e",
".",
"scikit",
"-",
"learn",
"format"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L204-L275 | train |
reiinakano/xcessiv | xcessiv/functions.py | get_path_from_query_string | def get_path_from_query_string(req):
"""Gets path from query string
Args:
req (flask.request): Request object from Flask
Returns:
path (str): Value of "path" parameter from query string
Raises:
exceptions.UserError: If "path" is not found in query string
"""
if req.arg... | python | def get_path_from_query_string(req):
"""Gets path from query string
Args:
req (flask.request): Request object from Flask
Returns:
path (str): Value of "path" parameter from query string
Raises:
exceptions.UserError: If "path" is not found in query string
"""
if req.arg... | [
"def",
"get_path_from_query_string",
"(",
"req",
")",
":",
"if",
"req",
".",
"args",
".",
"get",
"(",
"'path'",
")",
"is",
"None",
":",
"raise",
"exceptions",
".",
"UserError",
"(",
"'Path not found in query string'",
")",
"return",
"req",
".",
"args",
".",
... | Gets path from query string
Args:
req (flask.request): Request object from Flask
Returns:
path (str): Value of "path" parameter from query string
Raises:
exceptions.UserError: If "path" is not found in query string | [
"Gets",
"path",
"from",
"query",
"string"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/functions.py#L278-L292 | train |
reiinakano/xcessiv | xcessiv/models.py | Extraction.return_main_dataset | def return_main_dataset(self):
"""Returns main data set from self
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels
"""
if not self.main_dataset['source']:
raise exceptions.UserError('Source is empty')
extraction_code = self.mai... | python | def return_main_dataset(self):
"""Returns main data set from self
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels
"""
if not self.main_dataset['source']:
raise exceptions.UserError('Source is empty')
extraction_code = self.mai... | [
"def",
"return_main_dataset",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"main_dataset",
"[",
"'source'",
"]",
":",
"raise",
"exceptions",
".",
"UserError",
"(",
"'Source is empty'",
")",
"extraction_code",
"=",
"self",
".",
"main_dataset",
"[",
"\"sourc... | Returns main data set from self
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels | [
"Returns",
"main",
"data",
"set",
"from",
"self"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L70-L92 | train |
reiinakano/xcessiv | xcessiv/models.py | Extraction.return_train_dataset | def return_train_dataset(self):
"""Returns train data set
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels
"""
X, y = self.return_main_dataset()
if self.test_dataset['method'] == 'split_from_main':
X, X_test, y, y_test = train_... | python | def return_train_dataset(self):
"""Returns train data set
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels
"""
X, y = self.return_main_dataset()
if self.test_dataset['method'] == 'split_from_main':
X, X_test, y, y_test = train_... | [
"def",
"return_train_dataset",
"(",
"self",
")",
":",
"X",
",",
"y",
"=",
"self",
".",
"return_main_dataset",
"(",
")",
"if",
"self",
".",
"test_dataset",
"[",
"'method'",
"]",
"==",
"'split_from_main'",
":",
"X",
",",
"X_test",
",",
"y",
",",
"y_test",
... | Returns train data set
Returns:
X (numpy.ndarray): Features
y (numpy.ndarray): Labels | [
"Returns",
"train",
"data",
"set"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L94-L113 | train |
reiinakano/xcessiv | xcessiv/models.py | BaseLearnerOrigin.return_estimator | def return_estimator(self):
"""Returns estimator from base learner origin
Returns:
est (estimator): Estimator object
"""
extraction_code = self.source
estimator = functions.import_object_from_string_code(extraction_code, "base_learner")
return estimator | python | def return_estimator(self):
"""Returns estimator from base learner origin
Returns:
est (estimator): Estimator object
"""
extraction_code = self.source
estimator = functions.import_object_from_string_code(extraction_code, "base_learner")
return estimator | [
"def",
"return_estimator",
"(",
"self",
")",
":",
"extraction_code",
"=",
"self",
".",
"source",
"estimator",
"=",
"functions",
".",
"import_object_from_string_code",
"(",
"extraction_code",
",",
"\"base_learner\"",
")",
"return",
"estimator"
] | Returns estimator from base learner origin
Returns:
est (estimator): Estimator object | [
"Returns",
"estimator",
"from",
"base",
"learner",
"origin"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L192-L201 | train |
reiinakano/xcessiv | xcessiv/models.py | BaseLearnerOrigin.export_as_file | def export_as_file(self, filepath, hyperparameters):
"""Generates a Python file with the importable base learner set to ``hyperparameters``
This function generates a Python file in the specified file path that contains
the base learner as an importable variable stored in ``base_learner``. The... | python | def export_as_file(self, filepath, hyperparameters):
"""Generates a Python file with the importable base learner set to ``hyperparameters``
This function generates a Python file in the specified file path that contains
the base learner as an importable variable stored in ``base_learner``. The... | [
"def",
"export_as_file",
"(",
"self",
",",
"filepath",
",",
"hyperparameters",
")",
":",
"if",
"not",
"filepath",
".",
"endswith",
"(",
"'.py'",
")",
":",
"filepath",
"+=",
"'.py'",
"file_contents",
"=",
"''",
"file_contents",
"+=",
"self",
".",
"source",
... | Generates a Python file with the importable base learner set to ``hyperparameters``
This function generates a Python file in the specified file path that contains
the base learner as an importable variable stored in ``base_learner``. The base
learner will be set to the appropriate hyperpara... | [
"Generates",
"a",
"Python",
"file",
"with",
"the",
"importable",
"base",
"learner",
"set",
"to",
"hyperparameters"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L212-L232 | train |
reiinakano/xcessiv | xcessiv/models.py | BaseLearner.return_estimator | def return_estimator(self):
"""Returns base learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object
"""
estimator = self.base_learner_origin.return_estimator()
estimator = estimator.set_params(**self.hyperparameters)
... | python | def return_estimator(self):
"""Returns base learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object
"""
estimator = self.base_learner_origin.return_estimator()
estimator = estimator.set_params(**self.hyperparameters)
... | [
"def",
"return_estimator",
"(",
"self",
")",
":",
"estimator",
"=",
"self",
".",
"base_learner_origin",
".",
"return_estimator",
"(",
")",
"estimator",
"=",
"estimator",
".",
"set_params",
"(",
"**",
"self",
".",
"hyperparameters",
")",
"return",
"estimator"
] | Returns base learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object | [
"Returns",
"base",
"learner",
"using",
"its",
"origin",
"and",
"the",
"given",
"hyperparameters"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L307-L315 | train |
reiinakano/xcessiv | xcessiv/models.py | BaseLearner.meta_features_path | def meta_features_path(self, path):
"""Returns path for meta-features
Args:
path (str): Absolute/local path of xcessiv folder
"""
return os.path.join(
path,
app.config['XCESSIV_META_FEATURES_FOLDER'],
str(self.id)
)... | python | def meta_features_path(self, path):
"""Returns path for meta-features
Args:
path (str): Absolute/local path of xcessiv folder
"""
return os.path.join(
path,
app.config['XCESSIV_META_FEATURES_FOLDER'],
str(self.id)
)... | [
"def",
"meta_features_path",
"(",
"self",
",",
"path",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"app",
".",
"config",
"[",
"'XCESSIV_META_FEATURES_FOLDER'",
"]",
",",
"str",
"(",
"self",
".",
"id",
")",
")",
"+",
"'.npy'"
] | Returns path for meta-features
Args:
path (str): Absolute/local path of xcessiv folder | [
"Returns",
"path",
"for",
"meta",
"-",
"features"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L317-L327 | train |
reiinakano/xcessiv | xcessiv/models.py | BaseLearner.delete_meta_features | def delete_meta_features(self, path):
"""Deletes meta-features of base learner if it exists
Args:
path (str): Absolute/local path of xcessiv folder
"""
if os.path.exists(self.meta_features_path(path)):
os.remove(self.meta_features_path(path)) | python | def delete_meta_features(self, path):
"""Deletes meta-features of base learner if it exists
Args:
path (str): Absolute/local path of xcessiv folder
"""
if os.path.exists(self.meta_features_path(path)):
os.remove(self.meta_features_path(path)) | [
"def",
"delete_meta_features",
"(",
"self",
",",
"path",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"meta_features_path",
"(",
"path",
")",
")",
":",
"os",
".",
"remove",
"(",
"self",
".",
"meta_features_path",
"(",
"path",
")"... | Deletes meta-features of base learner if it exists
Args:
path (str): Absolute/local path of xcessiv folder | [
"Deletes",
"meta",
"-",
"features",
"of",
"base",
"learner",
"if",
"it",
"exists"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L342-L349 | train |
reiinakano/xcessiv | xcessiv/models.py | StackedEnsemble.return_secondary_learner | def return_secondary_learner(self):
"""Returns secondary learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object
"""
estimator = self.base_learner_origin.return_estimator()
estimator = estimator.set_params(**self.secondary_le... | python | def return_secondary_learner(self):
"""Returns secondary learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object
"""
estimator = self.base_learner_origin.return_estimator()
estimator = estimator.set_params(**self.secondary_le... | [
"def",
"return_secondary_learner",
"(",
"self",
")",
":",
"estimator",
"=",
"self",
".",
"base_learner_origin",
".",
"return_estimator",
"(",
")",
"estimator",
"=",
"estimator",
".",
"set_params",
"(",
"**",
"self",
".",
"secondary_learner_hyperparameters",
")",
"... | Returns secondary learner using its origin and the given hyperparameters
Returns:
est (estimator): Estimator object | [
"Returns",
"secondary",
"learner",
"using",
"its",
"origin",
"and",
"the",
"given",
"hyperparameters"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L402-L410 | train |
reiinakano/xcessiv | xcessiv/models.py | StackedEnsemble.export_as_code | def export_as_code(self, cv_source):
"""Returns a string value that contains the Python code for the ensemble
Args:
cv_source (str, unicode): String containing actual code for base learner
cross-validation used to generate secondary meta-features.
Returns:
... | python | def export_as_code(self, cv_source):
"""Returns a string value that contains the Python code for the ensemble
Args:
cv_source (str, unicode): String containing actual code for base learner
cross-validation used to generate secondary meta-features.
Returns:
... | [
"def",
"export_as_code",
"(",
"self",
",",
"cv_source",
")",
":",
"rand_value",
"=",
"''",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"string",
".",
"ascii_uppercase",
"+",
"string",
".",
"digits",
")",
"for",
"_",
"in",
"range",
"(",
"25",
")",
... | Returns a string value that contains the Python code for the ensemble
Args:
cv_source (str, unicode): String containing actual code for base learner
cross-validation used to generate secondary meta-features.
Returns:
base_learner_code (str, unicode): String that... | [
"Returns",
"a",
"string",
"value",
"that",
"contains",
"the",
"Python",
"code",
"for",
"the",
"ensemble"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L412-L486 | train |
reiinakano/xcessiv | xcessiv/models.py | StackedEnsemble.export_as_file | def export_as_file(self, file_path, cv_source):
"""Export the ensemble as a single Python file and saves it to `file_path`.
This is EXPERIMENTAL as putting different modules together would probably wreak havoc
especially on modules that make heavy use of global variables.
Args:
... | python | def export_as_file(self, file_path, cv_source):
"""Export the ensemble as a single Python file and saves it to `file_path`.
This is EXPERIMENTAL as putting different modules together would probably wreak havoc
especially on modules that make heavy use of global variables.
Args:
... | [
"def",
"export_as_file",
"(",
"self",
",",
"file_path",
",",
"cv_source",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"file_path",
")",
":",
"raise",
"exceptions",
".",
"UserError",
"(",
"'{} already exists'",
".",
"format",
"(",
"file_path",
")... | Export the ensemble as a single Python file and saves it to `file_path`.
This is EXPERIMENTAL as putting different modules together would probably wreak havoc
especially on modules that make heavy use of global variables.
Args:
file_path (str, unicode): Absolute/local path of place... | [
"Export",
"the",
"ensemble",
"as",
"a",
"single",
"Python",
"file",
"and",
"saves",
"it",
"to",
"file_path",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L488-L504 | train |
reiinakano/xcessiv | xcessiv/models.py | StackedEnsemble.export_as_package | def export_as_package(self, package_path, cv_source):
"""Exports the ensemble as a Python package and saves it to `package_path`.
Args:
package_path (str, unicode): Absolute/local path of place to save package in
cv_source (str, unicode): String containing actual code for base ... | python | def export_as_package(self, package_path, cv_source):
"""Exports the ensemble as a Python package and saves it to `package_path`.
Args:
package_path (str, unicode): Absolute/local path of place to save package in
cv_source (str, unicode): String containing actual code for base ... | [
"def",
"export_as_package",
"(",
"self",
",",
"package_path",
",",
"cv_source",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"package_path",
")",
":",
"raise",
"exceptions",
".",
"UserError",
"(",
"'{} already exists'",
".",
"format",
"(",
"package... | Exports the ensemble as a Python package and saves it to `package_path`.
Args:
package_path (str, unicode): Absolute/local path of place to save package in
cv_source (str, unicode): String containing actual code for base learner
cross-validation used to generate seconda... | [
"Exports",
"the",
"ensemble",
"as",
"a",
"Python",
"package",
"and",
"saves",
"it",
"to",
"package_path",
"."
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/models.py#L506-L591 | train |
reiinakano/xcessiv | xcessiv/views.py | verify_full_extraction | def verify_full_extraction():
"""This is an experimental endpoint to simultaneously verify data
statistics and extraction for training, test, and holdout datasets.
With this, the other three verification methods will no longer be
necessary.
"""
path = functions.get_path_from_query_string(request... | python | def verify_full_extraction():
"""This is an experimental endpoint to simultaneously verify data
statistics and extraction for training, test, and holdout datasets.
With this, the other three verification methods will no longer be
necessary.
"""
path = functions.get_path_from_query_string(request... | [
"def",
"verify_full_extraction",
"(",
")",
":",
"path",
"=",
"functions",
".",
"get_path_from_query_string",
"(",
"request",
")",
"if",
"request",
".",
"method",
"==",
"'POST'",
":",
"rqtasks",
".",
"extraction_data_statistics",
"(",
"path",
")",
"with",
"functi... | This is an experimental endpoint to simultaneously verify data
statistics and extraction for training, test, and holdout datasets.
With this, the other three verification methods will no longer be
necessary. | [
"This",
"is",
"an",
"experimental",
"endpoint",
"to",
"simultaneously",
"verify",
"data",
"statistics",
"and",
"extraction",
"for",
"training",
"test",
"and",
"holdout",
"datasets",
".",
"With",
"this",
"the",
"other",
"three",
"verification",
"methods",
"will",
... | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/views.py#L156-L169 | train |
reiinakano/xcessiv | xcessiv/views.py | create_base_learner | def create_base_learner(id):
"""This creates a single base learner from a base learner origin and queues it up"""
path = functions.get_path_from_query_string(request)
with functions.DBContextManager(path) as session:
base_learner_origin = session.query(models.BaseLearnerOrigin).filter_by(id=id).fir... | python | def create_base_learner(id):
"""This creates a single base learner from a base learner origin and queues it up"""
path = functions.get_path_from_query_string(request)
with functions.DBContextManager(path) as session:
base_learner_origin = session.query(models.BaseLearnerOrigin).filter_by(id=id).fir... | [
"def",
"create_base_learner",
"(",
"id",
")",
":",
"path",
"=",
"functions",
".",
"get_path_from_query_string",
"(",
"request",
")",
"with",
"functions",
".",
"DBContextManager",
"(",
"path",
")",
"as",
"session",
":",
"base_learner_origin",
"=",
"session",
".",... | This creates a single base learner from a base learner origin and queues it up | [
"This",
"creates",
"a",
"single",
"base",
"learner",
"from",
"a",
"base",
"learner",
"origin",
"and",
"queues",
"it",
"up"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/views.py#L306-L348 | train |
reiinakano/xcessiv | xcessiv/views.py | search_base_learner | def search_base_learner(id):
"""Creates a set of base learners from base learner origin using grid search
and queues them up
"""
path = functions.get_path_from_query_string(request)
req_body = request.get_json()
if req_body['method'] == 'grid':
param_grid = functions.import_object_from_s... | python | def search_base_learner(id):
"""Creates a set of base learners from base learner origin using grid search
and queues them up
"""
path = functions.get_path_from_query_string(request)
req_body = request.get_json()
if req_body['method'] == 'grid':
param_grid = functions.import_object_from_s... | [
"def",
"search_base_learner",
"(",
"id",
")",
":",
"path",
"=",
"functions",
".",
"get_path_from_query_string",
"(",
"request",
")",
"req_body",
"=",
"request",
".",
"get_json",
"(",
")",
"if",
"req_body",
"[",
"'method'",
"]",
"==",
"'grid'",
":",
"param_gr... | Creates a set of base learners from base learner origin using grid search
and queues them up | [
"Creates",
"a",
"set",
"of",
"base",
"learners",
"from",
"base",
"learner",
"origin",
"using",
"grid",
"search",
"and",
"queues",
"them",
"up"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/views.py#L352-L424 | train |
reiinakano/xcessiv | xcessiv/views.py | get_automated_runs | def get_automated_runs():
"""Return all automated runs"""
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
automated_runs = session.query(models.AutomatedRun).all()
return jsonify(list(map(lamb... | python | def get_automated_runs():
"""Return all automated runs"""
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
automated_runs = session.query(models.AutomatedRun).all()
return jsonify(list(map(lamb... | [
"def",
"get_automated_runs",
"(",
")",
":",
"path",
"=",
"functions",
".",
"get_path_from_query_string",
"(",
"request",
")",
"if",
"request",
".",
"method",
"==",
"'GET'",
":",
"with",
"functions",
".",
"DBContextManager",
"(",
"path",
")",
"as",
"session",
... | Return all automated runs | [
"Return",
"all",
"automated",
"runs"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/views.py#L428-L476 | train |
reiinakano/xcessiv | xcessiv/stacker.py | XcessivStackedEnsemble._process_using_meta_feature_generator | def _process_using_meta_feature_generator(self, X, meta_feature_generator):
"""Process using secondary learner meta-feature generator
Since secondary learner meta-feature generator can be anything e.g. predict, predict_proba,
this internal method gives the ability to use any string. Just make s... | python | def _process_using_meta_feature_generator(self, X, meta_feature_generator):
"""Process using secondary learner meta-feature generator
Since secondary learner meta-feature generator can be anything e.g. predict, predict_proba,
this internal method gives the ability to use any string. Just make s... | [
"def",
"_process_using_meta_feature_generator",
"(",
"self",
",",
"X",
",",
"meta_feature_generator",
")",
":",
"all_learner_meta_features",
"=",
"[",
"]",
"for",
"idx",
",",
"base_learner",
"in",
"enumerate",
"(",
"self",
".",
"base_learners",
")",
":",
"single_l... | Process using secondary learner meta-feature generator
Since secondary learner meta-feature generator can be anything e.g. predict, predict_proba,
this internal method gives the ability to use any string. Just make sure secondary learner
has the method.
Args:
X (array-like)... | [
"Process",
"using",
"secondary",
"learner",
"meta",
"-",
"feature",
"generator"
] | a48dff7d370c84eb5c243bde87164c1f5fd096d5 | https://github.com/reiinakano/xcessiv/blob/a48dff7d370c84eb5c243bde87164c1f5fd096d5/xcessiv/stacker.py#L77-L103 | train |
madedotcom/photon-pump | photonpump/messages.py | NewEvent | def NewEvent(
type: str, id: UUID = None, data: JsonDict = None, metadata: JsonDict = None
) -> NewEventData:
"""Build the data structure for a new event.
Args:
type: An event type.
id: The uuid identifier for the event.
data: A dict containing data for the event. These data
... | python | def NewEvent(
type: str, id: UUID = None, data: JsonDict = None, metadata: JsonDict = None
) -> NewEventData:
"""Build the data structure for a new event.
Args:
type: An event type.
id: The uuid identifier for the event.
data: A dict containing data for the event. These data
... | [
"def",
"NewEvent",
"(",
"type",
":",
"str",
",",
"id",
":",
"UUID",
"=",
"None",
",",
"data",
":",
"JsonDict",
"=",
"None",
",",
"metadata",
":",
"JsonDict",
"=",
"None",
")",
"->",
"NewEventData",
":",
"return",
"NewEventData",
"(",
"id",
"or",
"uui... | Build the data structure for a new event.
Args:
type: An event type.
id: The uuid identifier for the event.
data: A dict containing data for the event. These data
must be json serializable.
metadata: A dict containing metadata about the event.
These must be j... | [
"Build",
"the",
"data",
"structure",
"for",
"a",
"new",
"event",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/messages.py#L439-L453 | train |
madedotcom/photon-pump | photonpump/messages.py | Credential.from_bytes | def from_bytes(cls, data):
"""
I am so sorry.
"""
len_username = int.from_bytes(data[0:2], byteorder="big")
offset_username = 2 + len_username
username = data[2:offset_username].decode("UTF-8")
offset_password = 2 + offset_username
len_password = int.from_... | python | def from_bytes(cls, data):
"""
I am so sorry.
"""
len_username = int.from_bytes(data[0:2], byteorder="big")
offset_username = 2 + len_username
username = data[2:offset_username].decode("UTF-8")
offset_password = 2 + offset_username
len_password = int.from_... | [
"def",
"from_bytes",
"(",
"cls",
",",
"data",
")",
":",
"len_username",
"=",
"int",
".",
"from_bytes",
"(",
"data",
"[",
"0",
":",
"2",
"]",
",",
"byteorder",
"=",
"\"big\"",
")",
"offset_username",
"=",
"2",
"+",
"len_username",
"username",
"=",
"data... | I am so sorry. | [
"I",
"am",
"so",
"sorry",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/messages.py#L155-L170 | train |
madedotcom/photon-pump | photonpump/connection.py | connect | def connect(
host="localhost",
port=1113,
discovery_host=None,
discovery_port=2113,
username=None,
password=None,
loop=None,
name=None,
selector=select_random,
) -> Client:
""" Create a new client.
Examples:
Since the Client is an async context manager, we ca... | python | def connect(
host="localhost",
port=1113,
discovery_host=None,
discovery_port=2113,
username=None,
password=None,
loop=None,
name=None,
selector=select_random,
) -> Client:
""" Create a new client.
Examples:
Since the Client is an async context manager, we ca... | [
"def",
"connect",
"(",
"host",
"=",
"\"localhost\"",
",",
"port",
"=",
"1113",
",",
"discovery_host",
"=",
"None",
",",
"discovery_port",
"=",
"2113",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
",",
"loop",
"=",
"None",
",",
"name",
"=... | Create a new client.
Examples:
Since the Client is an async context manager, we can use it in a
with block for automatic connect/disconnect semantics.
>>> async with connect(host='127.0.0.1', port=1113) as c:
>>> await c.ping()
Or we can call co... | [
"Create",
"a",
"new",
"client",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L1190-L1290 | train |
madedotcom/photon-pump | photonpump/connection.py | MessageReader.start | async def start(self):
"""Loop forever reading messages and invoking
the operation that caused them"""
while True:
try:
data = await self.reader.read(8192)
if self._trace_enabled:
self._logger.trace(
"Re... | python | async def start(self):
"""Loop forever reading messages and invoking
the operation that caused them"""
while True:
try:
data = await self.reader.read(8192)
if self._trace_enabled:
self._logger.trace(
"Re... | [
"async",
"def",
"start",
"(",
"self",
")",
":",
"while",
"True",
":",
"try",
":",
"data",
"=",
"await",
"self",
".",
"reader",
".",
"read",
"(",
"8192",
")",
"if",
"self",
".",
"_trace_enabled",
":",
"self",
".",
"_logger",
".",
"trace",
"(",
"\"Re... | Loop forever reading messages and invoking
the operation that caused them | [
"Loop",
"forever",
"reading",
"messages",
"and",
"invoking",
"the",
"operation",
"that",
"caused",
"them"
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L397-L416 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.ping | async def ping(self, conversation_id: uuid.UUID = None) -> float:
"""
Send a message to the remote server to check liveness.
Returns:
The round-trip time to receive a Pong message in fractional seconds
Examples:
>>> async with connect() as conn:
>>>... | python | async def ping(self, conversation_id: uuid.UUID = None) -> float:
"""
Send a message to the remote server to check liveness.
Returns:
The round-trip time to receive a Pong message in fractional seconds
Examples:
>>> async with connect() as conn:
>>>... | [
"async",
"def",
"ping",
"(",
"self",
",",
"conversation_id",
":",
"uuid",
".",
"UUID",
"=",
"None",
")",
"->",
"float",
":",
"cmd",
"=",
"convo",
".",
"Ping",
"(",
"conversation_id",
"=",
"conversation_id",
"or",
"uuid",
".",
"uuid4",
"(",
")",
")",
... | Send a message to the remote server to check liveness.
Returns:
The round-trip time to receive a Pong message in fractional seconds
Examples:
>>> async with connect() as conn:
>>> print("Sending a PING to the server")
>>> time_secs = await conn.... | [
"Send",
"a",
"message",
"to",
"the",
"remote",
"server",
"to",
"check",
"liveness",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L581-L599 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.publish_event | async def publish_event(
self,
stream: str,
type: str,
body: Optional[Any] = None,
id: Optional[uuid.UUID] = None,
metadata: Optional[Any] = None,
expected_version: int = -2,
require_master: bool = False,
) -> None:
"""
Publish a single... | python | async def publish_event(
self,
stream: str,
type: str,
body: Optional[Any] = None,
id: Optional[uuid.UUID] = None,
metadata: Optional[Any] = None,
expected_version: int = -2,
require_master: bool = False,
) -> None:
"""
Publish a single... | [
"async",
"def",
"publish_event",
"(",
"self",
",",
"stream",
":",
"str",
",",
"type",
":",
"str",
",",
"body",
":",
"Optional",
"[",
"Any",
"]",
"=",
"None",
",",
"id",
":",
"Optional",
"[",
"uuid",
".",
"UUID",
"]",
"=",
"None",
",",
"metadata",
... | Publish a single event to the EventStore.
This method publishes a single event to the remote server and waits
for acknowledgement.
Args:
stream: The stream to publish the event to.
type: the event's type.
body: a serializable body for the event.
... | [
"Publish",
"a",
"single",
"event",
"to",
"the",
"EventStore",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L601-L663 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.get_event | async def get_event(
self,
stream: str,
event_number: int,
resolve_links=True,
require_master=False,
correlation_id: uuid.UUID = None,
) -> msg.Event:
"""
Get a single event by stream and event number.
Args:
stream: The name of the... | python | async def get_event(
self,
stream: str,
event_number: int,
resolve_links=True,
require_master=False,
correlation_id: uuid.UUID = None,
) -> msg.Event:
"""
Get a single event by stream and event number.
Args:
stream: The name of the... | [
"async",
"def",
"get_event",
"(",
"self",
",",
"stream",
":",
"str",
",",
"event_number",
":",
"int",
",",
"resolve_links",
"=",
"True",
",",
"require_master",
"=",
"False",
",",
"correlation_id",
":",
"uuid",
".",
"UUID",
"=",
"None",
",",
")",
"->",
... | Get a single event by stream and event number.
Args:
stream: The name of the stream containing the event.
event_number: The sequence number of the event to read.
resolve_links (optional): True if eventstore should
automatically resolve Link Events, otherwise ... | [
"Get",
"a",
"single",
"event",
"by",
"stream",
"and",
"event",
"number",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L682-L724 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.get | async def get(
self,
stream: str,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_event: int = 0,
max_count: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.UUID = None,
):
"""
... | python | async def get(
self,
stream: str,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_event: int = 0,
max_count: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.UUID = None,
):
"""
... | [
"async",
"def",
"get",
"(",
"self",
",",
"stream",
":",
"str",
",",
"direction",
":",
"msg",
".",
"StreamDirection",
"=",
"msg",
".",
"StreamDirection",
".",
"Forward",
",",
"from_event",
":",
"int",
"=",
"0",
",",
"max_count",
":",
"int",
"=",
"100",
... | Read a range of events from a stream.
Args:
stream: The name of the stream to read
direction (optional): Controls whether to read events forward or backward.
defaults to Forward.
from_event (optional): The first event to read.
defaults to the begi... | [
"Read",
"a",
"range",
"of",
"events",
"from",
"a",
"stream",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L726-L786 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.get_all | async def get_all(
self,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_position: Optional[Union[msg.Position, msg._PositionSentinel]] = None,
max_count: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.... | python | async def get_all(
self,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_position: Optional[Union[msg.Position, msg._PositionSentinel]] = None,
max_count: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.... | [
"async",
"def",
"get_all",
"(",
"self",
",",
"direction",
":",
"msg",
".",
"StreamDirection",
"=",
"msg",
".",
"StreamDirection",
".",
"Forward",
",",
"from_position",
":",
"Optional",
"[",
"Union",
"[",
"msg",
".",
"Position",
",",
"msg",
".",
"_PositionS... | Read a range of events from the whole database.
Args:
direction (optional): Controls whether to read events forward or backward.
defaults to Forward.
from_position (optional): The position to read from.
defaults to the beginning of the stream when direction i... | [
"Read",
"a",
"range",
"of",
"events",
"from",
"the",
"whole",
"database",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L788-L840 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.iter | async def iter(
self,
stream: str,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_event: int = None,
batch_size: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.UUID = None,
):
"""
... | python | async def iter(
self,
stream: str,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_event: int = None,
batch_size: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: uuid.UUID = None,
):
"""
... | [
"async",
"def",
"iter",
"(",
"self",
",",
"stream",
":",
"str",
",",
"direction",
":",
"msg",
".",
"StreamDirection",
"=",
"msg",
".",
"StreamDirection",
".",
"Forward",
",",
"from_event",
":",
"int",
"=",
"None",
",",
"batch_size",
":",
"int",
"=",
"1... | Read through a stream of events until the end and then stop.
Args:
stream: The name of the stream to read.
direction: Controls whether to read forward or backward through the
stream. Defaults to StreamDirection.Forward
from_event: The sequence number of the fi... | [
"Read",
"through",
"a",
"stream",
"of",
"events",
"until",
"the",
"end",
"and",
"then",
"stop",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L842-L902 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.iter_all | async def iter_all(
self,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_position: Optional[Union[msg.Position, msg._PositionSentinel]] = None,
batch_size: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: Opt... | python | async def iter_all(
self,
direction: msg.StreamDirection = msg.StreamDirection.Forward,
from_position: Optional[Union[msg.Position, msg._PositionSentinel]] = None,
batch_size: int = 100,
resolve_links: bool = True,
require_master: bool = False,
correlation_id: Opt... | [
"async",
"def",
"iter_all",
"(",
"self",
",",
"direction",
":",
"msg",
".",
"StreamDirection",
"=",
"msg",
".",
"StreamDirection",
".",
"Forward",
",",
"from_position",
":",
"Optional",
"[",
"Union",
"[",
"msg",
".",
"Position",
",",
"msg",
".",
"_Position... | Read through all the events in the database.
Args:
direction (optional): Controls whether to read forward or backward
through the events. Defaults to StreamDirection.Forward
from_position (optional): The position to start reading from.
Defaults to photonpump... | [
"Read",
"through",
"all",
"the",
"events",
"in",
"the",
"database",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L904-L965 | train |
madedotcom/photon-pump | photonpump/connection.py | Client.subscribe_to | async def subscribe_to(
self, stream, start_from=-1, resolve_link_tos=True, batch_size: int = 100
):
"""
Subscribe to receive notifications when a new event is published
to a stream.
Args:
stream: The name of the stream.
start_from (optional): The fir... | python | async def subscribe_to(
self, stream, start_from=-1, resolve_link_tos=True, batch_size: int = 100
):
"""
Subscribe to receive notifications when a new event is published
to a stream.
Args:
stream: The name of the stream.
start_from (optional): The fir... | [
"async",
"def",
"subscribe_to",
"(",
"self",
",",
"stream",
",",
"start_from",
"=",
"-",
"1",
",",
"resolve_link_tos",
"=",
"True",
",",
"batch_size",
":",
"int",
"=",
"100",
")",
":",
"if",
"start_from",
"==",
"-",
"1",
":",
"cmd",
":",
"convo",
"."... | Subscribe to receive notifications when a new event is published
to a stream.
Args:
stream: The name of the stream.
start_from (optional): The first event to read.
This parameter defaults to the magic value -1 which is treated
as meaning "from the... | [
"Subscribe",
"to",
"receive",
"notifications",
"when",
"a",
"new",
"event",
"is",
"published",
"to",
"a",
"stream",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/connection.py#L1029-L1086 | train |
madedotcom/photon-pump | photonpump/discovery.py | prefer_master | def prefer_master(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
"""
Select the master if available, otherwise fall back to a replica.
"""
return max(nodes, key=attrgetter("state")) | python | def prefer_master(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
"""
Select the master if available, otherwise fall back to a replica.
"""
return max(nodes, key=attrgetter("state")) | [
"def",
"prefer_master",
"(",
"nodes",
":",
"List",
"[",
"DiscoveredNode",
"]",
")",
"->",
"Optional",
"[",
"DiscoveredNode",
"]",
":",
"return",
"max",
"(",
"nodes",
",",
"key",
"=",
"attrgetter",
"(",
"\"state\"",
")",
")"
] | Select the master if available, otherwise fall back to a replica. | [
"Select",
"the",
"master",
"if",
"available",
"otherwise",
"fall",
"back",
"to",
"a",
"replica",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/discovery.py#L60-L64 | train |
madedotcom/photon-pump | photonpump/discovery.py | prefer_replica | def prefer_replica(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
"""
Select a random replica if any are available or fall back to the master.
"""
masters = [node for node in nodes if node.state == NodeState.Master]
replicas = [node for node in nodes if node.state != NodeState.Master]
... | python | def prefer_replica(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
"""
Select a random replica if any are available or fall back to the master.
"""
masters = [node for node in nodes if node.state == NodeState.Master]
replicas = [node for node in nodes if node.state != NodeState.Master]
... | [
"def",
"prefer_replica",
"(",
"nodes",
":",
"List",
"[",
"DiscoveredNode",
"]",
")",
"->",
"Optional",
"[",
"DiscoveredNode",
"]",
":",
"masters",
"=",
"[",
"node",
"for",
"node",
"in",
"nodes",
"if",
"node",
".",
"state",
"==",
"NodeState",
".",
"Master... | Select a random replica if any are available or fall back to the master. | [
"Select",
"a",
"random",
"replica",
"if",
"any",
"are",
"available",
"or",
"fall",
"back",
"to",
"the",
"master",
"."
] | ff0736c9cacd43c1f783c9668eefb53d03a3a93e | https://github.com/madedotcom/photon-pump/blob/ff0736c9cacd43c1f783c9668eefb53d03a3a93e/photonpump/discovery.py#L67-L79 | train |
nteract/vdom | vdom/core.py | create_event_handler | def create_event_handler(event_type, handler):
"""Register a comm and return a serializable object with target name"""
target_name = '{hash}_{event_type}'.format(hash=hash(handler), event_type=event_type)
def handle_comm_opened(comm, msg):
@comm.on_msg
def _handle_msg(msg):
dat... | python | def create_event_handler(event_type, handler):
"""Register a comm and return a serializable object with target name"""
target_name = '{hash}_{event_type}'.format(hash=hash(handler), event_type=event_type)
def handle_comm_opened(comm, msg):
@comm.on_msg
def _handle_msg(msg):
dat... | [
"def",
"create_event_handler",
"(",
"event_type",
",",
"handler",
")",
":",
"target_name",
"=",
"'{hash}_{event_type}'",
".",
"format",
"(",
"hash",
"=",
"hash",
"(",
"handler",
")",
",",
"event_type",
"=",
"event_type",
")",
"def",
"handle_comm_opened",
"(",
... | Register a comm and return a serializable object with target name | [
"Register",
"a",
"comm",
"and",
"return",
"a",
"serializable",
"object",
"with",
"target",
"name"
] | d1ef48dc20d50379b8137a104125c92f64b916e4 | https://github.com/nteract/vdom/blob/d1ef48dc20d50379b8137a104125c92f64b916e4/vdom/core.py#L49-L70 | train |
nteract/vdom | vdom/core.py | to_json | def to_json(el, schema=None):
"""Convert an element to VDOM JSON
If you wish to validate the JSON, pass in a schema via the schema keyword
argument. If a schema is provided, this raises a ValidationError if JSON
does not match the schema.
"""
if type(el) is str:
json_el = el
elif ty... | python | def to_json(el, schema=None):
"""Convert an element to VDOM JSON
If you wish to validate the JSON, pass in a schema via the schema keyword
argument. If a schema is provided, this raises a ValidationError if JSON
does not match the schema.
"""
if type(el) is str:
json_el = el
elif ty... | [
"def",
"to_json",
"(",
"el",
",",
"schema",
"=",
"None",
")",
":",
"if",
"type",
"(",
"el",
")",
"is",
"str",
":",
"json_el",
"=",
"el",
"elif",
"type",
"(",
"el",
")",
"is",
"list",
":",
"json_el",
"=",
"list",
"(",
"map",
"(",
"to_json",
",",... | Convert an element to VDOM JSON
If you wish to validate the JSON, pass in a schema via the schema keyword
argument. If a schema is provided, this raises a ValidationError if JSON
does not match the schema. | [
"Convert",
"an",
"element",
"to",
"VDOM",
"JSON"
] | d1ef48dc20d50379b8137a104125c92f64b916e4 | https://github.com/nteract/vdom/blob/d1ef48dc20d50379b8137a104125c92f64b916e4/vdom/core.py#L73-L102 | train |
nteract/vdom | vdom/core.py | create_component | def create_component(tag_name, allow_children=True):
"""
Create a component for an HTML Tag
Examples:
>>> marquee = create_component('marquee')
>>> marquee('woohoo')
<marquee>woohoo</marquee>
"""
def _component(*children, **kwargs):
if 'children' in kwargs:
... | python | def create_component(tag_name, allow_children=True):
"""
Create a component for an HTML Tag
Examples:
>>> marquee = create_component('marquee')
>>> marquee('woohoo')
<marquee>woohoo</marquee>
"""
def _component(*children, **kwargs):
if 'children' in kwargs:
... | [
"def",
"create_component",
"(",
"tag_name",
",",
"allow_children",
"=",
"True",
")",
":",
"def",
"_component",
"(",
"*",
"children",
",",
"**",
"kwargs",
")",
":",
"if",
"'children'",
"in",
"kwargs",
":",
"children",
"=",
"kwargs",
".",
"pop",
"(",
"'chi... | Create a component for an HTML Tag
Examples:
>>> marquee = create_component('marquee')
>>> marquee('woohoo')
<marquee>woohoo</marquee> | [
"Create",
"a",
"component",
"for",
"an",
"HTML",
"Tag"
] | d1ef48dc20d50379b8137a104125c92f64b916e4 | https://github.com/nteract/vdom/blob/d1ef48dc20d50379b8137a104125c92f64b916e4/vdom/core.py#L301-L343 | train |
nteract/vdom | vdom/core.py | VDOM.validate | def validate(self, schema):
"""
Validate VDOM against given JSON Schema
Raises ValidationError if schema does not match
"""
try:
validate(instance=self.to_dict(), schema=schema, cls=Draft4Validator)
except ValidationError as e:
raise ValidationErr... | python | def validate(self, schema):
"""
Validate VDOM against given JSON Schema
Raises ValidationError if schema does not match
"""
try:
validate(instance=self.to_dict(), schema=schema, cls=Draft4Validator)
except ValidationError as e:
raise ValidationErr... | [
"def",
"validate",
"(",
"self",
",",
"schema",
")",
":",
"try",
":",
"validate",
"(",
"instance",
"=",
"self",
".",
"to_dict",
"(",
")",
",",
"schema",
"=",
"schema",
",",
"cls",
"=",
"Draft4Validator",
")",
"except",
"ValidationError",
"as",
"e",
":",... | Validate VDOM against given JSON Schema
Raises ValidationError if schema does not match | [
"Validate",
"VDOM",
"against",
"given",
"JSON",
"Schema"
] | d1ef48dc20d50379b8137a104125c92f64b916e4 | https://github.com/nteract/vdom/blob/d1ef48dc20d50379b8137a104125c92f64b916e4/vdom/core.py#L174-L183 | train |
nteract/vdom | vdom/core.py | VDOM.to_dict | def to_dict(self):
"""Converts VDOM object to a dictionary that passes our schema
"""
attributes = dict(self.attributes.items())
if self.style:
attributes.update({"style": dict(self.style.items())})
vdom_dict = {'tagName': self.tag_name, 'attributes': attributes}
... | python | def to_dict(self):
"""Converts VDOM object to a dictionary that passes our schema
"""
attributes = dict(self.attributes.items())
if self.style:
attributes.update({"style": dict(self.style.items())})
vdom_dict = {'tagName': self.tag_name, 'attributes': attributes}
... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"attributes",
"=",
"dict",
"(",
"self",
".",
"attributes",
".",
"items",
"(",
")",
")",
"if",
"self",
".",
"style",
":",
"attributes",
".",
"update",
"(",
"{",
"\"style\"",
":",
"dict",
"(",
"self",
".",
"st... | Converts VDOM object to a dictionary that passes our schema | [
"Converts",
"VDOM",
"object",
"to",
"a",
"dictionary",
"that",
"passes",
"our",
"schema"
] | d1ef48dc20d50379b8137a104125c92f64b916e4 | https://github.com/nteract/vdom/blob/d1ef48dc20d50379b8137a104125c92f64b916e4/vdom/core.py#L185-L201 | train |
konstantint/PassportEye | passporteye/mrz/text.py | MRZ._guess_type | def _guess_type(mrz_lines):
"""Guesses the type of the MRZ from given lines. Returns 'TD1', 'TD2', 'TD3', 'MRVA', 'MRVB' or None.
The algorithm is basically just counting lines, looking at their length and checking whether the first character is a 'V'
>>> MRZ._guess_type([]) is None
Tru... | python | def _guess_type(mrz_lines):
"""Guesses the type of the MRZ from given lines. Returns 'TD1', 'TD2', 'TD3', 'MRVA', 'MRVB' or None.
The algorithm is basically just counting lines, looking at their length and checking whether the first character is a 'V'
>>> MRZ._guess_type([]) is None
Tru... | [
"def",
"_guess_type",
"(",
"mrz_lines",
")",
":",
"try",
":",
"if",
"len",
"(",
"mrz_lines",
")",
"==",
"3",
":",
"return",
"'TD1'",
"elif",
"len",
"(",
"mrz_lines",
")",
"==",
"2",
"and",
"len",
"(",
"mrz_lines",
"[",
"0",
"]",
")",
"<",
"40",
"... | Guesses the type of the MRZ from given lines. Returns 'TD1', 'TD2', 'TD3', 'MRVA', 'MRVB' or None.
The algorithm is basically just counting lines, looking at their length and checking whether the first character is a 'V'
>>> MRZ._guess_type([]) is None
True
>>> MRZ._guess_type([1]) is N... | [
"Guesses",
"the",
"type",
"of",
"the",
"MRZ",
"from",
"given",
"lines",
".",
"Returns",
"TD1",
"TD2",
"TD3",
"MRVA",
"MRVB",
"or",
"None",
".",
"The",
"algorithm",
"is",
"basically",
"just",
"counting",
"lines",
"looking",
"at",
"their",
"length",
"and",
... | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/text.py#L129-L160 | train |
konstantint/PassportEye | passporteye/util/pipeline.py | Pipeline.remove_component | def remove_component(self, name):
"""Removes an existing component with a given name, invalidating all the values computed by
the previous component."""
if name not in self.components:
raise Exception("No component named %s" % name)
del self.components[name]
del self.... | python | def remove_component(self, name):
"""Removes an existing component with a given name, invalidating all the values computed by
the previous component."""
if name not in self.components:
raise Exception("No component named %s" % name)
del self.components[name]
del self.... | [
"def",
"remove_component",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"components",
":",
"raise",
"Exception",
"(",
"\"No component named %s\"",
"%",
"name",
")",
"del",
"self",
".",
"components",
"[",
"name",
"]",
"del",
... | Removes an existing component with a given name, invalidating all the values computed by
the previous component. | [
"Removes",
"an",
"existing",
"component",
"with",
"a",
"given",
"name",
"invalidating",
"all",
"the",
"values",
"computed",
"by",
"the",
"previous",
"component",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/pipeline.py#L68-L78 | train |
konstantint/PassportEye | passporteye/util/pipeline.py | Pipeline.replace_component | def replace_component(self, name, callable, provides=None, depends=None):
"""Changes an existing component with a given name, invalidating all the values computed by
the previous component and its successors."""
self.remove_component(name)
self.add_component(name, callable, provides, dep... | python | def replace_component(self, name, callable, provides=None, depends=None):
"""Changes an existing component with a given name, invalidating all the values computed by
the previous component and its successors."""
self.remove_component(name)
self.add_component(name, callable, provides, dep... | [
"def",
"replace_component",
"(",
"self",
",",
"name",
",",
"callable",
",",
"provides",
"=",
"None",
",",
"depends",
"=",
"None",
")",
":",
"self",
".",
"remove_component",
"(",
"name",
")",
"self",
".",
"add_component",
"(",
"name",
",",
"callable",
","... | Changes an existing component with a given name, invalidating all the values computed by
the previous component and its successors. | [
"Changes",
"an",
"existing",
"component",
"with",
"a",
"given",
"name",
"invalidating",
"all",
"the",
"values",
"computed",
"by",
"the",
"previous",
"component",
"and",
"its",
"successors",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/pipeline.py#L80-L84 | train |
konstantint/PassportEye | passporteye/util/pipeline.py | Pipeline.invalidate | def invalidate(self, key):
"""Remove the given data item along with all items that depend on it in the graph."""
if key not in self.data:
return
del self.data[key]
# Find all components that used it and invalidate their results
for cname in self.components:
... | python | def invalidate(self, key):
"""Remove the given data item along with all items that depend on it in the graph."""
if key not in self.data:
return
del self.data[key]
# Find all components that used it and invalidate their results
for cname in self.components:
... | [
"def",
"invalidate",
"(",
"self",
",",
"key",
")",
":",
"if",
"key",
"not",
"in",
"self",
".",
"data",
":",
"return",
"del",
"self",
".",
"data",
"[",
"key",
"]",
"for",
"cname",
"in",
"self",
".",
"components",
":",
"if",
"key",
"in",
"self",
".... | Remove the given data item along with all items that depend on it in the graph. | [
"Remove",
"the",
"given",
"data",
"item",
"along",
"with",
"all",
"items",
"that",
"depend",
"on",
"it",
"in",
"the",
"graph",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/pipeline.py#L86-L96 | train |
konstantint/PassportEye | passporteye/util/ocr.py | ocr | def ocr(img, mrz_mode=True, extra_cmdline_params=''):
"""Runs Tesseract on a given image. Writes an intermediate tempfile and then runs the tesseract command on the image.
This is a simplified modification of image_to_string from PyTesseract, which is adapted to SKImage rather than PIL.
In principle we co... | python | def ocr(img, mrz_mode=True, extra_cmdline_params=''):
"""Runs Tesseract on a given image. Writes an intermediate tempfile and then runs the tesseract command on the image.
This is a simplified modification of image_to_string from PyTesseract, which is adapted to SKImage rather than PIL.
In principle we co... | [
"def",
"ocr",
"(",
"img",
",",
"mrz_mode",
"=",
"True",
",",
"extra_cmdline_params",
"=",
"''",
")",
":",
"input_file_name",
"=",
"'%s.bmp'",
"%",
"_tempnam",
"(",
")",
"output_file_name_base",
"=",
"'%s'",
"%",
"_tempnam",
"(",
")",
"output_file_name",
"=",... | Runs Tesseract on a given image. Writes an intermediate tempfile and then runs the tesseract command on the image.
This is a simplified modification of image_to_string from PyTesseract, which is adapted to SKImage rather than PIL.
In principle we could have reimplemented it just as well - there are some appar... | [
"Runs",
"Tesseract",
"on",
"a",
"given",
"image",
".",
"Writes",
"an",
"intermediate",
"tempfile",
"and",
"then",
"runs",
"the",
"tesseract",
"command",
"on",
"the",
"image",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/ocr.py#L16-L64 | train |
konstantint/PassportEye | passporteye/util/geometry.py | RotatedBox.approx_equal | def approx_equal(self, center, width, height, angle, tol=1e-6):
"Method mainly useful for testing"
return abs(self.cx - center[0]) < tol and abs(self.cy - center[1]) < tol and abs(self.width - width) < tol and \
abs(self.height - height) < tol and abs(self.angle - angle) < tol | python | def approx_equal(self, center, width, height, angle, tol=1e-6):
"Method mainly useful for testing"
return abs(self.cx - center[0]) < tol and abs(self.cy - center[1]) < tol and abs(self.width - width) < tol and \
abs(self.height - height) < tol and abs(self.angle - angle) < tol | [
"def",
"approx_equal",
"(",
"self",
",",
"center",
",",
"width",
",",
"height",
",",
"angle",
",",
"tol",
"=",
"1e-6",
")",
":",
"\"Method mainly useful for testing\"",
"return",
"abs",
"(",
"self",
".",
"cx",
"-",
"center",
"[",
"0",
"]",
")",
"<",
"t... | Method mainly useful for testing | [
"Method",
"mainly",
"useful",
"for",
"testing"
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/geometry.py#L49-L52 | train |
konstantint/PassportEye | passporteye/util/geometry.py | RotatedBox.rotated | def rotated(self, rotation_center, angle):
"""Returns a RotatedBox that is obtained by rotating this box around a given center by a given angle.
>>> assert RotatedBox([2, 2], 2, 1, 0.1).rotated([1, 1], np.pi/2).approx_equal([0, 2], 2, 1, np.pi/2+0.1)
"""
rot = np.array([[np.cos(angle), ... | python | def rotated(self, rotation_center, angle):
"""Returns a RotatedBox that is obtained by rotating this box around a given center by a given angle.
>>> assert RotatedBox([2, 2], 2, 1, 0.1).rotated([1, 1], np.pi/2).approx_equal([0, 2], 2, 1, np.pi/2+0.1)
"""
rot = np.array([[np.cos(angle), ... | [
"def",
"rotated",
"(",
"self",
",",
"rotation_center",
",",
"angle",
")",
":",
"rot",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"np",
".",
"cos",
"(",
"angle",
")",
",",
"np",
".",
"sin",
"(",
"angle",
")",
"]",
",",
"[",
"-",
"np",
".",
"sin",... | Returns a RotatedBox that is obtained by rotating this box around a given center by a given angle.
>>> assert RotatedBox([2, 2], 2, 1, 0.1).rotated([1, 1], np.pi/2).approx_equal([0, 2], 2, 1, np.pi/2+0.1) | [
"Returns",
"a",
"RotatedBox",
"that",
"is",
"obtained",
"by",
"rotating",
"this",
"box",
"around",
"a",
"given",
"center",
"by",
"a",
"given",
"angle",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/geometry.py#L54-L62 | train |
konstantint/PassportEye | passporteye/util/geometry.py | RotatedBox.as_poly | def as_poly(self, margin_width=0, margin_height=0):
"""Converts this box to a polygon, i.e. 4x2 array, representing the four corners starting from lower left to upper left counterclockwise.
:param margin_width: The additional "margin" that will be added to the box along its width dimension (from both s... | python | def as_poly(self, margin_width=0, margin_height=0):
"""Converts this box to a polygon, i.e. 4x2 array, representing the four corners starting from lower left to upper left counterclockwise.
:param margin_width: The additional "margin" that will be added to the box along its width dimension (from both s... | [
"def",
"as_poly",
"(",
"self",
",",
"margin_width",
"=",
"0",
",",
"margin_height",
"=",
"0",
")",
":",
"v_hor",
"=",
"(",
"self",
".",
"width",
"/",
"2",
"+",
"margin_width",
")",
"*",
"np",
".",
"array",
"(",
"[",
"np",
".",
"cos",
"(",
"self",... | Converts this box to a polygon, i.e. 4x2 array, representing the four corners starting from lower left to upper left counterclockwise.
:param margin_width: The additional "margin" that will be added to the box along its width dimension (from both sides) before conversion.
:param margin_height: The addi... | [
"Converts",
"this",
"box",
"to",
"a",
"polygon",
"i",
".",
"e",
".",
"4x2",
"array",
"representing",
"the",
"four",
"corners",
"starting",
"from",
"lower",
"left",
"to",
"upper",
"left",
"counterclockwise",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/geometry.py#L64-L94 | train |
konstantint/PassportEye | passporteye/util/geometry.py | RotatedBox.extract_from_image | def extract_from_image(self, img, scale=1.0, margin_width=5, margin_height=5):
"""Extracts the contents of this box from a given image.
For that the image is "unrotated" by the appropriate angle, and the corresponding part is extracted from it.
Returns an image with dimensions height*scale x wi... | python | def extract_from_image(self, img, scale=1.0, margin_width=5, margin_height=5):
"""Extracts the contents of this box from a given image.
For that the image is "unrotated" by the appropriate angle, and the corresponding part is extracted from it.
Returns an image with dimensions height*scale x wi... | [
"def",
"extract_from_image",
"(",
"self",
",",
"img",
",",
"scale",
"=",
"1.0",
",",
"margin_width",
"=",
"5",
",",
"margin_height",
"=",
"5",
")",
":",
"rotate_by",
"=",
"(",
"np",
".",
"pi",
"/",
"2",
"-",
"self",
".",
"angle",
")",
"*",
"180",
... | Extracts the contents of this box from a given image.
For that the image is "unrotated" by the appropriate angle, and the corresponding part is extracted from it.
Returns an image with dimensions height*scale x width*scale.
Note that the box coordinates are interpreted as "image coordinates" (i... | [
"Extracts",
"the",
"contents",
"of",
"this",
"box",
"from",
"a",
"given",
"image",
".",
"For",
"that",
"the",
"image",
"is",
"unrotated",
"by",
"the",
"appropriate",
"angle",
"and",
"the",
"corresponding",
"part",
"is",
"extracted",
"from",
"it",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/util/geometry.py#L119-L149 | train |
konstantint/PassportEye | passporteye/mrz/image.py | read_mrz | def read_mrz(file, save_roi=False, extra_cmdline_params=''):
"""The main interface function to this module, encapsulating the recognition pipeline.
Given an image filename, runs MRZPipeline on it, returning the parsed MRZ object.
:param file: A filename or a stream to read the file data from.
:param... | python | def read_mrz(file, save_roi=False, extra_cmdline_params=''):
"""The main interface function to this module, encapsulating the recognition pipeline.
Given an image filename, runs MRZPipeline on it, returning the parsed MRZ object.
:param file: A filename or a stream to read the file data from.
:param... | [
"def",
"read_mrz",
"(",
"file",
",",
"save_roi",
"=",
"False",
",",
"extra_cmdline_params",
"=",
"''",
")",
":",
"p",
"=",
"MRZPipeline",
"(",
"file",
",",
"extra_cmdline_params",
")",
"mrz",
"=",
"p",
".",
"result",
"if",
"mrz",
"is",
"not",
"None",
"... | The main interface function to this module, encapsulating the recognition pipeline.
Given an image filename, runs MRZPipeline on it, returning the parsed MRZ object.
:param file: A filename or a stream to read the file data from.
:param save_roi: when this is True, the .aux['roi'] field will contain the... | [
"The",
"main",
"interface",
"function",
"to",
"this",
"module",
"encapsulating",
"the",
"recognition",
"pipeline",
".",
"Given",
"an",
"image",
"filename",
"runs",
"MRZPipeline",
"on",
"it",
"returning",
"the",
"parsed",
"MRZ",
"object",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L328-L343 | train |
konstantint/PassportEye | passporteye/mrz/image.py | Loader._imread | def _imread(self, file):
"""Proxy to skimage.io.imread with some fixes."""
# For now, we have to select the imageio plugin to read image from byte stream
# When ski-image v0.15 is released, imageio will be the default plugin, so this
# code can be simplified at that time. See issue repo... | python | def _imread(self, file):
"""Proxy to skimage.io.imread with some fixes."""
# For now, we have to select the imageio plugin to read image from byte stream
# When ski-image v0.15 is released, imageio will be the default plugin, so this
# code can be simplified at that time. See issue repo... | [
"def",
"_imread",
"(",
"self",
",",
"file",
")",
":",
"img",
"=",
"skimage_io",
".",
"imread",
"(",
"file",
",",
"as_gray",
"=",
"self",
".",
"as_gray",
",",
"plugin",
"=",
"'imageio'",
")",
"if",
"img",
"is",
"not",
"None",
"and",
"len",
"(",
"img... | Proxy to skimage.io.imread with some fixes. | [
"Proxy",
"to",
"skimage",
".",
"io",
".",
"imread",
"with",
"some",
"fixes",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L30-L41 | train |
konstantint/PassportEye | passporteye/mrz/image.py | MRZBoxLocator._are_aligned_angles | def _are_aligned_angles(self, b1, b2):
"Are two boxes aligned according to their angle?"
return abs(b1 - b2) <= self.angle_tol or abs(np.pi - abs(b1 - b2)) <= self.angle_tol | python | def _are_aligned_angles(self, b1, b2):
"Are two boxes aligned according to their angle?"
return abs(b1 - b2) <= self.angle_tol or abs(np.pi - abs(b1 - b2)) <= self.angle_tol | [
"def",
"_are_aligned_angles",
"(",
"self",
",",
"b1",
",",
"b2",
")",
":",
"\"Are two boxes aligned according to their angle?\"",
"return",
"abs",
"(",
"b1",
"-",
"b2",
")",
"<=",
"self",
".",
"angle_tol",
"or",
"abs",
"(",
"np",
".",
"pi",
"-",
"abs",
"("... | Are two boxes aligned according to their angle? | [
"Are",
"two",
"boxes",
"aligned",
"according",
"to",
"their",
"angle?"
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L136-L138 | train |
konstantint/PassportEye | passporteye/mrz/image.py | MRZBoxLocator._are_nearby_parallel_boxes | def _are_nearby_parallel_boxes(self, b1, b2):
"Are two boxes nearby, parallel, and similar in width?"
if not self._are_aligned_angles(b1.angle, b2.angle):
return False
# Otherwise pick the smaller angle and see whether the two boxes are close according to the "up" direction wrt that ... | python | def _are_nearby_parallel_boxes(self, b1, b2):
"Are two boxes nearby, parallel, and similar in width?"
if not self._are_aligned_angles(b1.angle, b2.angle):
return False
# Otherwise pick the smaller angle and see whether the two boxes are close according to the "up" direction wrt that ... | [
"def",
"_are_nearby_parallel_boxes",
"(",
"self",
",",
"b1",
",",
"b2",
")",
":",
"\"Are two boxes nearby, parallel, and similar in width?\"",
"if",
"not",
"self",
".",
"_are_aligned_angles",
"(",
"b1",
".",
"angle",
",",
"b2",
".",
"angle",
")",
":",
"return",
... | Are two boxes nearby, parallel, and similar in width? | [
"Are",
"two",
"boxes",
"nearby",
"parallel",
"and",
"similar",
"in",
"width?"
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L140-L147 | train |
konstantint/PassportEye | passporteye/mrz/image.py | MRZBoxLocator._merge_any_two_boxes | def _merge_any_two_boxes(self, box_list):
"""Given a list of boxes, finds two nearby parallel ones and merges them. Returns false if none found."""
n = len(box_list)
for i in range(n):
for j in range(i + 1, n):
if self._are_nearby_parallel_boxes(box_list[i], box_list[... | python | def _merge_any_two_boxes(self, box_list):
"""Given a list of boxes, finds two nearby parallel ones and merges them. Returns false if none found."""
n = len(box_list)
for i in range(n):
for j in range(i + 1, n):
if self._are_nearby_parallel_boxes(box_list[i], box_list[... | [
"def",
"_merge_any_two_boxes",
"(",
"self",
",",
"box_list",
")",
":",
"n",
"=",
"len",
"(",
"box_list",
")",
"for",
"i",
"in",
"range",
"(",
"n",
")",
":",
"for",
"j",
"in",
"range",
"(",
"i",
"+",
"1",
",",
"n",
")",
":",
"if",
"self",
".",
... | Given a list of boxes, finds two nearby parallel ones and merges them. Returns false if none found. | [
"Given",
"a",
"list",
"of",
"boxes",
"finds",
"two",
"nearby",
"parallel",
"ones",
"and",
"merges",
"them",
".",
"Returns",
"false",
"if",
"none",
"found",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L149-L164 | train |
konstantint/PassportEye | passporteye/mrz/image.py | BoxToMRZ._try_larger_image | def _try_larger_image(self, roi, cur_text, cur_mrz, filter_order=3):
"""Attempts to improve the OCR result by scaling the image. If the new mrz is better, returns it, otherwise returns
the old mrz."""
if roi.shape[1] <= 700:
scale_by = int(1050.0 / roi.shape[1] + 0.5)
roi... | python | def _try_larger_image(self, roi, cur_text, cur_mrz, filter_order=3):
"""Attempts to improve the OCR result by scaling the image. If the new mrz is better, returns it, otherwise returns
the old mrz."""
if roi.shape[1] <= 700:
scale_by = int(1050.0 / roi.shape[1] + 0.5)
roi... | [
"def",
"_try_larger_image",
"(",
"self",
",",
"roi",
",",
"cur_text",
",",
"cur_mrz",
",",
"filter_order",
"=",
"3",
")",
":",
"if",
"roi",
".",
"shape",
"[",
"1",
"]",
"<=",
"700",
":",
"scale_by",
"=",
"int",
"(",
"1050.0",
"/",
"roi",
".",
"shap... | Attempts to improve the OCR result by scaling the image. If the new mrz is better, returns it, otherwise returns
the old mrz. | [
"Attempts",
"to",
"improve",
"the",
"OCR",
"result",
"by",
"scaling",
"the",
"image",
".",
"If",
"the",
"new",
"mrz",
"is",
"better",
"returns",
"it",
"otherwise",
"returns",
"the",
"old",
"mrz",
"."
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/image.py#L254-L267 | train |
konstantint/PassportEye | passporteye/mrz/scripts.py | mrz | def mrz():
"""
Command-line script for extracting MRZ from a given image
"""
parser = argparse.ArgumentParser(description='Run the MRZ OCR recognition algorithm on the given image.')
parser.add_argument('filename')
parser.add_argument('--json', action='store_true', help='Produce JSON (rather tha... | python | def mrz():
"""
Command-line script for extracting MRZ from a given image
"""
parser = argparse.ArgumentParser(description='Run the MRZ OCR recognition algorithm on the given image.')
parser.add_argument('filename')
parser.add_argument('--json', action='store_true', help='Produce JSON (rather tha... | [
"def",
"mrz",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Run the MRZ OCR recognition algorithm on the given image.'",
")",
"parser",
".",
"add_argument",
"(",
"'filename'",
")",
"parser",
".",
"add_argument",
"(",
"'-... | Command-line script for extracting MRZ from a given image | [
"Command",
"-",
"line",
"script",
"for",
"extracting",
"MRZ",
"from",
"a",
"given",
"image"
] | b32afba0f5dc4eb600c4edc4f49e5d49959c5415 | https://github.com/konstantint/PassportEye/blob/b32afba0f5dc4eb600c4edc4f49e5d49959c5415/passporteye/mrz/scripts.py#L134-L174 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows._check_count | def _check_count(self, result, func, args):
#pylint: disable=unused-argument
""" Private function to return ctypes errors cleanly """
if result == 0:
raise ctypes.WinError(ctypes.get_last_error())
return args | python | def _check_count(self, result, func, args):
#pylint: disable=unused-argument
""" Private function to return ctypes errors cleanly """
if result == 0:
raise ctypes.WinError(ctypes.get_last_error())
return args | [
"def",
"_check_count",
"(",
"self",
",",
"result",
",",
"func",
",",
"args",
")",
":",
"if",
"result",
"==",
"0",
":",
"raise",
"ctypes",
".",
"WinError",
"(",
"ctypes",
".",
"get_last_error",
"(",
")",
")",
"return",
"args"
] | Private function to return ctypes errors cleanly | [
"Private",
"function",
"to",
"return",
"ctypes",
"errors",
"cleanly"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L210-L215 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows._getMonitorInfo | def _getMonitorInfo(self):
""" Returns info about the attached monitors, in device order
[0] is always the primary monitor
"""
monitors = []
CCHDEVICENAME = 32
def _MonitorEnumProcCallback(hMonitor, hdcMonitor, lprcMonitor, dwData):
class MONITORINFOEX(ctypes... | python | def _getMonitorInfo(self):
""" Returns info about the attached monitors, in device order
[0] is always the primary monitor
"""
monitors = []
CCHDEVICENAME = 32
def _MonitorEnumProcCallback(hMonitor, hdcMonitor, lprcMonitor, dwData):
class MONITORINFOEX(ctypes... | [
"def",
"_getMonitorInfo",
"(",
"self",
")",
":",
"monitors",
"=",
"[",
"]",
"CCHDEVICENAME",
"=",
"32",
"def",
"_MonitorEnumProcCallback",
"(",
"hMonitor",
",",
"hdcMonitor",
",",
"lprcMonitor",
",",
"dwData",
")",
":",
"class",
"MONITORINFOEX",
"(",
"ctypes",... | Returns info about the attached monitors, in device order
[0] is always the primary monitor | [
"Returns",
"info",
"about",
"the",
"attached",
"monitors",
"in",
"device",
"order"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L401-L443 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows._getVirtualScreenRect | def _getVirtualScreenRect(self):
""" The virtual screen is the bounding box containing all monitors.
Not all regions in the virtual screen are actually visible. The (0,0) coordinate
is the top left corner of the primary screen rather than the whole bounding box, so
some regions of the v... | python | def _getVirtualScreenRect(self):
""" The virtual screen is the bounding box containing all monitors.
Not all regions in the virtual screen are actually visible. The (0,0) coordinate
is the top left corner of the primary screen rather than the whole bounding box, so
some regions of the v... | [
"def",
"_getVirtualScreenRect",
"(",
"self",
")",
":",
"SM_XVIRTUALSCREEN",
"=",
"76",
"SM_YVIRTUALSCREEN",
"=",
"77",
"SM_CXVIRTUALSCREEN",
"=",
"78",
"SM_CYVIRTUALSCREEN",
"=",
"79",
"return",
"(",
"self",
".",
"_user32",
".",
"GetSystemMetrics",
"(",
"SM_XVIRTU... | The virtual screen is the bounding box containing all monitors.
Not all regions in the virtual screen are actually visible. The (0,0) coordinate
is the top left corner of the primary screen rather than the whole bounding box, so
some regions of the virtual screen may have negative coordinates i... | [
"The",
"virtual",
"screen",
"is",
"the",
"bounding",
"box",
"containing",
"all",
"monitors",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L444-L462 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows.osPaste | def osPaste(self):
""" Triggers the OS "paste" keyboard shortcut """
from .InputEmulation import Keyboard
k = Keyboard()
k.keyDown("{CTRL}")
k.type("v")
k.keyUp("{CTRL}") | python | def osPaste(self):
""" Triggers the OS "paste" keyboard shortcut """
from .InputEmulation import Keyboard
k = Keyboard()
k.keyDown("{CTRL}")
k.type("v")
k.keyUp("{CTRL}") | [
"def",
"osPaste",
"(",
"self",
")",
":",
"from",
".",
"InputEmulation",
"import",
"Keyboard",
"k",
"=",
"Keyboard",
"(",
")",
"k",
".",
"keyDown",
"(",
"\"{CTRL}\"",
")",
"k",
".",
"type",
"(",
"\"v\"",
")",
"k",
".",
"keyUp",
"(",
"\"{CTRL}\"",
")"
... | Triggers the OS "paste" keyboard shortcut | [
"Triggers",
"the",
"OS",
"paste",
"keyboard",
"shortcut"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L497-L503 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows.focusWindow | def focusWindow(self, hwnd):
""" Brings specified window to the front """
Debug.log(3, "Focusing window: " + str(hwnd))
SW_RESTORE = 9
if ctypes.windll.user32.IsIconic(hwnd):
ctypes.windll.user32.ShowWindow(hwnd, SW_RESTORE)
ctypes.windll.user32.SetForegroundWindow(hw... | python | def focusWindow(self, hwnd):
""" Brings specified window to the front """
Debug.log(3, "Focusing window: " + str(hwnd))
SW_RESTORE = 9
if ctypes.windll.user32.IsIconic(hwnd):
ctypes.windll.user32.ShowWindow(hwnd, SW_RESTORE)
ctypes.windll.user32.SetForegroundWindow(hw... | [
"def",
"focusWindow",
"(",
"self",
",",
"hwnd",
")",
":",
"Debug",
".",
"log",
"(",
"3",
",",
"\"Focusing window: \"",
"+",
"str",
"(",
"hwnd",
")",
")",
"SW_RESTORE",
"=",
"9",
"if",
"ctypes",
".",
"windll",
".",
"user32",
".",
"IsIconic",
"(",
"hwn... | Brings specified window to the front | [
"Brings",
"specified",
"window",
"to",
"the",
"front"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L557-L563 | train |
glitchassassin/lackey | lackey/PlatformManagerWindows.py | PlatformManagerWindows.isPIDValid | def isPIDValid(self, pid):
""" Checks if a PID is associated with a running process """
## Slightly copied wholesale from http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid
## Thanks to http://stackoverflow.com/users/1777162/ntrrgc and http://stacko... | python | def isPIDValid(self, pid):
""" Checks if a PID is associated with a running process """
## Slightly copied wholesale from http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid
## Thanks to http://stackoverflow.com/users/1777162/ntrrgc and http://stacko... | [
"def",
"isPIDValid",
"(",
"self",
",",
"pid",
")",
":",
"class",
"ExitCodeProcess",
"(",
"ctypes",
".",
"Structure",
")",
":",
"_fields_",
"=",
"[",
"(",
"'hProcess'",
",",
"ctypes",
".",
"c_void_p",
")",
",",
"(",
"'lpExitCode'",
",",
"ctypes",
".",
"... | Checks if a PID is associated with a running process | [
"Checks",
"if",
"a",
"PID",
"is",
"associated",
"with",
"a",
"running",
"process"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/PlatformManagerWindows.py#L608-L635 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Pattern.similar | def similar(self, similarity):
""" Returns a new Pattern with the specified similarity threshold """
pattern = Pattern(self.path)
pattern.similarity = similarity
return pattern | python | def similar(self, similarity):
""" Returns a new Pattern with the specified similarity threshold """
pattern = Pattern(self.path)
pattern.similarity = similarity
return pattern | [
"def",
"similar",
"(",
"self",
",",
"similarity",
")",
":",
"pattern",
"=",
"Pattern",
"(",
"self",
".",
"path",
")",
"pattern",
".",
"similarity",
"=",
"similarity",
"return",
"pattern"
] | Returns a new Pattern with the specified similarity threshold | [
"Returns",
"a",
"new",
"Pattern",
"with",
"the",
"specified",
"similarity",
"threshold"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L73-L77 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Pattern.targetOffset | def targetOffset(self, dx, dy):
""" Returns a new Pattern with the given target offset """
pattern = Pattern(self.path)
pattern.similarity = self.similarity
pattern.offset = Location(dx, dy)
return pattern | python | def targetOffset(self, dx, dy):
""" Returns a new Pattern with the given target offset """
pattern = Pattern(self.path)
pattern.similarity = self.similarity
pattern.offset = Location(dx, dy)
return pattern | [
"def",
"targetOffset",
"(",
"self",
",",
"dx",
",",
"dy",
")",
":",
"pattern",
"=",
"Pattern",
"(",
"self",
".",
"path",
")",
"pattern",
".",
"similarity",
"=",
"self",
".",
"similarity",
"pattern",
".",
"offset",
"=",
"Location",
"(",
"dx",
",",
"dy... | Returns a new Pattern with the given target offset | [
"Returns",
"a",
"new",
"Pattern",
"with",
"the",
"given",
"target",
"offset"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L88-L93 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Pattern.debugPreview | def debugPreview(self, title="Debug"):
""" Loads and displays the image at ``Pattern.path`` """
haystack = Image.open(self.path)
haystack.show() | python | def debugPreview(self, title="Debug"):
""" Loads and displays the image at ``Pattern.path`` """
haystack = Image.open(self.path)
haystack.show() | [
"def",
"debugPreview",
"(",
"self",
",",
"title",
"=",
"\"Debug\"",
")",
":",
"haystack",
"=",
"Image",
".",
"open",
"(",
"self",
".",
"path",
")",
"haystack",
".",
"show",
"(",
")"
] | Loads and displays the image at ``Pattern.path`` | [
"Loads",
"and",
"displays",
"the",
"image",
"at",
"Pattern",
".",
"path"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L127-L130 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.setLocation | def setLocation(self, location):
""" Change the upper left-hand corner to a new ``Location``
Doesn't change width or height
"""
if not location or not isinstance(location, Location):
raise ValueError("setLocation expected a Location object")
self.x = location.x
... | python | def setLocation(self, location):
""" Change the upper left-hand corner to a new ``Location``
Doesn't change width or height
"""
if not location or not isinstance(location, Location):
raise ValueError("setLocation expected a Location object")
self.x = location.x
... | [
"def",
"setLocation",
"(",
"self",
",",
"location",
")",
":",
"if",
"not",
"location",
"or",
"not",
"isinstance",
"(",
"location",
",",
"Location",
")",
":",
"raise",
"ValueError",
"(",
"\"setLocation expected a Location object\"",
")",
"self",
".",
"x",
"=",
... | Change the upper left-hand corner to a new ``Location``
Doesn't change width or height | [
"Change",
"the",
"upper",
"left",
"-",
"hand",
"corner",
"to",
"a",
"new",
"Location"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L222-L231 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.contains | def contains(self, point_or_region):
""" Checks if ``point_or_region`` is within this region """
if isinstance(point_or_region, Location):
return (self.x < point_or_region.x < self.x + self.w) and (self.y < point_or_region.y < self.y + self.h)
elif isinstance(point_or_region, Region)... | python | def contains(self, point_or_region):
""" Checks if ``point_or_region`` is within this region """
if isinstance(point_or_region, Location):
return (self.x < point_or_region.x < self.x + self.w) and (self.y < point_or_region.y < self.y + self.h)
elif isinstance(point_or_region, Region)... | [
"def",
"contains",
"(",
"self",
",",
"point_or_region",
")",
":",
"if",
"isinstance",
"(",
"point_or_region",
",",
"Location",
")",
":",
"return",
"(",
"self",
".",
"x",
"<",
"point_or_region",
".",
"x",
"<",
"self",
".",
"x",
"+",
"self",
".",
"w",
... | Checks if ``point_or_region`` is within this region | [
"Checks",
"if",
"point_or_region",
"is",
"within",
"this",
"region"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L251-L261 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.morphTo | def morphTo(self, region):
""" Change shape of this region to match the given ``Region`` object """
if not region or not isinstance(region, Region):
raise TypeError("morphTo expected a Region object")
self.setROI(region)
return self | python | def morphTo(self, region):
""" Change shape of this region to match the given ``Region`` object """
if not region or not isinstance(region, Region):
raise TypeError("morphTo expected a Region object")
self.setROI(region)
return self | [
"def",
"morphTo",
"(",
"self",
",",
"region",
")",
":",
"if",
"not",
"region",
"or",
"not",
"isinstance",
"(",
"region",
",",
"Region",
")",
":",
"raise",
"TypeError",
"(",
"\"morphTo expected a Region object\"",
")",
"self",
".",
"setROI",
"(",
"region",
... | Change shape of this region to match the given ``Region`` object | [
"Change",
"shape",
"of",
"this",
"region",
"to",
"match",
"the",
"given",
"Region",
"object"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L264-L269 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.getCenter | def getCenter(self):
""" Return the ``Location`` of the center of this region """
return Location(self.x+(self.w/2), self.y+(self.h/2)) | python | def getCenter(self):
""" Return the ``Location`` of the center of this region """
return Location(self.x+(self.w/2), self.y+(self.h/2)) | [
"def",
"getCenter",
"(",
"self",
")",
":",
"return",
"Location",
"(",
"self",
".",
"x",
"+",
"(",
"self",
".",
"w",
"/",
"2",
")",
",",
"self",
".",
"y",
"+",
"(",
"self",
".",
"h",
"/",
"2",
")",
")"
] | Return the ``Location`` of the center of this region | [
"Return",
"the",
"Location",
"of",
"the",
"center",
"of",
"this",
"region"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L280-L282 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.getBottomRight | def getBottomRight(self):
""" Return the ``Location`` of the bottom right corner of this region """
return Location(self.x+self.w, self.y+self.h) | python | def getBottomRight(self):
""" Return the ``Location`` of the bottom right corner of this region """
return Location(self.x+self.w, self.y+self.h) | [
"def",
"getBottomRight",
"(",
"self",
")",
":",
"return",
"Location",
"(",
"self",
".",
"x",
"+",
"self",
".",
"w",
",",
"self",
".",
"y",
"+",
"self",
".",
"h",
")"
] | Return the ``Location`` of the bottom right corner of this region | [
"Return",
"the",
"Location",
"of",
"the",
"bottom",
"right",
"corner",
"of",
"this",
"region"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L292-L294 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.offset | def offset(self, location, dy=0):
""" Returns a new ``Region`` offset from this one by ``location``
Width and height remain the same
"""
if not isinstance(location, Location):
# Assume variables passed were dx,dy
location = Location(location, dy)
r = Regi... | python | def offset(self, location, dy=0):
""" Returns a new ``Region`` offset from this one by ``location``
Width and height remain the same
"""
if not isinstance(location, Location):
# Assume variables passed were dx,dy
location = Location(location, dy)
r = Regi... | [
"def",
"offset",
"(",
"self",
",",
"location",
",",
"dy",
"=",
"0",
")",
":",
"if",
"not",
"isinstance",
"(",
"location",
",",
"Location",
")",
":",
"location",
"=",
"Location",
"(",
"location",
",",
"dy",
")",
"r",
"=",
"Region",
"(",
"self",
".",... | Returns a new ``Region`` offset from this one by ``location``
Width and height remain the same | [
"Returns",
"a",
"new",
"Region",
"offset",
"from",
"this",
"one",
"by",
"location"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L331-L343 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.grow | def grow(self, width, height=None):
""" Expands the region by ``width`` on both sides and ``height`` on the top and bottom.
If only one value is provided, expands the region by that amount on all sides.
Equivalent to ``nearby()``.
"""
if height is None:
return self.n... | python | def grow(self, width, height=None):
""" Expands the region by ``width`` on both sides and ``height`` on the top and bottom.
If only one value is provided, expands the region by that amount on all sides.
Equivalent to ``nearby()``.
"""
if height is None:
return self.n... | [
"def",
"grow",
"(",
"self",
",",
"width",
",",
"height",
"=",
"None",
")",
":",
"if",
"height",
"is",
"None",
":",
"return",
"self",
".",
"nearby",
"(",
"width",
")",
"else",
":",
"return",
"Region",
"(",
"self",
".",
"x",
"-",
"width",
",",
"sel... | Expands the region by ``width`` on both sides and ``height`` on the top and bottom.
If only one value is provided, expands the region by that amount on all sides.
Equivalent to ``nearby()``. | [
"Expands",
"the",
"region",
"by",
"width",
"on",
"both",
"sides",
"and",
"height",
"on",
"the",
"top",
"and",
"bottom",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L344-L357 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.nearby | def nearby(self, expand=50):
""" Returns a new Region that includes the nearby neighbourhood of the the current region.
The new region is defined by extending the current region's dimensions
all directions by range number of pixels. The center of the new region remains the
same.
... | python | def nearby(self, expand=50):
""" Returns a new Region that includes the nearby neighbourhood of the the current region.
The new region is defined by extending the current region's dimensions
all directions by range number of pixels. The center of the new region remains the
same.
... | [
"def",
"nearby",
"(",
"self",
",",
"expand",
"=",
"50",
")",
":",
"return",
"Region",
"(",
"self",
".",
"x",
"-",
"expand",
",",
"self",
".",
"y",
"-",
"expand",
",",
"self",
".",
"w",
"+",
"(",
"2",
"*",
"expand",
")",
",",
"self",
".",
"h",... | Returns a new Region that includes the nearby neighbourhood of the the current region.
The new region is defined by extending the current region's dimensions
all directions by range number of pixels. The center of the new region remains the
same. | [
"Returns",
"a",
"new",
"Region",
"that",
"includes",
"the",
"nearby",
"neighbourhood",
"of",
"the",
"the",
"current",
"region",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L361-L372 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.left | def left(self, expand=None):
""" Returns a new Region left of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the left border
of the screen. The new region has the same height and y-position as the current region.
... | python | def left(self, expand=None):
""" Returns a new Region left of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the left border
of the screen. The new region has the same height and y-position as the current region.
... | [
"def",
"left",
"(",
"self",
",",
"expand",
"=",
"None",
")",
":",
"if",
"expand",
"==",
"None",
":",
"x",
"=",
"0",
"y",
"=",
"self",
".",
"y",
"w",
"=",
"self",
".",
"x",
"h",
"=",
"self",
".",
"h",
"else",
":",
"x",
"=",
"self",
".",
"x... | Returns a new Region left of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the left border
of the screen. The new region has the same height and y-position as the current region. | [
"Returns",
"a",
"new",
"Region",
"left",
"of",
"the",
"current",
"region",
"with",
"a",
"width",
"of",
"expand",
"pixels",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L407-L423 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.right | def right(self, expand=None):
""" Returns a new Region right of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the right border
of the screen. The new region has the same height and y-position as the current region.
... | python | def right(self, expand=None):
""" Returns a new Region right of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the right border
of the screen. The new region has the same height and y-position as the current region.
... | [
"def",
"right",
"(",
"self",
",",
"expand",
"=",
"None",
")",
":",
"if",
"expand",
"==",
"None",
":",
"x",
"=",
"self",
".",
"x",
"+",
"self",
".",
"w",
"y",
"=",
"self",
".",
"y",
"w",
"=",
"self",
".",
"getScreen",
"(",
")",
".",
"getBounds... | Returns a new Region right of the current region with a width of ``expand`` pixels.
Does not include the current region. If range is omitted, it reaches to the right border
of the screen. The new region has the same height and y-position as the current region. | [
"Returns",
"a",
"new",
"Region",
"right",
"of",
"the",
"current",
"region",
"with",
"a",
"width",
"of",
"expand",
"pixels",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L424-L440 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.getBitmap | def getBitmap(self):
""" Captures screen area of this region, at least the part that is on the screen
Returns image as numpy array
"""
return PlatformManager.getBitmapFromRect(self.x, self.y, self.w, self.h) | python | def getBitmap(self):
""" Captures screen area of this region, at least the part that is on the screen
Returns image as numpy array
"""
return PlatformManager.getBitmapFromRect(self.x, self.y, self.w, self.h) | [
"def",
"getBitmap",
"(",
"self",
")",
":",
"return",
"PlatformManager",
".",
"getBitmapFromRect",
"(",
"self",
".",
"x",
",",
"self",
".",
"y",
",",
"self",
".",
"w",
",",
"self",
".",
"h",
")"
] | Captures screen area of this region, at least the part that is on the screen
Returns image as numpy array | [
"Captures",
"screen",
"area",
"of",
"this",
"region",
"at",
"least",
"the",
"part",
"that",
"is",
"on",
"the",
"screen"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L449-L454 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.debugPreview | def debugPreview(self, title="Debug"):
""" Displays the region in a preview window.
If the region is a Match, circles the target area. If the region is larger than half the
primary screen in either dimension, scales it down to half size.
"""
region = self
haystack = self... | python | def debugPreview(self, title="Debug"):
""" Displays the region in a preview window.
If the region is a Match, circles the target area. If the region is larger than half the
primary screen in either dimension, scales it down to half size.
"""
region = self
haystack = self... | [
"def",
"debugPreview",
"(",
"self",
",",
"title",
"=",
"\"Debug\"",
")",
":",
"region",
"=",
"self",
"haystack",
"=",
"self",
".",
"getBitmap",
"(",
")",
"if",
"isinstance",
"(",
"region",
",",
"Match",
")",
":",
"cv2",
".",
"circle",
"(",
"haystack",
... | Displays the region in a preview window.
If the region is a Match, circles the target area. If the region is larger than half the
primary screen in either dimension, scales it down to half size. | [
"Displays",
"the",
"region",
"in",
"a",
"preview",
"window",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L455-L472 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.wait | def wait(self, pattern, seconds=None):
""" Searches for an image pattern in the given region, given a specified timeout period
Functionally identical to find(). If a number is passed instead of a pattern,
just waits the specified number of seconds.
Sikuli supports OCR search with a text... | python | def wait(self, pattern, seconds=None):
""" Searches for an image pattern in the given region, given a specified timeout period
Functionally identical to find(). If a number is passed instead of a pattern,
just waits the specified number of seconds.
Sikuli supports OCR search with a text... | [
"def",
"wait",
"(",
"self",
",",
"pattern",
",",
"seconds",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"pattern",
",",
"(",
"int",
",",
"float",
")",
")",
":",
"if",
"pattern",
"==",
"FOREVER",
":",
"while",
"True",
":",
"time",
".",
"sleep",
... | Searches for an image pattern in the given region, given a specified timeout period
Functionally identical to find(). If a number is passed instead of a pattern,
just waits the specified number of seconds.
Sikuli supports OCR search with a text parameter. This does not (yet). | [
"Searches",
"for",
"an",
"image",
"pattern",
"in",
"the",
"given",
"region",
"given",
"a",
"specified",
"timeout",
"period"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L566-L596 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.waitVanish | def waitVanish(self, pattern, seconds=None):
""" Waits until the specified pattern is not visible on screen.
If ``seconds`` pass and the pattern is still visible, raises FindFailed exception.
Sikuli supports OCR search with a text parameter. This does not (yet).
"""
r = self.cli... | python | def waitVanish(self, pattern, seconds=None):
""" Waits until the specified pattern is not visible on screen.
If ``seconds`` pass and the pattern is still visible, raises FindFailed exception.
Sikuli supports OCR search with a text parameter. This does not (yet).
"""
r = self.cli... | [
"def",
"waitVanish",
"(",
"self",
",",
"pattern",
",",
"seconds",
"=",
"None",
")",
":",
"r",
"=",
"self",
".",
"clipRegionToScreen",
"(",
")",
"if",
"r",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Region outside all visible screens\"",
")",
"return",... | Waits until the specified pattern is not visible on screen.
If ``seconds`` pass and the pattern is still visible, raises FindFailed exception.
Sikuli supports OCR search with a text parameter. This does not (yet). | [
"Waits",
"until",
"the",
"specified",
"pattern",
"is",
"not",
"visible",
"on",
"screen",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L597-L624 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.click | def click(self, target=None, modifiers=""):
""" Moves the cursor to the target location and clicks the default mouse button. """
if target is None:
target = self._lastMatch or self # Whichever one is not None
target_location = None
if isinstance(target, Pattern):
... | python | def click(self, target=None, modifiers=""):
""" Moves the cursor to the target location and clicks the default mouse button. """
if target is None:
target = self._lastMatch or self # Whichever one is not None
target_location = None
if isinstance(target, Pattern):
... | [
"def",
"click",
"(",
"self",
",",
"target",
"=",
"None",
",",
"modifiers",
"=",
"\"\"",
")",
":",
"if",
"target",
"is",
"None",
":",
"target",
"=",
"self",
".",
"_lastMatch",
"or",
"self",
"target_location",
"=",
"None",
"if",
"isinstance",
"(",
"targe... | Moves the cursor to the target location and clicks the default mouse button. | [
"Moves",
"the",
"cursor",
"to",
"the",
"target",
"location",
"and",
"clicks",
"the",
"default",
"mouse",
"button",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L686-L717 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.hover | def hover(self, target=None):
""" Moves the cursor to the target location """
if target is None:
target = self._lastMatch or self # Whichever one is not None
target_location = None
if isinstance(target, Pattern):
target_location = self.find(target).getTarget()
... | python | def hover(self, target=None):
""" Moves the cursor to the target location """
if target is None:
target = self._lastMatch or self # Whichever one is not None
target_location = None
if isinstance(target, Pattern):
target_location = self.find(target).getTarget()
... | [
"def",
"hover",
"(",
"self",
",",
"target",
"=",
"None",
")",
":",
"if",
"target",
"is",
"None",
":",
"target",
"=",
"self",
".",
"_lastMatch",
"or",
"self",
"target_location",
"=",
"None",
"if",
"isinstance",
"(",
"target",
",",
"Pattern",
")",
":",
... | Moves the cursor to the target location | [
"Moves",
"the",
"cursor",
"to",
"the",
"target",
"location"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L785-L803 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.drag | def drag(self, dragFrom=None):
""" Starts a dragDrop operation.
Moves the cursor to the target location and clicks the mouse in preparation to drag
a screen element """
if dragFrom is None:
dragFrom = self._lastMatch or self # Whichever one is not None
dragFromLocati... | python | def drag(self, dragFrom=None):
""" Starts a dragDrop operation.
Moves the cursor to the target location and clicks the mouse in preparation to drag
a screen element """
if dragFrom is None:
dragFrom = self._lastMatch or self # Whichever one is not None
dragFromLocati... | [
"def",
"drag",
"(",
"self",
",",
"dragFrom",
"=",
"None",
")",
":",
"if",
"dragFrom",
"is",
"None",
":",
"dragFrom",
"=",
"self",
".",
"_lastMatch",
"or",
"self",
"dragFromLocation",
"=",
"None",
"if",
"isinstance",
"(",
"dragFrom",
",",
"Pattern",
")",
... | Starts a dragDrop operation.
Moves the cursor to the target location and clicks the mouse in preparation to drag
a screen element | [
"Starts",
"a",
"dragDrop",
"operation",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L804-L827 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.dropAt | def dropAt(self, dragTo=None, delay=None):
""" Completes a dragDrop operation
Moves the cursor to the target location, waits ``delay`` seconds, and releases the mouse
button """
if dragTo is None:
dragTo = self._lastMatch or self # Whichever one is not None
if isinst... | python | def dropAt(self, dragTo=None, delay=None):
""" Completes a dragDrop operation
Moves the cursor to the target location, waits ``delay`` seconds, and releases the mouse
button """
if dragTo is None:
dragTo = self._lastMatch or self # Whichever one is not None
if isinst... | [
"def",
"dropAt",
"(",
"self",
",",
"dragTo",
"=",
"None",
",",
"delay",
"=",
"None",
")",
":",
"if",
"dragTo",
"is",
"None",
":",
"dragTo",
"=",
"self",
".",
"_lastMatch",
"or",
"self",
"if",
"isinstance",
"(",
"dragTo",
",",
"Pattern",
")",
":",
"... | Completes a dragDrop operation
Moves the cursor to the target location, waits ``delay`` seconds, and releases the mouse
button | [
"Completes",
"a",
"dragDrop",
"operation"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L828-L851 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.dragDrop | def dragDrop(self, target, target2=None, modifiers=""):
""" Performs a dragDrop operation.
Holds down the mouse button on ``dragFrom``, moves the mouse to ``dragTo``, and releases
the mouse button.
``modifiers`` may be a typeKeys() compatible string. The specified keys will be held
... | python | def dragDrop(self, target, target2=None, modifiers=""):
""" Performs a dragDrop operation.
Holds down the mouse button on ``dragFrom``, moves the mouse to ``dragTo``, and releases
the mouse button.
``modifiers`` may be a typeKeys() compatible string. The specified keys will be held
... | [
"def",
"dragDrop",
"(",
"self",
",",
"target",
",",
"target2",
"=",
"None",
",",
"modifiers",
"=",
"\"\"",
")",
":",
"if",
"modifiers",
"!=",
"\"\"",
":",
"keyboard",
".",
"keyDown",
"(",
"modifiers",
")",
"if",
"target2",
"is",
"None",
":",
"dragFrom"... | Performs a dragDrop operation.
Holds down the mouse button on ``dragFrom``, moves the mouse to ``dragTo``, and releases
the mouse button.
``modifiers`` may be a typeKeys() compatible string. The specified keys will be held
during the drag-drop operation. | [
"Performs",
"a",
"dragDrop",
"operation",
"."
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L852-L876 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.mouseMove | def mouseMove(self, PSRML=None, dy=0):
""" Low-level mouse actions """
if PSRML is None:
PSRML = self._lastMatch or self # Whichever one is not None
if isinstance(PSRML, Pattern):
move_location = self.find(PSRML).getTarget()
elif isinstance(PSRML, basestring):
... | python | def mouseMove(self, PSRML=None, dy=0):
""" Low-level mouse actions """
if PSRML is None:
PSRML = self._lastMatch or self # Whichever one is not None
if isinstance(PSRML, Pattern):
move_location = self.find(PSRML).getTarget()
elif isinstance(PSRML, basestring):
... | [
"def",
"mouseMove",
"(",
"self",
",",
"PSRML",
"=",
"None",
",",
"dy",
"=",
"0",
")",
":",
"if",
"PSRML",
"is",
"None",
":",
"PSRML",
"=",
"self",
".",
"_lastMatch",
"or",
"self",
"if",
"isinstance",
"(",
"PSRML",
",",
"Pattern",
")",
":",
"move_lo... | Low-level mouse actions | [
"Low",
"-",
"level",
"mouse",
"actions"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L959-L979 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.isRegionValid | def isRegionValid(self):
""" Returns false if the whole region is not even partially inside any screen, otherwise true """
screens = PlatformManager.getScreenDetails()
for screen in screens:
s_x, s_y, s_w, s_h = screen["rect"]
if self.x+self.w >= s_x and s_x+s_w >= self.x... | python | def isRegionValid(self):
""" Returns false if the whole region is not even partially inside any screen, otherwise true """
screens = PlatformManager.getScreenDetails()
for screen in screens:
s_x, s_y, s_w, s_h = screen["rect"]
if self.x+self.w >= s_x and s_x+s_w >= self.x... | [
"def",
"isRegionValid",
"(",
"self",
")",
":",
"screens",
"=",
"PlatformManager",
".",
"getScreenDetails",
"(",
")",
"for",
"screen",
"in",
"screens",
":",
"s_x",
",",
"s_y",
",",
"s_w",
",",
"s_h",
"=",
"screen",
"[",
"\"rect\"",
"]",
"if",
"self",
".... | Returns false if the whole region is not even partially inside any screen, otherwise true | [
"Returns",
"false",
"if",
"the",
"whole",
"region",
"is",
"not",
"even",
"partially",
"inside",
"any",
"screen",
"otherwise",
"true"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1017-L1025 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.clipRegionToScreen | def clipRegionToScreen(self):
""" Returns the part of the region that is visible on a screen
If the region equals to all visible screens, returns Screen(-1).
If the region is visible on multiple screens, returns the screen with the smallest ID.
Returns None if the region is outside the ... | python | def clipRegionToScreen(self):
""" Returns the part of the region that is visible on a screen
If the region equals to all visible screens, returns Screen(-1).
If the region is visible on multiple screens, returns the screen with the smallest ID.
Returns None if the region is outside the ... | [
"def",
"clipRegionToScreen",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"isRegionValid",
"(",
")",
":",
"return",
"None",
"screens",
"=",
"PlatformManager",
".",
"getScreenDetails",
"(",
")",
"total_x",
",",
"total_y",
",",
"total_w",
",",
"total_h",
... | Returns the part of the region that is visible on a screen
If the region equals to all visible screens, returns Screen(-1).
If the region is visible on multiple screens, returns the screen with the smallest ID.
Returns None if the region is outside the screen. | [
"Returns",
"the",
"part",
"of",
"the",
"region",
"that",
"is",
"visible",
"on",
"a",
"screen"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1027-L1057 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.get | def get(self, part):
""" Returns a section of the region as a new region
Accepts partitioning constants, e.g. Region.NORTH, Region.NORTH_WEST, etc.
Also accepts an int 200-999:
* First digit: Raster (*n* rows by *n* columns)
* Second digit: Row index (if equal to raster, gets t... | python | def get(self, part):
""" Returns a section of the region as a new region
Accepts partitioning constants, e.g. Region.NORTH, Region.NORTH_WEST, etc.
Also accepts an int 200-999:
* First digit: Raster (*n* rows by *n* columns)
* Second digit: Row index (if equal to raster, gets t... | [
"def",
"get",
"(",
"self",
",",
"part",
")",
":",
"if",
"part",
"==",
"self",
".",
"MID_VERTICAL",
":",
"return",
"Region",
"(",
"self",
".",
"x",
"+",
"(",
"self",
".",
"w",
"/",
"4",
")",
",",
"y",
",",
"self",
".",
"w",
"/",
"2",
",",
"s... | Returns a section of the region as a new region
Accepts partitioning constants, e.g. Region.NORTH, Region.NORTH_WEST, etc.
Also accepts an int 200-999:
* First digit: Raster (*n* rows by *n* columns)
* Second digit: Row index (if equal to raster, gets the whole row)
* Third dig... | [
"Returns",
"a",
"section",
"of",
"the",
"region",
"as",
"a",
"new",
"region"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1160-L1192 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.setCenter | def setCenter(self, loc):
""" Move this region so it is centered on ``loc`` """
offset = self.getCenter().getOffset(loc) # Calculate offset from current center
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | python | def setCenter(self, loc):
""" Move this region so it is centered on ``loc`` """
offset = self.getCenter().getOffset(loc) # Calculate offset from current center
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | [
"def",
"setCenter",
"(",
"self",
",",
"loc",
")",
":",
"offset",
"=",
"self",
".",
"getCenter",
"(",
")",
".",
"getOffset",
"(",
"loc",
")",
"return",
"self",
".",
"setLocation",
"(",
"self",
".",
"getTopLeft",
"(",
")",
".",
"offset",
"(",
"offset",... | Move this region so it is centered on ``loc`` | [
"Move",
"this",
"region",
"so",
"it",
"is",
"centered",
"on",
"loc"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1226-L1229 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.setTopRight | def setTopRight(self, loc):
""" Move this region so its top right corner is on ``loc`` """
offset = self.getTopRight().getOffset(loc) # Calculate offset from current top right
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | python | def setTopRight(self, loc):
""" Move this region so its top right corner is on ``loc`` """
offset = self.getTopRight().getOffset(loc) # Calculate offset from current top right
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | [
"def",
"setTopRight",
"(",
"self",
",",
"loc",
")",
":",
"offset",
"=",
"self",
".",
"getTopRight",
"(",
")",
".",
"getOffset",
"(",
"loc",
")",
"return",
"self",
".",
"setLocation",
"(",
"self",
".",
"getTopLeft",
"(",
")",
".",
"offset",
"(",
"offs... | Move this region so its top right corner is on ``loc`` | [
"Move",
"this",
"region",
"so",
"its",
"top",
"right",
"corner",
"is",
"on",
"loc"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1233-L1236 | train |
glitchassassin/lackey | lackey/RegionMatching.py | Region.setBottomLeft | def setBottomLeft(self, loc):
""" Move this region so its bottom left corner is on ``loc`` """
offset = self.getBottomLeft().getOffset(loc) # Calculate offset from current bottom left
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | python | def setBottomLeft(self, loc):
""" Move this region so its bottom left corner is on ``loc`` """
offset = self.getBottomLeft().getOffset(loc) # Calculate offset from current bottom left
return self.setLocation(self.getTopLeft().offset(offset)) # Move top left corner by the same offset | [
"def",
"setBottomLeft",
"(",
"self",
",",
"loc",
")",
":",
"offset",
"=",
"self",
".",
"getBottomLeft",
"(",
")",
".",
"getOffset",
"(",
"loc",
")",
"return",
"self",
".",
"setLocation",
"(",
"self",
".",
"getTopLeft",
"(",
")",
".",
"offset",
"(",
"... | Move this region so its bottom left corner is on ``loc`` | [
"Move",
"this",
"region",
"so",
"its",
"bottom",
"left",
"corner",
"is",
"on",
"loc"
] | 7adadfacd7f45d81186710be992f5668b15399fe | https://github.com/glitchassassin/lackey/blob/7adadfacd7f45d81186710be992f5668b15399fe/lackey/RegionMatching.py#L1237-L1240 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.