id
int32
0
252k
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
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
2,300
ergoithz/browsepy
browsepy/file.py
generic_filename
def generic_filename(path): ''' Extract filename of given path os-indepently, taking care of known path separators. :param path: path :return: filename :rtype: str or unicode (depending on given path) ''' for sep in common_path_separators: if sep in path: _, path = ...
python
def generic_filename(path): ''' Extract filename of given path os-indepently, taking care of known path separators. :param path: path :return: filename :rtype: str or unicode (depending on given path) ''' for sep in common_path_separators: if sep in path: _, path = ...
[ "def", "generic_filename", "(", "path", ")", ":", "for", "sep", "in", "common_path_separators", ":", "if", "sep", "in", "path", ":", "_", ",", "path", "=", "path", ".", "rsplit", "(", "sep", ",", "1", ")", "return", "path" ]
Extract filename of given path os-indepently, taking care of known path separators. :param path: path :return: filename :rtype: str or unicode (depending on given path)
[ "Extract", "filename", "of", "given", "path", "os", "-", "indepently", "taking", "care", "of", "known", "path", "separators", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L799-L812
2,301
ergoithz/browsepy
browsepy/file.py
clean_restricted_chars
def clean_restricted_chars(path, restricted_chars=restricted_chars): ''' Get path without restricted characters. :param path: path :return: path without restricted characters :rtype: str or unicode (depending on given path) ''' for character in restricted_chars: path = path.replace(...
python
def clean_restricted_chars(path, restricted_chars=restricted_chars): ''' Get path without restricted characters. :param path: path :return: path without restricted characters :rtype: str or unicode (depending on given path) ''' for character in restricted_chars: path = path.replace(...
[ "def", "clean_restricted_chars", "(", "path", ",", "restricted_chars", "=", "restricted_chars", ")", ":", "for", "character", "in", "restricted_chars", ":", "path", "=", "path", ".", "replace", "(", "character", ",", "'_'", ")", "return", "path" ]
Get path without restricted characters. :param path: path :return: path without restricted characters :rtype: str or unicode (depending on given path)
[ "Get", "path", "without", "restricted", "characters", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L815-L825
2,302
ergoithz/browsepy
browsepy/file.py
check_forbidden_filename
def check_forbidden_filename(filename, destiny_os=os.name, restricted_names=restricted_names): ''' Get if given filename is forbidden for current OS or filesystem. :param filename: :param destiny_os: destination operative system :param fs_en...
python
def check_forbidden_filename(filename, destiny_os=os.name, restricted_names=restricted_names): ''' Get if given filename is forbidden for current OS or filesystem. :param filename: :param destiny_os: destination operative system :param fs_en...
[ "def", "check_forbidden_filename", "(", "filename", ",", "destiny_os", "=", "os", ".", "name", ",", "restricted_names", "=", "restricted_names", ")", ":", "return", "(", "filename", "in", "restricted_names", "or", "destiny_os", "==", "'nt'", "and", "filename", "...
Get if given filename is forbidden for current OS or filesystem. :param filename: :param destiny_os: destination operative system :param fs_encoding: destination filesystem filename encoding :return: wether is forbidden on given OS (or filesystem) or not :rtype: bool
[ "Get", "if", "given", "filename", "is", "forbidden", "for", "current", "OS", "or", "filesystem", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L828-L844
2,303
ergoithz/browsepy
browsepy/file.py
check_path
def check_path(path, base, os_sep=os.sep): ''' Check if both given paths are equal. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :type base: str :return: wether two path are equal or not ...
python
def check_path(path, base, os_sep=os.sep): ''' Check if both given paths are equal. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :type base: str :return: wether two path are equal or not ...
[ "def", "check_path", "(", "path", ",", "base", ",", "os_sep", "=", "os", ".", "sep", ")", ":", "base", "=", "base", "[", ":", "-", "len", "(", "os_sep", ")", "]", "if", "base", ".", "endswith", "(", "os_sep", ")", "else", "base", "return", "os", ...
Check if both given paths are equal. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :type base: str :return: wether two path are equal or not :rtype: bool
[ "Check", "if", "both", "given", "paths", "are", "equal", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L847-L861
2,304
ergoithz/browsepy
browsepy/file.py
check_base
def check_base(path, base, os_sep=os.sep): ''' Check if given absolute path is under or given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether path is under given base or no...
python
def check_base(path, base, os_sep=os.sep): ''' Check if given absolute path is under or given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether path is under given base or no...
[ "def", "check_base", "(", "path", ",", "base", ",", "os_sep", "=", "os", ".", "sep", ")", ":", "return", "(", "check_path", "(", "path", ",", "base", ",", "os_sep", ")", "or", "check_under_base", "(", "path", ",", "base", ",", "os_sep", ")", ")" ]
Check if given absolute path is under or given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether path is under given base or not :rtype: bool
[ "Check", "if", "given", "absolute", "path", "is", "under", "or", "given", "base", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L864-L879
2,305
ergoithz/browsepy
browsepy/file.py
check_under_base
def check_under_base(path, base, os_sep=os.sep): ''' Check if given absolute path is under given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether file is under given base or...
python
def check_under_base(path, base, os_sep=os.sep): ''' Check if given absolute path is under given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether file is under given base or...
[ "def", "check_under_base", "(", "path", ",", "base", ",", "os_sep", "=", "os", ".", "sep", ")", ":", "prefix", "=", "base", "if", "base", ".", "endswith", "(", "os_sep", ")", "else", "base", "+", "os_sep", "return", "os", ".", "path", ".", "normcase"...
Check if given absolute path is under given base. :param path: absolute path :type path: str :param base: absolute base path :type base: str :param os_sep: path separator, defaults to os.sep :return: wether file is under given base or not :rtype: bool
[ "Check", "if", "given", "absolute", "path", "is", "under", "given", "base", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L882-L895
2,306
ergoithz/browsepy
browsepy/file.py
secure_filename
def secure_filename(path, destiny_os=os.name, fs_encoding=compat.FS_ENCODING): ''' Get rid of parent path components and special filenames. If path is invalid or protected, return empty string. :param path: unsafe path, only basename will be used :type: str :param destiny_os: destination opera...
python
def secure_filename(path, destiny_os=os.name, fs_encoding=compat.FS_ENCODING): ''' Get rid of parent path components and special filenames. If path is invalid or protected, return empty string. :param path: unsafe path, only basename will be used :type: str :param destiny_os: destination opera...
[ "def", "secure_filename", "(", "path", ",", "destiny_os", "=", "os", ".", "name", ",", "fs_encoding", "=", "compat", ".", "FS_ENCODING", ")", ":", "path", "=", "generic_filename", "(", "path", ")", "path", "=", "clean_restricted_chars", "(", "path", ",", "...
Get rid of parent path components and special filenames. If path is invalid or protected, return empty string. :param path: unsafe path, only basename will be used :type: str :param destiny_os: destination operative system (defaults to os.name) :type destiny_os: str :param fs_encoding: fs path...
[ "Get", "rid", "of", "parent", "path", "components", "and", "special", "filenames", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L898-L938
2,307
ergoithz/browsepy
browsepy/file.py
alternative_filename
def alternative_filename(filename, attempt=None): ''' Generates an alternative version of given filename. If an number attempt parameter is given, will be used on the alternative name, a random value will be used otherwise. :param filename: original filename :param attempt: optional attempt nu...
python
def alternative_filename(filename, attempt=None): ''' Generates an alternative version of given filename. If an number attempt parameter is given, will be used on the alternative name, a random value will be used otherwise. :param filename: original filename :param attempt: optional attempt nu...
[ "def", "alternative_filename", "(", "filename", ",", "attempt", "=", "None", ")", ":", "filename_parts", "=", "filename", ".", "rsplit", "(", "u'.'", ",", "2", ")", "name", "=", "filename_parts", "[", "0", "]", "ext", "=", "''", ".", "join", "(", "u'.%...
Generates an alternative version of given filename. If an number attempt parameter is given, will be used on the alternative name, a random value will be used otherwise. :param filename: original filename :param attempt: optional attempt number, defaults to null :return: new filename :rtype: s...
[ "Generates", "an", "alternative", "version", "of", "given", "filename", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L941-L961
2,308
ergoithz/browsepy
browsepy/file.py
scandir
def scandir(path, app=None): ''' Config-aware scandir. Currently, only aware of ``exclude_fnc``. :param path: absolute path :type path: str :param app: flask application :type app: flask.Flask or None :returns: filtered scandir entries :rtype: iterator ''' exclude = app and app....
python
def scandir(path, app=None): ''' Config-aware scandir. Currently, only aware of ``exclude_fnc``. :param path: absolute path :type path: str :param app: flask application :type app: flask.Flask or None :returns: filtered scandir entries :rtype: iterator ''' exclude = app and app....
[ "def", "scandir", "(", "path", ",", "app", "=", "None", ")", ":", "exclude", "=", "app", "and", "app", ".", "config", ".", "get", "(", "'exclude_fnc'", ")", "if", "exclude", ":", "return", "(", "item", "for", "item", "in", "compat", ".", "scandir", ...
Config-aware scandir. Currently, only aware of ``exclude_fnc``. :param path: absolute path :type path: str :param app: flask application :type app: flask.Flask or None :returns: filtered scandir entries :rtype: iterator
[ "Config", "-", "aware", "scandir", ".", "Currently", "only", "aware", "of", "exclude_fnc", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L964-L982
2,309
ergoithz/browsepy
browsepy/file.py
Node.link
def link(self): ''' Get last widget with place "entry-link". :returns: widget on entry-link (ideally a link one) :rtype: namedtuple instance ''' link = None for widget in self.widgets: if widget.place == 'entry-link': link = widget ...
python
def link(self): ''' Get last widget with place "entry-link". :returns: widget on entry-link (ideally a link one) :rtype: namedtuple instance ''' link = None for widget in self.widgets: if widget.place == 'entry-link': link = widget ...
[ "def", "link", "(", "self", ")", ":", "link", "=", "None", "for", "widget", "in", "self", ".", "widgets", ":", "if", "widget", ".", "place", "==", "'entry-link'", ":", "link", "=", "widget", "return", "link" ]
Get last widget with place "entry-link". :returns: widget on entry-link (ideally a link one) :rtype: namedtuple instance
[ "Get", "last", "widget", "with", "place", "entry", "-", "link", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L111-L122
2,310
ergoithz/browsepy
browsepy/file.py
Node.can_remove
def can_remove(self): ''' Get if current node can be removed based on app config's directory_remove. :returns: True if current node can be removed, False otherwise. :rtype: bool ''' dirbase = self.app.config["directory_remove"] return bool(dirbase and che...
python
def can_remove(self): ''' Get if current node can be removed based on app config's directory_remove. :returns: True if current node can be removed, False otherwise. :rtype: bool ''' dirbase = self.app.config["directory_remove"] return bool(dirbase and che...
[ "def", "can_remove", "(", "self", ")", ":", "dirbase", "=", "self", ".", "app", ".", "config", "[", "\"directory_remove\"", "]", "return", "bool", "(", "dirbase", "and", "check_under_base", "(", "self", ".", "path", ",", "dirbase", ")", ")" ]
Get if current node can be removed based on app config's directory_remove. :returns: True if current node can be removed, False otherwise. :rtype: bool
[ "Get", "if", "current", "node", "can", "be", "removed", "based", "on", "app", "config", "s", "directory_remove", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L125-L134
2,311
ergoithz/browsepy
browsepy/file.py
Node.parent
def parent(self): ''' Get parent node if available based on app config's directory_base. :returns: parent object if available :rtype: Node instance or None ''' if check_path(self.path, self.app.config['directory_base']): return None parent = os.path.d...
python
def parent(self): ''' Get parent node if available based on app config's directory_base. :returns: parent object if available :rtype: Node instance or None ''' if check_path(self.path, self.app.config['directory_base']): return None parent = os.path.d...
[ "def", "parent", "(", "self", ")", ":", "if", "check_path", "(", "self", ".", "path", ",", "self", ".", "app", ".", "config", "[", "'directory_base'", "]", ")", ":", "return", "None", "parent", "=", "os", ".", "path", ".", "dirname", "(", "self", "...
Get parent node if available based on app config's directory_base. :returns: parent object if available :rtype: Node instance or None
[ "Get", "parent", "node", "if", "available", "based", "on", "app", "config", "s", "directory_base", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L158-L168
2,312
ergoithz/browsepy
browsepy/file.py
Node.ancestors
def ancestors(self): ''' Get list of ancestors until app config's directory_base is reached. :returns: list of ancestors starting from nearest. :rtype: list of Node objects ''' ancestors = [] parent = self.parent while parent: ancestors.append...
python
def ancestors(self): ''' Get list of ancestors until app config's directory_base is reached. :returns: list of ancestors starting from nearest. :rtype: list of Node objects ''' ancestors = [] parent = self.parent while parent: ancestors.append...
[ "def", "ancestors", "(", "self", ")", ":", "ancestors", "=", "[", "]", "parent", "=", "self", ".", "parent", "while", "parent", ":", "ancestors", ".", "append", "(", "parent", ")", "parent", "=", "parent", ".", "parent", "return", "ancestors" ]
Get list of ancestors until app config's directory_base is reached. :returns: list of ancestors starting from nearest. :rtype: list of Node objects
[ "Get", "list", "of", "ancestors", "until", "app", "config", "s", "directory_base", "is", "reached", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L171-L183
2,313
ergoithz/browsepy
browsepy/file.py
Node.modified
def modified(self): ''' Get human-readable last modification date-time. :returns: iso9008-like date-time string (without timezone) :rtype: str ''' try: dt = datetime.datetime.fromtimestamp(self.stats.st_mtime) return dt.strftime('%Y.%m.%d %H:%M:%S...
python
def modified(self): ''' Get human-readable last modification date-time. :returns: iso9008-like date-time string (without timezone) :rtype: str ''' try: dt = datetime.datetime.fromtimestamp(self.stats.st_mtime) return dt.strftime('%Y.%m.%d %H:%M:%S...
[ "def", "modified", "(", "self", ")", ":", "try", ":", "dt", "=", "datetime", ".", "datetime", ".", "fromtimestamp", "(", "self", ".", "stats", ".", "st_mtime", ")", "return", "dt", ".", "strftime", "(", "'%Y.%m.%d %H:%M:%S'", ")", "except", "OSError", ":...
Get human-readable last modification date-time. :returns: iso9008-like date-time string (without timezone) :rtype: str
[ "Get", "human", "-", "readable", "last", "modification", "date", "-", "time", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L186-L197
2,314
ergoithz/browsepy
browsepy/file.py
Node.from_urlpath
def from_urlpath(cls, path, app=None): ''' Alternative constructor which accepts a path as taken from URL and uses the given app or the current app config to get the real path. If class has attribute `generic` set to True, `directory_class` or `file_class` will be used as type. ...
python
def from_urlpath(cls, path, app=None): ''' Alternative constructor which accepts a path as taken from URL and uses the given app or the current app config to get the real path. If class has attribute `generic` set to True, `directory_class` or `file_class` will be used as type. ...
[ "def", "from_urlpath", "(", "cls", ",", "path", ",", "app", "=", "None", ")", ":", "app", "=", "app", "or", "current_app", "base", "=", "app", ".", "config", "[", "'directory_base'", "]", "path", "=", "urlpath_to_abspath", "(", "path", ",", "base", ")"...
Alternative constructor which accepts a path as taken from URL and uses the given app or the current app config to get the real path. If class has attribute `generic` set to True, `directory_class` or `file_class` will be used as type. :param path: relative path as from URL :pa...
[ "Alternative", "constructor", "which", "accepts", "a", "path", "as", "taken", "from", "URL", "and", "uses", "the", "given", "app", "or", "the", "current", "app", "config", "to", "get", "the", "real", "path", "." ]
1612a930ef220fae507e1b152c531707e555bd92
https://github.com/ergoithz/browsepy/blob/1612a930ef220fae507e1b152c531707e555bd92/browsepy/file.py#L274-L296
2,315
brutasse/graphite-api
graphite_api/finders/whisper.py
WhisperFinder._find_paths
def _find_paths(self, current_dir, patterns): """Recursively generates absolute paths whose components underneath current_dir match the corresponding pattern in patterns""" pattern = patterns[0] patterns = patterns[1:] has_wildcard = is_pattern(pattern) using_glob...
python
def _find_paths(self, current_dir, patterns): pattern = patterns[0] patterns = patterns[1:] has_wildcard = is_pattern(pattern) using_globstar = pattern == "**" # This avoids os.listdir() for performance if has_wildcard: entries = [x.name for x in scandir(curr...
[ "def", "_find_paths", "(", "self", ",", "current_dir", ",", "patterns", ")", ":", "pattern", "=", "patterns", "[", "0", "]", "patterns", "=", "patterns", "[", "1", ":", "]", "has_wildcard", "=", "is_pattern", "(", "pattern", ")", "using_globstar", "=", "...
Recursively generates absolute paths whose components underneath current_dir match the corresponding pattern in patterns
[ "Recursively", "generates", "absolute", "paths", "whose", "components", "underneath", "current_dir", "match", "the", "corresponding", "pattern", "in", "patterns" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/finders/whisper.py#L73-L113
2,316
brutasse/graphite-api
graphite_api/intervals.py
union_overlapping
def union_overlapping(intervals): """Union any overlapping intervals in the given set.""" disjoint_intervals = [] for interval in intervals: if disjoint_intervals and disjoint_intervals[-1].overlaps(interval): disjoint_intervals[-1] = disjoint_intervals[-1].union(interval) else:...
python
def union_overlapping(intervals): disjoint_intervals = [] for interval in intervals: if disjoint_intervals and disjoint_intervals[-1].overlaps(interval): disjoint_intervals[-1] = disjoint_intervals[-1].union(interval) else: disjoint_intervals.append(interval) return...
[ "def", "union_overlapping", "(", "intervals", ")", ":", "disjoint_intervals", "=", "[", "]", "for", "interval", "in", "intervals", ":", "if", "disjoint_intervals", "and", "disjoint_intervals", "[", "-", "1", "]", ".", "overlaps", "(", "interval", ")", ":", "...
Union any overlapping intervals in the given set.
[ "Union", "any", "overlapping", "intervals", "in", "the", "given", "set", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/intervals.py#L128-L138
2,317
brutasse/graphite-api
graphite_api/app.py
recurse
def recurse(query, index): """ Recursively walk across paths, adding leaves to the index as they're found. """ for node in app.store.find(query): if node.is_leaf: index.add(node.path) else: recurse('{0}.*'.format(node.path), index)
python
def recurse(query, index): for node in app.store.find(query): if node.is_leaf: index.add(node.path) else: recurse('{0}.*'.format(node.path), index)
[ "def", "recurse", "(", "query", ",", "index", ")", ":", "for", "node", "in", "app", ".", "store", ".", "find", "(", "query", ")", ":", "if", "node", ".", "is_leaf", ":", "index", ".", "add", "(", "node", ".", "path", ")", "else", ":", "recurse", ...
Recursively walk across paths, adding leaves to the index as they're found.
[ "Recursively", "walk", "across", "paths", "adding", "leaves", "to", "the", "index", "as", "they", "re", "found", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/app.py#L204-L212
2,318
brutasse/graphite-api
graphite_api/_vendor/whisper.py
__archive_fetch
def __archive_fetch(fh, archive, fromTime, untilTime): """ Fetch data from a single archive. Note that checks for validity of the time period requested happen above this level so it's possible to wrap around the archive on a read and request data older than the archive's retention """ fromInterval = int( fromTime -...
python
def __archive_fetch(fh, archive, fromTime, untilTime): fromInterval = int( fromTime - (fromTime % archive['secondsPerPoint']) ) + archive['secondsPerPoint'] untilInterval = int( untilTime - (untilTime % archive['secondsPerPoint']) ) + archive['secondsPerPoint'] if fromInterval == untilInterval: # Zero-length ...
[ "def", "__archive_fetch", "(", "fh", ",", "archive", ",", "fromTime", ",", "untilTime", ")", ":", "fromInterval", "=", "int", "(", "fromTime", "-", "(", "fromTime", "%", "archive", "[", "'secondsPerPoint'", "]", ")", ")", "+", "archive", "[", "'secondsPerP...
Fetch data from a single archive. Note that checks for validity of the time period requested happen above this level so it's possible to wrap around the archive on a read and request data older than the archive's retention
[ "Fetch", "data", "from", "a", "single", "archive", ".", "Note", "that", "checks", "for", "validity", "of", "the", "time", "period", "requested", "happen", "above", "this", "level", "so", "it", "s", "possible", "to", "wrap", "around", "the", "archive", "on"...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/_vendor/whisper.py#L797-L860
2,319
brutasse/graphite-api
graphite_api/_vendor/whisper.py
merge
def merge(path_from, path_to): """ Merges the data from one whisper file into another. Each file must have the same archive configuration """ fh_from = open(path_from, 'rb') fh_to = open(path_to, 'rb+') return file_merge(fh_from, fh_to)
python
def merge(path_from, path_to): fh_from = open(path_from, 'rb') fh_to = open(path_to, 'rb+') return file_merge(fh_from, fh_to)
[ "def", "merge", "(", "path_from", ",", "path_to", ")", ":", "fh_from", "=", "open", "(", "path_from", ",", "'rb'", ")", "fh_to", "=", "open", "(", "path_to", ",", "'rb+'", ")", "return", "file_merge", "(", "fh_from", ",", "fh_to", ")" ]
Merges the data from one whisper file into another. Each file must have the same archive configuration
[ "Merges", "the", "data", "from", "one", "whisper", "file", "into", "another", ".", "Each", "file", "must", "have", "the", "same", "archive", "configuration" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/_vendor/whisper.py#L862-L868
2,320
brutasse/graphite-api
graphite_api/_vendor/whisper.py
diff
def diff(path_from, path_to, ignore_empty = False): """ Compare two whisper databases. Each file must have the same archive configuration """ fh_from = open(path_from, 'rb') fh_to = open(path_to, 'rb') diffs = file_diff(fh_from, fh_to, ignore_empty) fh_to.close() fh_from.close() return diffs
python
def diff(path_from, path_to, ignore_empty = False): fh_from = open(path_from, 'rb') fh_to = open(path_to, 'rb') diffs = file_diff(fh_from, fh_to, ignore_empty) fh_to.close() fh_from.close() return diffs
[ "def", "diff", "(", "path_from", ",", "path_to", ",", "ignore_empty", "=", "False", ")", ":", "fh_from", "=", "open", "(", "path_from", ",", "'rb'", ")", "fh_to", "=", "open", "(", "path_to", ",", "'rb'", ")", "diffs", "=", "file_diff", "(", "fh_from",...
Compare two whisper databases. Each file must have the same archive configuration
[ "Compare", "two", "whisper", "databases", ".", "Each", "file", "must", "have", "the", "same", "archive", "configuration" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/_vendor/whisper.py#L895-L902
2,321
brutasse/graphite-api
graphite_api/render/datalib.py
DataStore.add_data
def add_data(self, path, time_info, data, exprs): """ Stores data before it can be put into a time series """ # Dont add if empty if not nonempty(data): for d in self.data[path]: if nonempty(d['values']): return # Add data ...
python
def add_data(self, path, time_info, data, exprs): # Dont add if empty if not nonempty(data): for d in self.data[path]: if nonempty(d['values']): return # Add data to path for expr in exprs: self.paths[expr].add(path) se...
[ "def", "add_data", "(", "self", ",", "path", ",", "time_info", ",", "data", ",", "exprs", ")", ":", "# Dont add if empty", "if", "not", "nonempty", "(", "data", ")", ":", "for", "d", "in", "self", ".", "data", "[", "path", "]", ":", "if", "nonempty",...
Stores data before it can be put into a time series
[ "Stores", "data", "before", "it", "can", "be", "put", "into", "a", "time", "series" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/datalib.py#L117-L133
2,322
brutasse/graphite-api
graphite_api/carbonlink.py
CarbonLinkPool.select_host
def select_host(self, metric): """ Returns the carbon host that has data for the given metric. """ key = self.keyfunc(metric) nodes = [] servers = set() for node in self.hash_ring.get_nodes(key): server, instance = node if server in servers...
python
def select_host(self, metric): key = self.keyfunc(metric) nodes = [] servers = set() for node in self.hash_ring.get_nodes(key): server, instance = node if server in servers: continue servers.add(server) nodes.append(node) ...
[ "def", "select_host", "(", "self", ",", "metric", ")", ":", "key", "=", "self", ".", "keyfunc", "(", "metric", ")", "nodes", "=", "[", "]", "servers", "=", "set", "(", ")", "for", "node", "in", "self", ".", "hash_ring", ".", "get_nodes", "(", "key"...
Returns the carbon host that has data for the given metric.
[ "Returns", "the", "carbon", "host", "that", "has", "data", "for", "the", "given", "metric", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/carbonlink.py#L180-L196
2,323
brutasse/graphite-api
graphite_api/render/glyph.py
safeArgs
def safeArgs(args): """Iterate over valid, finite values in an iterable. Skip any items that are None, NaN, or infinite. """ return (arg for arg in args if arg is not None and not math.isnan(arg) and not math.isinf(arg))
python
def safeArgs(args): return (arg for arg in args if arg is not None and not math.isnan(arg) and not math.isinf(arg))
[ "def", "safeArgs", "(", "args", ")", ":", "return", "(", "arg", "for", "arg", "in", "args", "if", "arg", "is", "not", "None", "and", "not", "math", ".", "isnan", "(", "arg", ")", "and", "not", "math", ".", "isinf", "(", "arg", ")", ")" ]
Iterate over valid, finite values in an iterable. Skip any items that are None, NaN, or infinite.
[ "Iterate", "over", "valid", "finite", "values", "in", "an", "iterable", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L2147-L2153
2,324
brutasse/graphite-api
graphite_api/render/glyph.py
format_units
def format_units(v, step=None, system="si", units=None): """Format the given value in standardized units. ``system`` is either 'binary' or 'si' For more info, see: http://en.wikipedia.org/wiki/SI_prefix http://en.wikipedia.org/wiki/Binary_prefix """ if v is None: return 0, ...
python
def format_units(v, step=None, system="si", units=None): if v is None: return 0, '' for prefix, size in UnitSystems[system]: if condition(v, size, step): v2 = v / size if v2 - math.floor(v2) < 0.00000000001 and v > 1: v2 = float(math.floor(v2)) ...
[ "def", "format_units", "(", "v", ",", "step", "=", "None", ",", "system", "=", "\"si\"", ",", "units", "=", "None", ")", ":", "if", "v", "is", "None", ":", "return", "0", ",", "''", "for", "prefix", ",", "size", "in", "UnitSystems", "[", "system", ...
Format the given value in standardized units. ``system`` is either 'binary' or 'si' For more info, see: http://en.wikipedia.org/wiki/SI_prefix http://en.wikipedia.org/wiki/Binary_prefix
[ "Format", "the", "given", "value", "in", "standardized", "units", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L2219-L2246
2,325
brutasse/graphite-api
graphite_api/render/glyph.py
_AxisTics.checkFinite
def checkFinite(value, name='value'): """Check that value is a finite number. If it is, return it. If not, raise GraphError describing the problem, using name in the error message. """ if math.isnan(value): raise GraphError('Encountered NaN %s' % (name,)) eli...
python
def checkFinite(value, name='value'): if math.isnan(value): raise GraphError('Encountered NaN %s' % (name,)) elif math.isinf(value): raise GraphError('Encountered infinite %s' % (name,)) return value
[ "def", "checkFinite", "(", "value", ",", "name", "=", "'value'", ")", ":", "if", "math", ".", "isnan", "(", "value", ")", ":", "raise", "GraphError", "(", "'Encountered NaN %s'", "%", "(", "name", ",", ")", ")", "elif", "math", ".", "isinf", "(", "va...
Check that value is a finite number. If it is, return it. If not, raise GraphError describing the problem, using name in the error message.
[ "Check", "that", "value", "is", "a", "finite", "number", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L347-L357
2,326
brutasse/graphite-api
graphite_api/render/glyph.py
_AxisTics.reconcileLimits
def reconcileLimits(self): """If self.minValue is not less than self.maxValue, fix the problem. If self.minValue is not less than self.maxValue, adjust self.minValue and/or self.maxValue (depending on which was not specified explicitly by the user) to make self.minValue < self.m...
python
def reconcileLimits(self): if self.minValue < self.maxValue: # The limits are already OK. return minFixed = (self.minValueSource in ['min']) maxFixed = (self.maxValueSource in ['max', 'limit']) if minFixed and maxFixed: raise GraphError('The %s must ...
[ "def", "reconcileLimits", "(", "self", ")", ":", "if", "self", ".", "minValue", "<", "self", ".", "maxValue", ":", "# The limits are already OK.", "return", "minFixed", "=", "(", "self", ".", "minValueSource", "in", "[", "'min'", "]", ")", "maxFixed", "=", ...
If self.minValue is not less than self.maxValue, fix the problem. If self.minValue is not less than self.maxValue, adjust self.minValue and/or self.maxValue (depending on which was not specified explicitly by the user) to make self.minValue < self.maxValue. If the user specified both li...
[ "If", "self", ".", "minValue", "is", "not", "less", "than", "self", ".", "maxValue", "fix", "the", "problem", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L371-L399
2,327
brutasse/graphite-api
graphite_api/render/glyph.py
_AxisTics.applySettings
def applySettings(self, axisMin=None, axisMax=None, axisLimit=None): """Apply the specified settings to this axis. Set self.minValue, self.minValueSource, self.maxValue, self.maxValueSource, and self.axisLimit reasonably based on the parameters provided. Arguments: axi...
python
def applySettings(self, axisMin=None, axisMax=None, axisLimit=None): if axisMin is not None and not math.isnan(axisMin): self.minValueSource = 'min' self.minValue = self.checkFinite(axisMin, 'axis min') if axisMax == 'max': self.maxValueSource = 'extremum' el...
[ "def", "applySettings", "(", "self", ",", "axisMin", "=", "None", ",", "axisMax", "=", "None", ",", "axisLimit", "=", "None", ")", ":", "if", "axisMin", "is", "not", "None", "and", "not", "math", ".", "isnan", "(", "axisMin", ")", ":", "self", ".", ...
Apply the specified settings to this axis. Set self.minValue, self.minValueSource, self.maxValue, self.maxValueSource, and self.axisLimit reasonably based on the parameters provided. Arguments: axisMin -- a finite number, or None to choose a round minimum limit tha...
[ "Apply", "the", "specified", "settings", "to", "this", "axis", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L401-L446
2,328
brutasse/graphite-api
graphite_api/render/glyph.py
_AxisTics.makeLabel
def makeLabel(self, value): """Create a label for the specified value. Create a label string containing the value and its units (if any), based on the values of self.step, self.span, and self.unitSystem. """ value, prefix = format_units(value, self.step, ...
python
def makeLabel(self, value): value, prefix = format_units(value, self.step, system=self.unitSystem) span, spanPrefix = format_units(self.span, self.step, system=self.unitSystem) if prefix: prefix += " " ...
[ "def", "makeLabel", "(", "self", ",", "value", ")", ":", "value", ",", "prefix", "=", "format_units", "(", "value", ",", "self", ".", "step", ",", "system", "=", "self", ".", "unitSystem", ")", "span", ",", "spanPrefix", "=", "format_units", "(", "self...
Create a label for the specified value. Create a label string containing the value and its units (if any), based on the values of self.step, self.span, and self.unitSystem.
[ "Create", "a", "label", "for", "the", "specified", "value", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L448-L474
2,329
brutasse/graphite-api
graphite_api/render/glyph.py
_LinearAxisTics.generateSteps
def generateSteps(self, minStep): """Generate allowed steps with step >= minStep in increasing order.""" self.checkFinite(minStep) if self.binary: base = 2.0 mantissas = [1.0] exponent = math.floor(math.log(minStep, 2) - EPSILON) else: bas...
python
def generateSteps(self, minStep): self.checkFinite(minStep) if self.binary: base = 2.0 mantissas = [1.0] exponent = math.floor(math.log(minStep, 2) - EPSILON) else: base = 10.0 mantissas = [1.0, 2.0, 5.0] exponent = math.fl...
[ "def", "generateSteps", "(", "self", ",", "minStep", ")", ":", "self", ".", "checkFinite", "(", "minStep", ")", "if", "self", ".", "binary", ":", "base", "=", "2.0", "mantissas", "=", "[", "1.0", "]", "exponent", "=", "math", ".", "floor", "(", "math...
Generate allowed steps with step >= minStep in increasing order.
[ "Generate", "allowed", "steps", "with", "step", ">", "=", "minStep", "in", "increasing", "order", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L490-L509
2,330
brutasse/graphite-api
graphite_api/render/glyph.py
_LinearAxisTics.computeSlop
def computeSlop(self, step, divisor): """Compute the slop that would result from step and divisor. Return the slop, or None if this combination can't cover the full range. See chooseStep() for the definition of "slop". """ bottom = step * math.floor(self.minValue / float(step) ...
python
def computeSlop(self, step, divisor): bottom = step * math.floor(self.minValue / float(step) + EPSILON) top = bottom + step * divisor if top >= self.maxValue - EPSILON * step: return max(top - self.maxValue, self.minValue - bottom) else: return None
[ "def", "computeSlop", "(", "self", ",", "step", ",", "divisor", ")", ":", "bottom", "=", "step", "*", "math", ".", "floor", "(", "self", ".", "minValue", "/", "float", "(", "step", ")", "+", "EPSILON", ")", "top", "=", "bottom", "+", "step", "*", ...
Compute the slop that would result from step and divisor. Return the slop, or None if this combination can't cover the full range. See chooseStep() for the definition of "slop".
[ "Compute", "the", "slop", "that", "would", "result", "from", "step", "and", "divisor", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L511-L524
2,331
brutasse/graphite-api
graphite_api/render/glyph.py
_LinearAxisTics.chooseStep
def chooseStep(self, divisors=None, binary=False): """Choose a nice, pretty size for the steps between axis labels. Our main constraint is that the number of divisions must be taken from the divisors list. We pick a number of divisions and a step size that minimizes the amount of whites...
python
def chooseStep(self, divisors=None, binary=False): self.binary = binary if divisors is None: divisors = [4, 5, 6] else: for divisor in divisors: self.checkFinite(divisor, 'divisor') if divisor < 1: raise GraphError('Divi...
[ "def", "chooseStep", "(", "self", ",", "divisors", "=", "None", ",", "binary", "=", "False", ")", ":", "self", ".", "binary", "=", "binary", "if", "divisors", "is", "None", ":", "divisors", "=", "[", "4", ",", "5", ",", "6", "]", "else", ":", "fo...
Choose a nice, pretty size for the steps between axis labels. Our main constraint is that the number of divisions must be taken from the divisors list. We pick a number of divisions and a step size that minimizes the amount of whitespace ("slop") that would need to be included outside o...
[ "Choose", "a", "nice", "pretty", "size", "for", "the", "steps", "between", "axis", "labels", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/render/glyph.py#L526-L604
2,332
brutasse/graphite-api
graphite_api/functions.py
formatPathExpressions
def formatPathExpressions(seriesList): """ Returns a comma-separated list of unique path expressions. """ pathExpressions = sorted(set([s.pathExpression for s in seriesList])) return ','.join(pathExpressions)
python
def formatPathExpressions(seriesList): pathExpressions = sorted(set([s.pathExpression for s in seriesList])) return ','.join(pathExpressions)
[ "def", "formatPathExpressions", "(", "seriesList", ")", ":", "pathExpressions", "=", "sorted", "(", "set", "(", "[", "s", ".", "pathExpression", "for", "s", "in", "seriesList", "]", ")", ")", "return", "','", ".", "join", "(", "pathExpressions", ")" ]
Returns a comma-separated list of unique path expressions.
[ "Returns", "a", "comma", "-", "separated", "list", "of", "unique", "path", "expressions", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L185-L190
2,333
brutasse/graphite-api
graphite_api/functions.py
rangeOfSeries
def rangeOfSeries(requestContext, *seriesLists): """ Takes a wildcard seriesList. Distills down a set of inputs into the range of the series Example:: &target=rangeOfSeries(Server*.connections.total) """ if not seriesLists or not any(seriesLists): return [] seriesList, sta...
python
def rangeOfSeries(requestContext, *seriesLists): if not seriesLists or not any(seriesLists): return [] seriesList, start, end, step = normalize(seriesLists) name = "rangeOfSeries(%s)" % formatPathExpressions(seriesList) values = (safeSubtract(max(row), min(row)) for ro...
[ "def", "rangeOfSeries", "(", "requestContext", ",", "*", "seriesLists", ")", ":", "if", "not", "seriesLists", "or", "not", "any", "(", "seriesLists", ")", ":", "return", "[", "]", "seriesList", ",", "start", ",", "end", ",", "step", "=", "normalize", "("...
Takes a wildcard seriesList. Distills down a set of inputs into the range of the series Example:: &target=rangeOfSeries(Server*.connections.total)
[ "Takes", "a", "wildcard", "seriesList", ".", "Distills", "down", "a", "set", "of", "inputs", "into", "the", "range", "of", "the", "series" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L434-L452
2,334
brutasse/graphite-api
graphite_api/functions.py
percentileOfSeries
def percentileOfSeries(requestContext, seriesList, n, interpolate=False): """ percentileOfSeries returns a single series which is composed of the n-percentile values taken across a wildcard series at each point. Unless `interpolate` is set to True, percentile values are actual values contained in on...
python
def percentileOfSeries(requestContext, seriesList, n, interpolate=False): if n <= 0: raise ValueError( 'The requested percent is required to be greater than 0') if not seriesList: return [] name = 'percentileOfSeries(%s,%g)' % (seriesList[0].pathExpression, n) start, end, st...
[ "def", "percentileOfSeries", "(", "requestContext", ",", "seriesList", ",", "n", ",", "interpolate", "=", "False", ")", ":", "if", "n", "<=", "0", ":", "raise", "ValueError", "(", "'The requested percent is required to be greater than 0'", ")", "if", "not", "serie...
percentileOfSeries returns a single series which is composed of the n-percentile values taken across a wildcard series at each point. Unless `interpolate` is set to True, percentile values are actual values contained in one of the supplied series.
[ "percentileOfSeries", "returns", "a", "single", "series", "which", "is", "composed", "of", "the", "n", "-", "percentile", "values", "taken", "across", "a", "wildcard", "series", "at", "each", "point", ".", "Unless", "interpolate", "is", "set", "to", "True", ...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L455-L474
2,335
brutasse/graphite-api
graphite_api/functions.py
weightedAverage
def weightedAverage(requestContext, seriesListAvg, seriesListWeight, *nodes): """ Takes a series of average values and a series of weights and produces a weighted average for all values. The corresponding values should share one or more zero-indexed nodes. Example:: &target=weightedAverag...
python
def weightedAverage(requestContext, seriesListAvg, seriesListWeight, *nodes): if isinstance(nodes, int): nodes = [nodes] sortedSeries = {} for seriesAvg, seriesWeight in zip_longest( seriesListAvg, seriesListWeight): key = '' for node in nodes: key += series...
[ "def", "weightedAverage", "(", "requestContext", ",", "seriesListAvg", ",", "seriesListWeight", ",", "*", "nodes", ")", ":", "if", "isinstance", "(", "nodes", ",", "int", ")", ":", "nodes", "=", "[", "nodes", "]", "sortedSeries", "=", "{", "}", "for", "s...
Takes a series of average values and a series of weights and produces a weighted average for all values. The corresponding values should share one or more zero-indexed nodes. Example:: &target=weightedAverage(*.transactions.mean,*.transactions.count,0) &target=weightedAverage(*.transactio...
[ "Takes", "a", "series", "of", "average", "values", "and", "a", "series", "of", "weights", "and", "produces", "a", "weighted", "average", "for", "all", "values", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L773-L843
2,336
brutasse/graphite-api
graphite_api/functions.py
scale
def scale(requestContext, seriesList, factor): """ Takes one metric or a wildcard seriesList followed by a constant, and multiplies the datapoint by the constant provided at each point. Example:: &target=scale(Server.instance01.threads.busy,10) &target=scale(Server.instance*.threads.bu...
python
def scale(requestContext, seriesList, factor): for series in seriesList: series.name = "scale(%s,%g)" % (series.name, float(factor)) series.pathExpression = series.name for i, value in enumerate(series): series[i] = safeMul(value, factor) return seriesList
[ "def", "scale", "(", "requestContext", ",", "seriesList", ",", "factor", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"scale(%s,%g)\"", "%", "(", "series", ".", "name", ",", "float", "(", "factor", ")", ")", "series",...
Takes one metric or a wildcard seriesList followed by a constant, and multiplies the datapoint by the constant provided at each point. Example:: &target=scale(Server.instance01.threads.busy,10) &target=scale(Server.instance*.threads.busy,10)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "constant", "and", "multiplies", "the", "datapoint", "by", "the", "constant", "provided", "at", "each", "point", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L994-L1010
2,337
brutasse/graphite-api
graphite_api/functions.py
scaleToSeconds
def scaleToSeconds(requestContext, seriesList, seconds): """ Takes one metric or a wildcard seriesList and returns "value per seconds" where seconds is a last argument to this functions. Useful in conjunction with derivative or integral function if you want to normalize its result to a known resolu...
python
def scaleToSeconds(requestContext, seriesList, seconds): for series in seriesList: series.name = "scaleToSeconds(%s,%d)" % (series.name, seconds) series.pathExpression = series.name factor = seconds * 1.0 / series.step for i, value in enumerate(series): series[i] = safeMu...
[ "def", "scaleToSeconds", "(", "requestContext", ",", "seriesList", ",", "seconds", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"scaleToSeconds(%s,%d)\"", "%", "(", "series", ".", "name", ",", "seconds", ")", "series", "....
Takes one metric or a wildcard seriesList and returns "value per seconds" where seconds is a last argument to this functions. Useful in conjunction with derivative or integral function if you want to normalize its result to a known resolution for arbitrary retentions
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "and", "returns", "value", "per", "seconds", "where", "seconds", "is", "a", "last", "argument", "to", "this", "functions", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1013-L1028
2,338
brutasse/graphite-api
graphite_api/functions.py
pow
def pow(requestContext, seriesList, factor): """ Takes one metric or a wildcard seriesList followed by a constant, and raises the datapoint by the power of the constant provided at each point. Example:: &target=pow(Server.instance01.threads.busy,10) &target=pow(Server.instance*.threads...
python
def pow(requestContext, seriesList, factor): for series in seriesList: series.name = "pow(%s,%g)" % (series.name, float(factor)) series.pathExpression = series.name for i, value in enumerate(series): series[i] = safePow(value, factor) return seriesList
[ "def", "pow", "(", "requestContext", ",", "seriesList", ",", "factor", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"pow(%s,%g)\"", "%", "(", "series", ".", "name", ",", "float", "(", "factor", ")", ")", "series", "...
Takes one metric or a wildcard seriesList followed by a constant, and raises the datapoint by the power of the constant provided at each point. Example:: &target=pow(Server.instance01.threads.busy,10) &target=pow(Server.instance*.threads.busy,10)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "constant", "and", "raises", "the", "datapoint", "by", "the", "power", "of", "the", "constant", "provided", "at", "each", "point", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1031-L1047
2,339
brutasse/graphite-api
graphite_api/functions.py
powSeries
def powSeries(requestContext, *seriesLists): """ Takes two or more series and pows their points. A constant line may be used. Example:: &target=powSeries(Server.instance01.app.requests, Server.instance01.app.replies) """ if not seriesLists or not any(seriesLi...
python
def powSeries(requestContext, *seriesLists): if not seriesLists or not any(seriesLists): return [] seriesList, start, end, step = normalize(seriesLists) name = "powSeries(%s)" % ','.join([s.name for s in seriesList]) values = [] for row in zip_longest(*seriesList): first = True ...
[ "def", "powSeries", "(", "requestContext", ",", "*", "seriesLists", ")", ":", "if", "not", "seriesLists", "or", "not", "any", "(", "seriesLists", ")", ":", "return", "[", "]", "seriesList", ",", "start", ",", "end", ",", "step", "=", "normalize", "(", ...
Takes two or more series and pows their points. A constant line may be used. Example:: &target=powSeries(Server.instance01.app.requests, Server.instance01.app.replies)
[ "Takes", "two", "or", "more", "series", "and", "pows", "their", "points", ".", "A", "constant", "line", "may", "be", "used", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1050-L1079
2,340
brutasse/graphite-api
graphite_api/functions.py
squareRoot
def squareRoot(requestContext, seriesList): """ Takes one metric or a wildcard seriesList, and computes the square root of each datapoint. Example:: &target=squareRoot(Server.instance01.threads.busy) """ for series in seriesList: series.name = "squareRoot(%s)" % (series.name) ...
python
def squareRoot(requestContext, seriesList): for series in seriesList: series.name = "squareRoot(%s)" % (series.name) for i, value in enumerate(series): series[i] = safePow(value, 0.5) return seriesList
[ "def", "squareRoot", "(", "requestContext", ",", "seriesList", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"squareRoot(%s)\"", "%", "(", "series", ".", "name", ")", "for", "i", ",", "value", "in", "enumerate", "(", "...
Takes one metric or a wildcard seriesList, and computes the square root of each datapoint. Example:: &target=squareRoot(Server.instance01.threads.busy)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "and", "computes", "the", "square", "root", "of", "each", "datapoint", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1082-L1096
2,341
brutasse/graphite-api
graphite_api/functions.py
absolute
def absolute(requestContext, seriesList): """ Takes one metric or a wildcard seriesList and applies the mathematical abs function to each datapoint transforming it to its absolute value. Example:: &target=absolute(Server.instance01.threads.busy) &target=absolute(Server.instance*.thread...
python
def absolute(requestContext, seriesList): for series in seriesList: series.name = "absolute(%s)" % (series.name) series.pathExpression = series.name for i, value in enumerate(series): series[i] = safeAbs(value) return seriesList
[ "def", "absolute", "(", "requestContext", ",", "seriesList", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"absolute(%s)\"", "%", "(", "series", ".", "name", ")", "series", ".", "pathExpression", "=", "series", ".", "nam...
Takes one metric or a wildcard seriesList and applies the mathematical abs function to each datapoint transforming it to its absolute value. Example:: &target=absolute(Server.instance01.threads.busy) &target=absolute(Server.instance*.threads.busy)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "and", "applies", "the", "mathematical", "abs", "function", "to", "each", "datapoint", "transforming", "it", "to", "its", "absolute", "value", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1116-L1131
2,342
brutasse/graphite-api
graphite_api/functions.py
offset
def offset(requestContext, seriesList, factor): """ Takes one metric or a wildcard seriesList followed by a constant, and adds the constant to each datapoint. Example:: &target=offset(Server.instance01.threads.busy,10) """ for series in seriesList: series.name = "offset(%s,%g)...
python
def offset(requestContext, seriesList, factor): for series in seriesList: series.name = "offset(%s,%g)" % (series.name, float(factor)) series.pathExpression = series.name for i, value in enumerate(series): if value is not None: series[i] = value + factor retur...
[ "def", "offset", "(", "requestContext", ",", "seriesList", ",", "factor", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"offset(%s,%g)\"", "%", "(", "series", ".", "name", ",", "float", "(", "factor", ")", ")", "series...
Takes one metric or a wildcard seriesList followed by a constant, and adds the constant to each datapoint. Example:: &target=offset(Server.instance01.threads.busy,10)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "constant", "and", "adds", "the", "constant", "to", "each", "datapoint", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1134-L1150
2,343
brutasse/graphite-api
graphite_api/functions.py
offsetToZero
def offsetToZero(requestContext, seriesList): """ Offsets a metric or wildcard seriesList by subtracting the minimum value in the series from each datapoint. Useful to compare different series where the values in each series may be higher or lower on average but you're only interested in the re...
python
def offsetToZero(requestContext, seriesList): for series in seriesList: series.name = "offsetToZero(%s)" % (series.name) minimum = safeMin(series) for i, value in enumerate(series): if value is not None: series[i] = value - minimum return seriesList
[ "def", "offsetToZero", "(", "requestContext", ",", "seriesList", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "\"offsetToZero(%s)\"", "%", "(", "series", ".", "name", ")", "minimum", "=", "safeMin", "(", "series", ")", "f...
Offsets a metric or wildcard seriesList by subtracting the minimum value in the series from each datapoint. Useful to compare different series where the values in each series may be higher or lower on average but you're only interested in the relative difference. An example use case is for compari...
[ "Offsets", "a", "metric", "or", "wildcard", "seriesList", "by", "subtracting", "the", "minimum", "value", "in", "the", "series", "from", "each", "datapoint", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1153-L1187
2,344
brutasse/graphite-api
graphite_api/functions.py
consolidateBy
def consolidateBy(requestContext, seriesList, consolidationFunc): """ Takes one metric or a wildcard seriesList and a consolidation function name. Valid function names are 'sum', 'average', 'min', and 'max'. When a graph is drawn where width of the graph size in pixels is smaller than the numb...
python
def consolidateBy(requestContext, seriesList, consolidationFunc): for series in seriesList: # datalib will throw an exception, so it's not necessary to validate # here series.consolidationFunc = consolidationFunc series.name = 'consolidateBy(%s,"%s")' % (series.name, ...
[ "def", "consolidateBy", "(", "requestContext", ",", "seriesList", ",", "consolidationFunc", ")", ":", "for", "series", "in", "seriesList", ":", "# datalib will throw an exception, so it's not necessary to validate", "# here", "series", ".", "consolidationFunc", "=", "consol...
Takes one metric or a wildcard seriesList and a consolidation function name. Valid function names are 'sum', 'average', 'min', and 'max'. When a graph is drawn where width of the graph size in pixels is smaller than the number of datapoints to be graphed, Graphite consolidates the values to to pre...
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "and", "a", "consolidation", "function", "name", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1464-L1492
2,345
brutasse/graphite-api
graphite_api/functions.py
integral
def integral(requestContext, seriesList): """ This will show the sum over time, sort of like a continuous addition function. Useful for finding totals or trends in metrics that are collected per minute. Example:: &target=integral(company.sales.perMinute) This would start at zero on th...
python
def integral(requestContext, seriesList): results = [] for series in seriesList: newValues = [] current = 0.0 for val in series: if val is None: newValues.append(None) else: current += val newValues.append(current) ...
[ "def", "integral", "(", "requestContext", ",", "seriesList", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "newValues", "=", "[", "]", "current", "=", "0.0", "for", "val", "in", "series", ":", "if", "val", "is", "None", ...
This will show the sum over time, sort of like a continuous addition function. Useful for finding totals or trends in metrics that are collected per minute. Example:: &target=integral(company.sales.perMinute) This would start at zero on the left side of the graph, adding the sales each mi...
[ "This", "will", "show", "the", "sum", "over", "time", "sort", "of", "like", "a", "continuous", "addition", "function", ".", "Useful", "for", "finding", "totals", "or", "trends", "in", "metrics", "that", "are", "collected", "per", "minute", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1617-L1646
2,346
brutasse/graphite-api
graphite_api/functions.py
areaBetween
def areaBetween(requestContext, *seriesLists): """ Draws the vertical area in between the two series in seriesList. Useful for visualizing a range such as the minimum and maximum latency for a service. areaBetween expects **exactly one argument** that results in exactly two series (see example belo...
python
def areaBetween(requestContext, *seriesLists): if len(seriesLists) == 1: [seriesLists] = seriesLists assert len(seriesLists) == 2, ("areaBetween series argument must " "reference *exactly* 2 series") lower, upper = seriesLists if len(lower) == 1: [lower...
[ "def", "areaBetween", "(", "requestContext", ",", "*", "seriesLists", ")", ":", "if", "len", "(", "seriesLists", ")", "==", "1", ":", "[", "seriesLists", "]", "=", "seriesLists", "assert", "len", "(", "seriesLists", ")", "==", "2", ",", "(", "\"areaBetwe...
Draws the vertical area in between the two series in seriesList. Useful for visualizing a range such as the minimum and maximum latency for a service. areaBetween expects **exactly one argument** that results in exactly two series (see example below). The order of the lower and higher values series doe...
[ "Draws", "the", "vertical", "area", "in", "between", "the", "two", "series", "in", "seriesList", ".", "Useful", "for", "visualizing", "a", "range", "such", "as", "the", "minimum", "and", "maximum", "latency", "for", "a", "service", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1789-L1828
2,347
brutasse/graphite-api
graphite_api/functions.py
alias
def alias(requestContext, seriesList, newName): """ Takes one metric or a wildcard seriesList and a string in quotes. Prints the string instead of the metric name in the legend. Example:: &target=alias(Sales.widgets.largeBlue,"Large Blue Widgets") """ try: seriesList.name = ne...
python
def alias(requestContext, seriesList, newName): try: seriesList.name = newName except AttributeError: for series in seriesList: series.name = newName return seriesList
[ "def", "alias", "(", "requestContext", ",", "seriesList", ",", "newName", ")", ":", "try", ":", "seriesList", ".", "name", "=", "newName", "except", "AttributeError", ":", "for", "series", "in", "seriesList", ":", "series", ".", "name", "=", "newName", "re...
Takes one metric or a wildcard seriesList and a string in quotes. Prints the string instead of the metric name in the legend. Example:: &target=alias(Sales.widgets.largeBlue,"Large Blue Widgets")
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "and", "a", "string", "in", "quotes", ".", "Prints", "the", "string", "instead", "of", "the", "metric", "name", "in", "the", "legend", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1847-L1862
2,348
brutasse/graphite-api
graphite_api/functions.py
_getFirstPathExpression
def _getFirstPathExpression(name): """Returns the first metric path in an expression.""" tokens = grammar.parseString(name) pathExpression = None while pathExpression is None: if tokens.pathExpression: pathExpression = tokens.pathExpression elif tokens.expression: ...
python
def _getFirstPathExpression(name): tokens = grammar.parseString(name) pathExpression = None while pathExpression is None: if tokens.pathExpression: pathExpression = tokens.pathExpression elif tokens.expression: tokens = tokens.expression elif tokens.call: ...
[ "def", "_getFirstPathExpression", "(", "name", ")", ":", "tokens", "=", "grammar", ".", "parseString", "(", "name", ")", "pathExpression", "=", "None", "while", "pathExpression", "is", "None", ":", "if", "tokens", ".", "pathExpression", ":", "pathExpression", ...
Returns the first metric path in an expression.
[ "Returns", "the", "first", "metric", "path", "in", "an", "expression", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L1921-L1934
2,349
brutasse/graphite-api
graphite_api/functions.py
alpha
def alpha(requestContext, seriesList, alpha): """ Assigns the given alpha transparency setting to the series. Takes a float value between 0 and 1. """ for series in seriesList: series.options['alpha'] = alpha return seriesList
python
def alpha(requestContext, seriesList, alpha): for series in seriesList: series.options['alpha'] = alpha return seriesList
[ "def", "alpha", "(", "requestContext", ",", "seriesList", ",", "alpha", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "options", "[", "'alpha'", "]", "=", "alpha", "return", "seriesList" ]
Assigns the given alpha transparency setting to the series. Takes a float value between 0 and 1.
[ "Assigns", "the", "given", "alpha", "transparency", "setting", "to", "the", "series", ".", "Takes", "a", "float", "value", "between", "0", "and", "1", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2006-L2013
2,350
brutasse/graphite-api
graphite_api/functions.py
color
def color(requestContext, seriesList, theColor): """ Assigns the given color to the seriesList Example:: &target=color(collectd.hostname.cpu.0.user, 'green') &target=color(collectd.hostname.cpu.0.system, 'ff0000') &target=color(collectd.hostname.cpu.0.idle, 'gray') &target=...
python
def color(requestContext, seriesList, theColor): for series in seriesList: series.color = theColor return seriesList
[ "def", "color", "(", "requestContext", ",", "seriesList", ",", "theColor", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "color", "=", "theColor", "return", "seriesList" ]
Assigns the given color to the seriesList Example:: &target=color(collectd.hostname.cpu.0.user, 'green') &target=color(collectd.hostname.cpu.0.system, 'ff0000') &target=color(collectd.hostname.cpu.0.idle, 'gray') &target=color(collectd.hostname.cpu.0.idle, '6464ffaa')
[ "Assigns", "the", "given", "color", "to", "the", "seriesList" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2016-L2030
2,351
brutasse/graphite-api
graphite_api/functions.py
logarithm
def logarithm(requestContext, seriesList, base=10): """ Takes one metric or a wildcard seriesList, a base, and draws the y-axis in logarithmic format. If base is omitted, the function defaults to base 10. Example:: &target=log(carbon.agents.hostname.avgUpdateTime,2) """ results = [] ...
python
def logarithm(requestContext, seriesList, base=10): results = [] for series in seriesList: newValues = [] for val in series: if val is None: newValues.append(None) elif val <= 0: newValues.append(None) else: newV...
[ "def", "logarithm", "(", "requestContext", ",", "seriesList", ",", "base", "=", "10", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "newValues", "=", "[", "]", "for", "val", "in", "series", ":", "if", "val", "is", "Non...
Takes one metric or a wildcard seriesList, a base, and draws the y-axis in logarithmic format. If base is omitted, the function defaults to base 10. Example:: &target=log(carbon.agents.hostname.avgUpdateTime,2)
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "a", "base", "and", "draws", "the", "y", "-", "axis", "in", "logarithmic", "format", ".", "If", "base", "is", "omitted", "the", "function", "defaults", "to", "base", "10", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2065-L2090
2,352
brutasse/graphite-api
graphite_api/functions.py
maximumBelow
def maximumBelow(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a maximum value below n. Example:: &target=maximumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which alw...
python
def maximumBelow(requestContext, seriesList, n): results = [] for series in seriesList: val = safeMax(series) if val is None or val <= n: results.append(series) return results
[ "def", "maximumBelow", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "val", "=", "safeMax", "(", "series", ")", "if", "val", "is", "None", "or", "val", "<=", "n", ":"...
Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a maximum value below n. Example:: &target=maximumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which always sent less than 1000 packets/min.
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "constant", "n", ".", "Draws", "only", "the", "metrics", "with", "a", "maximum", "value", "below", "n", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2133-L2150
2,353
brutasse/graphite-api
graphite_api/functions.py
minimumBelow
def minimumBelow(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a minimum value below n. Example:: &target=minimumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which sen...
python
def minimumBelow(requestContext, seriesList, n): results = [] for series in seriesList: val = safeMin(series) if val is None or val <= n: results.append(series) return results
[ "def", "minimumBelow", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "val", "=", "safeMin", "(", "series", ")", "if", "val", "is", "None", "or", "val", "<=", "n", ":"...
Takes one metric or a wildcard seriesList followed by a constant n. Draws only the metrics with a minimum value below n. Example:: &target=minimumBelow(system.interface.eth*.packetsSent,1000) This would only display interfaces which sent at one point less than 1000 packets/min.
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "constant", "n", ".", "Draws", "only", "the", "metrics", "with", "a", "minimum", "value", "below", "n", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2153-L2170
2,354
brutasse/graphite-api
graphite_api/functions.py
highestMax
def highestMax(requestContext, seriesList, n=1): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the N metrics with the highest maximum value in the time period specified. Example:: &target=highestMax(server*.instance*.threads....
python
def highestMax(requestContext, seriesList, n=1): result_list = sorted(seriesList, key=lambda s: safeMax(s))[-n:] return sorted(result_list, key=lambda s: max(s), reverse=True)
[ "def", "highestMax", "(", "requestContext", ",", "seriesList", ",", "n", "=", "1", ")", ":", "result_list", "=", "sorted", "(", "seriesList", ",", "key", "=", "lambda", "s", ":", "safeMax", "(", "s", ")", ")", "[", "-", "n", ":", "]", "return", "so...
Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the N metrics with the highest maximum value in the time period specified. Example:: &target=highestMax(server*.instance*.threads.busy,5) Draws the top 5 servers who have had the most bu...
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "an", "integer", "N", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2189-L2205
2,355
brutasse/graphite-api
graphite_api/functions.py
currentAbove
def currentAbove(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics whose value is above N at the end of the time period specified. Example:: &target=currentAbove(server*.instance*.thread...
python
def currentAbove(requestContext, seriesList, n): results = [] for series in seriesList: val = safeLast(series) if val is not None and val >= n: results.append(series) return results
[ "def", "currentAbove", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "val", "=", "safeLast", "(", "series", ")", "if", "val", "is", "not", "None", "and", "val", ">=", ...
Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics whose value is above N at the end of the time period specified. Example:: &target=currentAbove(server*.instance*.threads.busy,50) Draws the servers with more than 50 busy thre...
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "an", "integer", "N", ".", "Out", "of", "all", "metrics", "passed", "draws", "only", "the", "metrics", "whose", "value", "is", "above", "N", "at", "the", "end", "of", "the",...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2224-L2242
2,356
brutasse/graphite-api
graphite_api/functions.py
averageAbove
def averageAbove(requestContext, seriesList, n): """ Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics with an average value above N for the time period specified. Example:: &target=averageAbove(server*.instance*.threads.b...
python
def averageAbove(requestContext, seriesList, n): results = [] for series in seriesList: val = safeAvg(series) if val is not None and val >= n: results.append(series) return results
[ "def", "averageAbove", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "val", "=", "safeAvg", "(", "series", ")", "if", "val", "is", "not", "None", "and", "val", ">=", ...
Takes one metric or a wildcard seriesList followed by an integer N. Out of all metrics passed, draws only the metrics with an average value above N for the time period specified. Example:: &target=averageAbove(server*.instance*.threads.busy,25) Draws the servers with average values above 25.
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "an", "integer", "N", ".", "Out", "of", "all", "metrics", "passed", "draws", "only", "the", "metrics", "with", "an", "average", "value", "above", "N", "for", "the", "time", ...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2298-L2316
2,357
brutasse/graphite-api
graphite_api/functions.py
nPercentile
def nPercentile(requestContext, seriesList, n): """Returns n-percent of each series in the seriesList.""" assert n, 'The requested percent is required to be greater than 0' results = [] for s in seriesList: # Create a sorted copy of the TimeSeries excluding None values in the # values l...
python
def nPercentile(requestContext, seriesList, n): assert n, 'The requested percent is required to be greater than 0' results = [] for s in seriesList: # Create a sorted copy of the TimeSeries excluding None values in the # values list. s_copy = TimeSeries(s.name, s.start, s.end, s.ste...
[ "def", "nPercentile", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "assert", "n", ",", "'The requested percent is required to be greater than 0'", "results", "=", "[", "]", "for", "s", "in", "seriesList", ":", "# Create a sorted copy of the TimeSeries e...
Returns n-percent of each series in the seriesList.
[ "Returns", "n", "-", "percent", "of", "each", "series", "in", "the", "seriesList", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2371-L2392
2,358
brutasse/graphite-api
graphite_api/functions.py
averageOutsidePercentile
def averageOutsidePercentile(requestContext, seriesList, n): """ Removes functions lying inside an average percentile interval """ averages = [safeAvg(s) for s in seriesList] if n < 50: n = 100 - n lowPercentile = _getPercentile(averages, 100 - n) highPercentile = _getPercentile(av...
python
def averageOutsidePercentile(requestContext, seriesList, n): averages = [safeAvg(s) for s in seriesList] if n < 50: n = 100 - n lowPercentile = _getPercentile(averages, 100 - n) highPercentile = _getPercentile(averages, n) return [s for s in seriesList if not lowPercentile < s...
[ "def", "averageOutsidePercentile", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "averages", "=", "[", "safeAvg", "(", "s", ")", "for", "s", "in", "seriesList", "]", "if", "n", "<", "50", ":", "n", "=", "100", "-", "n", "lowPercentile",...
Removes functions lying inside an average percentile interval
[ "Removes", "functions", "lying", "inside", "an", "average", "percentile", "interval" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2395-L2408
2,359
brutasse/graphite-api
graphite_api/functions.py
removeBetweenPercentile
def removeBetweenPercentile(requestContext, seriesList, n): """ Removes lines who do not have an value lying in the x-percentile of all the values at a moment """ if n < 50: n = 100 - n transposed = list(zip_longest(*seriesList)) lowPercentiles = [_getPercentile(col, 100-n) for col...
python
def removeBetweenPercentile(requestContext, seriesList, n): if n < 50: n = 100 - n transposed = list(zip_longest(*seriesList)) lowPercentiles = [_getPercentile(col, 100-n) for col in transposed] highPercentiles = [_getPercentile(col, n) for col in transposed] return [l for l in seriesList...
[ "def", "removeBetweenPercentile", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "if", "n", "<", "50", ":", "n", "=", "100", "-", "n", "transposed", "=", "list", "(", "zip_longest", "(", "*", "seriesList", ")", ")", "lowPercentiles", "=", ...
Removes lines who do not have an value lying in the x-percentile of all the values at a moment
[ "Removes", "lines", "who", "do", "not", "have", "an", "value", "lying", "in", "the", "x", "-", "percentile", "of", "all", "the", "values", "at", "a", "moment" ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2411-L2426
2,360
brutasse/graphite-api
graphite_api/functions.py
removeAboveValue
def removeAboveValue(requestContext, seriesList, n): """ Removes data above the given threshold from the series or list of series provided. Values above this threshold are assigned a value of None. """ for s in seriesList: s.name = 'removeAboveValue(%s, %g)' % (s.name, n) s.pathExpre...
python
def removeAboveValue(requestContext, seriesList, n): for s in seriesList: s.name = 'removeAboveValue(%s, %g)' % (s.name, n) s.pathExpression = s.name for (index, val) in enumerate(s): if val is None: continue if val > n: s[index] = None...
[ "def", "removeAboveValue", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "for", "s", "in", "seriesList", ":", "s", ".", "name", "=", "'removeAboveValue(%s, %g)'", "%", "(", "s", ".", "name", ",", "n", ")", "s", ".", "pathExpression", "=",...
Removes data above the given threshold from the series or list of series provided. Values above this threshold are assigned a value of None.
[ "Removes", "data", "above", "the", "given", "threshold", "from", "the", "series", "or", "list", "of", "series", "provided", ".", "Values", "above", "this", "threshold", "are", "assigned", "a", "value", "of", "None", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2450-L2464
2,361
brutasse/graphite-api
graphite_api/functions.py
removeBelowPercentile
def removeBelowPercentile(requestContext, seriesList, n): """ Removes data below the nth percentile from the series or list of series provided. Values below this percentile are assigned a value of None. """ for s in seriesList: s.name = 'removeBelowPercentile(%s, %g)' % (s.name, n) s...
python
def removeBelowPercentile(requestContext, seriesList, n): for s in seriesList: s.name = 'removeBelowPercentile(%s, %g)' % (s.name, n) s.pathExpression = s.name try: percentile = nPercentile(requestContext, [s], n)[0][0] except IndexError: continue for ...
[ "def", "removeBelowPercentile", "(", "requestContext", ",", "seriesList", ",", "n", ")", ":", "for", "s", "in", "seriesList", ":", "s", ".", "name", "=", "'removeBelowPercentile(%s, %g)'", "%", "(", "s", ".", "name", ",", "n", ")", "s", ".", "pathExpressio...
Removes data below the nth percentile from the series or list of series provided. Values below this percentile are assigned a value of None.
[ "Removes", "data", "below", "the", "nth", "percentile", "from", "the", "series", "or", "list", "of", "series", "provided", ".", "Values", "below", "this", "percentile", "are", "assigned", "a", "value", "of", "None", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2467-L2485
2,362
brutasse/graphite-api
graphite_api/functions.py
useSeriesAbove
def useSeriesAbove(requestContext, seriesList, value, search, replace): """ Compares the maximum of each series against the given `value`. If the series maximum is greater than `value`, the regular expression search and replace is applied against the series name to plot a related metric. e.g. given...
python
def useSeriesAbove(requestContext, seriesList, value, search, replace): newSeries = [] for series in seriesList: newname = re.sub(search, replace, series.name) if safeMax(series) > value: n = evaluateTarget(requestContext, newname) if n is not None and len(n) > 0: ...
[ "def", "useSeriesAbove", "(", "requestContext", ",", "seriesList", ",", "value", ",", "search", ",", "replace", ")", ":", "newSeries", "=", "[", "]", "for", "series", "in", "seriesList", ":", "newname", "=", "re", ".", "sub", "(", "search", ",", "replace...
Compares the maximum of each series against the given `value`. If the series maximum is greater than `value`, the regular expression search and replace is applied against the series name to plot a related metric. e.g. given useSeriesAbove(ganglia.metric1.reqs,10,'reqs','time'), the response time metric...
[ "Compares", "the", "maximum", "of", "each", "series", "against", "the", "given", "value", ".", "If", "the", "series", "maximum", "is", "greater", "than", "value", "the", "regular", "expression", "search", "and", "replace", "is", "applied", "against", "the", ...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2585-L2608
2,363
brutasse/graphite-api
graphite_api/functions.py
secondYAxis
def secondYAxis(requestContext, seriesList): """ Graph the series on the secondary Y axis. """ for series in seriesList: series.options['secondYAxis'] = True series.name = 'secondYAxis(%s)' % series.name return seriesList
python
def secondYAxis(requestContext, seriesList): for series in seriesList: series.options['secondYAxis'] = True series.name = 'secondYAxis(%s)' % series.name return seriesList
[ "def", "secondYAxis", "(", "requestContext", ",", "seriesList", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "options", "[", "'secondYAxis'", "]", "=", "True", "series", ".", "name", "=", "'secondYAxis(%s)'", "%", "series", ".", "name",...
Graph the series on the secondary Y axis.
[ "Graph", "the", "series", "on", "the", "secondary", "Y", "axis", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2731-L2738
2,364
brutasse/graphite-api
graphite_api/functions.py
holtWintersForecast
def holtWintersForecast(requestContext, seriesList): """ Performs a Holt-Winters forecast using the series as input data. Data from one week previous to the series is used to bootstrap the initial forecast. """ previewSeconds = 7 * 86400 # 7 days # ignore original data and pull new, including o...
python
def holtWintersForecast(requestContext, seriesList): previewSeconds = 7 * 86400 # 7 days # ignore original data and pull new, including our preview newContext = requestContext.copy() newContext['startTime'] = (requestContext['startTime'] - timedelta(seconds=previewSeconds...
[ "def", "holtWintersForecast", "(", "requestContext", ",", "seriesList", ")", ":", "previewSeconds", "=", "7", "*", "86400", "# 7 days", "# ignore original data and pull new, including our preview", "newContext", "=", "requestContext", ".", "copy", "(", ")", "newContext", ...
Performs a Holt-Winters forecast using the series as input data. Data from one week previous to the series is used to bootstrap the initial forecast.
[ "Performs", "a", "Holt", "-", "Winters", "forecast", "using", "the", "series", "as", "input", "data", ".", "Data", "from", "one", "week", "previous", "to", "the", "series", "is", "used", "to", "bootstrap", "the", "initial", "forecast", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2854-L2876
2,365
brutasse/graphite-api
graphite_api/functions.py
holtWintersConfidenceBands
def holtWintersConfidenceBands(requestContext, seriesList, delta=3): """ Performs a Holt-Winters forecast using the series as input data and plots upper and lower bands with the predicted forecast deviations. """ previewSeconds = 7 * 86400 # 7 days # ignore original data and pull new, including...
python
def holtWintersConfidenceBands(requestContext, seriesList, delta=3): previewSeconds = 7 * 86400 # 7 days # ignore original data and pull new, including our preview newContext = requestContext.copy() newContext['startTime'] = (requestContext['startTime'] - timedelta(second...
[ "def", "holtWintersConfidenceBands", "(", "requestContext", ",", "seriesList", ",", "delta", "=", "3", ")", ":", "previewSeconds", "=", "7", "*", "86400", "# 7 days", "# ignore original data and pull new, including our preview", "newContext", "=", "requestContext", ".", ...
Performs a Holt-Winters forecast using the series as input data and plots upper and lower bands with the predicted forecast deviations.
[ "Performs", "a", "Holt", "-", "Winters", "forecast", "using", "the", "series", "as", "input", "data", "and", "plots", "upper", "and", "lower", "bands", "with", "the", "predicted", "forecast", "deviations", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2879-L2932
2,366
brutasse/graphite-api
graphite_api/functions.py
holtWintersAberration
def holtWintersAberration(requestContext, seriesList, delta=3): """ Performs a Holt-Winters forecast using the series as input data and plots the positive or negative deviation of the series data from the forecast. """ results = [] for series in seriesList: confidenceBands = holtWintersC...
python
def holtWintersAberration(requestContext, seriesList, delta=3): results = [] for series in seriesList: confidenceBands = holtWintersConfidenceBands(requestContext, [series], delta) lowerBand = confidenceBands[0] upperBand = confidenceB...
[ "def", "holtWintersAberration", "(", "requestContext", ",", "seriesList", ",", "delta", "=", "3", ")", ":", "results", "=", "[", "]", "for", "series", "in", "seriesList", ":", "confidenceBands", "=", "holtWintersConfidenceBands", "(", "requestContext", ",", "[",...
Performs a Holt-Winters forecast using the series as input data and plots the positive or negative deviation of the series data from the forecast.
[ "Performs", "a", "Holt", "-", "Winters", "forecast", "using", "the", "series", "as", "input", "data", "and", "plots", "the", "positive", "or", "negative", "deviation", "of", "the", "series", "data", "from", "the", "forecast", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2935-L2960
2,367
brutasse/graphite-api
graphite_api/functions.py
holtWintersConfidenceArea
def holtWintersConfidenceArea(requestContext, seriesList, delta=3): """ Performs a Holt-Winters forecast using the series as input data and plots the area between the upper and lower bands of the predicted forecast deviations. """ bands = holtWintersConfidenceBands(requestContext, seriesList, de...
python
def holtWintersConfidenceArea(requestContext, seriesList, delta=3): bands = holtWintersConfidenceBands(requestContext, seriesList, delta) results = areaBetween(requestContext, bands) for series in results: series.name = series.name.replace('areaBetween', 'ho...
[ "def", "holtWintersConfidenceArea", "(", "requestContext", ",", "seriesList", ",", "delta", "=", "3", ")", ":", "bands", "=", "holtWintersConfidenceBands", "(", "requestContext", ",", "seriesList", ",", "delta", ")", "results", "=", "areaBetween", "(", "requestCon...
Performs a Holt-Winters forecast using the series as input data and plots the area between the upper and lower bands of the predicted forecast deviations.
[ "Performs", "a", "Holt", "-", "Winters", "forecast", "using", "the", "series", "as", "input", "data", "and", "plots", "the", "area", "between", "the", "upper", "and", "lower", "bands", "of", "the", "predicted", "forecast", "deviations", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2963-L2974
2,368
brutasse/graphite-api
graphite_api/functions.py
linearRegressionAnalysis
def linearRegressionAnalysis(series): """ Returns factor and offset of linear regression function by least squares method. """ n = safeLen(series) sumI = sum([i for i, v in enumerate(series) if v is not None]) sumV = sum([v for i, v in enumerate(series) if v is not None]) sumII = sum([i...
python
def linearRegressionAnalysis(series): n = safeLen(series) sumI = sum([i for i, v in enumerate(series) if v is not None]) sumV = sum([v for i, v in enumerate(series) if v is not None]) sumII = sum([i * i for i, v in enumerate(series) if v is not None]) sumIV = sum([i * v for i, v in enumerate(series)...
[ "def", "linearRegressionAnalysis", "(", "series", ")", ":", "n", "=", "safeLen", "(", "series", ")", "sumI", "=", "sum", "(", "[", "i", "for", "i", ",", "v", "in", "enumerate", "(", "series", ")", "if", "v", "is", "not", "None", "]", ")", "sumV", ...
Returns factor and offset of linear regression function by least squares method.
[ "Returns", "factor", "and", "offset", "of", "linear", "regression", "function", "by", "least", "squares", "method", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2977-L2995
2,369
brutasse/graphite-api
graphite_api/functions.py
linearRegression
def linearRegression(requestContext, seriesList, startSourceAt=None, endSourceAt=None): """ Graphs the liner regression function by least squares method. Takes one metric or a wildcard seriesList, followed by a quoted string with the time to start the line and another quoted string...
python
def linearRegression(requestContext, seriesList, startSourceAt=None, endSourceAt=None): from .app import evaluateTarget results = [] sourceContext = requestContext.copy() if startSourceAt is not None: sourceContext['startTime'] = parseATTime(startSourceAt) if endSourceAt...
[ "def", "linearRegression", "(", "requestContext", ",", "seriesList", ",", "startSourceAt", "=", "None", ",", "endSourceAt", "=", "None", ")", ":", "from", ".", "app", "import", "evaluateTarget", "results", "=", "[", "]", "sourceContext", "=", "requestContext", ...
Graphs the liner regression function by least squares method. Takes one metric or a wildcard seriesList, followed by a quoted string with the time to start the line and another quoted string with the time to end the line. The start and end times are inclusive (default range is from to until). See ``fro...
[ "Graphs", "the", "liner", "regression", "function", "by", "least", "squares", "method", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L2998-L3044
2,370
brutasse/graphite-api
graphite_api/functions.py
drawAsInfinite
def drawAsInfinite(requestContext, seriesList): """ Takes one metric or a wildcard seriesList. If the value is zero, draw the line at 0. If the value is above zero, draw the line at infinity. If the value is null or less than zero, do not draw the line. Useful for displaying on/off metrics, suc...
python
def drawAsInfinite(requestContext, seriesList): for series in seriesList: series.options['drawAsInfinite'] = True series.name = 'drawAsInfinite(%s)' % series.name return seriesList
[ "def", "drawAsInfinite", "(", "requestContext", ",", "seriesList", ")", ":", "for", "series", "in", "seriesList", ":", "series", ".", "options", "[", "'drawAsInfinite'", "]", "=", "True", "series", ".", "name", "=", "'drawAsInfinite(%s)'", "%", "series", ".", ...
Takes one metric or a wildcard seriesList. If the value is zero, draw the line at 0. If the value is above zero, draw the line at infinity. If the value is null or less than zero, do not draw the line. Useful for displaying on/off metrics, such as exit codes. (0 = success, anything else = failure.)...
[ "Takes", "one", "metric", "or", "a", "wildcard", "seriesList", ".", "If", "the", "value", "is", "zero", "draw", "the", "line", "at", "0", ".", "If", "the", "value", "is", "above", "zero", "draw", "the", "line", "at", "infinity", ".", "If", "the", "va...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3047-L3065
2,371
brutasse/graphite-api
graphite_api/functions.py
constantLine
def constantLine(requestContext, value): """ Takes a float F. Draws a horizontal line at value F across the graph. Example:: &target=constantLine(123.456) """ name = "constantLine(%s)" % str(value) start = int(epoch(requestContext['startTime'])) end = int(epoch(requestContext...
python
def constantLine(requestContext, value): name = "constantLine(%s)" % str(value) start = int(epoch(requestContext['startTime'])) end = int(epoch(requestContext['endTime'])) step = int((end - start) / 2.0) series = TimeSeries(str(value), start, end, step, [value, value, value]) series.pathExpressi...
[ "def", "constantLine", "(", "requestContext", ",", "value", ")", ":", "name", "=", "\"constantLine(%s)\"", "%", "str", "(", "value", ")", "start", "=", "int", "(", "epoch", "(", "requestContext", "[", "'startTime'", "]", ")", ")", "end", "=", "int", "(",...
Takes a float F. Draws a horizontal line at value F across the graph. Example:: &target=constantLine(123.456)
[ "Takes", "a", "float", "F", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3278-L3295
2,372
brutasse/graphite-api
graphite_api/functions.py
aggregateLine
def aggregateLine(requestContext, seriesList, func='avg'): """ Takes a metric or wildcard seriesList and draws a horizontal line based on the function applied to each series. Note: By default, the graphite renderer consolidates data points by averaging data points over time. If you are using the 'm...
python
def aggregateLine(requestContext, seriesList, func='avg'): t_funcs = {'avg': safeAvg, 'min': safeMin, 'max': safeMax} if func not in t_funcs: raise ValueError("Invalid function %s" % func) results = [] for series in seriesList: value = t_funcs[func](series) if value is not None...
[ "def", "aggregateLine", "(", "requestContext", ",", "seriesList", ",", "func", "=", "'avg'", ")", ":", "t_funcs", "=", "{", "'avg'", ":", "safeAvg", ",", "'min'", ":", "safeMin", ",", "'max'", ":", "safeMax", "}", "if", "func", "not", "in", "t_funcs", ...
Takes a metric or wildcard seriesList and draws a horizontal line based on the function applied to each series. Note: By default, the graphite renderer consolidates data points by averaging data points over time. If you are using the 'min' or 'max' function for aggregateLine, this can cause an unusual ...
[ "Takes", "a", "metric", "or", "wildcard", "seriesList", "and", "draws", "a", "horizontal", "line", "based", "on", "the", "function", "applied", "to", "each", "series", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3298-L3335
2,373
brutasse/graphite-api
graphite_api/functions.py
verticalLine
def verticalLine(requestContext, ts, label=None, color=None): """ Takes a timestamp string ts. Draws a vertical line at the designated timestamp with optional 'label' and 'color'. Supported timestamp formats include both relative (e.g. -3h) and absolute (e.g. 16:00_20110501) strings, such as th...
python
def verticalLine(requestContext, ts, label=None, color=None): ts = int(epoch(parseATTime(ts, requestContext['tzinfo']))) start = int(epoch(requestContext['startTime'])) end = int(epoch(requestContext['endTime'])) if ts < start: raise ValueError("verticalLine(): timestamp %s exists " ...
[ "def", "verticalLine", "(", "requestContext", ",", "ts", ",", "label", "=", "None", ",", "color", "=", "None", ")", ":", "ts", "=", "int", "(", "epoch", "(", "parseATTime", "(", "ts", ",", "requestContext", "[", "'tzinfo'", "]", ")", ")", ")", "start...
Takes a timestamp string ts. Draws a vertical line at the designated timestamp with optional 'label' and 'color'. Supported timestamp formats include both relative (e.g. -3h) and absolute (e.g. 16:00_20110501) strings, such as those used with ``from`` and ``until`` parameters. When set, the 'label'...
[ "Takes", "a", "timestamp", "string", "ts", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3338-L3373
2,374
brutasse/graphite-api
graphite_api/functions.py
transformNull
def transformNull(requestContext, seriesList, default=0, referenceSeries=None): """ Takes a metric or wildcard seriesList and replaces null values with the value specified by `default`. The value 0 used if not specified. The optional referenceSeries, if specified, is a metric or wildcard series lis...
python
def transformNull(requestContext, seriesList, default=0, referenceSeries=None): def transform(v, d): if v is None: return d else: return v if referenceSeries: defaults = [default if any(v is not None for v in x) else None for x in zip_longest(...
[ "def", "transformNull", "(", "requestContext", ",", "seriesList", ",", "default", "=", "0", ",", "referenceSeries", "=", "None", ")", ":", "def", "transform", "(", "v", ",", "d", ")", ":", "if", "v", "is", "None", ":", "return", "d", "else", ":", "re...
Takes a metric or wildcard seriesList and replaces null values with the value specified by `default`. The value 0 used if not specified. The optional referenceSeries, if specified, is a metric or wildcard series list that governs which time intervals nulls should be replaced. If specified, nulls are re...
[ "Takes", "a", "metric", "or", "wildcard", "seriesList", "and", "replaces", "null", "values", "with", "the", "value", "specified", "by", "default", ".", "The", "value", "0", "used", "if", "not", "specified", ".", "The", "optional", "referenceSeries", "if", "s...
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3396-L3440
2,375
brutasse/graphite-api
graphite_api/functions.py
countSeries
def countSeries(requestContext, *seriesLists): """ Draws a horizontal line representing the number of nodes found in the seriesList. Example:: &target=countSeries(carbon.agents.*.*) """ if not seriesLists or not any(seriesLists): series = constantLine(requestContext, 0).pop() ...
python
def countSeries(requestContext, *seriesLists): if not seriesLists or not any(seriesLists): series = constantLine(requestContext, 0).pop() series.pathExpression = "countSeries()" else: seriesList, start, end, step = normalize(seriesLists) name = "countSeries(%s)" % formatPathExpre...
[ "def", "countSeries", "(", "requestContext", ",", "*", "seriesLists", ")", ":", "if", "not", "seriesLists", "or", "not", "any", "(", "seriesLists", ")", ":", "series", "=", "constantLine", "(", "requestContext", ",", "0", ")", ".", "pop", "(", ")", "seri...
Draws a horizontal line representing the number of nodes found in the seriesList. Example:: &target=countSeries(carbon.agents.*.*)
[ "Draws", "a", "horizontal", "line", "representing", "the", "number", "of", "nodes", "found", "in", "the", "seriesList", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3499-L3519
2,376
brutasse/graphite-api
graphite_api/functions.py
group
def group(requestContext, *seriesLists): """ Takes an arbitrary number of seriesLists and adds them to a single seriesList. This is used to pass multiple seriesLists to a function which only takes one. """ seriesGroup = [] for s in seriesLists: seriesGroup.extend(s) return serie...
python
def group(requestContext, *seriesLists): seriesGroup = [] for s in seriesLists: seriesGroup.extend(s) return seriesGroup
[ "def", "group", "(", "requestContext", ",", "*", "seriesLists", ")", ":", "seriesGroup", "=", "[", "]", "for", "s", "in", "seriesLists", ":", "seriesGroup", ".", "extend", "(", "s", ")", "return", "seriesGroup" ]
Takes an arbitrary number of seriesLists and adds them to a single seriesList. This is used to pass multiple seriesLists to a function which only takes one.
[ "Takes", "an", "arbitrary", "number", "of", "seriesLists", "and", "adds", "them", "to", "a", "single", "seriesList", ".", "This", "is", "used", "to", "pass", "multiple", "seriesLists", "to", "a", "function", "which", "only", "takes", "one", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3522-L3532
2,377
brutasse/graphite-api
graphite_api/functions.py
groupByNode
def groupByNode(requestContext, seriesList, nodeNum, callback): """ Takes a serieslist and maps a callback to subgroups within as defined by a common node. Example:: &target=groupByNode(ganglia.by-function.*.*.cpu.load5,2,"sumSeries") Would return multiple series which are each the result...
python
def groupByNode(requestContext, seriesList, nodeNum, callback): return groupByNodes(requestContext, seriesList, callback, nodeNum)
[ "def", "groupByNode", "(", "requestContext", ",", "seriesList", ",", "nodeNum", ",", "callback", ")", ":", "return", "groupByNodes", "(", "requestContext", ",", "seriesList", ",", "callback", ",", "nodeNum", ")" ]
Takes a serieslist and maps a callback to subgroups within as defined by a common node. Example:: &target=groupByNode(ganglia.by-function.*.*.cpu.load5,2,"sumSeries") Would return multiple series which are each the result of applying the "sumSeries" function to groups joined on the second nod...
[ "Takes", "a", "serieslist", "and", "maps", "a", "callback", "to", "subgroups", "within", "as", "defined", "by", "a", "common", "node", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3680-L3697
2,378
brutasse/graphite-api
graphite_api/functions.py
groupByNodes
def groupByNodes(requestContext, seriesList, callback, *nodes): """ Takes a serieslist and maps a callback to subgroups within as defined by multiple nodes. Example:: &target=groupByNodes(ganglia.server*.*.cpu.load*,"sumSeries",1,4) Would return multiple series which are each the result o...
python
def groupByNodes(requestContext, seriesList, callback, *nodes): from .app import app metaSeries = {} keys = [] if isinstance(nodes, int): nodes = [nodes] for series in seriesList: key = '.'.join(series.name.split(".")[n] for n in nodes) if key not in metaSeries: m...
[ "def", "groupByNodes", "(", "requestContext", ",", "seriesList", ",", "callback", ",", "*", "nodes", ")", ":", "from", ".", "app", "import", "app", "metaSeries", "=", "{", "}", "keys", "=", "[", "]", "if", "isinstance", "(", "nodes", ",", "int", ")", ...
Takes a serieslist and maps a callback to subgroups within as defined by multiple nodes. Example:: &target=groupByNodes(ganglia.server*.*.cpu.load*,"sumSeries",1,4) Would return multiple series which are each the result of applying the "sumSeries" function to groups joined on the nodes' list ...
[ "Takes", "a", "serieslist", "and", "maps", "a", "callback", "to", "subgroups", "within", "as", "defined", "by", "multiple", "nodes", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3700-L3737
2,379
brutasse/graphite-api
graphite_api/functions.py
exclude
def exclude(requestContext, seriesList, pattern): """ Takes a metric or a wildcard seriesList, followed by a regular expression in double quotes. Excludes metrics that match the regular expression. Example:: &target=exclude(servers*.instance*.threads.busy,"server02") """ regex = re....
python
def exclude(requestContext, seriesList, pattern): regex = re.compile(pattern) return [s for s in seriesList if not regex.search(s.name)]
[ "def", "exclude", "(", "requestContext", ",", "seriesList", ",", "pattern", ")", ":", "regex", "=", "re", ".", "compile", "(", "pattern", ")", "return", "[", "s", "for", "s", "in", "seriesList", "if", "not", "regex", ".", "search", "(", "s", ".", "na...
Takes a metric or a wildcard seriesList, followed by a regular expression in double quotes. Excludes metrics that match the regular expression. Example:: &target=exclude(servers*.instance*.threads.busy,"server02")
[ "Takes", "a", "metric", "or", "a", "wildcard", "seriesList", "followed", "by", "a", "regular", "expression", "in", "double", "quotes", ".", "Excludes", "metrics", "that", "match", "the", "regular", "expression", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3740-L3750
2,380
brutasse/graphite-api
graphite_api/functions.py
summarize
def summarize(requestContext, seriesList, intervalString, func='sum', alignToFrom=False): """ Summarize the data into interval buckets of a certain size. By default, the contents of each interval bucket are summed together. This is useful for counters where each increment represents a dis...
python
def summarize(requestContext, seriesList, intervalString, func='sum', alignToFrom=False): results = [] delta = parseTimeOffset(intervalString) interval = to_seconds(delta) for series in seriesList: buckets = {} timestamps = range(int(series.start), int(series.end) + 1, ...
[ "def", "summarize", "(", "requestContext", ",", "seriesList", ",", "intervalString", ",", "func", "=", "'sum'", ",", "alignToFrom", "=", "False", ")", ":", "results", "=", "[", "]", "delta", "=", "parseTimeOffset", "(", "intervalString", ")", "interval", "="...
Summarize the data into interval buckets of a certain size. By default, the contents of each interval bucket are summed together. This is useful for counters where each increment represents a discrete event and retrieving a "per X" value requires summing all the events in that interval. Specifying...
[ "Summarize", "the", "data", "into", "interval", "buckets", "of", "a", "certain", "size", "." ]
0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff
https://github.com/brutasse/graphite-api/blob/0886b7adcf985a1e8bcb084f6dd1dc166a3f3dff/graphite_api/functions.py#L3857-L3963
2,381
opencobra/memote
memote/experimental/medium.py
Medium.apply
def apply(self, model): """Set the defined medium on the given model.""" model.medium = {row.exchange: row.uptake for row in self.data.itertuples(index=False)}
python
def apply(self, model): model.medium = {row.exchange: row.uptake for row in self.data.itertuples(index=False)}
[ "def", "apply", "(", "self", ",", "model", ")", ":", "model", ".", "medium", "=", "{", "row", ".", "exchange", ":", "row", ".", "uptake", "for", "row", "in", "self", ".", "data", ".", "itertuples", "(", "index", "=", "False", ")", "}" ]
Set the defined medium on the given model.
[ "Set", "the", "defined", "medium", "on", "the", "given", "model", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/medium.py#L56-L59
2,382
opencobra/memote
memote/suite/results/result.py
MemoteResult.add_environment_information
def add_environment_information(meta): """Record environment information.""" meta["timestamp"] = datetime.utcnow().isoformat(" ") meta["platform"] = platform.system() meta["release"] = platform.release() meta["python"] = platform.python_version() meta["packages"] = get_pk...
python
def add_environment_information(meta): meta["timestamp"] = datetime.utcnow().isoformat(" ") meta["platform"] = platform.system() meta["release"] = platform.release() meta["python"] = platform.python_version() meta["packages"] = get_pkg_info("memote")
[ "def", "add_environment_information", "(", "meta", ")", ":", "meta", "[", "\"timestamp\"", "]", "=", "datetime", ".", "utcnow", "(", ")", ".", "isoformat", "(", "\" \"", ")", "meta", "[", "\"platform\"", "]", "=", "platform", ".", "system", "(", ")", "me...
Record environment information.
[ "Record", "environment", "information", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/result.py#L46-L52
2,383
opencobra/memote
memote/support/helpers.py
find_transported_elements
def find_transported_elements(rxn): """ Return a dictionary showing the amount of transported elements of a rxn. Collects the elements for each metabolite participating in a reaction, multiplies the amount by the metabolite's stoichiometry in the reaction and bins the result according to the compar...
python
def find_transported_elements(rxn): element_dist = defaultdict() # Collecting elements for each metabolite. for met in rxn.metabolites: if met.compartment not in element_dist: # Multiplication by the metabolite stoichiometry. element_dist[met.compartment] = \ ...
[ "def", "find_transported_elements", "(", "rxn", ")", ":", "element_dist", "=", "defaultdict", "(", ")", "# Collecting elements for each metabolite.", "for", "met", "in", "rxn", ".", "metabolites", ":", "if", "met", ".", "compartment", "not", "in", "element_dist", ...
Return a dictionary showing the amount of transported elements of a rxn. Collects the elements for each metabolite participating in a reaction, multiplies the amount by the metabolite's stoichiometry in the reaction and bins the result according to the compartment that metabolite is in. This produces a...
[ "Return", "a", "dictionary", "showing", "the", "amount", "of", "transported", "elements", "of", "a", "rxn", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L81-L120
2,384
opencobra/memote
memote/support/helpers.py
find_transport_reactions
def find_transport_reactions(model): """ Return a list of all transport reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- A transport reaction is defined as follows: 1. It contains metabolites from at least 2 compartme...
python
def find_transport_reactions(model): transport_reactions = [] transport_rxn_candidates = set(model.reactions) - set(model.boundary) \ - set(find_biomass_reaction(model)) transport_rxn_candidates = set( [rxn for rxn in transport_rxn_candidates if len(rxn.compartments) >= 2] ) # Add al...
[ "def", "find_transport_reactions", "(", "model", ")", ":", "transport_reactions", "=", "[", "]", "transport_rxn_candidates", "=", "set", "(", "model", ".", "reactions", ")", "-", "set", "(", "model", ".", "boundary", ")", "-", "set", "(", "find_biomass_reactio...
Return a list of all transport reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- A transport reaction is defined as follows: 1. It contains metabolites from at least 2 compartments and 2. at least 1 metabolite undergoes no...
[ "Return", "a", "list", "of", "all", "transport", "reactions", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L124-L181
2,385
opencobra/memote
memote/support/helpers.py
find_converting_reactions
def find_converting_reactions(model, pair): """ Find all reactions which convert a given metabolite pair. Parameters ---------- model : cobra.Model The metabolic model under investigation. pair: tuple or list A pair of metabolite identifiers without compartment suffix. Retu...
python
def find_converting_reactions(model, pair): first = set(find_met_in_model(model, pair[0])) second = set(find_met_in_model(model, pair[1])) hits = list() for rxn in model.reactions: # FIXME: Use `set.issubset` much more idiomatic. if len(first & set(rxn.reactants)) > 0 and len( ...
[ "def", "find_converting_reactions", "(", "model", ",", "pair", ")", ":", "first", "=", "set", "(", "find_met_in_model", "(", "model", ",", "pair", "[", "0", "]", ")", ")", "second", "=", "set", "(", "find_met_in_model", "(", "model", ",", "pair", "[", ...
Find all reactions which convert a given metabolite pair. Parameters ---------- model : cobra.Model The metabolic model under investigation. pair: tuple or list A pair of metabolite identifiers without compartment suffix. Returns ------- frozenset The set of reactio...
[ "Find", "all", "reactions", "which", "convert", "a", "given", "metabolite", "pair", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L249-L278
2,386
opencobra/memote
memote/support/helpers.py
find_demand_reactions
def find_demand_reactions(model): u""" Return a list of demand reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines demand reactions as: -- 'unbalanced network reactions that allow the accumulation of a compou...
python
def find_demand_reactions(model): u""" Return a list of demand reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines demand reactions as: -- 'unbalanced network reactions that allow the accumulation of a compou...
[ "def", "find_demand_reactions", "(", "model", ")", ":", "try", ":", "extracellular", "=", "find_compartment_id_in_model", "(", "model", ",", "'e'", ")", "except", "KeyError", ":", "extracellular", "=", "None", "return", "find_boundary_types", "(", "model", ",", ...
u""" Return a list of demand reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines demand reactions as: -- 'unbalanced network reactions that allow the accumulation of a compound' -- reactions that are chiefly ...
[ "u", "Return", "a", "list", "of", "demand", "reactions", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L337-L373
2,387
opencobra/memote
memote/support/helpers.py
find_sink_reactions
def find_sink_reactions(model): u""" Return a list of sink reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines sink reactions as: -- 'similar to demand reactions' but reversible, thus able to supply the m...
python
def find_sink_reactions(model): u""" Return a list of sink reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines sink reactions as: -- 'similar to demand reactions' but reversible, thus able to supply the m...
[ "def", "find_sink_reactions", "(", "model", ")", ":", "try", ":", "extracellular", "=", "find_compartment_id_in_model", "(", "model", ",", "'e'", ")", "except", "KeyError", ":", "extracellular", "=", "None", "return", "find_boundary_types", "(", "model", ",", "'...
u""" Return a list of sink reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines sink reactions as: -- 'similar to demand reactions' but reversible, thus able to supply the model with metabolites -- reactio...
[ "u", "Return", "a", "list", "of", "sink", "reactions", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L377-L412
2,388
opencobra/memote
memote/support/helpers.py
find_exchange_rxns
def find_exchange_rxns(model): u""" Return a list of exchange reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines exchange reactions as: -- reactions that 'define the extracellular environment' -- 'unbala...
python
def find_exchange_rxns(model): u""" Return a list of exchange reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines exchange reactions as: -- reactions that 'define the extracellular environment' -- 'unbala...
[ "def", "find_exchange_rxns", "(", "model", ")", ":", "try", ":", "extracellular", "=", "find_compartment_id_in_model", "(", "model", ",", "'e'", ")", "except", "KeyError", ":", "extracellular", "=", "None", "return", "find_boundary_types", "(", "model", ",", "'e...
u""" Return a list of exchange reactions. Parameters ---------- model : cobra.Model The metabolic model under investigation. Notes ----- [1] defines exchange reactions as: -- reactions that 'define the extracellular environment' -- 'unbalanced, extra-organism reactions that...
[ "u", "Return", "a", "list", "of", "exchange", "reactions", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L416-L450
2,389
opencobra/memote
memote/support/helpers.py
find_interchange_biomass_reactions
def find_interchange_biomass_reactions(model, biomass=None): """ Return the set of all transport, boundary, and biomass reactions. These reactions are either pseudo-reactions, or incorporated to allow metabolites to pass between compartments. Some tests focus on purely metabolic reactions and hence...
python
def find_interchange_biomass_reactions(model, biomass=None): boundary = set(model.boundary) transporters = find_transport_reactions(model) if biomass is None: biomass = set(find_biomass_reaction(model)) return boundary | transporters | biomass
[ "def", "find_interchange_biomass_reactions", "(", "model", ",", "biomass", "=", "None", ")", ":", "boundary", "=", "set", "(", "model", ".", "boundary", ")", "transporters", "=", "find_transport_reactions", "(", "model", ")", "if", "biomass", "is", "None", ":"...
Return the set of all transport, boundary, and biomass reactions. These reactions are either pseudo-reactions, or incorporated to allow metabolites to pass between compartments. Some tests focus on purely metabolic reactions and hence exclude this set. Parameters ---------- model : cobra.Model...
[ "Return", "the", "set", "of", "all", "transport", "boundary", "and", "biomass", "reactions", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L453-L473
2,390
opencobra/memote
memote/support/helpers.py
run_fba
def run_fba(model, rxn_id, direction="max", single_value=True): """ Return the solution of an FBA to a set objective function. Parameters ---------- model : cobra.Model The metabolic model under investigation. rxn_id : string A string containing the reaction ID of the desired FB...
python
def run_fba(model, rxn_id, direction="max", single_value=True): model.objective = model.reactions.get_by_id(rxn_id) model.objective_direction = direction if single_value: try: return model.slim_optimize() except Infeasible: return np.nan else: try: ...
[ "def", "run_fba", "(", "model", ",", "rxn_id", ",", "direction", "=", "\"max\"", ",", "single_value", "=", "True", ")", ":", "model", ".", "objective", "=", "model", ".", "reactions", ".", "get_by_id", "(", "rxn_id", ")", "model", ".", "objective_direction...
Return the solution of an FBA to a set objective function. Parameters ---------- model : cobra.Model The metabolic model under investigation. rxn_id : string A string containing the reaction ID of the desired FBA objective. direction: string A string containing either "max" ...
[ "Return", "the", "solution", "of", "an", "FBA", "to", "a", "set", "objective", "function", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L476-L511
2,391
opencobra/memote
memote/support/helpers.py
close_boundaries_sensibly
def close_boundaries_sensibly(model): """ Return a cobra model with all boundaries closed and changed constraints. In the returned model previously fixed reactions are no longer constrained as such. Instead reactions are constrained according to their reversibility. This is to prevent the FBA from ...
python
def close_boundaries_sensibly(model): for rxn in model.reactions: if rxn.reversibility: rxn.bounds = -1, 1 else: rxn.bounds = 0, 1 for boundary in model.boundary: boundary.bounds = (0, 0)
[ "def", "close_boundaries_sensibly", "(", "model", ")", ":", "for", "rxn", "in", "model", ".", "reactions", ":", "if", "rxn", ".", "reversibility", ":", "rxn", ".", "bounds", "=", "-", "1", ",", "1", "else", ":", "rxn", ".", "bounds", "=", "0", ",", ...
Return a cobra model with all boundaries closed and changed constraints. In the returned model previously fixed reactions are no longer constrained as such. Instead reactions are constrained according to their reversibility. This is to prevent the FBA from becoming infeasible when trying to solve a mod...
[ "Return", "a", "cobra", "model", "with", "all", "boundaries", "closed", "and", "changed", "constraints", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L514-L541
2,392
opencobra/memote
memote/support/helpers.py
metabolites_per_compartment
def metabolites_per_compartment(model, compartment_id): """ Identify all metabolites that belong to a given compartment. Parameters ---------- model : cobra.Model The metabolic model under investigation. compartment_id : string Model specific compartment identifier. Returns...
python
def metabolites_per_compartment(model, compartment_id): return [met for met in model.metabolites if met.compartment == compartment_id]
[ "def", "metabolites_per_compartment", "(", "model", ",", "compartment_id", ")", ":", "return", "[", "met", "for", "met", "in", "model", ".", "metabolites", "if", "met", ".", "compartment", "==", "compartment_id", "]" ]
Identify all metabolites that belong to a given compartment. Parameters ---------- model : cobra.Model The metabolic model under investigation. compartment_id : string Model specific compartment identifier. Returns ------- list List of metabolites belonging to a giv...
[ "Identify", "all", "metabolites", "that", "belong", "to", "a", "given", "compartment", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L572-L590
2,393
opencobra/memote
memote/support/helpers.py
largest_compartment_id_met
def largest_compartment_id_met(model): """ Return the ID of the compartment with the most metabolites. Parameters ---------- model : cobra.Model The metabolic model under investigation. Returns ------- string Compartment ID of the compartment with the most metabolites. ...
python
def largest_compartment_id_met(model): # Sort compartments by decreasing size and extract the largest two. candidate, second = sorted( ((c, len(metabolites_per_compartment(model, c))) for c in model.compartments), reverse=True, key=itemgetter(1))[:2] # Compare the size of the compartments. ...
[ "def", "largest_compartment_id_met", "(", "model", ")", ":", "# Sort compartments by decreasing size and extract the largest two.", "candidate", ",", "second", "=", "sorted", "(", "(", "(", "c", ",", "len", "(", "metabolites_per_compartment", "(", "model", ",", "c", "...
Return the ID of the compartment with the most metabolites. Parameters ---------- model : cobra.Model The metabolic model under investigation. Returns ------- string Compartment ID of the compartment with the most metabolites.
[ "Return", "the", "ID", "of", "the", "compartment", "with", "the", "most", "metabolites", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L593-L618
2,394
opencobra/memote
memote/support/helpers.py
find_compartment_id_in_model
def find_compartment_id_in_model(model, compartment_id): """ Identify a model compartment by looking up names in COMPARTMENT_SHORTLIST. Parameters ---------- model : cobra.Model The metabolic model under investigation. compartment_id : string Memote internal compartment identifi...
python
def find_compartment_id_in_model(model, compartment_id): if compartment_id not in COMPARTMENT_SHORTLIST.keys(): raise KeyError("{} is not in the COMPARTMENT_SHORTLIST! Make sure " "you typed the ID correctly, if yes, update the " "shortlist manually.".format(com...
[ "def", "find_compartment_id_in_model", "(", "model", ",", "compartment_id", ")", ":", "if", "compartment_id", "not", "in", "COMPARTMENT_SHORTLIST", ".", "keys", "(", ")", ":", "raise", "KeyError", "(", "\"{} is not in the COMPARTMENT_SHORTLIST! Make sure \"", "\"you typed...
Identify a model compartment by looking up names in COMPARTMENT_SHORTLIST. Parameters ---------- model : cobra.Model The metabolic model under investigation. compartment_id : string Memote internal compartment identifier used to access compartment name shortlist to look up poten...
[ "Identify", "a", "model", "compartment", "by", "looking", "up", "names", "in", "COMPARTMENT_SHORTLIST", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L621-L661
2,395
opencobra/memote
memote/support/helpers.py
find_met_in_model
def find_met_in_model(model, mnx_id, compartment_id=None): """ Return specific metabolites by looking up IDs in METANETX_SHORTLIST. Parameters ---------- model : cobra.Model The metabolic model under investigation. mnx_id : string Memote internal MetaNetX metabolite identifier u...
python
def find_met_in_model(model, mnx_id, compartment_id=None): def compare_annotation(annotation): """ Return annotation IDs that match to METANETX_SHORTLIST references. Compares the set of METANETX_SHORTLIST references for a given mnx_id and the annotation IDs stored in a given annotat...
[ "def", "find_met_in_model", "(", "model", ",", "mnx_id", ",", "compartment_id", "=", "None", ")", ":", "def", "compare_annotation", "(", "annotation", ")", ":", "\"\"\"\n Return annotation IDs that match to METANETX_SHORTLIST references.\n\n Compares the set of META...
Return specific metabolites by looking up IDs in METANETX_SHORTLIST. Parameters ---------- model : cobra.Model The metabolic model under investigation. mnx_id : string Memote internal MetaNetX metabolite identifier used to map between cross-references in the METANETX_SHORTLIST. ...
[ "Return", "specific", "metabolites", "by", "looking", "up", "IDs", "in", "METANETX_SHORTLIST", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L664-L764
2,396
opencobra/memote
memote/support/helpers.py
find_bounds
def find_bounds(model): """ Return the median upper and lower bound of the metabolic model. Bounds can vary from model to model. Cobrapy defaults to (-1000, 1000) but this may not be the case for merged or autogenerated models. In these cases, this function is used to iterate over all the bounds of...
python
def find_bounds(model): lower_bounds = np.asarray([rxn.lower_bound for rxn in model.reactions], dtype=float) upper_bounds = np.asarray([rxn.upper_bound for rxn in model.reactions], dtype=float) lower_bound = np.nanmedian(lower_bounds[lower_bounds !...
[ "def", "find_bounds", "(", "model", ")", ":", "lower_bounds", "=", "np", ".", "asarray", "(", "[", "rxn", ".", "lower_bound", "for", "rxn", "in", "model", ".", "reactions", "]", ",", "dtype", "=", "float", ")", "upper_bounds", "=", "np", ".", "asarray"...
Return the median upper and lower bound of the metabolic model. Bounds can vary from model to model. Cobrapy defaults to (-1000, 1000) but this may not be the case for merged or autogenerated models. In these cases, this function is used to iterate over all the bounds of all the reactions and find the ...
[ "Return", "the", "median", "upper", "and", "lower", "bound", "of", "the", "metabolic", "model", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/helpers.py#L781-L809
2,397
opencobra/memote
memote/suite/reporting/report.py
Report.render_html
def render_html(self): """Render an HTML report.""" return self._template.safe_substitute( report_type=self._report_type, results=self.render_json() )
python
def render_html(self): return self._template.safe_substitute( report_type=self._report_type, results=self.render_json() )
[ "def", "render_html", "(", "self", ")", ":", "return", "self", ".", "_template", ".", "safe_substitute", "(", "report_type", "=", "self", ".", "_report_type", ",", "results", "=", "self", ".", "render_json", "(", ")", ")" ]
Render an HTML report.
[ "Render", "an", "HTML", "report", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/reporting/report.py#L80-L85
2,398
opencobra/memote
memote/suite/reporting/report.py
Report.compute_score
def compute_score(self): """Calculate the overall test score using the configuration.""" # LOGGER.info("Begin scoring") cases = self.get_configured_tests() | set(self.result.cases) scores = DataFrame({"score": 0.0, "max": 1.0}, index=sorted(cases)) self...
python
def compute_score(self): # LOGGER.info("Begin scoring") cases = self.get_configured_tests() | set(self.result.cases) scores = DataFrame({"score": 0.0, "max": 1.0}, index=sorted(cases)) self.result.setdefault("score", dict()) self.result["score"]["sectio...
[ "def", "compute_score", "(", "self", ")", ":", "# LOGGER.info(\"Begin scoring\")", "cases", "=", "self", ".", "get_configured_tests", "(", ")", "|", "set", "(", "self", ".", "result", ".", "cases", ")", "scores", "=", "DataFrame", "(", "{", "\"score\"", ":",...
Calculate the overall test score using the configuration.
[ "Calculate", "the", "overall", "test", "score", "using", "the", "configuration", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/reporting/report.py#L114-L164
2,399
opencobra/memote
memote/support/sbo.py
find_components_without_sbo_terms
def find_components_without_sbo_terms(model, components): """ Find model components that are not annotated with any SBO terms. Parameters ---------- model : cobra.Model The metabolic model under investigation. components : {"metabolites", "reactions", "genes"} A string denoting ...
python
def find_components_without_sbo_terms(model, components): return [elem for elem in getattr(model, components) if elem.annotation is None or 'sbo' not in elem.annotation]
[ "def", "find_components_without_sbo_terms", "(", "model", ",", "components", ")", ":", "return", "[", "elem", "for", "elem", "in", "getattr", "(", "model", ",", "components", ")", "if", "elem", ".", "annotation", "is", "None", "or", "'sbo'", "not", "in", "...
Find model components that are not annotated with any SBO terms. Parameters ---------- model : cobra.Model The metabolic model under investigation. components : {"metabolites", "reactions", "genes"} A string denoting `cobra.Model` components. Returns ------- list Th...
[ "Find", "model", "components", "that", "are", "not", "annotated", "with", "any", "SBO", "terms", "." ]
276630fcd4449fb7b914186edfd38c239e7052df
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/sbo.py#L27-L45