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
floydhub/floyd-cli
floyd/cli/auth.py
login
def login(token, apikey, username, password): """ Login to FloydHub. """ if manual_login_success(token, username, password): return if not apikey: if has_browser(): apikey = wait_for_apikey() else: floyd_logger.error( "No browser found...
python
def login(token, apikey, username, password): """ Login to FloydHub. """ if manual_login_success(token, username, password): return if not apikey: if has_browser(): apikey = wait_for_apikey() else: floyd_logger.error( "No browser found...
[ "def", "login", "(", "token", ",", "apikey", ",", "username", ",", "password", ")", ":", "if", "manual_login_success", "(", "token", ",", "username", ",", "password", ")", ":", "return", "if", "not", "apikey", ":", "if", "has_browser", "(", ")", ":", "...
Login to FloydHub.
[ "Login", "to", "FloydHub", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/cli/auth.py#L77-L98
train
floydhub/floyd-cli
floyd/main.py
check_cli_version
def check_cli_version(): """ Check if the current cli version satisfies the server requirements """ should_exit = False server_version = VersionClient().get_cli_version() current_version = get_cli_version() if LooseVersion(current_version) < LooseVersion(server_version.min_version): ...
python
def check_cli_version(): """ Check if the current cli version satisfies the server requirements """ should_exit = False server_version = VersionClient().get_cli_version() current_version = get_cli_version() if LooseVersion(current_version) < LooseVersion(server_version.min_version): ...
[ "def", "check_cli_version", "(", ")", ":", "should_exit", "=", "False", "server_version", "=", "VersionClient", "(", ")", ".", "get_cli_version", "(", ")", "current_version", "=", "get_cli_version", "(", ")", "if", "LooseVersion", "(", "current_version", ")", "<...
Check if the current cli version satisfies the server requirements
[ "Check", "if", "the", "current", "cli", "version", "satisfies", "the", "server", "requirements" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/main.py#L36-L67
train
floydhub/floyd-cli
floyd/client/base.py
FloydHttpClient.request
def request(self, method, url, params=None, data=None, files=None, json=None, timeout=5, headers=None, skip_auth=False): """ Execute the request using requests ...
python
def request(self, method, url, params=None, data=None, files=None, json=None, timeout=5, headers=None, skip_auth=False): """ Execute the request using requests ...
[ "def", "request", "(", "self", ",", "method", ",", "url", ",", "params", "=", "None", ",", "data", "=", "None", ",", "files", "=", "None", ",", "json", "=", "None", ",", "timeout", "=", "5", ",", "headers", "=", "None", ",", "skip_auth", "=", "Fa...
Execute the request using requests library
[ "Execute", "the", "request", "using", "requests", "library" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/base.py#L30-L72
train
floydhub/floyd-cli
floyd/client/base.py
FloydHttpClient.download
def download(self, url, filename, relative=False, headers=None, timeout=5): """ Download the file from the given url at the current path """ request_url = self.base_url + url if relative else url floyd_logger.debug("Downloading file from url: {}".format(request_url)) # A...
python
def download(self, url, filename, relative=False, headers=None, timeout=5): """ Download the file from the given url at the current path """ request_url = self.base_url + url if relative else url floyd_logger.debug("Downloading file from url: {}".format(request_url)) # A...
[ "def", "download", "(", "self", ",", "url", ",", "filename", ",", "relative", "=", "False", ",", "headers", "=", "None", ",", "timeout", "=", "5", ")", ":", "request_url", "=", "self", ".", "base_url", "+", "url", "if", "relative", "else", "url", "fl...
Download the file from the given url at the current path
[ "Download", "the", "file", "from", "the", "given", "url", "at", "the", "current", "path" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/base.py#L74-L113
train
floydhub/floyd-cli
floyd/client/base.py
FloydHttpClient.download_tar
def download_tar(self, url, untar=True, delete_after_untar=False, destination_dir='.'): """ Download and optionally untar the tar file from the given url """ try: floyd_logger.info("Downloading the tar file to the current directory ...") filename = self.download(u...
python
def download_tar(self, url, untar=True, delete_after_untar=False, destination_dir='.'): """ Download and optionally untar the tar file from the given url """ try: floyd_logger.info("Downloading the tar file to the current directory ...") filename = self.download(u...
[ "def", "download_tar", "(", "self", ",", "url", ",", "untar", "=", "True", ",", "delete_after_untar", "=", "False", ",", "destination_dir", "=", "'.'", ")", ":", "try", ":", "floyd_logger", ".", "info", "(", "\"Downloading the tar file to the current directory ......
Download and optionally untar the tar file from the given url
[ "Download", "and", "optionally", "untar", "the", "tar", "file", "from", "the", "given", "url" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/base.py#L115-L133
train
floydhub/floyd-cli
floyd/client/base.py
FloydHttpClient.check_response_status
def check_response_status(self, response): """ Check if response is successful. Else raise Exception. """ if not (200 <= response.status_code < 300): try: message = response.json()["errors"] except Exception: message = None ...
python
def check_response_status(self, response): """ Check if response is successful. Else raise Exception. """ if not (200 <= response.status_code < 300): try: message = response.json()["errors"] except Exception: message = None ...
[ "def", "check_response_status", "(", "self", ",", "response", ")", ":", "if", "not", "(", "200", "<=", "response", ".", "status_code", "<", "300", ")", ":", "try", ":", "message", "=", "response", ".", "json", "(", ")", "[", "\"errors\"", "]", "except"...
Check if response is successful. Else raise Exception.
[ "Check", "if", "response", "is", "successful", ".", "Else", "raise", "Exception", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/base.py#L135-L169
train
floydhub/floyd-cli
floyd/development/dev.py
cli
def cli(verbose): """ Floyd CLI interacts with FloydHub server and executes your commands. More help is available under each command listed below. """ floyd.floyd_host = floyd.floyd_web_host = "https://dev.floydhub.com" floyd.tus_server_endpoint = "https://upload-v2-dev.floydhub.com/api/v1/uploa...
python
def cli(verbose): """ Floyd CLI interacts with FloydHub server and executes your commands. More help is available under each command listed below. """ floyd.floyd_host = floyd.floyd_web_host = "https://dev.floydhub.com" floyd.tus_server_endpoint = "https://upload-v2-dev.floydhub.com/api/v1/uploa...
[ "def", "cli", "(", "verbose", ")", ":", "floyd", ".", "floyd_host", "=", "floyd", ".", "floyd_web_host", "=", "\"https://dev.floydhub.com\"", "floyd", ".", "tus_server_endpoint", "=", "\"https://upload-v2-dev.floydhub.com/api/v1/upload/\"", "configure_logger", "(", "verbo...
Floyd CLI interacts with FloydHub server and executes your commands. More help is available under each command listed below.
[ "Floyd", "CLI", "interacts", "with", "FloydHub", "server", "and", "executes", "your", "commands", ".", "More", "help", "is", "available", "under", "each", "command", "listed", "below", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/development/dev.py#L10-L18
train
floydhub/floyd-cli
floyd/client/files.py
get_unignored_file_paths
def get_unignored_file_paths(ignore_list=None, whitelist=None): """ Given an ignore_list and a whitelist of glob patterns, returns the list of unignored file paths in the current directory and its subdirectories """ unignored_files = [] if ignore_list is None: ignore_list = [] if whi...
python
def get_unignored_file_paths(ignore_list=None, whitelist=None): """ Given an ignore_list and a whitelist of glob patterns, returns the list of unignored file paths in the current directory and its subdirectories """ unignored_files = [] if ignore_list is None: ignore_list = [] if whi...
[ "def", "get_unignored_file_paths", "(", "ignore_list", "=", "None", ",", "whitelist", "=", "None", ")", ":", "unignored_files", "=", "[", "]", "if", "ignore_list", "is", "None", ":", "ignore_list", "=", "[", "]", "if", "whitelist", "is", "None", ":", "whit...
Given an ignore_list and a whitelist of glob patterns, returns the list of unignored file paths in the current directory and its subdirectories
[ "Given", "an", "ignore_list", "and", "a", "whitelist", "of", "glob", "patterns", "returns", "the", "list", "of", "unignored", "file", "paths", "in", "the", "current", "directory", "and", "its", "subdirectories" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L22-L59
train
floydhub/floyd-cli
floyd/client/files.py
ignore_path
def ignore_path(path, ignore_list=None, whitelist=None): """ Returns a boolean indicating if a path should be ignored given an ignore_list and a whitelist of glob patterns. """ if ignore_list is None: return True should_ignore = matches_glob_list(path, ignore_list) if whitelist is N...
python
def ignore_path(path, ignore_list=None, whitelist=None): """ Returns a boolean indicating if a path should be ignored given an ignore_list and a whitelist of glob patterns. """ if ignore_list is None: return True should_ignore = matches_glob_list(path, ignore_list) if whitelist is N...
[ "def", "ignore_path", "(", "path", ",", "ignore_list", "=", "None", ",", "whitelist", "=", "None", ")", ":", "if", "ignore_list", "is", "None", ":", "return", "True", "should_ignore", "=", "matches_glob_list", "(", "path", ",", "ignore_list", ")", "if", "w...
Returns a boolean indicating if a path should be ignored given an ignore_list and a whitelist of glob patterns.
[ "Returns", "a", "boolean", "indicating", "if", "a", "path", "should", "be", "ignored", "given", "an", "ignore_list", "and", "a", "whitelist", "of", "glob", "patterns", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L62-L74
train
floydhub/floyd-cli
floyd/client/files.py
matches_glob_list
def matches_glob_list(path, glob_list): """ Given a list of glob patterns, returns a boolean indicating if a path matches any glob in the list """ for glob in glob_list: try: if PurePath(path).match(glob): return True except TypeError: pass ...
python
def matches_glob_list(path, glob_list): """ Given a list of glob patterns, returns a boolean indicating if a path matches any glob in the list """ for glob in glob_list: try: if PurePath(path).match(glob): return True except TypeError: pass ...
[ "def", "matches_glob_list", "(", "path", ",", "glob_list", ")", ":", "for", "glob", "in", "glob_list", ":", "try", ":", "if", "PurePath", "(", "path", ")", ".", "match", "(", "glob", ")", ":", "return", "True", "except", "TypeError", ":", "pass", "retu...
Given a list of glob patterns, returns a boolean indicating if a path matches any glob in the list
[ "Given", "a", "list", "of", "glob", "patterns", "returns", "a", "boolean", "indicating", "if", "a", "path", "matches", "any", "glob", "in", "the", "list" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L77-L88
train
floydhub/floyd-cli
floyd/client/files.py
get_files_in_current_directory
def get_files_in_current_directory(file_type): """ Gets the list of files in the current directory and subdirectories. Respects .floydignore file if present """ local_files = [] total_file_size = 0 ignore_list, whitelist = FloydIgnoreManager.get_lists() floyd_logger.debug("Ignoring: %s...
python
def get_files_in_current_directory(file_type): """ Gets the list of files in the current directory and subdirectories. Respects .floydignore file if present """ local_files = [] total_file_size = 0 ignore_list, whitelist = FloydIgnoreManager.get_lists() floyd_logger.debug("Ignoring: %s...
[ "def", "get_files_in_current_directory", "(", "file_type", ")", ":", "local_files", "=", "[", "]", "total_file_size", "=", "0", "ignore_list", ",", "whitelist", "=", "FloydIgnoreManager", ".", "get_lists", "(", ")", "floyd_logger", ".", "debug", "(", "\"Ignoring: ...
Gets the list of files in the current directory and subdirectories. Respects .floydignore file if present
[ "Gets", "the", "list", "of", "files", "in", "the", "current", "directory", "and", "subdirectories", ".", "Respects", ".", "floydignore", "file", "if", "present" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L91-L110
train
floydhub/floyd-cli
floyd/client/files.py
DataCompressor.__get_nfiles_to_compress
def __get_nfiles_to_compress(self): """ Return the number of files to compress Note: it should take about 0.1s for counting 100k files on a dual core machine """ floyd_logger.info("Get number of files to compress... (this could take a few seconds)") paths = [self.source_...
python
def __get_nfiles_to_compress(self): """ Return the number of files to compress Note: it should take about 0.1s for counting 100k files on a dual core machine """ floyd_logger.info("Get number of files to compress... (this could take a few seconds)") paths = [self.source_...
[ "def", "__get_nfiles_to_compress", "(", "self", ")", ":", "floyd_logger", ".", "info", "(", "\"Get number of files to compress... (this could take a few seconds)\"", ")", "paths", "=", "[", "self", ".", "source_dir", "]", "try", ":", "while", "paths", ":", "path", "...
Return the number of files to compress Note: it should take about 0.1s for counting 100k files on a dual core machine
[ "Return", "the", "number", "of", "files", "to", "compress" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L153-L178
train
floydhub/floyd-cli
floyd/client/files.py
DataCompressor.create_tarfile
def create_tarfile(self): """ Create a tar file with the contents of the current directory """ floyd_logger.info("Compressing data...") # Show progress bar (file_compressed/file_to_compress) self.__compression_bar = ProgressBar(expected_size=self.__files_to_compress, fill...
python
def create_tarfile(self): """ Create a tar file with the contents of the current directory """ floyd_logger.info("Compressing data...") # Show progress bar (file_compressed/file_to_compress) self.__compression_bar = ProgressBar(expected_size=self.__files_to_compress, fill...
[ "def", "create_tarfile", "(", "self", ")", ":", "floyd_logger", ".", "info", "(", "\"Compressing data...\"", ")", "self", ".", "__compression_bar", "=", "ProgressBar", "(", "expected_size", "=", "self", ".", "__files_to_compress", ",", "filled_char", "=", "'='", ...
Create a tar file with the contents of the current directory
[ "Create", "a", "tar", "file", "with", "the", "contents", "of", "the", "current", "directory" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/files.py#L180-L237
train
floydhub/floyd-cli
floyd/client/data.py
DataClient.create
def create(self, data): """ Create a temporary directory for the tar file that will be removed at the end of the operation. """ try: floyd_logger.info("Making create request to server...") post_body = data.to_dict() post_body["resumable"] = Tru...
python
def create(self, data): """ Create a temporary directory for the tar file that will be removed at the end of the operation. """ try: floyd_logger.info("Making create request to server...") post_body = data.to_dict() post_body["resumable"] = Tru...
[ "def", "create", "(", "self", ",", "data", ")", ":", "try", ":", "floyd_logger", ".", "info", "(", "\"Making create request to server...\"", ")", "post_body", "=", "data", ".", "to_dict", "(", ")", "post_body", "[", "\"resumable\"", "]", "=", "True", "respon...
Create a temporary directory for the tar file that will be removed at the end of the operation.
[ "Create", "a", "temporary", "directory", "for", "the", "tar", "file", "that", "will", "be", "removed", "at", "the", "end", "of", "the", "operation", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/client/data.py#L27-L47
train
floydhub/floyd-cli
floyd/cli/run.py
get_command_line
def get_command_line(instance_type, env, message, data, mode, open_notebook, command_str): """ Return a string representing the full floyd command entered in the command line """ floyd_command = ["floyd", "run"] if instance_type: floyd_command.append('--' + INSTANCE_NAME_MAP[instance_type]) ...
python
def get_command_line(instance_type, env, message, data, mode, open_notebook, command_str): """ Return a string representing the full floyd command entered in the command line """ floyd_command = ["floyd", "run"] if instance_type: floyd_command.append('--' + INSTANCE_NAME_MAP[instance_type]) ...
[ "def", "get_command_line", "(", "instance_type", ",", "env", ",", "message", ",", "data", ",", "mode", ",", "open_notebook", ",", "command_str", ")", ":", "floyd_command", "=", "[", "\"floyd\"", ",", "\"run\"", "]", "if", "instance_type", ":", "floyd_command",...
Return a string representing the full floyd command entered in the command line
[ "Return", "a", "string", "representing", "the", "full", "floyd", "command", "entered", "in", "the", "command", "line" ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/cli/run.py#L353-L380
train
floydhub/floyd-cli
floyd/cli/run.py
restart
def restart(ctx, job_name, data, open_notebook, env, message, gpu, cpu, gpup, cpup, command): """ Restart a finished job as a new job. """ # Error early if more than one --env is passed. Then get the first/only # --env out of the list so all other operations work normally (they don't # expect an...
python
def restart(ctx, job_name, data, open_notebook, env, message, gpu, cpu, gpup, cpup, command): """ Restart a finished job as a new job. """ # Error early if more than one --env is passed. Then get the first/only # --env out of the list so all other operations work normally (they don't # expect an...
[ "def", "restart", "(", "ctx", ",", "job_name", ",", "data", ",", "open_notebook", ",", "env", ",", "message", ",", "gpu", ",", "cpu", ",", "gpup", ",", "cpup", ",", "command", ")", ":", "if", "len", "(", "env", ")", ">", "1", ":", "floyd_logger", ...
Restart a finished job as a new job.
[ "Restart", "a", "finished", "job", "as", "a", "new", "job", "." ]
ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c
https://github.com/floydhub/floyd-cli/blob/ea6b9521119cbde2dfc71ce0cc87c0d9c143fc6c/floyd/cli/run.py#L405-L466
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
filter_user
def filter_user(user, using='records', interaction=None, part_of_week='allweek', part_of_day='allday'): """ Filter records of a User objects by interaction, part of week and day. Parameters ---------- user : User a bandicoot User object type : str, default 'records' ...
python
def filter_user(user, using='records', interaction=None, part_of_week='allweek', part_of_day='allday'): """ Filter records of a User objects by interaction, part of week and day. Parameters ---------- user : User a bandicoot User object type : str, default 'records' ...
[ "def", "filter_user", "(", "user", ",", "using", "=", "'records'", ",", "interaction", "=", "None", ",", "part_of_week", "=", "'allweek'", ",", "part_of_day", "=", "'allday'", ")", ":", "if", "using", "==", "'recharges'", ":", "records", "=", "user", ".", ...
Filter records of a User objects by interaction, part of week and day. Parameters ---------- user : User a bandicoot User object type : str, default 'records' 'records' or 'recharges' part_of_week : {'allweek', 'weekday', 'weekend'}, default 'allweek' * 'weekend': keep only ...
[ "Filter", "records", "of", "a", "User", "objects", "by", "interaction", "part", "of", "week", "and", "day", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L43-L105
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
positions_binning
def positions_binning(records): """ Bin records by chunks of 30 minutes, returning the most prevalent position. If multiple positions have the same number of occurrences (during 30 minutes), we select the last one. """ def get_key(d): return (d.year, d.day, d.hour, d.minute // 30) ...
python
def positions_binning(records): """ Bin records by chunks of 30 minutes, returning the most prevalent position. If multiple positions have the same number of occurrences (during 30 minutes), we select the last one. """ def get_key(d): return (d.year, d.day, d.hour, d.minute // 30) ...
[ "def", "positions_binning", "(", "records", ")", ":", "def", "get_key", "(", "d", ")", ":", "return", "(", "d", ".", "year", ",", "d", ".", "day", ",", "d", ".", "hour", ",", "d", ".", "minute", "//", "30", ")", "chunks", "=", "itertools", ".", ...
Bin records by chunks of 30 minutes, returning the most prevalent position. If multiple positions have the same number of occurrences (during 30 minutes), we select the last one.
[ "Bin", "records", "by", "chunks", "of", "30", "minutes", "returning", "the", "most", "prevalent", "position", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L108-L124
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
_group_range
def _group_range(records, method): """ Yield the range of all dates between the extrema of a list of records, separated by a given time delta. """ start_date = records[0].datetime end_date = records[-1].datetime _fun = DATE_GROUPERS[method] d = start_date # Day and week use timede...
python
def _group_range(records, method): """ Yield the range of all dates between the extrema of a list of records, separated by a given time delta. """ start_date = records[0].datetime end_date = records[-1].datetime _fun = DATE_GROUPERS[method] d = start_date # Day and week use timede...
[ "def", "_group_range", "(", "records", ",", "method", ")", ":", "start_date", "=", "records", "[", "0", "]", ".", "datetime", "end_date", "=", "records", "[", "-", "1", "]", ".", "datetime", "_fun", "=", "DATE_GROUPERS", "[", "method", "]", "d", "=", ...
Yield the range of all dates between the extrema of a list of records, separated by a given time delta.
[ "Yield", "the", "range", "of", "all", "dates", "between", "the", "extrema", "of", "a", "list", "of", "records", "separated", "by", "a", "given", "time", "delta", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L127-L158
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
group_records
def group_records(records, groupby='week'): """ Group records by year, month, week, or day. Parameters ---------- records : iterator An iterator over records groupby : Default is 'week': * 'week': group all records by year and week * None: records are not grouped. This ...
python
def group_records(records, groupby='week'): """ Group records by year, month, week, or day. Parameters ---------- records : iterator An iterator over records groupby : Default is 'week': * 'week': group all records by year and week * None: records are not grouped. This ...
[ "def", "group_records", "(", "records", ",", "groupby", "=", "'week'", ")", ":", "def", "_group_date", "(", "records", ",", "_fun", ")", ":", "for", "_", ",", "chunk", "in", "itertools", ".", "groupby", "(", "records", ",", "key", "=", "lambda", "r", ...
Group records by year, month, week, or day. Parameters ---------- records : iterator An iterator over records groupby : Default is 'week': * 'week': group all records by year and week * None: records are not grouped. This is useful if you don't want to divide records ...
[ "Group", "records", "by", "year", "month", "week", "or", "day", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L186-L206
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
infer_type
def infer_type(data): """ Infer the type of objects returned by indicators. infer_type returns: - 'scalar' for a number or None, - 'summarystats' for a SummaryStats object, - 'distribution_scalar' for a list of scalars, - 'distribution_summarystats' for a list of SummaryStats objects ...
python
def infer_type(data): """ Infer the type of objects returned by indicators. infer_type returns: - 'scalar' for a number or None, - 'summarystats' for a SummaryStats object, - 'distribution_scalar' for a list of scalars, - 'distribution_summarystats' for a list of SummaryStats objects ...
[ "def", "infer_type", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "(", "type", "(", "None", ")", ",", "numbers", ".", "Number", ")", ")", ":", "return", "'scalar'", "if", "isinstance", "(", "data", ",", "SummaryStats", ")", ":", "retu...
Infer the type of objects returned by indicators. infer_type returns: - 'scalar' for a number or None, - 'summarystats' for a SummaryStats object, - 'distribution_scalar' for a list of scalars, - 'distribution_summarystats' for a list of SummaryStats objects
[ "Infer", "the", "type", "of", "objects", "returned", "by", "indicators", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L209-L239
train
yvesalexandre/bandicoot
bandicoot/helper/group.py
grouping
def grouping(f=None, interaction=['call', 'text'], summary='default', user_kwd=False): """ ``grouping`` is a decorator for indicator functions, used to simplify the source code. Parameters ---------- f : function The function to decorate user_kwd : boolean If us...
python
def grouping(f=None, interaction=['call', 'text'], summary='default', user_kwd=False): """ ``grouping`` is a decorator for indicator functions, used to simplify the source code. Parameters ---------- f : function The function to decorate user_kwd : boolean If us...
[ "def", "grouping", "(", "f", "=", "None", ",", "interaction", "=", "[", "'call'", ",", "'text'", "]", ",", "summary", "=", "'default'", ",", "user_kwd", "=", "False", ")", ":", "if", "f", "is", "None", ":", "return", "partial", "(", "grouping", ",", ...
``grouping`` is a decorator for indicator functions, used to simplify the source code. Parameters ---------- f : function The function to decorate user_kwd : boolean If user_kwd is True, the user object will be passed to the decorated function interaction : 'call', 'text...
[ "grouping", "is", "a", "decorator", "for", "indicator", "functions", "used", "to", "simplify", "the", "source", "code", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/group.py#L396-L456
train
yvesalexandre/bandicoot
bandicoot/helper/maths.py
kurtosis
def kurtosis(data): """ Return the kurtosis for ``data``. """ if len(data) == 0: return None num = moment(data, 4) denom = moment(data, 2) ** 2. return num / denom if denom != 0 else 0
python
def kurtosis(data): """ Return the kurtosis for ``data``. """ if len(data) == 0: return None num = moment(data, 4) denom = moment(data, 2) ** 2. return num / denom if denom != 0 else 0
[ "def", "kurtosis", "(", "data", ")", ":", "if", "len", "(", "data", ")", "==", "0", ":", "return", "None", "num", "=", "moment", "(", "data", ",", "4", ")", "denom", "=", "moment", "(", "data", ",", "2", ")", "**", "2.", "return", "num", "/", ...
Return the kurtosis for ``data``.
[ "Return", "the", "kurtosis", "for", "data", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/maths.py#L44-L55
train
yvesalexandre/bandicoot
bandicoot/helper/maths.py
skewness
def skewness(data): """ Returns the skewness of ``data``. """ if len(data) == 0: return None num = moment(data, 3) denom = moment(data, 2) ** 1.5 return num / denom if denom != 0 else 0.
python
def skewness(data): """ Returns the skewness of ``data``. """ if len(data) == 0: return None num = moment(data, 3) denom = moment(data, 2) ** 1.5 return num / denom if denom != 0 else 0.
[ "def", "skewness", "(", "data", ")", ":", "if", "len", "(", "data", ")", "==", "0", ":", "return", "None", "num", "=", "moment", "(", "data", ",", "3", ")", "denom", "=", "moment", "(", "data", ",", "2", ")", "**", "1.5", "return", "num", "/", ...
Returns the skewness of ``data``.
[ "Returns", "the", "skewness", "of", "data", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/maths.py#L58-L69
train
yvesalexandre/bandicoot
bandicoot/helper/maths.py
median
def median(data): """ Return the median of numeric data, unsing the "mean of middle two" method. If ``data`` is empty, ``0`` is returned. Examples -------- >>> median([1, 3, 5]) 3.0 When the number of data points is even, the median is interpolated: >>> median([1, 3, 5, 7]) 4....
python
def median(data): """ Return the median of numeric data, unsing the "mean of middle two" method. If ``data`` is empty, ``0`` is returned. Examples -------- >>> median([1, 3, 5]) 3.0 When the number of data points is even, the median is interpolated: >>> median([1, 3, 5, 7]) 4....
[ "def", "median", "(", "data", ")", ":", "if", "len", "(", "data", ")", "==", "0", ":", "return", "None", "data", "=", "sorted", "(", "data", ")", "return", "float", "(", "(", "data", "[", "len", "(", "data", ")", "//", "2", "]", "+", "data", ...
Return the median of numeric data, unsing the "mean of middle two" method. If ``data`` is empty, ``0`` is returned. Examples -------- >>> median([1, 3, 5]) 3.0 When the number of data points is even, the median is interpolated: >>> median([1, 3, 5, 7]) 4.0
[ "Return", "the", "median", "of", "numeric", "data", "unsing", "the", "mean", "of", "middle", "two", "method", ".", "If", "data", "is", "empty", "0", "is", "returned", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/maths.py#L88-L108
train
yvesalexandre/bandicoot
bandicoot/helper/maths.py
entropy
def entropy(data): """ Compute the Shannon entropy, a measure of uncertainty. """ if len(data) == 0: return None n = sum(data) _op = lambda f: f * math.log(f) return - sum(_op(float(i) / n) for i in data)
python
def entropy(data): """ Compute the Shannon entropy, a measure of uncertainty. """ if len(data) == 0: return None n = sum(data) _op = lambda f: f * math.log(f) return - sum(_op(float(i) / n) for i in data)
[ "def", "entropy", "(", "data", ")", ":", "if", "len", "(", "data", ")", "==", "0", ":", "return", "None", "n", "=", "sum", "(", "data", ")", "_op", "=", "lambda", "f", ":", "f", "*", "math", ".", "log", "(", "f", ")", "return", "-", "sum", ...
Compute the Shannon entropy, a measure of uncertainty.
[ "Compute", "the", "Shannon", "entropy", "a", "measure", "of", "uncertainty", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/maths.py#L206-L217
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
advanced_wrap
def advanced_wrap(f, wrapper): """ Wrap a decorated function while keeping the same keyword arguments """ f_sig = list(inspect.getargspec(f)) wrap_sig = list(inspect.getargspec(wrapper)) # Update the keyword arguments of the wrapper if f_sig[3] is None or f_sig[3] == []: f_sig[3], f...
python
def advanced_wrap(f, wrapper): """ Wrap a decorated function while keeping the same keyword arguments """ f_sig = list(inspect.getargspec(f)) wrap_sig = list(inspect.getargspec(wrapper)) # Update the keyword arguments of the wrapper if f_sig[3] is None or f_sig[3] == []: f_sig[3], f...
[ "def", "advanced_wrap", "(", "f", ",", "wrapper", ")", ":", "f_sig", "=", "list", "(", "inspect", ".", "getargspec", "(", "f", ")", ")", "wrap_sig", "=", "list", "(", "inspect", ".", "getargspec", "(", "wrapper", ")", ")", "if", "f_sig", "[", "3", ...
Wrap a decorated function while keeping the same keyword arguments
[ "Wrap", "a", "decorated", "function", "while", "keeping", "the", "same", "keyword", "arguments" ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L67-L93
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
percent_records_missing_location
def percent_records_missing_location(user, method=None): """ Return the percentage of records missing a location parameter. """ if len(user.records) == 0: return 0. missing_locations = sum([1 for record in user.records if record.position._get_location(user) is None]) return float(missi...
python
def percent_records_missing_location(user, method=None): """ Return the percentage of records missing a location parameter. """ if len(user.records) == 0: return 0. missing_locations = sum([1 for record in user.records if record.position._get_location(user) is None]) return float(missi...
[ "def", "percent_records_missing_location", "(", "user", ",", "method", "=", "None", ")", ":", "if", "len", "(", "user", ".", "records", ")", "==", "0", ":", "return", "0.", "missing_locations", "=", "sum", "(", "[", "1", "for", "record", "in", "user", ...
Return the percentage of records missing a location parameter.
[ "Return", "the", "percentage", "of", "records", "missing", "a", "location", "parameter", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L198-L207
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
percent_overlapping_calls
def percent_overlapping_calls(records, min_gab=300): """ Return the percentage of calls that overlap with the next call. Parameters ---------- records : list The records for a single user. min_gab : int Number of seconds that the calls must overlap to be considered an issue. ...
python
def percent_overlapping_calls(records, min_gab=300): """ Return the percentage of calls that overlap with the next call. Parameters ---------- records : list The records for a single user. min_gab : int Number of seconds that the calls must overlap to be considered an issue. ...
[ "def", "percent_overlapping_calls", "(", "records", ",", "min_gab", "=", "300", ")", ":", "calls", "=", "[", "r", "for", "r", "in", "records", "if", "r", ".", "interaction", "==", "\"call\"", "]", "if", "len", "(", "calls", ")", "==", "0", ":", "retu...
Return the percentage of calls that overlap with the next call. Parameters ---------- records : list The records for a single user. min_gab : int Number of seconds that the calls must overlap to be considered an issue. Defaults to 5 minutes.
[ "Return", "the", "percentage", "of", "calls", "that", "overlap", "with", "the", "next", "call", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L210-L234
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
antennas_missing_locations
def antennas_missing_locations(user, Method=None): """ Return the number of antennas missing locations in the records of a given user. """ unique_antennas = set([record.position.antenna for record in user.records if record.position.antenna is not None]) return sum([1 for a...
python
def antennas_missing_locations(user, Method=None): """ Return the number of antennas missing locations in the records of a given user. """ unique_antennas = set([record.position.antenna for record in user.records if record.position.antenna is not None]) return sum([1 for a...
[ "def", "antennas_missing_locations", "(", "user", ",", "Method", "=", "None", ")", ":", "unique_antennas", "=", "set", "(", "[", "record", ".", "position", ".", "antenna", "for", "record", "in", "user", ".", "records", "if", "record", ".", "position", ".",...
Return the number of antennas missing locations in the records of a given user.
[ "Return", "the", "number", "of", "antennas", "missing", "locations", "in", "the", "records", "of", "a", "given", "user", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L237-L243
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
bandicoot_code_signature
def bandicoot_code_signature(): """ Returns a unique hash of the Python source code in the current bandicoot module, using the cryptographic hash function SHA-1. """ checksum = hashlib.sha1() for root, dirs, files in os.walk(MAIN_DIRECTORY): for filename in sorted(files): if...
python
def bandicoot_code_signature(): """ Returns a unique hash of the Python source code in the current bandicoot module, using the cryptographic hash function SHA-1. """ checksum = hashlib.sha1() for root, dirs, files in os.walk(MAIN_DIRECTORY): for filename in sorted(files): if...
[ "def", "bandicoot_code_signature", "(", ")", ":", "checksum", "=", "hashlib", ".", "sha1", "(", ")", "for", "root", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "MAIN_DIRECTORY", ")", ":", "for", "filename", "in", "sorted", "(", "files", ")...
Returns a unique hash of the Python source code in the current bandicoot module, using the cryptographic hash function SHA-1.
[ "Returns", "a", "unique", "hash", "of", "the", "Python", "source", "code", "in", "the", "current", "bandicoot", "module", "using", "the", "cryptographic", "hash", "function", "SHA", "-", "1", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L280-L298
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
_AnsiColorizer.supported
def supported(cls, stream=sys.stdout): """ A class method that returns True if the current platform supports coloring terminal output using this method. Returns False otherwise. """ if not stream.isatty(): return False # auto color only on TTYs try: ...
python
def supported(cls, stream=sys.stdout): """ A class method that returns True if the current platform supports coloring terminal output using this method. Returns False otherwise. """ if not stream.isatty(): return False # auto color only on TTYs try: ...
[ "def", "supported", "(", "cls", ",", "stream", "=", "sys", ".", "stdout", ")", ":", "if", "not", "stream", ".", "isatty", "(", ")", ":", "return", "False", "try", ":", "import", "curses", "except", "ImportError", ":", "return", "False", "else", ":", ...
A class method that returns True if the current platform supports coloring terminal output using this method. Returns False otherwise.
[ "A", "class", "method", "that", "returns", "True", "if", "the", "current", "platform", "supports", "coloring", "terminal", "output", "using", "this", "method", ".", "Returns", "False", "otherwise", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L147-L168
train
yvesalexandre/bandicoot
bandicoot/helper/tools.py
_AnsiColorizer.write
def write(self, text, color): """ Write the given text to the stream in the given color. """ color = self._colors[color] self.stream.write('\x1b[{}m{}\x1b[0m'.format(color, text))
python
def write(self, text, color): """ Write the given text to the stream in the given color. """ color = self._colors[color] self.stream.write('\x1b[{}m{}\x1b[0m'.format(color, text))
[ "def", "write", "(", "self", ",", "text", ",", "color", ")", ":", "color", "=", "self", ".", "_colors", "[", "color", "]", "self", ".", "stream", ".", "write", "(", "'\\x1b[{}m{}\\x1b[0m'", ".", "format", "(", "color", ",", "text", ")", ")" ]
Write the given text to the stream in the given color.
[ "Write", "the", "given", "text", "to", "the", "stream", "in", "the", "given", "color", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/tools.py#L170-L175
train
yvesalexandre/bandicoot
bandicoot/spatial.py
percent_at_home
def percent_at_home(positions, user): """ The percentage of interactions the user had while he was at home. .. note:: The position of the home is computed using :meth:`User.recompute_home <bandicoot.core.User.recompute_home>`. If no home can be found, the percentage of interactions ...
python
def percent_at_home(positions, user): """ The percentage of interactions the user had while he was at home. .. note:: The position of the home is computed using :meth:`User.recompute_home <bandicoot.core.User.recompute_home>`. If no home can be found, the percentage of interactions ...
[ "def", "percent_at_home", "(", "positions", ",", "user", ")", ":", "if", "not", "user", ".", "has_home", ":", "return", "None", "total_home", "=", "sum", "(", "1", "for", "p", "in", "positions", "if", "p", "==", "user", ".", "home", ")", "return", "f...
The percentage of interactions the user had while he was at home. .. note:: The position of the home is computed using :meth:`User.recompute_home <bandicoot.core.User.recompute_home>`. If no home can be found, the percentage of interactions at home will be ``None``.
[ "The", "percentage", "of", "interactions", "the", "user", "had", "while", "he", "was", "at", "home", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/spatial.py#L34-L49
train
yvesalexandre/bandicoot
bandicoot/spatial.py
entropy_of_antennas
def entropy_of_antennas(positions, normalize=False): """ The entropy of visited antennas. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1. """ counter = Counter(p for p in positions) raw_entropy = entropy(list(counter.value...
python
def entropy_of_antennas(positions, normalize=False): """ The entropy of visited antennas. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1. """ counter = Counter(p for p in positions) raw_entropy = entropy(list(counter.value...
[ "def", "entropy_of_antennas", "(", "positions", ",", "normalize", "=", "False", ")", ":", "counter", "=", "Counter", "(", "p", "for", "p", "in", "positions", ")", "raw_entropy", "=", "entropy", "(", "list", "(", "counter", ".", "values", "(", ")", ")", ...
The entropy of visited antennas. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1.
[ "The", "entropy", "of", "visited", "antennas", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/spatial.py#L88-L103
train
yvesalexandre/bandicoot
bandicoot/spatial.py
churn_rate
def churn_rate(user, summary='default', **kwargs): """ Computes the frequency spent at every towers each week, and returns the distribution of the cosine similarity between two consecutives week. .. note:: The churn rate is always computed between pairs of weeks. """ if len(user.records) == 0: ...
python
def churn_rate(user, summary='default', **kwargs): """ Computes the frequency spent at every towers each week, and returns the distribution of the cosine similarity between two consecutives week. .. note:: The churn rate is always computed between pairs of weeks. """ if len(user.records) == 0: ...
[ "def", "churn_rate", "(", "user", ",", "summary", "=", "'default'", ",", "**", "kwargs", ")", ":", "if", "len", "(", "user", ".", "records", ")", "==", "0", ":", "return", "statistics", "(", "[", "]", ",", "summary", "=", "summary", ")", "query", "...
Computes the frequency spent at every towers each week, and returns the distribution of the cosine similarity between two consecutives week. .. note:: The churn rate is always computed between pairs of weeks.
[ "Computes", "the", "frequency", "spent", "at", "every", "towers", "each", "week", "and", "returns", "the", "distribution", "of", "the", "cosine", "similarity", "between", "two", "consecutives", "week", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/spatial.py#L133-L173
train
yvesalexandre/bandicoot
bandicoot/core.py
User.describe
def describe(self): """ Generates a short description of the object, and writes it to the standard output. Examples -------- >>> import bandicoot as bc >>> user = bc.User() >>> user.records = bc.tests.generate_user.random_burst(5) >>> user.describ...
python
def describe(self): """ Generates a short description of the object, and writes it to the standard output. Examples -------- >>> import bandicoot as bc >>> user = bc.User() >>> user.records = bc.tests.generate_user.random_burst(5) >>> user.describ...
[ "def", "describe", "(", "self", ")", ":", "def", "format_int", "(", "name", ",", "n", ")", ":", "if", "n", "==", "0", "or", "n", "==", "1", ":", "return", "\"%i %s\"", "%", "(", "n", ",", "name", "[", ":", "-", "1", "]", ")", "else", ":", "...
Generates a short description of the object, and writes it to the standard output. Examples -------- >>> import bandicoot as bc >>> user = bc.User() >>> user.records = bc.tests.generate_user.random_burst(5) >>> user.describe() [x] 5 records from 2014-01-0...
[ "Generates", "a", "short", "description", "of", "the", "object", "and", "writes", "it", "to", "the", "standard", "output", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/core.py#L294-L365
train
yvesalexandre/bandicoot
bandicoot/core.py
User.recompute_home
def recompute_home(self): """ Return the antenna where the user spends most of his time at night. None is returned if there are no candidates for a home antenna """ if self.night_start < self.night_end: night_filter = lambda r: self.night_end > r.datetime.time( ...
python
def recompute_home(self): """ Return the antenna where the user spends most of his time at night. None is returned if there are no candidates for a home antenna """ if self.night_start < self.night_end: night_filter = lambda r: self.night_end > r.datetime.time( ...
[ "def", "recompute_home", "(", "self", ")", ":", "if", "self", ".", "night_start", "<", "self", ".", "night_end", ":", "night_filter", "=", "lambda", "r", ":", "self", ".", "night_end", ">", "r", ".", "datetime", ".", "time", "(", ")", ">", "self", "....
Return the antenna where the user spends most of his time at night. None is returned if there are no candidates for a home antenna
[ "Return", "the", "antenna", "where", "the", "user", "spends", "most", "of", "his", "time", "at", "night", ".", "None", "is", "returned", "if", "there", "are", "no", "candidates", "for", "a", "home", "antenna" ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/core.py#L367-L390
train
yvesalexandre/bandicoot
bandicoot/core.py
User.set_home
def set_home(self, new_home): """ Sets the user's home. The argument can be a Position object or a tuple containing location data. """ if type(new_home) is Position: self.home = new_home elif type(new_home) is tuple: self.home = Position(location=...
python
def set_home(self, new_home): """ Sets the user's home. The argument can be a Position object or a tuple containing location data. """ if type(new_home) is Position: self.home = new_home elif type(new_home) is tuple: self.home = Position(location=...
[ "def", "set_home", "(", "self", ",", "new_home", ")", ":", "if", "type", "(", "new_home", ")", "is", "Position", ":", "self", ".", "home", "=", "new_home", "elif", "type", "(", "new_home", ")", "is", "tuple", ":", "self", ".", "home", "=", "Position"...
Sets the user's home. The argument can be a Position object or a tuple containing location data.
[ "Sets", "the", "user", "s", "home", ".", "The", "argument", "can", "be", "a", "Position", "object", "or", "a", "tuple", "containing", "location", "data", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/core.py#L417-L431
train
yvesalexandre/bandicoot
bandicoot/recharge.py
interevent_time_recharges
def interevent_time_recharges(recharges): """ Return the distribution of time between consecutive recharges of the user. """ time_pairs = pairwise(r.datetime for r in recharges) times = [(new - old).total_seconds() for old, new in time_pairs] return summary_stats(times)
python
def interevent_time_recharges(recharges): """ Return the distribution of time between consecutive recharges of the user. """ time_pairs = pairwise(r.datetime for r in recharges) times = [(new - old).total_seconds() for old, new in time_pairs] return summary_stats(times)
[ "def", "interevent_time_recharges", "(", "recharges", ")", ":", "time_pairs", "=", "pairwise", "(", "r", ".", "datetime", "for", "r", "in", "recharges", ")", "times", "=", "[", "(", "new", "-", "old", ")", ".", "total_seconds", "(", ")", "for", "old", ...
Return the distribution of time between consecutive recharges of the user.
[ "Return", "the", "distribution", "of", "time", "between", "consecutive", "recharges", "of", "the", "user", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/recharge.py#L39-L46
train
yvesalexandre/bandicoot
bandicoot/recharge.py
percent_pareto_recharges
def percent_pareto_recharges(recharges, percentage=0.8): """ Percentage of recharges that account for 80% of total recharged amount. """ amounts = sorted([r.amount for r in recharges], reverse=True) total_sum = sum(amounts) partial_sum = 0 for count, a in enumerate(amounts): partial...
python
def percent_pareto_recharges(recharges, percentage=0.8): """ Percentage of recharges that account for 80% of total recharged amount. """ amounts = sorted([r.amount for r in recharges], reverse=True) total_sum = sum(amounts) partial_sum = 0 for count, a in enumerate(amounts): partial...
[ "def", "percent_pareto_recharges", "(", "recharges", ",", "percentage", "=", "0.8", ")", ":", "amounts", "=", "sorted", "(", "[", "r", ".", "amount", "for", "r", "in", "recharges", "]", ",", "reverse", "=", "True", ")", "total_sum", "=", "sum", "(", "a...
Percentage of recharges that account for 80% of total recharged amount.
[ "Percentage", "of", "recharges", "that", "account", "for", "80%", "of", "total", "recharged", "amount", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/recharge.py#L50-L63
train
yvesalexandre/bandicoot
bandicoot/recharge.py
average_balance_recharges
def average_balance_recharges(user, **kwargs): """ Return the average daily balance estimated from all recharges. We assume a linear usage between two recharges, and an empty balance before a recharge. The average balance can be seen as the area under the curve delimited by all recharges. """ ...
python
def average_balance_recharges(user, **kwargs): """ Return the average daily balance estimated from all recharges. We assume a linear usage between two recharges, and an empty balance before a recharge. The average balance can be seen as the area under the curve delimited by all recharges. """ ...
[ "def", "average_balance_recharges", "(", "user", ",", "**", "kwargs", ")", ":", "balance", "=", "0", "for", "r1", ",", "r2", "in", "pairwise", "(", "user", ".", "recharges", ")", ":", "balance", "+=", "r1", ".", "amount", "*", "min", "(", "1", ",", ...
Return the average daily balance estimated from all recharges. We assume a linear usage between two recharges, and an empty balance before a recharge. The average balance can be seen as the area under the curve delimited by all recharges.
[ "Return", "the", "average", "daily", "balance", "estimated", "from", "all", "recharges", ".", "We", "assume", "a", "linear", "usage", "between", "two", "recharges", "and", "an", "empty", "balance", "before", "a", "recharge", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/recharge.py#L74-L91
train
yvesalexandre/bandicoot
bandicoot/network.py
_round_half_hour
def _round_half_hour(record): """ Round a time DOWN to half nearest half-hour. """ k = record.datetime + timedelta(minutes=-(record.datetime.minute % 30)) return datetime(k.year, k.month, k.day, k.hour, k.minute, 0)
python
def _round_half_hour(record): """ Round a time DOWN to half nearest half-hour. """ k = record.datetime + timedelta(minutes=-(record.datetime.minute % 30)) return datetime(k.year, k.month, k.day, k.hour, k.minute, 0)
[ "def", "_round_half_hour", "(", "record", ")", ":", "k", "=", "record", ".", "datetime", "+", "timedelta", "(", "minutes", "=", "-", "(", "record", ".", "datetime", ".", "minute", "%", "30", ")", ")", "return", "datetime", "(", "k", ".", "year", ",",...
Round a time DOWN to half nearest half-hour.
[ "Round", "a", "time", "DOWN", "to", "half", "nearest", "half", "-", "hour", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L36-L41
train
yvesalexandre/bandicoot
bandicoot/network.py
matrix_index
def matrix_index(user): """ Returns the keys associated with each axis of the matrices. The first key is always the name of the current user, followed by the sorted names of all the correspondants. """ other_keys = sorted([k for k in user.network.keys() if k != user.name]) return [user.nam...
python
def matrix_index(user): """ Returns the keys associated with each axis of the matrices. The first key is always the name of the current user, followed by the sorted names of all the correspondants. """ other_keys = sorted([k for k in user.network.keys() if k != user.name]) return [user.nam...
[ "def", "matrix_index", "(", "user", ")", ":", "other_keys", "=", "sorted", "(", "[", "k", "for", "k", "in", "user", ".", "network", ".", "keys", "(", ")", "if", "k", "!=", "user", ".", "name", "]", ")", "return", "[", "user", ".", "name", "]", ...
Returns the keys associated with each axis of the matrices. The first key is always the name of the current user, followed by the sorted names of all the correspondants.
[ "Returns", "the", "keys", "associated", "with", "each", "axis", "of", "the", "matrices", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L94-L103
train
yvesalexandre/bandicoot
bandicoot/network.py
matrix_directed_unweighted
def matrix_directed_unweighted(user): """ Returns a directed, unweighted matrix where an edge exists if there is at least one call or text. """ matrix = _interaction_matrix(user, interaction=None) for a in range(len(matrix)): for b in range(len(matrix)): if matrix[a][b] is no...
python
def matrix_directed_unweighted(user): """ Returns a directed, unweighted matrix where an edge exists if there is at least one call or text. """ matrix = _interaction_matrix(user, interaction=None) for a in range(len(matrix)): for b in range(len(matrix)): if matrix[a][b] is no...
[ "def", "matrix_directed_unweighted", "(", "user", ")", ":", "matrix", "=", "_interaction_matrix", "(", "user", ",", "interaction", "=", "None", ")", "for", "a", "in", "range", "(", "len", "(", "matrix", ")", ")", ":", "for", "b", "in", "range", "(", "l...
Returns a directed, unweighted matrix where an edge exists if there is at least one call or text.
[ "Returns", "a", "directed", "unweighted", "matrix", "where", "an", "edge", "exists", "if", "there", "is", "at", "least", "one", "call", "or", "text", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L124-L135
train
yvesalexandre/bandicoot
bandicoot/network.py
matrix_undirected_weighted
def matrix_undirected_weighted(user, interaction=None): """ Returns an undirected, weighted matrix for call, text and call duration where an edge exists if the relationship is reciprocated. """ matrix = _interaction_matrix(user, interaction=interaction) result = [[0 for _ in range(len(matrix))] ...
python
def matrix_undirected_weighted(user, interaction=None): """ Returns an undirected, weighted matrix for call, text and call duration where an edge exists if the relationship is reciprocated. """ matrix = _interaction_matrix(user, interaction=interaction) result = [[0 for _ in range(len(matrix))] ...
[ "def", "matrix_undirected_weighted", "(", "user", ",", "interaction", "=", "None", ")", ":", "matrix", "=", "_interaction_matrix", "(", "user", ",", "interaction", "=", "interaction", ")", "result", "=", "[", "[", "0", "for", "_", "in", "range", "(", "len"...
Returns an undirected, weighted matrix for call, text and call duration where an edge exists if the relationship is reciprocated.
[ "Returns", "an", "undirected", "weighted", "matrix", "for", "call", "text", "and", "call", "duration", "where", "an", "edge", "exists", "if", "the", "relationship", "is", "reciprocated", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L138-L155
train
yvesalexandre/bandicoot
bandicoot/network.py
matrix_undirected_unweighted
def matrix_undirected_unweighted(user): """ Returns an undirected, unweighted matrix where an edge exists if the relationship is reciprocated. """ matrix = matrix_undirected_weighted(user, interaction=None) for a, b in combinations(range(len(matrix)), 2): if matrix[a][b] is None or matri...
python
def matrix_undirected_unweighted(user): """ Returns an undirected, unweighted matrix where an edge exists if the relationship is reciprocated. """ matrix = matrix_undirected_weighted(user, interaction=None) for a, b in combinations(range(len(matrix)), 2): if matrix[a][b] is None or matri...
[ "def", "matrix_undirected_unweighted", "(", "user", ")", ":", "matrix", "=", "matrix_undirected_weighted", "(", "user", ",", "interaction", "=", "None", ")", "for", "a", ",", "b", "in", "combinations", "(", "range", "(", "len", "(", "matrix", ")", ")", ","...
Returns an undirected, unweighted matrix where an edge exists if the relationship is reciprocated.
[ "Returns", "an", "undirected", "unweighted", "matrix", "where", "an", "edge", "exists", "if", "the", "relationship", "is", "reciprocated", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L158-L171
train
yvesalexandre/bandicoot
bandicoot/network.py
clustering_coefficient_unweighted
def clustering_coefficient_unweighted(user): """ The clustering coefficient of the user in the unweighted, undirected ego network. It is defined by counting the number of closed triplets including the current user: .. math:: C = \\frac{2 * \\text{closed triplets}}{ \\text{degree} \, (\...
python
def clustering_coefficient_unweighted(user): """ The clustering coefficient of the user in the unweighted, undirected ego network. It is defined by counting the number of closed triplets including the current user: .. math:: C = \\frac{2 * \\text{closed triplets}}{ \\text{degree} \, (\...
[ "def", "clustering_coefficient_unweighted", "(", "user", ")", ":", "matrix", "=", "matrix_undirected_unweighted", "(", "user", ")", "closed_triplets", "=", "0", "for", "a", ",", "b", "in", "combinations", "(", "range", "(", "len", "(", "matrix", ")", ")", ",...
The clustering coefficient of the user in the unweighted, undirected ego network. It is defined by counting the number of closed triplets including the current user: .. math:: C = \\frac{2 * \\text{closed triplets}}{ \\text{degree} \, (\\text{degree - 1})} where ``degree`` is the degree o...
[ "The", "clustering", "coefficient", "of", "the", "user", "in", "the", "unweighted", "undirected", "ego", "network", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L174-L200
train
yvesalexandre/bandicoot
bandicoot/network.py
clustering_coefficient_weighted
def clustering_coefficient_weighted(user, interaction=None): """ The clustering coefficient of the user's weighted, undirected network. It is defined the same way as :meth`~bandicoot.network.clustering_coefficient_unweighted`, except that closed triplets are weighted by the number of interactions. For ...
python
def clustering_coefficient_weighted(user, interaction=None): """ The clustering coefficient of the user's weighted, undirected network. It is defined the same way as :meth`~bandicoot.network.clustering_coefficient_unweighted`, except that closed triplets are weighted by the number of interactions. For ...
[ "def", "clustering_coefficient_weighted", "(", "user", ",", "interaction", "=", "None", ")", ":", "matrix", "=", "matrix_undirected_weighted", "(", "user", ",", "interaction", "=", "interaction", ")", "weights", "=", "[", "weight", "for", "g", "in", "matrix", ...
The clustering coefficient of the user's weighted, undirected network. It is defined the same way as :meth`~bandicoot.network.clustering_coefficient_unweighted`, except that closed triplets are weighted by the number of interactions. For each triplet (A, B, C), we compute the geometric mean of the number o...
[ "The", "clustering", "coefficient", "of", "the", "user", "s", "weighted", "undirected", "network", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L203-L236
train
yvesalexandre/bandicoot
bandicoot/network.py
assortativity_indicators
def assortativity_indicators(user): """ Computes the assortativity of indicators. This indicator measures the similarity of the current user with his correspondants, for all bandicoot indicators. For each one, it calculates the variance of the current user's value with the values for all his co...
python
def assortativity_indicators(user): """ Computes the assortativity of indicators. This indicator measures the similarity of the current user with his correspondants, for all bandicoot indicators. For each one, it calculates the variance of the current user's value with the values for all his co...
[ "def", "assortativity_indicators", "(", "user", ")", ":", "matrix", "=", "matrix_undirected_unweighted", "(", "user", ")", "count_indicator", "=", "defaultdict", "(", "int", ")", "total_indicator", "=", "defaultdict", "(", "int", ")", "ego_indics", "=", "all", "...
Computes the assortativity of indicators. This indicator measures the similarity of the current user with his correspondants, for all bandicoot indicators. For each one, it calculates the variance of the current user's value with the values for all his correspondants: .. math:: \\text{ass...
[ "Computes", "the", "assortativity", "of", "indicators", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L239-L283
train
yvesalexandre/bandicoot
bandicoot/network.py
assortativity_attributes
def assortativity_attributes(user): """ Computes the assortativity of the nominal attributes. This indicator measures the homophily of the current user with his correspondants, for each attributes. It returns a value between 0 (no assortativity) and 1 (all the contacts share the same value): th...
python
def assortativity_attributes(user): """ Computes the assortativity of the nominal attributes. This indicator measures the homophily of the current user with his correspondants, for each attributes. It returns a value between 0 (no assortativity) and 1 (all the contacts share the same value): th...
[ "def", "assortativity_attributes", "(", "user", ")", ":", "matrix", "=", "matrix_undirected_unweighted", "(", "user", ")", "neighbors", "=", "[", "k", "for", "k", "in", "user", ".", "network", ".", "keys", "(", ")", "if", "k", "!=", "user", ".", "name", ...
Computes the assortativity of the nominal attributes. This indicator measures the homophily of the current user with his correspondants, for each attributes. It returns a value between 0 (no assortativity) and 1 (all the contacts share the same value): the percentage of contacts sharing the same value.
[ "Computes", "the", "assortativity", "of", "the", "nominal", "attributes", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L286-L314
train
yvesalexandre/bandicoot
bandicoot/network.py
network_sampling
def network_sampling(n, filename, directory=None, snowball=False, user=None): """ Selects a few users and exports a CSV of indicators for them. TODO: Returns the network/graph between the selected users. Parameters ---------- n : int Number of users to select. filename : string ...
python
def network_sampling(n, filename, directory=None, snowball=False, user=None): """ Selects a few users and exports a CSV of indicators for them. TODO: Returns the network/graph between the selected users. Parameters ---------- n : int Number of users to select. filename : string ...
[ "def", "network_sampling", "(", "n", ",", "filename", ",", "directory", "=", "None", ",", "snowball", "=", "False", ",", "user", "=", "None", ")", ":", "if", "snowball", ":", "if", "user", "is", "None", ":", "raise", "ValueError", "(", "\"Must specify a ...
Selects a few users and exports a CSV of indicators for them. TODO: Returns the network/graph between the selected users. Parameters ---------- n : int Number of users to select. filename : string File to export to. directory: string Directory to select users from if us...
[ "Selects", "a", "few", "users", "and", "exports", "a", "CSV", "of", "indicators", "for", "them", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/network.py#L317-L355
train
yvesalexandre/bandicoot
bandicoot/visualization.py
export
def export(user, directory=None, warnings=True): """ Build a temporary directory with the visualization. Returns the local path where files have been written. Examples -------- >>> bandicoot.visualization.export(U) Successfully exported the visualization to /tmp/tmpsIyncS """ ...
python
def export(user, directory=None, warnings=True): """ Build a temporary directory with the visualization. Returns the local path where files have been written. Examples -------- >>> bandicoot.visualization.export(U) Successfully exported the visualization to /tmp/tmpsIyncS """ ...
[ "def", "export", "(", "user", ",", "directory", "=", "None", ",", "warnings", "=", "True", ")", ":", "current_file", "=", "os", ".", "path", ".", "realpath", "(", "__file__", ")", "current_path", "=", "os", ".", "path", ".", "dirname", "(", "current_fi...
Build a temporary directory with the visualization. Returns the local path where files have been written. Examples -------- >>> bandicoot.visualization.export(U) Successfully exported the visualization to /tmp/tmpsIyncS
[ "Build", "a", "temporary", "directory", "with", "the", "visualization", ".", "Returns", "the", "local", "path", "where", "files", "have", "been", "written", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/visualization.py#L118-L151
train
yvesalexandre/bandicoot
bandicoot/visualization.py
run
def run(user, port=4242): """ Build a temporary directory with a visualization and serve it over HTTP. Examples -------- >>> bandicoot.visualization.run(U) Successfully exported the visualization to /tmp/tmpsIyncS Serving bandicoot visualization at http://0.0.0.0:4242 """ ...
python
def run(user, port=4242): """ Build a temporary directory with a visualization and serve it over HTTP. Examples -------- >>> bandicoot.visualization.run(U) Successfully exported the visualization to /tmp/tmpsIyncS Serving bandicoot visualization at http://0.0.0.0:4242 """ ...
[ "def", "run", "(", "user", ",", "port", "=", "4242", ")", ":", "owd", "=", "os", ".", "getcwd", "(", ")", "dir", "=", "export", "(", "user", ")", "os", ".", "chdir", "(", "dir", ")", "Handler", "=", "SimpleHTTPServer", ".", "SimpleHTTPRequestHandler"...
Build a temporary directory with a visualization and serve it over HTTP. Examples -------- >>> bandicoot.visualization.run(U) Successfully exported the visualization to /tmp/tmpsIyncS Serving bandicoot visualization at http://0.0.0.0:4242
[ "Build", "a", "temporary", "directory", "with", "a", "visualization", "and", "serve", "it", "over", "HTTP", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/visualization.py#L154-L178
train
yvesalexandre/bandicoot
bandicoot/io.py
to_csv
def to_csv(objects, filename, digits=5, warnings=True): """ Export the flatten indicators of one or several users to CSV. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. digits : int Precision of floats. ...
python
def to_csv(objects, filename, digits=5, warnings=True): """ Export the flatten indicators of one or several users to CSV. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. digits : int Precision of floats. ...
[ "def", "to_csv", "(", "objects", ",", "filename", ",", "digits", "=", "5", ",", "warnings", "=", "True", ")", ":", "if", "not", "isinstance", "(", "objects", ",", "list", ")", ":", "objects", "=", "[", "objects", "]", "data", "=", "[", "flatten", "...
Export the flatten indicators of one or several users to CSV. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. digits : int Precision of floats. Examples -------- This function can be used to export the re...
[ "Export", "the", "flatten", "indicators", "of", "one", "or", "several", "users", "to", "CSV", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/io.py#L46-L96
train
yvesalexandre/bandicoot
bandicoot/io.py
to_json
def to_json(objects, filename, warnings=True): """ Export the indicators of one or several users to JSON. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. Examples -------- This function can be use to export t...
python
def to_json(objects, filename, warnings=True): """ Export the indicators of one or several users to JSON. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. Examples -------- This function can be use to export t...
[ "def", "to_json", "(", "objects", ",", "filename", ",", "warnings", "=", "True", ")", ":", "if", "not", "isinstance", "(", "objects", ",", "list", ")", ":", "objects", "=", "[", "objects", "]", "obj_dict", "=", "OrderedDict", "(", "[", "(", "obj", "[...
Export the indicators of one or several users to JSON. Parameters ---------- objects : list List of objects to be exported. filename : string File to export to. Examples -------- This function can be use to export the results of :meth`bandicoot.utils.all`. >>> U_1 =...
[ "Export", "the", "indicators", "of", "one", "or", "several", "users", "to", "JSON", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/io.py#L99-L132
train
yvesalexandre/bandicoot
bandicoot/io.py
_parse_record
def _parse_record(data, duration_format='seconds'): """ Parse a raw data dictionary and return a Record object. """ def _map_duration(s): if s == '': return None elif duration_format.lower() == 'seconds': return int(s) else: t = time.strptime(...
python
def _parse_record(data, duration_format='seconds'): """ Parse a raw data dictionary and return a Record object. """ def _map_duration(s): if s == '': return None elif duration_format.lower() == 'seconds': return int(s) else: t = time.strptime(...
[ "def", "_parse_record", "(", "data", ",", "duration_format", "=", "'seconds'", ")", ":", "def", "_map_duration", "(", "s", ")", ":", "if", "s", "==", "''", ":", "return", "None", "elif", "duration_format", ".", "lower", "(", ")", "==", "'seconds'", ":", ...
Parse a raw data dictionary and return a Record object.
[ "Parse", "a", "raw", "data", "dictionary", "and", "return", "a", "Record", "object", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/io.py#L147-L187
train
yvesalexandre/bandicoot
bandicoot/io.py
filter_record
def filter_record(records): """ Filter records and remove items with missing or inconsistent fields Parameters ---------- records : list A list of Record objects Returns ------- records, ignored : (Record list, dict) A tuple of filtered records, and a dictionary counti...
python
def filter_record(records): """ Filter records and remove items with missing or inconsistent fields Parameters ---------- records : list A list of Record objects Returns ------- records, ignored : (Record list, dict) A tuple of filtered records, and a dictionary counti...
[ "def", "filter_record", "(", "records", ")", ":", "def", "scheme", "(", "r", ")", ":", "if", "r", ".", "interaction", "is", "None", ":", "call_duration_ok", "=", "True", "elif", "r", ".", "interaction", "==", "'call'", ":", "call_duration_ok", "=", "isin...
Filter records and remove items with missing or inconsistent fields Parameters ---------- records : list A list of Record objects Returns ------- records, ignored : (Record list, dict) A tuple of filtered records, and a dictionary counting the missings fields
[ "Filter", "records", "and", "remove", "items", "with", "missing", "or", "inconsistent", "fields" ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/io.py#L204-L269
train
yvesalexandre/bandicoot
bandicoot/io.py
read_csv
def read_csv(user_id, records_path, antennas_path=None, attributes_path=None, recharges_path=None, network=False, duration_format='seconds', describe=True, warnings=True, errors=False, drop_duplicates=False): """ Load user records from a CSV file. Parameters ---------- us...
python
def read_csv(user_id, records_path, antennas_path=None, attributes_path=None, recharges_path=None, network=False, duration_format='seconds', describe=True, warnings=True, errors=False, drop_duplicates=False): """ Load user records from a CSV file. Parameters ---------- us...
[ "def", "read_csv", "(", "user_id", ",", "records_path", ",", "antennas_path", "=", "None", ",", "attributes_path", "=", "None", ",", "recharges_path", "=", "None", ",", "network", "=", "False", ",", "duration_format", "=", "'seconds'", ",", "describe", "=", ...
Load user records from a CSV file. Parameters ---------- user_id : str ID of the user (filename) records_path : str Path of the directory all the user files. antennas_path : str, optional Path of the CSV file containing (place_id, latitude, longitude) values. This...
[ "Load", "user", "records", "from", "a", "CSV", "file", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/io.py#L488-L604
train
yvesalexandre/bandicoot
bandicoot/individual.py
interevent_time
def interevent_time(records): """ The interevent time between two records of the user. """ inter_events = pairwise(r.datetime for r in records) inter = [(new - old).total_seconds() for old, new in inter_events] return summary_stats(inter)
python
def interevent_time(records): """ The interevent time between two records of the user. """ inter_events = pairwise(r.datetime for r in records) inter = [(new - old).total_seconds() for old, new in inter_events] return summary_stats(inter)
[ "def", "interevent_time", "(", "records", ")", ":", "inter_events", "=", "pairwise", "(", "r", ".", "datetime", "for", "r", "in", "records", ")", "inter", "=", "[", "(", "new", "-", "old", ")", ".", "total_seconds", "(", ")", "for", "old", ",", "new"...
The interevent time between two records of the user.
[ "The", "interevent", "time", "between", "two", "records", "of", "the", "user", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L36-L43
train
yvesalexandre/bandicoot
bandicoot/individual.py
number_of_contacts
def number_of_contacts(records, direction=None, more=0): """ The number of contacts the user interacted with. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. more...
python
def number_of_contacts(records, direction=None, more=0): """ The number of contacts the user interacted with. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. more...
[ "def", "number_of_contacts", "(", "records", ",", "direction", "=", "None", ",", "more", "=", "0", ")", ":", "if", "direction", "is", "None", ":", "counter", "=", "Counter", "(", "r", ".", "correspondent_id", "for", "r", "in", "records", ")", "else", "...
The number of contacts the user interacted with. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. more : int, default is 0 Counts only contacts with more than this...
[ "The", "number", "of", "contacts", "the", "user", "interacted", "with", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L47-L63
train
yvesalexandre/bandicoot
bandicoot/individual.py
entropy_of_contacts
def entropy_of_contacts(records, normalize=False): """ The entropy of the user's contacts. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1. """ counter = Counter(r.correspondent_id for r in records) raw_entropy = entropy(...
python
def entropy_of_contacts(records, normalize=False): """ The entropy of the user's contacts. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1. """ counter = Counter(r.correspondent_id for r in records) raw_entropy = entropy(...
[ "def", "entropy_of_contacts", "(", "records", ",", "normalize", "=", "False", ")", ":", "counter", "=", "Counter", "(", "r", ".", "correspondent_id", "for", "r", "in", "records", ")", "raw_entropy", "=", "entropy", "(", "counter", ".", "values", "(", ")", ...
The entropy of the user's contacts. Parameters ---------- normalize: boolean, default is False Returns a normalized entropy between 0 and 1.
[ "The", "entropy", "of", "the", "user", "s", "contacts", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L67-L84
train
yvesalexandre/bandicoot
bandicoot/individual.py
interactions_per_contact
def interactions_per_contact(records, direction=None): """ The number of interactions a user had with each of its contacts. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outg...
python
def interactions_per_contact(records, direction=None): """ The number of interactions a user had with each of its contacts. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outg...
[ "def", "interactions_per_contact", "(", "records", ",", "direction", "=", "None", ")", ":", "if", "direction", "is", "None", ":", "counter", "=", "Counter", "(", "r", ".", "correspondent_id", "for", "r", "in", "records", ")", "else", ":", "counter", "=", ...
The number of interactions a user had with each of its contacts. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing.
[ "The", "number", "of", "interactions", "a", "user", "had", "with", "each", "of", "its", "contacts", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L88-L103
train
yvesalexandre/bandicoot
bandicoot/individual.py
percent_initiated_interactions
def percent_initiated_interactions(records, user): """ The percentage of calls initiated by the user. """ if len(records) == 0: return 0 initiated = sum(1 for r in records if r.direction == 'out') return initiated / len(records)
python
def percent_initiated_interactions(records, user): """ The percentage of calls initiated by the user. """ if len(records) == 0: return 0 initiated = sum(1 for r in records if r.direction == 'out') return initiated / len(records)
[ "def", "percent_initiated_interactions", "(", "records", ",", "user", ")", ":", "if", "len", "(", "records", ")", "==", "0", ":", "return", "0", "initiated", "=", "sum", "(", "1", "for", "r", "in", "records", "if", "r", ".", "direction", "==", "'out'",...
The percentage of calls initiated by the user.
[ "The", "percentage", "of", "calls", "initiated", "by", "the", "user", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L107-L115
train
yvesalexandre/bandicoot
bandicoot/individual.py
percent_nocturnal
def percent_nocturnal(records, user): """ The percentage of interactions the user had at night. By default, nights are 7pm-7am. Nightimes can be set in ``User.night_start`` and ``User.night_end``. """ if len(records) == 0: return 0 if user.night_start < user.night_end: nigh...
python
def percent_nocturnal(records, user): """ The percentage of interactions the user had at night. By default, nights are 7pm-7am. Nightimes can be set in ``User.night_start`` and ``User.night_end``. """ if len(records) == 0: return 0 if user.night_start < user.night_end: nigh...
[ "def", "percent_nocturnal", "(", "records", ",", "user", ")", ":", "if", "len", "(", "records", ")", "==", "0", ":", "return", "0", "if", "user", ".", "night_start", "<", "user", ".", "night_end", ":", "night_filter", "=", "lambda", "d", ":", "user", ...
The percentage of interactions the user had at night. By default, nights are 7pm-7am. Nightimes can be set in ``User.night_start`` and ``User.night_end``.
[ "The", "percentage", "of", "interactions", "the", "user", "had", "at", "night", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L119-L134
train
yvesalexandre/bandicoot
bandicoot/individual.py
call_duration
def call_duration(records, direction=None): """ The duration of the user's calls. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. """ if direction is None: ...
python
def call_duration(records, direction=None): """ The duration of the user's calls. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. """ if direction is None: ...
[ "def", "call_duration", "(", "records", ",", "direction", "=", "None", ")", ":", "if", "direction", "is", "None", ":", "call_durations", "=", "[", "r", ".", "call_duration", "for", "r", "in", "records", "]", "else", ":", "call_durations", "=", "[", "r", ...
The duration of the user's calls. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing.
[ "The", "duration", "of", "the", "user", "s", "calls", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L138-L153
train
yvesalexandre/bandicoot
bandicoot/individual.py
_conversations
def _conversations(group, delta=datetime.timedelta(hours=1)): """ Group texts into conversations. The function returns an iterator over records grouped by conversations. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations. A conversation begins when one person se...
python
def _conversations(group, delta=datetime.timedelta(hours=1)): """ Group texts into conversations. The function returns an iterator over records grouped by conversations. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations. A conversation begins when one person se...
[ "def", "_conversations", "(", "group", ",", "delta", "=", "datetime", ".", "timedelta", "(", "hours", "=", "1", ")", ")", ":", "last_time", "=", "None", "results", "=", "[", "]", "for", "g", "in", "group", ":", "if", "last_time", "is", "None", "or", ...
Group texts into conversations. The function returns an iterator over records grouped by conversations. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations. A conversation begins when one person sends a text-message to the other and ends when one of them makes a phon...
[ "Group", "texts", "into", "conversations", ".", "The", "function", "returns", "an", "iterator", "over", "records", "grouped", "by", "conversations", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L156-L194
train
yvesalexandre/bandicoot
bandicoot/individual.py
percent_initiated_conversations
def percent_initiated_conversations(records): """ The percentage of conversations that have been initiated by the user. Each call and each text conversation is weighted as a single interaction. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations. """ interact...
python
def percent_initiated_conversations(records): """ The percentage of conversations that have been initiated by the user. Each call and each text conversation is weighted as a single interaction. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations. """ interact...
[ "def", "percent_initiated_conversations", "(", "records", ")", ":", "interactions", "=", "defaultdict", "(", "list", ")", "for", "r", "in", "records", ":", "interactions", "[", "r", ".", "correspondent_id", "]", ".", "append", "(", "r", ")", "def", "_percent...
The percentage of conversations that have been initiated by the user. Each call and each text conversation is weighted as a single interaction. See :ref:`Using bandicoot <conversations-label>` for a definition of conversations.
[ "The", "percentage", "of", "conversations", "that", "have", "been", "initiated", "by", "the", "user", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L290-L316
train
yvesalexandre/bandicoot
bandicoot/individual.py
active_days
def active_days(records): """ The number of days during which the user was active. A user is considered active if he sends a text, receives a text, initiates a call, receives a call, or has a mobility point. """ days = set(r.datetime.date() for r in records) return len(days)
python
def active_days(records): """ The number of days during which the user was active. A user is considered active if he sends a text, receives a text, initiates a call, receives a call, or has a mobility point. """ days = set(r.datetime.date() for r in records) return len(days)
[ "def", "active_days", "(", "records", ")", ":", "days", "=", "set", "(", "r", ".", "datetime", ".", "date", "(", ")", "for", "r", "in", "records", ")", "return", "len", "(", "days", ")" ]
The number of days during which the user was active. A user is considered active if he sends a text, receives a text, initiates a call, receives a call, or has a mobility point.
[ "The", "number", "of", "days", "during", "which", "the", "user", "was", "active", ".", "A", "user", "is", "considered", "active", "if", "he", "sends", "a", "text", "receives", "a", "text", "initiates", "a", "call", "receives", "a", "call", "or", "has", ...
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L320-L327
train
yvesalexandre/bandicoot
bandicoot/individual.py
percent_pareto_interactions
def percent_pareto_interactions(records, percentage=0.8): """ The percentage of user's contacts that account for 80% of its interactions. """ if len(records) == 0: return None user_count = Counter(r.correspondent_id for r in records) target = int(math.ceil(sum(user_count.values()) * pe...
python
def percent_pareto_interactions(records, percentage=0.8): """ The percentage of user's contacts that account for 80% of its interactions. """ if len(records) == 0: return None user_count = Counter(r.correspondent_id for r in records) target = int(math.ceil(sum(user_count.values()) * pe...
[ "def", "percent_pareto_interactions", "(", "records", ",", "percentage", "=", "0.8", ")", ":", "if", "len", "(", "records", ")", "==", "0", ":", "return", "None", "user_count", "=", "Counter", "(", "r", ".", "correspondent_id", "for", "r", "in", "records",...
The percentage of user's contacts that account for 80% of its interactions.
[ "The", "percentage", "of", "user", "s", "contacts", "that", "account", "for", "80%", "of", "its", "interactions", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L331-L347
train
yvesalexandre/bandicoot
bandicoot/individual.py
number_of_interactions
def number_of_interactions(records, direction=None): """ The number of interactions. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. """ if direction is None:...
python
def number_of_interactions(records, direction=None): """ The number of interactions. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing. """ if direction is None:...
[ "def", "number_of_interactions", "(", "records", ",", "direction", "=", "None", ")", ":", "if", "direction", "is", "None", ":", "return", "len", "(", "records", ")", "else", ":", "return", "len", "(", "[", "r", "for", "r", "in", "records", "if", "r", ...
The number of interactions. Parameters ---------- direction : str, optional Filters the records by their direction: ``None`` for all records, ``'in'`` for incoming, and ``'out'`` for outgoing.
[ "The", "number", "of", "interactions", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L409-L422
train
yvesalexandre/bandicoot
bandicoot/weekmatrix.py
to_csv
def to_csv(weekmatrices, filename, digits=5): """ Exports a list of week-matrices to a specified filename in the CSV format. Parameters ---------- weekmatrices : list The week-matrices to export. filename : string Path for the exported CSV file. """ with open(filename, ...
python
def to_csv(weekmatrices, filename, digits=5): """ Exports a list of week-matrices to a specified filename in the CSV format. Parameters ---------- weekmatrices : list The week-matrices to export. filename : string Path for the exported CSV file. """ with open(filename, ...
[ "def", "to_csv", "(", "weekmatrices", ",", "filename", ",", "digits", "=", "5", ")", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "f", ":", "w", "=", "csv", ".", "writer", "(", "f", ",", "lineterminator", "=", "'\\n'", ")", "w", "...
Exports a list of week-matrices to a specified filename in the CSV format. Parameters ---------- weekmatrices : list The week-matrices to export. filename : string Path for the exported CSV file.
[ "Exports", "a", "list", "of", "week", "-", "matrices", "to", "a", "specified", "filename", "in", "the", "CSV", "format", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/weekmatrix.py#L105-L130
train
yvesalexandre/bandicoot
bandicoot/weekmatrix.py
read_csv
def read_csv(filename): """ Read a list of week-matrices from a CSV file. """ with open(filename, 'r') as f: r = csv.reader(f) next(r) # remove header wm = list(r) # remove header and convert to numeric for i, row in enumerate(wm): row[1:4] = map(int, row[1:4])...
python
def read_csv(filename): """ Read a list of week-matrices from a CSV file. """ with open(filename, 'r') as f: r = csv.reader(f) next(r) # remove header wm = list(r) # remove header and convert to numeric for i, row in enumerate(wm): row[1:4] = map(int, row[1:4])...
[ "def", "read_csv", "(", "filename", ")", ":", "with", "open", "(", "filename", ",", "'r'", ")", "as", "f", ":", "r", "=", "csv", ".", "reader", "(", "f", ")", "next", "(", "r", ")", "wm", "=", "list", "(", "r", ")", "for", "i", ",", "row", ...
Read a list of week-matrices from a CSV file.
[ "Read", "a", "list", "of", "week", "-", "matrices", "from", "a", "CSV", "file", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/weekmatrix.py#L133-L148
train
yvesalexandre/bandicoot
bandicoot/weekmatrix.py
_extract_list_from_generator
def _extract_list_from_generator(generator): """ Iterates over a generator to extract all the objects and add them to a list. Useful when the objects have to be used multiple times. """ extracted = [] for i in generator: extracted.append(list(i)) return extracted
python
def _extract_list_from_generator(generator): """ Iterates over a generator to extract all the objects and add them to a list. Useful when the objects have to be used multiple times. """ extracted = [] for i in generator: extracted.append(list(i)) return extracted
[ "def", "_extract_list_from_generator", "(", "generator", ")", ":", "extracted", "=", "[", "]", "for", "i", "in", "generator", ":", "extracted", ".", "append", "(", "list", "(", "i", ")", ")", "return", "extracted" ]
Iterates over a generator to extract all the objects and add them to a list. Useful when the objects have to be used multiple times.
[ "Iterates", "over", "a", "generator", "to", "extract", "all", "the", "objects", "and", "add", "them", "to", "a", "list", ".", "Useful", "when", "the", "objects", "have", "to", "be", "used", "multiple", "times", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/weekmatrix.py#L310-L319
train
yvesalexandre/bandicoot
bandicoot/weekmatrix.py
_seconds_to_section_split
def _seconds_to_section_split(record, sections): """ Finds the seconds to the next section from the datetime of a record. """ next_section = sections[ bisect_right(sections, _find_weektime(record.datetime))] * 60 return next_section - _find_weektime(record.datetime, time_type='sec')
python
def _seconds_to_section_split(record, sections): """ Finds the seconds to the next section from the datetime of a record. """ next_section = sections[ bisect_right(sections, _find_weektime(record.datetime))] * 60 return next_section - _find_weektime(record.datetime, time_type='sec')
[ "def", "_seconds_to_section_split", "(", "record", ",", "sections", ")", ":", "next_section", "=", "sections", "[", "bisect_right", "(", "sections", ",", "_find_weektime", "(", "record", ".", "datetime", ")", ")", "]", "*", "60", "return", "next_section", "-",...
Finds the seconds to the next section from the datetime of a record.
[ "Finds", "the", "seconds", "to", "the", "next", "section", "from", "the", "datetime", "of", "a", "record", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/weekmatrix.py#L322-L329
train
yvesalexandre/bandicoot
bandicoot/helper/stops.py
get_neighbors
def get_neighbors(distance_matrix, source, eps): """ Given a matrix of distance between couples of points, return the list of every point closer than eps from a certain point. """ return [dest for dest, distance in enumerate(distance_matrix[source]) if distance < eps]
python
def get_neighbors(distance_matrix, source, eps): """ Given a matrix of distance between couples of points, return the list of every point closer than eps from a certain point. """ return [dest for dest, distance in enumerate(distance_matrix[source]) if distance < eps]
[ "def", "get_neighbors", "(", "distance_matrix", ",", "source", ",", "eps", ")", ":", "return", "[", "dest", "for", "dest", ",", "distance", "in", "enumerate", "(", "distance_matrix", "[", "source", "]", ")", "if", "distance", "<", "eps", "]" ]
Given a matrix of distance between couples of points, return the list of every point closer than eps from a certain point.
[ "Given", "a", "matrix", "of", "distance", "between", "couples", "of", "points", "return", "the", "list", "of", "every", "point", "closer", "than", "eps", "from", "a", "certain", "point", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/stops.py#L37-L43
train
yvesalexandre/bandicoot
bandicoot/helper/stops.py
fix_location
def fix_location(records, max_elapsed_seconds=300): """ Update position of all records based on the position of the closest GPS record. .. note:: Use this function when call and text records are missing a location, but you have access to accurate GPS traces. """ groups = itertool...
python
def fix_location(records, max_elapsed_seconds=300): """ Update position of all records based on the position of the closest GPS record. .. note:: Use this function when call and text records are missing a location, but you have access to accurate GPS traces. """ groups = itertool...
[ "def", "fix_location", "(", "records", ",", "max_elapsed_seconds", "=", "300", ")", ":", "groups", "=", "itertools", ".", "groupby", "(", "records", ",", "lambda", "r", ":", "r", ".", "direction", ")", "groups", "=", "[", "(", "interaction", ",", "list",...
Update position of all records based on the position of the closest GPS record. .. note:: Use this function when call and text records are missing a location, but you have access to accurate GPS traces.
[ "Update", "position", "of", "all", "records", "based", "on", "the", "position", "of", "the", "closest", "GPS", "record", "." ]
73a658f6f17331541cf0b1547028db9b70e8d58a
https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/helper/stops.py#L174-L200
train
wbond/certvalidator
certvalidator/ocsp_client.py
fetch
def fetch(cert, issuer, hash_algo='sha1', nonce=True, user_agent=None, timeout=10): """ Fetches an OCSP response for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get an OCSP reponse for :param issuer: An asn1crypto.x509.Certificate object that is the issuer of ce...
python
def fetch(cert, issuer, hash_algo='sha1', nonce=True, user_agent=None, timeout=10): """ Fetches an OCSP response for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get an OCSP reponse for :param issuer: An asn1crypto.x509.Certificate object that is the issuer of ce...
[ "def", "fetch", "(", "cert", ",", "issuer", ",", "hash_algo", "=", "'sha1'", ",", "nonce", "=", "True", ",", "user_agent", "=", "None", ",", "timeout", "=", "10", ")", ":", "if", "not", "isinstance", "(", "cert", ",", "x509", ".", "Certificate", ")",...
Fetches an OCSP response for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get an OCSP reponse for :param issuer: An asn1crypto.x509.Certificate object that is the issuer of cert :param hash_algo: A unicode string of "sha1" or "sha256" :param nonce: ...
[ "Fetches", "an", "OCSP", "response", "for", "a", "certificate" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/ocsp_client.py#L14-L109
train
wbond/certvalidator
certvalidator/registry.py
CertificateRegistry._walk_issuers
def _walk_issuers(self, path, paths, failed_paths): """ Recursively looks through the list of known certificates for the issuer of the certificate specified, stopping once the certificate in question is one contained within the CA certs list :param path: A Validation...
python
def _walk_issuers(self, path, paths, failed_paths): """ Recursively looks through the list of known certificates for the issuer of the certificate specified, stopping once the certificate in question is one contained within the CA certs list :param path: A Validation...
[ "def", "_walk_issuers", "(", "self", ",", "path", ",", "paths", ",", "failed_paths", ")", ":", "if", "path", ".", "first", ".", "signature", "in", "self", ".", "_ca_lookup", ":", "paths", ".", "append", "(", "path", ")", "return", "new_branches", "=", ...
Recursively looks through the list of known certificates for the issuer of the certificate specified, stopping once the certificate in question is one contained within the CA certs list :param path: A ValidationPath object representing the current traversal of possible p...
[ "Recursively", "looks", "through", "the", "list", "of", "known", "certificates", "for", "the", "issuer", "of", "the", "certificate", "specified", "stopping", "once", "the", "certificate", "in", "question", "is", "one", "contained", "within", "the", "CA", "certs"...
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/registry.py#L325-L358
train
wbond/certvalidator
certvalidator/registry.py
CertificateRegistry._possible_issuers
def _possible_issuers(self, cert): """ Returns a generator that will list all possible issuers for the cert :param cert: An asn1crypto.x509.Certificate object to find the issuer of """ issuer_hashable = cert.issuer.hashable if issuer_hashable not in self._su...
python
def _possible_issuers(self, cert): """ Returns a generator that will list all possible issuers for the cert :param cert: An asn1crypto.x509.Certificate object to find the issuer of """ issuer_hashable = cert.issuer.hashable if issuer_hashable not in self._su...
[ "def", "_possible_issuers", "(", "self", ",", "cert", ")", ":", "issuer_hashable", "=", "cert", ".", "issuer", ".", "hashable", "if", "issuer_hashable", "not", "in", "self", ".", "_subject_map", ":", "return", "for", "issuer", "in", "self", ".", "_subject_ma...
Returns a generator that will list all possible issuers for the cert :param cert: An asn1crypto.x509.Certificate object to find the issuer of
[ "Returns", "a", "generator", "that", "will", "list", "all", "possible", "issuers", "for", "the", "cert" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/registry.py#L360-L383
train
wbond/certvalidator
certvalidator/path.py
ValidationPath.find_issuer
def find_issuer(self, cert): """ Return the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to get the issuer of :raises: LookupError - when the issuer of the certificate could not be found :retur...
python
def find_issuer(self, cert): """ Return the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to get the issuer of :raises: LookupError - when the issuer of the certificate could not be found :retur...
[ "def", "find_issuer", "(", "self", ",", "cert", ")", ":", "for", "entry", "in", "self", ":", "if", "entry", ".", "subject", "==", "cert", ".", "issuer", ":", "if", "entry", ".", "key_identifier", "and", "cert", ".", "authority_key_identifier", ":", "if",...
Return the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to get the issuer of :raises: LookupError - when the issuer of the certificate could not be found :return: An asn1crypto.x509.Certificate obj...
[ "Return", "the", "issuer", "of", "the", "cert", "specified", "as", "defined", "by", "this", "path" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/path.py#L47-L69
train
wbond/certvalidator
certvalidator/path.py
ValidationPath.truncate_to
def truncate_to(self, cert): """ Remove all certificates in the path after the cert specified :param cert: An asn1crypto.x509.Certificate object to find :raises: LookupError - when the certificate could not be found :return: The current Vali...
python
def truncate_to(self, cert): """ Remove all certificates in the path after the cert specified :param cert: An asn1crypto.x509.Certificate object to find :raises: LookupError - when the certificate could not be found :return: The current Vali...
[ "def", "truncate_to", "(", "self", ",", "cert", ")", ":", "cert_index", "=", "None", "for", "index", ",", "entry", "in", "enumerate", "(", "self", ")", ":", "if", "entry", ".", "issuer_serial", "==", "cert", ".", "issuer_serial", ":", "cert_index", "=", ...
Remove all certificates in the path after the cert specified :param cert: An asn1crypto.x509.Certificate object to find :raises: LookupError - when the certificate could not be found :return: The current ValidationPath object, for chaining
[ "Remove", "all", "certificates", "in", "the", "path", "after", "the", "cert", "specified" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/path.py#L71-L97
train
wbond/certvalidator
certvalidator/path.py
ValidationPath.truncate_to_issuer
def truncate_to_issuer(self, cert): """ Remove all certificates in the path after the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to find the issuer of :raises: LookupError - when the issuer of...
python
def truncate_to_issuer(self, cert): """ Remove all certificates in the path after the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to find the issuer of :raises: LookupError - when the issuer of...
[ "def", "truncate_to_issuer", "(", "self", ",", "cert", ")", ":", "issuer_index", "=", "None", "for", "index", ",", "entry", "in", "enumerate", "(", "self", ")", ":", "if", "entry", ".", "subject", "==", "cert", ".", "issuer", ":", "if", "entry", ".", ...
Remove all certificates in the path after the issuer of the cert specified, as defined by this path :param cert: An asn1crypto.x509.Certificate object to find the issuer of :raises: LookupError - when the issuer of the certificate could not be found :return: ...
[ "Remove", "all", "certificates", "in", "the", "path", "after", "the", "issuer", "of", "the", "cert", "specified", "as", "defined", "by", "this", "path" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/path.py#L99-L131
train
wbond/certvalidator
certvalidator/path.py
ValidationPath.copy
def copy(self): """ Creates a copy of this path :return: A ValidationPath object """ copy = self.__class__() copy._certs = self._certs[:] copy._cert_hashes = self._cert_hashes.copy() return copy
python
def copy(self): """ Creates a copy of this path :return: A ValidationPath object """ copy = self.__class__() copy._certs = self._certs[:] copy._cert_hashes = self._cert_hashes.copy() return copy
[ "def", "copy", "(", "self", ")", ":", "copy", "=", "self", ".", "__class__", "(", ")", "copy", ".", "_certs", "=", "self", ".", "_certs", "[", ":", "]", "copy", ".", "_cert_hashes", "=", "self", ".", "_cert_hashes", ".", "copy", "(", ")", "return",...
Creates a copy of this path :return: A ValidationPath object
[ "Creates", "a", "copy", "of", "this", "path" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/path.py#L133-L144
train
wbond/certvalidator
certvalidator/path.py
ValidationPath.pop
def pop(self): """ Removes the last certificate from the path :return: The current ValidationPath object, for chaining """ last_cert = self._certs.pop() self._cert_hashes.remove(last_cert.issuer_serial) return self
python
def pop(self): """ Removes the last certificate from the path :return: The current ValidationPath object, for chaining """ last_cert = self._certs.pop() self._cert_hashes.remove(last_cert.issuer_serial) return self
[ "def", "pop", "(", "self", ")", ":", "last_cert", "=", "self", ".", "_certs", ".", "pop", "(", ")", "self", ".", "_cert_hashes", ".", "remove", "(", "last_cert", ".", "issuer_serial", ")", "return", "self" ]
Removes the last certificate from the path :return: The current ValidationPath object, for chaining
[ "Removes", "the", "last", "certificate", "from", "the", "path" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/path.py#L146-L157
train
wbond/certvalidator
certvalidator/crl_client.py
fetch
def fetch(cert, use_deltas=True, user_agent=None, timeout=10): """ Fetches the CRLs for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get the CRL for :param use_deltas: A boolean indicating if delta CRLs should be fetched :param user_agent: The HTTP u...
python
def fetch(cert, use_deltas=True, user_agent=None, timeout=10): """ Fetches the CRLs for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get the CRL for :param use_deltas: A boolean indicating if delta CRLs should be fetched :param user_agent: The HTTP u...
[ "def", "fetch", "(", "cert", ",", "use_deltas", "=", "True", ",", "user_agent", "=", "None", ",", "timeout", "=", "10", ")", ":", "if", "not", "isinstance", "(", "cert", ",", "x509", ".", "Certificate", ")", ":", "raise", "TypeError", "(", "'cert must ...
Fetches the CRLs for a certificate :param cert: An asn1cyrpto.x509.Certificate object to get the CRL for :param use_deltas: A boolean indicating if delta CRLs should be fetched :param user_agent: The HTTP user agent to use when requesting the CRL. If None, a default is use...
[ "Fetches", "the", "CRLs", "for", "a", "certificate" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/crl_client.py#L11-L54
train
wbond/certvalidator
certvalidator/crl_client.py
_grab_crl
def _grab_crl(user_agent, url, timeout): """ Fetches a CRL and parses it :param user_agent: A unicode string of the user agent to use when fetching the URL :param url: A unicode string of the URL to fetch the CRL from :param timeout: The number of seconds after which an HT...
python
def _grab_crl(user_agent, url, timeout): """ Fetches a CRL and parses it :param user_agent: A unicode string of the user agent to use when fetching the URL :param url: A unicode string of the URL to fetch the CRL from :param timeout: The number of seconds after which an HT...
[ "def", "_grab_crl", "(", "user_agent", ",", "url", ",", "timeout", ")", ":", "request", "=", "Request", "(", "url", ")", "request", ".", "add_header", "(", "'Accept'", ",", "'application/pkix-crl'", ")", "request", ".", "add_header", "(", "'User-Agent'", ","...
Fetches a CRL and parses it :param user_agent: A unicode string of the user agent to use when fetching the URL :param url: A unicode string of the URL to fetch the CRL from :param timeout: The number of seconds after which an HTTP request should timeout :return: An as...
[ "Fetches", "a", "CRL", "and", "parses", "it" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/crl_client.py#L57-L80
train
wbond/certvalidator
certvalidator/crl_client.py
fetch_certs
def fetch_certs(certificate_list, user_agent=None, timeout=10): """ Fetches certificates from the authority information access extension of an asn1crypto.crl.CertificateList object and places them into the cert registry. :param certificate_list: An asn1crypto.crl.CertificateList object ...
python
def fetch_certs(certificate_list, user_agent=None, timeout=10): """ Fetches certificates from the authority information access extension of an asn1crypto.crl.CertificateList object and places them into the cert registry. :param certificate_list: An asn1crypto.crl.CertificateList object ...
[ "def", "fetch_certs", "(", "certificate_list", ",", "user_agent", "=", "None", ",", "timeout", "=", "10", ")", ":", "output", "=", "[", "]", "if", "user_agent", "is", "None", ":", "user_agent", "=", "'certvalidator %s'", "%", "__version__", "elif", "not", ...
Fetches certificates from the authority information access extension of an asn1crypto.crl.CertificateList object and places them into the cert registry. :param certificate_list: An asn1crypto.crl.CertificateList object :param user_agent: The HTTP user agent to use when requesting the C...
[ "Fetches", "certificates", "from", "the", "authority", "information", "access", "extension", "of", "an", "asn1crypto", ".", "crl", ".", "CertificateList", "object", "and", "places", "them", "into", "the", "cert", "registry", "." ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/crl_client.py#L83-L135
train
wbond/certvalidator
certvalidator/__init__.py
CertificateValidator.validate_usage
def validate_usage(self, key_usage, extended_key_usage=None, extended_optional=False): """ Validates the certificate path and that the certificate is valid for the key usage and extended key usage purposes specified. :param key_usage: A set of unicode strings of the required...
python
def validate_usage(self, key_usage, extended_key_usage=None, extended_optional=False): """ Validates the certificate path and that the certificate is valid for the key usage and extended key usage purposes specified. :param key_usage: A set of unicode strings of the required...
[ "def", "validate_usage", "(", "self", ",", "key_usage", ",", "extended_key_usage", "=", "None", ",", "extended_optional", "=", "False", ")", ":", "self", ".", "_validate_path", "(", ")", "validate_usage", "(", "self", ".", "_context", ",", "self", ".", "_cer...
Validates the certificate path and that the certificate is valid for the key usage and extended key usage purposes specified. :param key_usage: A set of unicode strings of the required key usage purposes. Valid values include: - "digital_signature" - "...
[ "Validates", "the", "certificate", "path", "and", "that", "the", "certificate", "is", "valid", "for", "the", "key", "usage", "and", "extended", "key", "usage", "purposes", "specified", "." ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/__init__.py#L140-L201
train
wbond/certvalidator
certvalidator/__init__.py
CertificateValidator.validate_tls
def validate_tls(self, hostname): """ Validates the certificate path, that the certificate is valid for the hostname provided and that the certificate is valid for the purpose of a TLS connection. :param hostname: A unicode string of the TLS server hostname ...
python
def validate_tls(self, hostname): """ Validates the certificate path, that the certificate is valid for the hostname provided and that the certificate is valid for the purpose of a TLS connection. :param hostname: A unicode string of the TLS server hostname ...
[ "def", "validate_tls", "(", "self", ",", "hostname", ")", ":", "self", ".", "_validate_path", "(", ")", "validate_tls_hostname", "(", "self", ".", "_context", ",", "self", ".", "_certificate", ",", "hostname", ")", "return", "self", ".", "_path" ]
Validates the certificate path, that the certificate is valid for the hostname provided and that the certificate is valid for the purpose of a TLS connection. :param hostname: A unicode string of the TLS server hostname :raises: certvalidator.errors.PathValidati...
[ "Validates", "the", "certificate", "path", "that", "the", "certificate", "is", "valid", "for", "the", "hostname", "provided", "and", "that", "the", "certificate", "is", "valid", "for", "the", "purpose", "of", "a", "TLS", "connection", "." ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/__init__.py#L203-L224
train
wbond/certvalidator
certvalidator/context.py
ValidationContext.crls
def crls(self): """ A list of all cached asn1crypto.crl.CertificateList objects """ if not self._allow_fetching: return self._crls output = [] for issuer_serial in self._fetched_crls: output.extend(self._fetched_crls[issuer_serial]) retur...
python
def crls(self): """ A list of all cached asn1crypto.crl.CertificateList objects """ if not self._allow_fetching: return self._crls output = [] for issuer_serial in self._fetched_crls: output.extend(self._fetched_crls[issuer_serial]) retur...
[ "def", "crls", "(", "self", ")", ":", "if", "not", "self", ".", "_allow_fetching", ":", "return", "self", ".", "_crls", "output", "=", "[", "]", "for", "issuer_serial", "in", "self", ".", "_fetched_crls", ":", "output", ".", "extend", "(", "self", ".",...
A list of all cached asn1crypto.crl.CertificateList objects
[ "A", "list", "of", "all", "cached", "asn1crypto", ".", "crl", ".", "CertificateList", "objects" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/context.py#L367-L378
train
wbond/certvalidator
certvalidator/context.py
ValidationContext.ocsps
def ocsps(self): """ A list of all cached asn1crypto.ocsp.OCSPResponse objects """ if not self._allow_fetching: return self._ocsps output = [] for issuer_serial in self._fetched_ocsps: output.extend(self._fetched_ocsps[issuer_serial]) ret...
python
def ocsps(self): """ A list of all cached asn1crypto.ocsp.OCSPResponse objects """ if not self._allow_fetching: return self._ocsps output = [] for issuer_serial in self._fetched_ocsps: output.extend(self._fetched_ocsps[issuer_serial]) ret...
[ "def", "ocsps", "(", "self", ")", ":", "if", "not", "self", ".", "_allow_fetching", ":", "return", "self", ".", "_ocsps", "output", "=", "[", "]", "for", "issuer_serial", "in", "self", ".", "_fetched_ocsps", ":", "output", ".", "extend", "(", "self", "...
A list of all cached asn1crypto.ocsp.OCSPResponse objects
[ "A", "list", "of", "all", "cached", "asn1crypto", ".", "ocsp", ".", "OCSPResponse", "objects" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/context.py#L381-L392
train
wbond/certvalidator
certvalidator/context.py
ValidationContext._extract_ocsp_certs
def _extract_ocsp_certs(self, ocsp_response): """ Extracts any certificates included with an OCSP response and adds them to the certificate registry :param ocsp_response: An asn1crypto.ocsp.OCSPResponse object to look for certs inside of """ status = ocsp_re...
python
def _extract_ocsp_certs(self, ocsp_response): """ Extracts any certificates included with an OCSP response and adds them to the certificate registry :param ocsp_response: An asn1crypto.ocsp.OCSPResponse object to look for certs inside of """ status = ocsp_re...
[ "def", "_extract_ocsp_certs", "(", "self", ",", "ocsp_response", ")", ":", "status", "=", "ocsp_response", "[", "'response_status'", "]", ".", "native", "if", "status", "==", "'successful'", ":", "response_bytes", "=", "ocsp_response", "[", "'response_bytes'", "]"...
Extracts any certificates included with an OCSP response and adds them to the certificate registry :param ocsp_response: An asn1crypto.ocsp.OCSPResponse object to look for certs inside of
[ "Extracts", "any", "certificates", "included", "with", "an", "OCSP", "response", "and", "adds", "them", "to", "the", "certificate", "registry" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/context.py#L516-L533
train
wbond/certvalidator
certvalidator/context.py
ValidationContext.check_validation
def check_validation(self, cert): """ Checks to see if a certificate has been validated, and if so, returns the ValidationPath used to validate it. :param cert: An asn1crypto.x509.Certificate object :return: None if not validated, or a certvalidator.path...
python
def check_validation(self, cert): """ Checks to see if a certificate has been validated, and if so, returns the ValidationPath used to validate it. :param cert: An asn1crypto.x509.Certificate object :return: None if not validated, or a certvalidator.path...
[ "def", "check_validation", "(", "self", ",", "cert", ")", ":", "if", "self", ".", "certificate_registry", ".", "is_ca", "(", "cert", ")", "and", "cert", ".", "signature", "not", "in", "self", ".", "_validate_map", ":", "self", ".", "_validate_map", "[", ...
Checks to see if a certificate has been validated, and if so, returns the ValidationPath used to validate it. :param cert: An asn1crypto.x509.Certificate object :return: None if not validated, or a certvalidator.path.ValidationPath object of the validation p...
[ "Checks", "to", "see", "if", "a", "certificate", "has", "been", "validated", "and", "if", "so", "returns", "the", "ValidationPath", "used", "to", "validate", "it", "." ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/context.py#L550-L567
train
wbond/certvalidator
certvalidator/context.py
ValidationContext.clear_validation
def clear_validation(self, cert): """ Clears the record that a certificate has been validated :param cert: An ans1crypto.x509.Certificate object """ if cert.signature in self._validate_map: del self._validate_map[cert.signature]
python
def clear_validation(self, cert): """ Clears the record that a certificate has been validated :param cert: An ans1crypto.x509.Certificate object """ if cert.signature in self._validate_map: del self._validate_map[cert.signature]
[ "def", "clear_validation", "(", "self", ",", "cert", ")", ":", "if", "cert", ".", "signature", "in", "self", ".", "_validate_map", ":", "del", "self", ".", "_validate_map", "[", "cert", ".", "signature", "]" ]
Clears the record that a certificate has been validated :param cert: An ans1crypto.x509.Certificate object
[ "Clears", "the", "record", "that", "a", "certificate", "has", "been", "validated" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/context.py#L569-L578
train
wbond/certvalidator
certvalidator/validate.py
_find_cert_in_list
def _find_cert_in_list(cert, issuer, certificate_list, crl_issuer): """ Looks for a cert in the list of revoked certificates :param cert: An asn1crypto.x509.Certificate object of the cert being checked :param issuer: An asn1crypto.x509.Certificate object of the cert issuer :param ...
python
def _find_cert_in_list(cert, issuer, certificate_list, crl_issuer): """ Looks for a cert in the list of revoked certificates :param cert: An asn1crypto.x509.Certificate object of the cert being checked :param issuer: An asn1crypto.x509.Certificate object of the cert issuer :param ...
[ "def", "_find_cert_in_list", "(", "cert", ",", "issuer", ",", "certificate_list", ",", "crl_issuer", ")", ":", "revoked_certificates", "=", "certificate_list", "[", "'tbs_cert_list'", "]", "[", "'revoked_certificates'", "]", "cert_serial", "=", "cert", ".", "serial_...
Looks for a cert in the list of revoked certificates :param cert: An asn1crypto.x509.Certificate object of the cert being checked :param issuer: An asn1crypto.x509.Certificate object of the cert issuer :param certificate_list: An ans1crypto.crl.CertificateList object to look in fo...
[ "Looks", "for", "a", "cert", "in", "the", "list", "of", "revoked", "certificates" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/validate.py#L1784-L1839
train
wbond/certvalidator
certvalidator/validate.py
PolicyTreeRoot.add_child
def add_child(self, valid_policy, qualifier_set, expected_policy_set): """ Creates a new PolicyTreeNode as a child of this node :param valid_policy: A unicode string of a policy name or OID :param qualifier_set: An instance of asn1crypto.x509.PolicyQualifierInfo...
python
def add_child(self, valid_policy, qualifier_set, expected_policy_set): """ Creates a new PolicyTreeNode as a child of this node :param valid_policy: A unicode string of a policy name or OID :param qualifier_set: An instance of asn1crypto.x509.PolicyQualifierInfo...
[ "def", "add_child", "(", "self", ",", "valid_policy", ",", "qualifier_set", ",", "expected_policy_set", ")", ":", "child", "=", "PolicyTreeNode", "(", "valid_policy", ",", "qualifier_set", ",", "expected_policy_set", ")", "child", ".", "parent", "=", "self", "se...
Creates a new PolicyTreeNode as a child of this node :param valid_policy: A unicode string of a policy name or OID :param qualifier_set: An instance of asn1crypto.x509.PolicyQualifierInfos :param expected_policy_set: A set of unicode strings containing poli...
[ "Creates", "a", "new", "PolicyTreeNode", "as", "a", "child", "of", "this", "node" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/validate.py#L1871-L1887
train
wbond/certvalidator
certvalidator/validate.py
PolicyTreeRoot.at_depth
def at_depth(self, depth): """ Returns a generator yielding all nodes in the tree at a specific depth :param depth: An integer >= 0 of the depth of nodes to yield :return: A generator yielding PolicyTreeNode objects """ for child in list(self.ch...
python
def at_depth(self, depth): """ Returns a generator yielding all nodes in the tree at a specific depth :param depth: An integer >= 0 of the depth of nodes to yield :return: A generator yielding PolicyTreeNode objects """ for child in list(self.ch...
[ "def", "at_depth", "(", "self", ",", "depth", ")", ":", "for", "child", "in", "list", "(", "self", ".", "children", ")", ":", "if", "depth", "==", "0", ":", "yield", "child", "else", ":", "for", "grandchild", "in", "child", ".", "at_depth", "(", "d...
Returns a generator yielding all nodes in the tree at a specific depth :param depth: An integer >= 0 of the depth of nodes to yield :return: A generator yielding PolicyTreeNode objects
[ "Returns", "a", "generator", "yielding", "all", "nodes", "in", "the", "tree", "at", "a", "specific", "depth" ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/validate.py#L1899-L1915
train
wbond/certvalidator
certvalidator/validate.py
PolicyTreeRoot.walk_up
def walk_up(self, depth): """ Returns a generator yielding all nodes in the tree at a specific depth, or above. Yields nodes starting with leaves and traversing up to the root. :param depth: An integer >= 0 of the depth of nodes to walk up from :return: ...
python
def walk_up(self, depth): """ Returns a generator yielding all nodes in the tree at a specific depth, or above. Yields nodes starting with leaves and traversing up to the root. :param depth: An integer >= 0 of the depth of nodes to walk up from :return: ...
[ "def", "walk_up", "(", "self", ",", "depth", ")", ":", "for", "child", "in", "list", "(", "self", ".", "children", ")", ":", "if", "depth", "!=", "0", ":", "for", "grandchild", "in", "child", ".", "walk_up", "(", "depth", "-", "1", ")", ":", "yie...
Returns a generator yielding all nodes in the tree at a specific depth, or above. Yields nodes starting with leaves and traversing up to the root. :param depth: An integer >= 0 of the depth of nodes to walk up from :return: A generator yielding PolicyTreeNode ob...
[ "Returns", "a", "generator", "yielding", "all", "nodes", "in", "the", "tree", "at", "a", "specific", "depth", "or", "above", ".", "Yields", "nodes", "starting", "with", "leaves", "and", "traversing", "up", "to", "the", "root", "." ]
c62233a713bcc36963e9d82323ec8d84f8e01485
https://github.com/wbond/certvalidator/blob/c62233a713bcc36963e9d82323ec8d84f8e01485/certvalidator/validate.py#L1917-L1934
train
aio-libs/aiomcache
aiomcache/pool.py
MemcachePool.clear
def clear(self): """Clear pool connections.""" while not self._pool.empty(): conn = yield from self._pool.get() self._do_close(conn)
python
def clear(self): """Clear pool connections.""" while not self._pool.empty(): conn = yield from self._pool.get() self._do_close(conn)
[ "def", "clear", "(", "self", ")", ":", "while", "not", "self", ".", "_pool", ".", "empty", "(", ")", ":", "conn", "=", "yield", "from", "self", ".", "_pool", ".", "get", "(", ")", "self", ".", "_do_close", "(", "conn", ")" ]
Clear pool connections.
[ "Clear", "pool", "connections", "." ]
75d44b201aea91bc2856b10940922d5ebfbfcd7b
https://github.com/aio-libs/aiomcache/blob/75d44b201aea91bc2856b10940922d5ebfbfcd7b/aiomcache/pool.py#L23-L27
train