repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
ejhigson/nestcheck | nestcheck/ns_run_utils.py | get_logw | def get_logw(ns_run, simulate=False):
r"""Calculates the log posterior weights of the samples (using logarithms
to avoid overflow errors with very large or small values).
Uses the trapezium rule such that the weight of point i is
.. math:: w_i = \mathcal{L}_i (X_{i-1} - X_{i+1}) / 2
Parameters
... | python | def get_logw(ns_run, simulate=False):
r"""Calculates the log posterior weights of the samples (using logarithms
to avoid overflow errors with very large or small values).
Uses the trapezium rule such that the weight of point i is
.. math:: w_i = \mathcal{L}_i (X_{i-1} - X_{i+1}) / 2
Parameters
... | [
"def",
"get_logw",
"(",
"ns_run",
",",
"simulate",
"=",
"False",
")",
":",
"try",
":",
"# find logX value for each point",
"logx",
"=",
"get_logx",
"(",
"ns_run",
"[",
"'nlive_array'",
"]",
",",
"simulate",
"=",
"simulate",
")",
"logw",
"=",
"np",
".",
"ze... | r"""Calculates the log posterior weights of the samples (using logarithms
to avoid overflow errors with very large or small values).
Uses the trapezium rule such that the weight of point i is
.. math:: w_i = \mathcal{L}_i (X_{i-1} - X_{i+1}) / 2
Parameters
----------
ns_run: dict
Nest... | [
"r",
"Calculates",
"the",
"log",
"posterior",
"weights",
"of",
"the",
"samples",
"(",
"using",
"logarithms",
"to",
"avoid",
"overflow",
"errors",
"with",
"very",
"large",
"or",
"small",
"values",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L289-L334 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | get_w_rel | def get_w_rel(ns_run, simulate=False):
"""Get the relative posterior weights of the samples, normalised so
the maximum sample weight is 1. This is calculated from get_logw with
protection against numerical overflows.
Parameters
----------
ns_run: dict
Nested sampling run dict (see data_... | python | def get_w_rel(ns_run, simulate=False):
"""Get the relative posterior weights of the samples, normalised so
the maximum sample weight is 1. This is calculated from get_logw with
protection against numerical overflows.
Parameters
----------
ns_run: dict
Nested sampling run dict (see data_... | [
"def",
"get_w_rel",
"(",
"ns_run",
",",
"simulate",
"=",
"False",
")",
":",
"logw",
"=",
"get_logw",
"(",
"ns_run",
",",
"simulate",
"=",
"simulate",
")",
"return",
"np",
".",
"exp",
"(",
"logw",
"-",
"logw",
".",
"max",
"(",
")",
")"
] | Get the relative posterior weights of the samples, normalised so
the maximum sample weight is 1. This is calculated from get_logw with
protection against numerical overflows.
Parameters
----------
ns_run: dict
Nested sampling run dict (see data_processing module docstring for more
d... | [
"Get",
"the",
"relative",
"posterior",
"weights",
"of",
"the",
"samples",
"normalised",
"so",
"the",
"maximum",
"sample",
"weight",
"is",
"1",
".",
"This",
"is",
"calculated",
"from",
"get_logw",
"with",
"protection",
"against",
"numerical",
"overflows",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L337-L356 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | get_logx | def get_logx(nlive, simulate=False):
r"""Returns a logx vector showing the expected or simulated logx positions
of points.
The shrinkage factor between two points
.. math:: t_i = X_{i-1} / X_{i}
is distributed as the largest of :math:`n_i` uniform random variables
between 1 and 0, where :math... | python | def get_logx(nlive, simulate=False):
r"""Returns a logx vector showing the expected or simulated logx positions
of points.
The shrinkage factor between two points
.. math:: t_i = X_{i-1} / X_{i}
is distributed as the largest of :math:`n_i` uniform random variables
between 1 and 0, where :math... | [
"def",
"get_logx",
"(",
"nlive",
",",
"simulate",
"=",
"False",
")",
":",
"assert",
"nlive",
".",
"min",
"(",
")",
">",
"0",
",",
"(",
"'nlive contains zeros or negative values! nlive = '",
"+",
"str",
"(",
"nlive",
")",
")",
"if",
"simulate",
":",
"logx_s... | r"""Returns a logx vector showing the expected or simulated logx positions
of points.
The shrinkage factor between two points
.. math:: t_i = X_{i-1} / X_{i}
is distributed as the largest of :math:`n_i` uniform random variables
between 1 and 0, where :math:`n_i` is the local number of live points... | [
"r",
"Returns",
"a",
"logx",
"vector",
"showing",
"the",
"expected",
"or",
"simulated",
"logx",
"positions",
"of",
"points",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L359-L396 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | log_subtract | def log_subtract(loga, logb):
r"""Numerically stable method for avoiding overflow errors when calculating
:math:`\log (a-b)`, given :math:`\log (a)`, :math:`\log (a)` and that
:math:`a > b`.
See https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/
for more details.
Parameters
... | python | def log_subtract(loga, logb):
r"""Numerically stable method for avoiding overflow errors when calculating
:math:`\log (a-b)`, given :math:`\log (a)`, :math:`\log (a)` and that
:math:`a > b`.
See https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/
for more details.
Parameters
... | [
"def",
"log_subtract",
"(",
"loga",
",",
"logb",
")",
":",
"return",
"loga",
"+",
"np",
".",
"log",
"(",
"1",
"-",
"np",
".",
"exp",
"(",
"logb",
"-",
"loga",
")",
")"
] | r"""Numerically stable method for avoiding overflow errors when calculating
:math:`\log (a-b)`, given :math:`\log (a)`, :math:`\log (a)` and that
:math:`a > b`.
See https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/
for more details.
Parameters
----------
loga: float
... | [
"r",
"Numerically",
"stable",
"method",
"for",
"avoiding",
"overflow",
"errors",
"when",
"calculating",
":",
"math",
":",
"\\",
"log",
"(",
"a",
"-",
"b",
")",
"given",
":",
"math",
":",
"\\",
"log",
"(",
"a",
")",
":",
"math",
":",
"\\",
"log",
"(... | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L399-L417 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | check_ns_run | def check_ns_run(run, dup_assert=False, dup_warn=False):
"""Checks a nestcheck format nested sampling run dictionary has the
expected properties (see the data_processing module docstring for more
details).
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: boo... | python | def check_ns_run(run, dup_assert=False, dup_warn=False):
"""Checks a nestcheck format nested sampling run dictionary has the
expected properties (see the data_processing module docstring for more
details).
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: boo... | [
"def",
"check_ns_run",
"(",
"run",
",",
"dup_assert",
"=",
"False",
",",
"dup_warn",
"=",
"False",
")",
":",
"assert",
"isinstance",
"(",
"run",
",",
"dict",
")",
"check_ns_run_members",
"(",
"run",
")",
"check_ns_run_logls",
"(",
"run",
",",
"dup_assert",
... | Checks a nestcheck format nested sampling run dictionary has the
expected properties (see the data_processing module docstring for more
details).
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: bool, optional
See check_ns_run_logls docstring.
dup_wa... | [
"Checks",
"a",
"nestcheck",
"format",
"nested",
"sampling",
"run",
"dictionary",
"has",
"the",
"expected",
"properties",
"(",
"see",
"the",
"data_processing",
"module",
"docstring",
"for",
"more",
"details",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L424-L447 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | check_ns_run_members | def check_ns_run_members(run):
"""Check nested sampling run member keys and values.
Parameters
----------
run: dict
nested sampling run to check.
Raises
------
AssertionError
if run does not have expected properties.
"""
run_keys = list(run.keys())
# Mandatory k... | python | def check_ns_run_members(run):
"""Check nested sampling run member keys and values.
Parameters
----------
run: dict
nested sampling run to check.
Raises
------
AssertionError
if run does not have expected properties.
"""
run_keys = list(run.keys())
# Mandatory k... | [
"def",
"check_ns_run_members",
"(",
"run",
")",
":",
"run_keys",
"=",
"list",
"(",
"run",
".",
"keys",
"(",
")",
")",
"# Mandatory keys",
"for",
"key",
"in",
"[",
"'logl'",
",",
"'nlive_array'",
",",
"'theta'",
",",
"'thread_labels'",
",",
"'thread_min_max'"... | Check nested sampling run member keys and values.
Parameters
----------
run: dict
nested sampling run to check.
Raises
------
AssertionError
if run does not have expected properties. | [
"Check",
"nested",
"sampling",
"run",
"member",
"keys",
"and",
"values",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L450-L487 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | check_ns_run_logls | def check_ns_run_logls(run, dup_assert=False, dup_warn=False):
"""Check run logls are unique and in the correct order.
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: bool, optional
Whether to raise and AssertionError if there are duplicate logl values.
... | python | def check_ns_run_logls(run, dup_assert=False, dup_warn=False):
"""Check run logls are unique and in the correct order.
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: bool, optional
Whether to raise and AssertionError if there are duplicate logl values.
... | [
"def",
"check_ns_run_logls",
"(",
"run",
",",
"dup_assert",
"=",
"False",
",",
"dup_warn",
"=",
"False",
")",
":",
"assert",
"np",
".",
"array_equal",
"(",
"run",
"[",
"'logl'",
"]",
",",
"run",
"[",
"'logl'",
"]",
"[",
"np",
".",
"argsort",
"(",
"ru... | Check run logls are unique and in the correct order.
Parameters
----------
run: dict
nested sampling run to check.
dup_assert: bool, optional
Whether to raise and AssertionError if there are duplicate logl values.
dup_warn: bool, optional
Whether to give a UserWarning if the... | [
"Check",
"run",
"logls",
"are",
"unique",
"and",
"in",
"the",
"correct",
"order",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L490-L523 |
ejhigson/nestcheck | nestcheck/ns_run_utils.py | check_ns_run_threads | def check_ns_run_threads(run):
"""Check thread labels and thread_min_max have expected properties.
Parameters
----------
run: dict
Nested sampling run to check.
Raises
------
AssertionError
If run does not have expected properties.
"""
assert run['thread_labels'].dt... | python | def check_ns_run_threads(run):
"""Check thread labels and thread_min_max have expected properties.
Parameters
----------
run: dict
Nested sampling run to check.
Raises
------
AssertionError
If run does not have expected properties.
"""
assert run['thread_labels'].dt... | [
"def",
"check_ns_run_threads",
"(",
"run",
")",
":",
"assert",
"run",
"[",
"'thread_labels'",
"]",
".",
"dtype",
"==",
"int",
"uniq_th",
"=",
"np",
".",
"unique",
"(",
"run",
"[",
"'thread_labels'",
"]",
")",
"assert",
"np",
".",
"array_equal",
"(",
"np"... | Check thread labels and thread_min_max have expected properties.
Parameters
----------
run: dict
Nested sampling run to check.
Raises
------
AssertionError
If run does not have expected properties. | [
"Check",
"thread",
"labels",
"and",
"thread_min_max",
"have",
"expected",
"properties",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/ns_run_utils.py#L526-L557 |
ejhigson/nestcheck | nestcheck/estimators.py | count_samples | def count_samples(ns_run, **kwargs):
r"""Number of samples in run.
Unlike most estimators this does not require log weights, but for
convenience will not throw an error if they are specified.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
... | python | def count_samples(ns_run, **kwargs):
r"""Number of samples in run.
Unlike most estimators this does not require log weights, but for
convenience will not throw an error if they are specified.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
... | [
"def",
"count_samples",
"(",
"ns_run",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"pop",
"(",
"'logw'",
",",
"None",
")",
"kwargs",
".",
"pop",
"(",
"'simulate'",
",",
"None",
")",
"if",
"kwargs",
":",
"raise",
"TypeError",
"(",
"'Unexpected **k... | r"""Number of samples in run.
Unlike most estimators this does not require log weights, but for
convenience will not throw an error if they are specified.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
R... | [
"r",
"Number",
"of",
"samples",
"in",
"run",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L32-L52 |
ejhigson/nestcheck | nestcheck/estimators.py | logz | def logz(ns_run, logw=None, simulate=False):
r"""Natural log of Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log wei... | python | def logz(ns_run, logw=None, simulate=False):
r"""Natural log of Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log wei... | [
"def",
"logz",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_logw",
"(",
"ns_run",
",",
"simulate",
"=",
"simulate",
")",
"r... | r"""Natural log of Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
simulate: bool, optional
... | [
"r",
"Natural",
"log",
"of",
"Bayesian",
"evidence",
":",
"math",
":",
"\\",
"log",
"\\",
"mathcal",
"{",
"Z",
"}",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L55-L75 |
ejhigson/nestcheck | nestcheck/estimators.py | evidence | def evidence(ns_run, logw=None, simulate=False):
r"""Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of sam... | python | def evidence(ns_run, logw=None, simulate=False):
r"""Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of sam... | [
"def",
"evidence",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_logw",
"(",
"ns_run",
",",
"simulate",
"=",
"simulate",
")",
... | r"""Bayesian evidence :math:`\log \mathcal{Z}`.
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
simulate: bool, optional
Passed to ... | [
"r",
"Bayesian",
"evidence",
":",
"math",
":",
"\\",
"log",
"\\",
"mathcal",
"{",
"Z",
"}",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L78-L98 |
ejhigson/nestcheck | nestcheck/estimators.py | param_mean | def param_mean(ns_run, logw=None, simulate=False, param_ind=0,
handle_indexerror=False):
"""Mean of a single parameter (single component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
... | python | def param_mean(ns_run, logw=None, simulate=False, param_ind=0,
handle_indexerror=False):
"""Mean of a single parameter (single component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
... | [
"def",
"param_mean",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
",",
"param_ind",
"=",
"0",
",",
"handle_indexerror",
"=",
"False",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
"... | Mean of a single parameter (single component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
simulate: bool, optional
Pa... | [
"Mean",
"of",
"a",
"single",
"parameter",
"(",
"single",
"component",
"of",
"theta",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L101-L138 |
ejhigson/nestcheck | nestcheck/estimators.py | param_cred | def param_cred(ns_run, logw=None, simulate=False, probability=0.5,
param_ind=0):
"""One-tailed credible interval on the value of a single parameter
(component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstr... | python | def param_cred(ns_run, logw=None, simulate=False, probability=0.5,
param_ind=0):
"""One-tailed credible interval on the value of a single parameter
(component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstr... | [
"def",
"param_cred",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
",",
"probability",
"=",
"0.5",
",",
"param_ind",
"=",
"0",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"g... | One-tailed credible interval on the value of a single parameter
(component of theta).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
s... | [
"One",
"-",
"tailed",
"credible",
"interval",
"on",
"the",
"value",
"of",
"a",
"single",
"parameter",
"(",
"component",
"of",
"theta",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L141-L173 |
ejhigson/nestcheck | nestcheck/estimators.py | param_squared_mean | def param_squared_mean(ns_run, logw=None, simulate=False, param_ind=0):
"""Mean of the square of single parameter (second moment of its
posterior distribution).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
... | python | def param_squared_mean(ns_run, logw=None, simulate=False, param_ind=0):
"""Mean of the square of single parameter (second moment of its
posterior distribution).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
... | [
"def",
"param_squared_mean",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
",",
"param_ind",
"=",
"0",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_logw",
"(",
"ns_run",
"... | Mean of the square of single parameter (second moment of its
posterior distribution).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
s... | [
"Mean",
"of",
"the",
"square",
"of",
"single",
"parameter",
"(",
"second",
"moment",
"of",
"its",
"posterior",
"distribution",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L176-L203 |
ejhigson/nestcheck | nestcheck/estimators.py | r_mean | def r_mean(ns_run, logw=None, simulate=False):
"""Mean of the radial coordinate (magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log we... | python | def r_mean(ns_run, logw=None, simulate=False):
"""Mean of the radial coordinate (magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log we... | [
"def",
"r_mean",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_logw",
"(",
"ns_run",
",",
"simulate",
"=",
"simulate",
")",
... | Mean of the radial coordinate (magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samples.
simulate: bool, optional
... | [
"Mean",
"of",
"the",
"radial",
"coordinate",
"(",
"magnitude",
"of",
"theta",
"vector",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L206-L228 |
ejhigson/nestcheck | nestcheck/estimators.py | r_cred | def r_cred(ns_run, logw=None, simulate=False, probability=0.5):
"""One-tailed credible interval on the value of the radial coordinate
(magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).... | python | def r_cred(ns_run, logw=None, simulate=False, probability=0.5):
"""One-tailed credible interval on the value of the radial coordinate
(magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).... | [
"def",
"r_cred",
"(",
"ns_run",
",",
"logw",
"=",
"None",
",",
"simulate",
"=",
"False",
",",
"probability",
"=",
"0.5",
")",
":",
"if",
"logw",
"is",
"None",
":",
"logw",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_logw",
"(",
"ns_run",
",",
"s... | One-tailed credible interval on the value of the radial coordinate
(magnitude of theta vector).
Parameters
----------
ns_run: dict
Nested sampling run dict (see the data_processing module
docstring for more details).
logw: None or 1d numpy array, optional
Log weights of samp... | [
"One",
"-",
"tailed",
"credible",
"interval",
"on",
"the",
"value",
"of",
"the",
"radial",
"coordinate",
"(",
"magnitude",
"of",
"theta",
"vector",
")",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L231-L258 |
ejhigson/nestcheck | nestcheck/estimators.py | get_latex_name | def get_latex_name(func_in, **kwargs):
"""
Produce a latex formatted name for each function for use in labelling
results.
Parameters
----------
func_in: function
kwargs: dict, optional
Kwargs for function.
Returns
-------
latex_name: str
Latex formatted name for... | python | def get_latex_name(func_in, **kwargs):
"""
Produce a latex formatted name for each function for use in labelling
results.
Parameters
----------
func_in: function
kwargs: dict, optional
Kwargs for function.
Returns
-------
latex_name: str
Latex formatted name for... | [
"def",
"get_latex_name",
"(",
"func_in",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"func_in",
",",
"functools",
".",
"partial",
")",
":",
"func",
"=",
"func_in",
".",
"func",
"assert",
"not",
"set",
"(",
"func_in",
".",
"keywords",
")... | Produce a latex formatted name for each function for use in labelling
results.
Parameters
----------
func_in: function
kwargs: dict, optional
Kwargs for function.
Returns
-------
latex_name: str
Latex formatted name for the function. | [
"Produce",
"a",
"latex",
"formatted",
"name",
"for",
"each",
"function",
"for",
"use",
"in",
"labelling",
"results",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L265-L316 |
ejhigson/nestcheck | nestcheck/estimators.py | weighted_quantile | def weighted_quantile(probability, values, weights):
"""
Get quantile estimate for input probability given weighted samples using
linear interpolation.
Parameters
----------
probability: float
Quantile to estimate - must be in open interval (0, 1).
For example, use 0.5 for the m... | python | def weighted_quantile(probability, values, weights):
"""
Get quantile estimate for input probability given weighted samples using
linear interpolation.
Parameters
----------
probability: float
Quantile to estimate - must be in open interval (0, 1).
For example, use 0.5 for the m... | [
"def",
"weighted_quantile",
"(",
"probability",
",",
"values",
",",
"weights",
")",
":",
"assert",
"1",
">",
"probability",
">",
"0",
",",
"(",
"'credible interval prob= '",
"+",
"str",
"(",
"probability",
")",
"+",
"' not in (0, 1)'",
")",
"assert",
"values",... | Get quantile estimate for input probability given weighted samples using
linear interpolation.
Parameters
----------
probability: float
Quantile to estimate - must be in open interval (0, 1).
For example, use 0.5 for the median and 0.84 for the upper
84% quantile.
values: 1d... | [
"Get",
"quantile",
"estimate",
"for",
"input",
"probability",
"given",
"weighted",
"samples",
"using",
"linear",
"interpolation",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/estimators.py#L319-L347 |
ejhigson/nestcheck | nestcheck/write_polychord_output.py | write_run_output | def write_run_output(run, **kwargs):
"""Writes PolyChord output files corresponding to the input nested sampling
run. The file root is
.. code-block:: python
root = os.path.join(run['output']['base_dir'],
run['output']['file_root'])
Output files which can be made w... | python | def write_run_output(run, **kwargs):
"""Writes PolyChord output files corresponding to the input nested sampling
run. The file root is
.. code-block:: python
root = os.path.join(run['output']['base_dir'],
run['output']['file_root'])
Output files which can be made w... | [
"def",
"write_run_output",
"(",
"run",
",",
"*",
"*",
"kwargs",
")",
":",
"write_dead",
"=",
"kwargs",
".",
"pop",
"(",
"'write_dead'",
",",
"True",
")",
"write_stats",
"=",
"kwargs",
".",
"pop",
"(",
"'write_stats'",
",",
"True",
")",
"posteriors",
"=",... | Writes PolyChord output files corresponding to the input nested sampling
run. The file root is
.. code-block:: python
root = os.path.join(run['output']['base_dir'],
run['output']['file_root'])
Output files which can be made with this function (see the PolyChord
doc... | [
"Writes",
"PolyChord",
"output",
"files",
"corresponding",
"to",
"the",
"input",
"nested",
"sampling",
"run",
".",
"The",
"file",
"root",
"is"
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/write_polychord_output.py#L16-L115 |
ejhigson/nestcheck | nestcheck/write_polychord_output.py | run_dead_birth_array | def run_dead_birth_array(run, **kwargs):
"""Converts input run into an array of the format of a PolyChord
<root>_dead-birth.txt file. Note that this in fact includes live points
remaining at termination as well as dead points.
Parameters
----------
ns_run: dict
Nested sampling run dict ... | python | def run_dead_birth_array(run, **kwargs):
"""Converts input run into an array of the format of a PolyChord
<root>_dead-birth.txt file. Note that this in fact includes live points
remaining at termination as well as dead points.
Parameters
----------
ns_run: dict
Nested sampling run dict ... | [
"def",
"run_dead_birth_array",
"(",
"run",
",",
"*",
"*",
"kwargs",
")",
":",
"nestcheck",
".",
"ns_run_utils",
".",
"check_ns_run",
"(",
"run",
",",
"*",
"*",
"kwargs",
")",
"threads",
"=",
"nestcheck",
".",
"ns_run_utils",
".",
"get_run_threads",
"(",
"r... | Converts input run into an array of the format of a PolyChord
<root>_dead-birth.txt file. Note that this in fact includes live points
remaining at termination as well as dead points.
Parameters
----------
ns_run: dict
Nested sampling run dict (see data_processing module docstring for more
... | [
"Converts",
"input",
"run",
"into",
"an",
"array",
"of",
"the",
"format",
"of",
"a",
"PolyChord",
"<root",
">",
"_dead",
"-",
"birth",
".",
"txt",
"file",
".",
"Note",
"that",
"this",
"in",
"fact",
"includes",
"live",
"points",
"remaining",
"at",
"termin... | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/write_polychord_output.py#L118-L154 |
ejhigson/nestcheck | nestcheck/write_polychord_output.py | write_stats_file | def write_stats_file(run_output_dict):
"""Writes a dummy PolyChord format .stats file for tests functions for
processing stats files. This is written to:
base_dir/file_root.stats
Also returns the data in the file as a dict for comparison.
Parameters
----------
run_output_dict: dict
... | python | def write_stats_file(run_output_dict):
"""Writes a dummy PolyChord format .stats file for tests functions for
processing stats files. This is written to:
base_dir/file_root.stats
Also returns the data in the file as a dict for comparison.
Parameters
----------
run_output_dict: dict
... | [
"def",
"write_stats_file",
"(",
"run_output_dict",
")",
":",
"mandatory_keys",
"=",
"[",
"'file_root'",
",",
"'base_dir'",
"]",
"for",
"key",
"in",
"mandatory_keys",
":",
"assert",
"key",
"in",
"run_output_dict",
",",
"key",
"+",
"' not in run_output_dict'",
"defa... | Writes a dummy PolyChord format .stats file for tests functions for
processing stats files. This is written to:
base_dir/file_root.stats
Also returns the data in the file as a dict for comparison.
Parameters
----------
run_output_dict: dict
Output information to write to .stats file. ... | [
"Writes",
"a",
"dummy",
"PolyChord",
"format",
".",
"stats",
"file",
"for",
"tests",
"functions",
"for",
"processing",
"stats",
"files",
".",
"This",
"is",
"written",
"to",
":"
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/write_polychord_output.py#L157-L248 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | run_list_error_values | def run_list_error_values(run_list, estimator_list, estimator_names,
n_simulate=100, **kwargs):
"""Gets a data frame with calculation values and error diagnostics for each
run in the input run list.
NB when parallelised the results will not be produced in order (so results
fro... | python | def run_list_error_values(run_list, estimator_list, estimator_names,
n_simulate=100, **kwargs):
"""Gets a data frame with calculation values and error diagnostics for each
run in the input run list.
NB when parallelised the results will not be produced in order (so results
fro... | [
"def",
"run_list_error_values",
"(",
"run_list",
",",
"estimator_list",
",",
"estimator_names",
",",
"n_simulate",
"=",
"100",
",",
"*",
"*",
"kwargs",
")",
":",
"thread_pvalue",
"=",
"kwargs",
".",
"pop",
"(",
"'thread_pvalue'",
",",
"False",
")",
"bs_stat_di... | Gets a data frame with calculation values and error diagnostics for each
run in the input run list.
NB when parallelised the results will not be produced in order (so results
from some run number will not nessesarily correspond to that number run in
run_list).
Parameters
----------
run_lis... | [
"Gets",
"a",
"data",
"frame",
"with",
"calculation",
"values",
"and",
"error",
"diagnostics",
"for",
"each",
"run",
"in",
"the",
"input",
"run",
"list",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L17-L119 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | estimator_values_df | def estimator_values_df(run_list, estimator_list, **kwargs):
"""Get a dataframe of estimator values.
NB when parallelised the results will not be produced in order (so results
from some run number will not nessesarily correspond to that number run in
run_list).
Parameters
----------
run_li... | python | def estimator_values_df(run_list, estimator_list, **kwargs):
"""Get a dataframe of estimator values.
NB when parallelised the results will not be produced in order (so results
from some run number will not nessesarily correspond to that number run in
run_list).
Parameters
----------
run_li... | [
"def",
"estimator_values_df",
"(",
"run_list",
",",
"estimator_list",
",",
"*",
"*",
"kwargs",
")",
":",
"estimator_names",
"=",
"kwargs",
".",
"pop",
"(",
"'estimator_names'",
",",
"[",
"'est_'",
"+",
"str",
"(",
"i",
")",
"for",
"i",
"in",
"range",
"("... | Get a dataframe of estimator values.
NB when parallelised the results will not be produced in order (so results
from some run number will not nessesarily correspond to that number run in
run_list).
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
est... | [
"Get",
"a",
"dataframe",
"of",
"estimator",
"values",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L123-L169 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | error_values_summary | def error_values_summary(error_values, **summary_df_kwargs):
"""Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
... | python | def error_values_summary(error_values, **summary_df_kwargs):
"""Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
... | [
"def",
"error_values_summary",
"(",
"error_values",
",",
"*",
"*",
"summary_df_kwargs",
")",
":",
"df",
"=",
"pf",
".",
"summary_df_from_multi",
"(",
"error_values",
",",
"*",
"*",
"summary_df_kwargs",
")",
"# get implementation stds",
"imp_std",
",",
"imp_std_unc",... | Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
summary_df_kwargs: dict, optional
See pandas_functions.su... | [
"Get",
"summary",
"statistics",
"about",
"calculation",
"errors",
"including",
"estimated",
"implementation",
"errors",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L172-L228 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | run_list_error_summary | def run_list_error_summary(run_list, estimator_list, estimator_names,
n_simulate, **kwargs):
"""Wrapper which runs run_list_error_values then applies error_values
summary to the resulting dataframe. See the docstrings for those two
funcions for more details and for descriptions of... | python | def run_list_error_summary(run_list, estimator_list, estimator_names,
n_simulate, **kwargs):
"""Wrapper which runs run_list_error_values then applies error_values
summary to the resulting dataframe. See the docstrings for those two
funcions for more details and for descriptions of... | [
"def",
"run_list_error_summary",
"(",
"run_list",
",",
"estimator_list",
",",
"estimator_names",
",",
"n_simulate",
",",
"*",
"*",
"kwargs",
")",
":",
"true_values",
"=",
"kwargs",
".",
"pop",
"(",
"'true_values'",
",",
"None",
")",
"include_true_values",
"=",
... | Wrapper which runs run_list_error_values then applies error_values
summary to the resulting dataframe. See the docstrings for those two
funcions for more details and for descriptions of parameters and output. | [
"Wrapper",
"which",
"runs",
"run_list_error_values",
"then",
"applies",
"error_values",
"summary",
"to",
"the",
"resulting",
"dataframe",
".",
"See",
"the",
"docstrings",
"for",
"those",
"two",
"funcions",
"for",
"more",
"details",
"and",
"for",
"descriptions",
"o... | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L231-L244 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | bs_values_df | def bs_values_df(run_list, estimator_list, estimator_names, n_simulate,
**kwargs):
"""Computes a data frame of bootstrap resampled values.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators t... | python | def bs_values_df(run_list, estimator_list, estimator_names, n_simulate,
**kwargs):
"""Computes a data frame of bootstrap resampled values.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators t... | [
"def",
"bs_values_df",
"(",
"run_list",
",",
"estimator_list",
",",
"estimator_names",
",",
"n_simulate",
",",
"*",
"*",
"kwargs",
")",
":",
"tqdm_kwargs",
"=",
"kwargs",
".",
"pop",
"(",
"'tqdm_kwargs'",
",",
"{",
"'desc'",
":",
"'bs values'",
"}",
")",
"... | Computes a data frame of bootstrap resampled values.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators to apply to runs.
estimator_names: list of strs
Name of each func in estimator_list.
n_simul... | [
"Computes",
"a",
"data",
"frame",
"of",
"bootstrap",
"resampled",
"values",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L247-L288 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | thread_values_df | def thread_values_df(run_list, estimator_list, estimator_names, **kwargs):
"""Calculates estimator values for the constituent threads of the input
runs.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators ... | python | def thread_values_df(run_list, estimator_list, estimator_names, **kwargs):
"""Calculates estimator values for the constituent threads of the input
runs.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators ... | [
"def",
"thread_values_df",
"(",
"run_list",
",",
"estimator_list",
",",
"estimator_names",
",",
"*",
"*",
"kwargs",
")",
":",
"tqdm_kwargs",
"=",
"kwargs",
".",
"pop",
"(",
"'tqdm_kwargs'",
",",
"{",
"'desc'",
":",
"'thread values'",
"}",
")",
"assert",
"len... | Calculates estimator values for the constituent threads of the input
runs.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators to apply to runs.
estimator_names: list of strs
Name of each func in e... | [
"Calculates",
"estimator",
"values",
"for",
"the",
"constituent",
"threads",
"of",
"the",
"input",
"runs",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L291-L331 |
ejhigson/nestcheck | nestcheck/diagnostics_tables.py | pairwise_dists_on_cols | def pairwise_dists_on_cols(df_in, earth_mover_dist=True, energy_dist=True):
"""Computes pairwise statistical distance measures.
parameters
----------
df_in: pandas data frame
Columns represent estimators and rows represent runs.
Each data frane element is an array of values which are us... | python | def pairwise_dists_on_cols(df_in, earth_mover_dist=True, energy_dist=True):
"""Computes pairwise statistical distance measures.
parameters
----------
df_in: pandas data frame
Columns represent estimators and rows represent runs.
Each data frane element is an array of values which are us... | [
"def",
"pairwise_dists_on_cols",
"(",
"df_in",
",",
"earth_mover_dist",
"=",
"True",
",",
"energy_dist",
"=",
"True",
")",
":",
"df",
"=",
"pd",
".",
"DataFrame",
"(",
")",
"for",
"col",
"in",
"df_in",
".",
"columns",
":",
"df",
"[",
"col",
"]",
"=",
... | Computes pairwise statistical distance measures.
parameters
----------
df_in: pandas data frame
Columns represent estimators and rows represent runs.
Each data frane element is an array of values which are used as samples
in the distance measures.
earth_mover_dist: bool, optiona... | [
"Computes",
"pairwise",
"statistical",
"distance",
"measures",
"."
] | train | https://github.com/ejhigson/nestcheck/blob/29151c314deb89746fd674f27f6ce54b77603189/nestcheck/diagnostics_tables.py#L334-L357 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL._backtick_columns | def _backtick_columns(cols):
"""
Quote the column names
"""
def bt(s):
b = '' if s == '*' or not s else '`'
return [_ for _ in [b + (s or '') + b] if _]
formatted = []
for c in cols:
if c[0] == '#':
formatted.append(c[1... | python | def _backtick_columns(cols):
"""
Quote the column names
"""
def bt(s):
b = '' if s == '*' or not s else '`'
return [_ for _ in [b + (s or '') + b] if _]
formatted = []
for c in cols:
if c[0] == '#':
formatted.append(c[1... | [
"def",
"_backtick_columns",
"(",
"cols",
")",
":",
"def",
"bt",
"(",
"s",
")",
":",
"b",
"=",
"''",
"if",
"s",
"==",
"'*'",
"or",
"not",
"s",
"else",
"'`'",
"return",
"[",
"_",
"for",
"_",
"in",
"[",
"b",
"+",
"(",
"s",
"or",
"''",
")",
"+"... | Quote the column names | [
"Quote",
"the",
"column",
"names"
] | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L49-L68 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL._value_parser | def _value_parser(self, value, columnname=False, placeholder='%s'):
"""
Input: {'c1': 'v', 'c2': None, '#c3': 'uuid()'}
Output:
('%s, %s, uuid()', [None, 'v']) # insert; columnname=False
('`c2` = %s, `c1` = %s, `c3` = uuid()', [None, 'v']) # upd... | python | def _value_parser(self, value, columnname=False, placeholder='%s'):
"""
Input: {'c1': 'v', 'c2': None, '#c3': 'uuid()'}
Output:
('%s, %s, uuid()', [None, 'v']) # insert; columnname=False
('`c2` = %s, `c1` = %s, `c3` = uuid()', [None, 'v']) # upd... | [
"def",
"_value_parser",
"(",
"self",
",",
"value",
",",
"columnname",
"=",
"False",
",",
"placeholder",
"=",
"'%s'",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Input value should be a dictionary'",
... | Input: {'c1': 'v', 'c2': None, '#c3': 'uuid()'}
Output:
('%s, %s, uuid()', [None, 'v']) # insert; columnname=False
('`c2` = %s, `c1` = %s, `c3` = uuid()', [None, 'v']) # update; columnname=True
No need to transform NULL value since it's supported in exe... | [
"Input",
":",
"{",
"c1",
":",
"v",
"c2",
":",
"None",
"#c3",
":",
"uuid",
"()",
"}",
"Output",
":",
"(",
"%s",
"%s",
"uuid",
"()",
"[",
"None",
"v",
"]",
")",
"#",
"insert",
";",
"columnname",
"=",
"False",
"(",
"c2",
"=",
"%s",
"c1",
"=",
... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L99-L117 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL._by_columns | def _by_columns(self, columns):
"""
Allow select.group and select.order accepting string and list
"""
return columns if self.isstr(columns) else self._backtick_columns(columns) | python | def _by_columns(self, columns):
"""
Allow select.group and select.order accepting string and list
"""
return columns if self.isstr(columns) else self._backtick_columns(columns) | [
"def",
"_by_columns",
"(",
"self",
",",
"columns",
")",
":",
"return",
"columns",
"if",
"self",
".",
"isstr",
"(",
"columns",
")",
"else",
"self",
".",
"_backtick_columns",
"(",
"columns",
")"
] | Allow select.group and select.order accepting string and list | [
"Allow",
"select",
".",
"group",
"and",
"select",
".",
"order",
"accepting",
"string",
"and",
"list"
] | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L299-L303 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.select | def select(self, table, columns=None, join=None, where=None, group=None, having=None, order=None, limit=None,
iterator=False, fetch=True):
"""
:type table: string
:type columns: list
:type join: dict
:param join: {'[>]table1(t1)': {'user.id': 't1.user_id'}} -> "LEF... | python | def select(self, table, columns=None, join=None, where=None, group=None, having=None, order=None, limit=None,
iterator=False, fetch=True):
"""
:type table: string
:type columns: list
:type join: dict
:param join: {'[>]table1(t1)': {'user.id': 't1.user_id'}} -> "LEF... | [
"def",
"select",
"(",
"self",
",",
"table",
",",
"columns",
"=",
"None",
",",
"join",
"=",
"None",
",",
"where",
"=",
"None",
",",
"group",
"=",
"None",
",",
"having",
"=",
"None",
",",
"order",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"itera... | :type table: string
:type columns: list
:type join: dict
:param join: {'[>]table1(t1)': {'user.id': 't1.user_id'}} -> "LEFT JOIN table AS t1 ON user.id = t1.user_id"
:type where: dict
:type group: string|list
:type having: string
:type order: string|list
:... | [
":",
"type",
"table",
":",
"string",
":",
"type",
"columns",
":",
"list",
":",
"type",
"join",
":",
"dict",
":",
"param",
"join",
":",
"{",
"[",
">",
"]",
"table1",
"(",
"t1",
")",
":",
"{",
"user",
".",
"id",
":",
"t1",
".",
"user_id",
"}}",
... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L305-L353 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.select_page | def select_page(self, limit, offset=0, **kwargs):
"""
:type limit: int
:param limit: The max row number for each page
:type offset: int
:param offset: The starting position of the page
:return:
"""
start = offset
while True:
result = se... | python | def select_page(self, limit, offset=0, **kwargs):
"""
:type limit: int
:param limit: The max row number for each page
:type offset: int
:param offset: The starting position of the page
:return:
"""
start = offset
while True:
result = se... | [
"def",
"select_page",
"(",
"self",
",",
"limit",
",",
"offset",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"start",
"=",
"offset",
"while",
"True",
":",
"result",
"=",
"self",
".",
"select",
"(",
"limit",
"=",
"[",
"start",
",",
"limit",
"]",
"... | :type limit: int
:param limit: The max row number for each page
:type offset: int
:param offset: The starting position of the page
:return: | [
":",
"type",
"limit",
":",
"int",
":",
"param",
"limit",
":",
"The",
"max",
"row",
"number",
"for",
"each",
"page",
":",
"type",
"offset",
":",
"int",
":",
"param",
"offset",
":",
"The",
"starting",
"position",
"of",
"the",
"page",
":",
"return",
":"... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L355-L372 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.get | def get(self, table, column, join=None, where=None, insert=False, ifnone=None):
"""
A simplified method of select, for getting the first result in one column only. A common case of using this
method is getting id.
:type table: string
:type column: str
:type join: dict
... | python | def get(self, table, column, join=None, where=None, insert=False, ifnone=None):
"""
A simplified method of select, for getting the first result in one column only. A common case of using this
method is getting id.
:type table: string
:type column: str
:type join: dict
... | [
"def",
"get",
"(",
"self",
",",
"table",
",",
"column",
",",
"join",
"=",
"None",
",",
"where",
"=",
"None",
",",
"insert",
"=",
"False",
",",
"ifnone",
"=",
"None",
")",
":",
"select_result",
"=",
"self",
".",
"select",
"(",
"table",
"=",
"table",... | A simplified method of select, for getting the first result in one column only. A common case of using this
method is getting id.
:type table: string
:type column: str
:type join: dict
:type where: dict
:type insert: bool
:param insert: If insert==True, insert the... | [
"A",
"simplified",
"method",
"of",
"select",
"for",
"getting",
"the",
"first",
"result",
"in",
"one",
"column",
"only",
".",
"A",
"common",
"case",
"of",
"using",
"this",
"method",
"is",
"getting",
"id",
".",
":",
"type",
"table",
":",
"string",
":",
"... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L374-L406 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.insert | def insert(self, table, value, ignore=False, commit=True):
"""
Insert a dict into db.
:type table: string
:type value: dict
:type ignore: bool
:type commit: bool
:return: int. The row id of the insert.
"""
value_q, _args = self._value_parser(value,... | python | def insert(self, table, value, ignore=False, commit=True):
"""
Insert a dict into db.
:type table: string
:type value: dict
:type ignore: bool
:type commit: bool
:return: int. The row id of the insert.
"""
value_q, _args = self._value_parser(value,... | [
"def",
"insert",
"(",
"self",
",",
"table",
",",
"value",
",",
"ignore",
"=",
"False",
",",
"commit",
"=",
"True",
")",
":",
"value_q",
",",
"_args",
"=",
"self",
".",
"_value_parser",
"(",
"value",
",",
"columnname",
"=",
"False",
")",
"_sql",
"=",
... | Insert a dict into db.
:type table: string
:type value: dict
:type ignore: bool
:type commit: bool
:return: int. The row id of the insert. | [
"Insert",
"a",
"dict",
"into",
"db",
".",
":",
"type",
"table",
":",
"string",
":",
"type",
"value",
":",
"dict",
":",
"type",
"ignore",
":",
"bool",
":",
"type",
"commit",
":",
"bool",
":",
"return",
":",
"int",
".",
"The",
"row",
"id",
"of",
"t... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L408-L427 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.upsert | def upsert(self, table, value, update_columns=None, commit=True):
"""
:type table: string
:type value: dict
:type update_columns: list
:param update_columns: specify the columns which will be updated if record exists
:type commit: bool
"""
if not isinstanc... | python | def upsert(self, table, value, update_columns=None, commit=True):
"""
:type table: string
:type value: dict
:type update_columns: list
:param update_columns: specify the columns which will be updated if record exists
:type commit: bool
"""
if not isinstanc... | [
"def",
"upsert",
"(",
"self",
",",
"table",
",",
"value",
",",
"update_columns",
"=",
"None",
",",
"commit",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Input value should be a diction... | :type table: string
:type value: dict
:type update_columns: list
:param update_columns: specify the columns which will be updated if record exists
:type commit: bool | [
":",
"type",
"table",
":",
"string",
":",
"type",
"value",
":",
"dict",
":",
"type",
"update_columns",
":",
"list",
":",
"param",
"update_columns",
":",
"specify",
"the",
"columns",
"which",
"will",
"be",
"updated",
"if",
"record",
"exists",
":",
"type",
... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L429-L456 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.insertmany | def insertmany(self, table, columns, value, ignore=False, commit=True):
"""
Insert multiple records within one query.
:type table: string
:type columns: list
:type value: list|tuple
:param value: Doesn't support MySQL functions
:param value: Example: [(value1_colu... | python | def insertmany(self, table, columns, value, ignore=False, commit=True):
"""
Insert multiple records within one query.
:type table: string
:type columns: list
:type value: list|tuple
:param value: Doesn't support MySQL functions
:param value: Example: [(value1_colu... | [
"def",
"insertmany",
"(",
"self",
",",
"table",
",",
"columns",
",",
"value",
",",
"ignore",
"=",
"False",
",",
"commit",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"raise",
"TypeE... | Insert multiple records within one query.
:type table: string
:type columns: list
:type value: list|tuple
:param value: Doesn't support MySQL functions
:param value: Example: [(value1_column1, value1_column2,), ]
:type ignore: bool
:type commit: bool
:retu... | [
"Insert",
"multiple",
"records",
"within",
"one",
"query",
".",
":",
"type",
"table",
":",
"string",
":",
"type",
"columns",
":",
"list",
":",
"type",
"value",
":",
"list|tuple",
":",
"param",
"value",
":",
"Doesn",
"t",
"support",
"MySQL",
"functions",
... | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L458-L492 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.update | def update(self, table, value, where, join=None, commit=True):
"""
:type table: string
:type value: dict
:type where: dict
:type join: dict
:type commit: bool
"""
value_q, _value_args = self._value_parser(value, columnname=True)
where_q, _where_a... | python | def update(self, table, value, where, join=None, commit=True):
"""
:type table: string
:type value: dict
:type where: dict
:type join: dict
:type commit: bool
"""
value_q, _value_args = self._value_parser(value, columnname=True)
where_q, _where_a... | [
"def",
"update",
"(",
"self",
",",
"table",
",",
"value",
",",
"where",
",",
"join",
"=",
"None",
",",
"commit",
"=",
"True",
")",
":",
"value_q",
",",
"_value_args",
"=",
"self",
".",
"_value_parser",
"(",
"value",
",",
"columnname",
"=",
"True",
")... | :type table: string
:type value: dict
:type where: dict
:type join: dict
:type commit: bool | [
":",
"type",
"table",
":",
"string",
":",
"type",
"value",
":",
"dict",
":",
"type",
"where",
":",
"dict",
":",
"type",
"join",
":",
"dict",
":",
"type",
"commit",
":",
"bool"
] | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L494-L518 |
ligyxy/DictMySQL | dictmysql.py | DictMySQL.delete | def delete(self, table, where=None, commit=True):
"""
:type table: string
:type where: dict
:type commit: bool
"""
where_q, _args = self._where_parser(where)
alias = self._tablename_parser(table)['alias']
_sql = ''.join(['DELETE ',
... | python | def delete(self, table, where=None, commit=True):
"""
:type table: string
:type where: dict
:type commit: bool
"""
where_q, _args = self._where_parser(where)
alias = self._tablename_parser(table)['alias']
_sql = ''.join(['DELETE ',
... | [
"def",
"delete",
"(",
"self",
",",
"table",
",",
"where",
"=",
"None",
",",
"commit",
"=",
"True",
")",
":",
"where_q",
",",
"_args",
"=",
"self",
".",
"_where_parser",
"(",
"where",
")",
"alias",
"=",
"self",
".",
"_tablename_parser",
"(",
"table",
... | :type table: string
:type where: dict
:type commit: bool | [
":",
"type",
"table",
":",
"string",
":",
"type",
"where",
":",
"dict",
":",
"type",
"commit",
":",
"bool"
] | train | https://github.com/ligyxy/DictMySQL/blob/f40d649193ccf58d1c7933189be1042b37afbe31/dictmysql.py#L520-L540 |
danmichaelo/mwtemplates | mwtemplates/templateeditor2.py | get_whitespace | def get_whitespace(txt):
"""
Returns a list containing the whitespace to the left and
right of a string as its two elements
"""
# if the entire parameter is whitespace
rall = re.search(r'^([\s])+$', txt)
if rall:
tmp = txt.split('\n', 1)
if len(tmp) == 2:
return ... | python | def get_whitespace(txt):
"""
Returns a list containing the whitespace to the left and
right of a string as its two elements
"""
# if the entire parameter is whitespace
rall = re.search(r'^([\s])+$', txt)
if rall:
tmp = txt.split('\n', 1)
if len(tmp) == 2:
return ... | [
"def",
"get_whitespace",
"(",
"txt",
")",
":",
"# if the entire parameter is whitespace",
"rall",
"=",
"re",
".",
"search",
"(",
"r'^([\\s])+$'",
",",
"txt",
")",
"if",
"rall",
":",
"tmp",
"=",
"txt",
".",
"split",
"(",
"'\\n'",
",",
"1",
")",
"if",
"len... | Returns a list containing the whitespace to the left and
right of a string as its two elements | [
"Returns",
"a",
"list",
"containing",
"the",
"whitespace",
"to",
"the",
"left",
"and",
"right",
"of",
"a",
"string",
"as",
"its",
"two",
"elements"
] | train | https://github.com/danmichaelo/mwtemplates/blob/4a57831ee32152eb6dea9d099cec478962782276/mwtemplates/templateeditor2.py#L89-L113 |
danmichaelo/mwtemplates | mwtemplates/templateeditor2.py | Parameters.find_whitespace_pattern | def find_whitespace_pattern(self):
"""
Try to find a whitespace pattern in the existing parameters
to be applied to a newly added parameter
"""
name_ws = []
value_ws = []
for entry in self._entries:
name_ws.append(get_whitespace(entry.name))
... | python | def find_whitespace_pattern(self):
"""
Try to find a whitespace pattern in the existing parameters
to be applied to a newly added parameter
"""
name_ws = []
value_ws = []
for entry in self._entries:
name_ws.append(get_whitespace(entry.name))
... | [
"def",
"find_whitespace_pattern",
"(",
"self",
")",
":",
"name_ws",
"=",
"[",
"]",
"value_ws",
"=",
"[",
"]",
"for",
"entry",
"in",
"self",
".",
"_entries",
":",
"name_ws",
".",
"append",
"(",
"get_whitespace",
"(",
"entry",
".",
"name",
")",
")",
"if"... | Try to find a whitespace pattern in the existing parameters
to be applied to a newly added parameter | [
"Try",
"to",
"find",
"a",
"whitespace",
"pattern",
"in",
"the",
"existing",
"parameters",
"to",
"be",
"applied",
"to",
"a",
"newly",
"added",
"parameter"
] | train | https://github.com/danmichaelo/mwtemplates/blob/4a57831ee32152eb6dea9d099cec478962782276/mwtemplates/templateeditor2.py#L323-L342 |
jantman/pypi-download-stats | pypi_download_stats/diskdatacache.py | DiskDataCache._path_for_file | def _path_for_file(self, project_name, date):
"""
Generate the path on disk for a specified project and date.
:param project_name: the PyPI project name for the data
:type project: str
:param date: the date for the data
:type date: datetime.datetime
:return: path... | python | def _path_for_file(self, project_name, date):
"""
Generate the path on disk for a specified project and date.
:param project_name: the PyPI project name for the data
:type project: str
:param date: the date for the data
:type date: datetime.datetime
:return: path... | [
"def",
"_path_for_file",
"(",
"self",
",",
"project_name",
",",
"date",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"cache_path",
",",
"'%s_%s.json'",
"%",
"(",
"project_name",
",",
"date",
".",
"strftime",
"(",
"'%Y%m%d'",
")",... | Generate the path on disk for a specified project and date.
:param project_name: the PyPI project name for the data
:type project: str
:param date: the date for the data
:type date: datetime.datetime
:return: path for where to store this data on disk
:rtype: str | [
"Generate",
"the",
"path",
"on",
"disk",
"for",
"a",
"specified",
"project",
"and",
"date",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/diskdatacache.py#L66-L80 |
jantman/pypi-download-stats | pypi_download_stats/diskdatacache.py | DiskDataCache.get | def get(self, project, date):
"""
Get the cache data for a specified project for the specified date.
Returns None if the data cannot be found in the cache.
:param project: PyPi project name to get data for
:type project: str
:param date: date to get data for
:typ... | python | def get(self, project, date):
"""
Get the cache data for a specified project for the specified date.
Returns None if the data cannot be found in the cache.
:param project: PyPi project name to get data for
:type project: str
:param date: date to get data for
:typ... | [
"def",
"get",
"(",
"self",
",",
"project",
",",
"date",
")",
":",
"fpath",
"=",
"self",
".",
"_path_for_file",
"(",
"project",
",",
"date",
")",
"logger",
".",
"debug",
"(",
"'Cache GET project=%s date=%s - path=%s'",
",",
"project",
",",
"date",
".",
"str... | Get the cache data for a specified project for the specified date.
Returns None if the data cannot be found in the cache.
:param project: PyPi project name to get data for
:type project: str
:param date: date to get data for
:type date: datetime.datetime
:return: dict of... | [
"Get",
"the",
"cache",
"data",
"for",
"a",
"specified",
"project",
"for",
"the",
"specified",
"date",
".",
"Returns",
"None",
"if",
"the",
"data",
"cannot",
"be",
"found",
"in",
"the",
"cache",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/diskdatacache.py#L82-L111 |
jantman/pypi-download-stats | pypi_download_stats/diskdatacache.py | DiskDataCache.set | def set(self, project, date, data, data_ts):
"""
Set the cache data for a specified project for the specified date.
:param project: project name to set data for
:type project: str
:param date: date to set data for
:type date: datetime.datetime
:param data: data t... | python | def set(self, project, date, data, data_ts):
"""
Set the cache data for a specified project for the specified date.
:param project: project name to set data for
:type project: str
:param date: date to set data for
:type date: datetime.datetime
:param data: data t... | [
"def",
"set",
"(",
"self",
",",
"project",
",",
"date",
",",
"data",
",",
"data_ts",
")",
":",
"data",
"[",
"'cache_metadata'",
"]",
"=",
"{",
"'project'",
":",
"project",
",",
"'date'",
":",
"date",
".",
"strftime",
"(",
"'%Y%m%d'",
")",
",",
"'upda... | Set the cache data for a specified project for the specified date.
:param project: project name to set data for
:type project: str
:param date: date to set data for
:type date: datetime.datetime
:param data: data to cache
:type data: dict
:param data_ts: maximum ... | [
"Set",
"the",
"cache",
"data",
"for",
"a",
"specified",
"project",
"for",
"the",
"specified",
"date",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/diskdatacache.py#L113-L137 |
jantman/pypi-download-stats | pypi_download_stats/diskdatacache.py | DiskDataCache.get_dates_for_project | def get_dates_for_project(self, project):
"""
Return a list of the dates we have in cache for the specified project,
sorted in ascending date order.
:param project: project name
:type project: str
:return: list of datetime.datetime objects
:rtype: datetime.dateti... | python | def get_dates_for_project(self, project):
"""
Return a list of the dates we have in cache for the specified project,
sorted in ascending date order.
:param project: project name
:type project: str
:return: list of datetime.datetime objects
:rtype: datetime.dateti... | [
"def",
"get_dates_for_project",
"(",
"self",
",",
"project",
")",
":",
"file_re",
"=",
"re",
".",
"compile",
"(",
"r'^%s_([0-9]{8})\\.json$'",
"%",
"project",
")",
"all_dates",
"=",
"[",
"]",
"for",
"f",
"in",
"os",
".",
"listdir",
"(",
"self",
".",
"cac... | Return a list of the dates we have in cache for the specified project,
sorted in ascending date order.
:param project: project name
:type project: str
:return: list of datetime.datetime objects
:rtype: datetime.datetime | [
"Return",
"a",
"list",
"of",
"the",
"dates",
"we",
"have",
"in",
"cache",
"for",
"the",
"specified",
"project",
"sorted",
"in",
"ascending",
"date",
"order",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/diskdatacache.py#L139-L158 |
jantman/pypi-download-stats | pypi_download_stats/runner.py | parse_args | def parse_args(argv):
"""
Use Argparse to parse command-line arguments.
:param argv: list of arguments to parse (``sys.argv[1:]``)
:type argv: ``list``
:return: parsed arguments
:rtype: :py:class:`argparse.Namespace`
"""
p = argparse.ArgumentParser(
description='pypi-download-st... | python | def parse_args(argv):
"""
Use Argparse to parse command-line arguments.
:param argv: list of arguments to parse (``sys.argv[1:]``)
:type argv: ``list``
:return: parsed arguments
:rtype: :py:class:`argparse.Namespace`
"""
p = argparse.ArgumentParser(
description='pypi-download-st... | [
"def",
"parse_args",
"(",
"argv",
")",
":",
"p",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'pypi-download-stats - Calculate detailed download stats '",
"'and generate HTML and badges for PyPI packages - '",
"'<%s>'",
"%",
"PROJECT_URL",
",",
"prog",
... | Use Argparse to parse command-line arguments.
:param argv: list of arguments to parse (``sys.argv[1:]``)
:type argv: ``list``
:return: parsed arguments
:rtype: :py:class:`argparse.Namespace` | [
"Use",
"Argparse",
"to",
"parse",
"command",
"-",
"line",
"arguments",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L69-L121 |
jantman/pypi-download-stats | pypi_download_stats/runner.py | set_log_level_format | def set_log_level_format(level, format):
"""
Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str
"""
formatter = logging.Formatter(fmt=format)
logger.handlers... | python | def set_log_level_format(level, format):
"""
Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str
"""
formatter = logging.Formatter(fmt=format)
logger.handlers... | [
"def",
"set_log_level_format",
"(",
"level",
",",
"format",
")",
":",
"formatter",
"=",
"logging",
".",
"Formatter",
"(",
"fmt",
"=",
"format",
")",
"logger",
".",
"handlers",
"[",
"0",
"]",
".",
"setFormatter",
"(",
"formatter",
")",
"logger",
".",
"set... | Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str | [
"Set",
"logger",
"level",
"and",
"format",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L139-L150 |
jantman/pypi-download-stats | pypi_download_stats/runner.py | _pypi_get_projects_for_user | def _pypi_get_projects_for_user(username):
"""
Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
... | python | def _pypi_get_projects_for_user(username):
"""
Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
... | [
"def",
"_pypi_get_projects_for_user",
"(",
"username",
")",
":",
"client",
"=",
"xmlrpclib",
".",
"ServerProxy",
"(",
"'https://pypi.python.org/pypi'",
")",
"pkgs",
"=",
"client",
".",
"user_packages",
"(",
"username",
")",
"# returns [role, package]",
"return",
"[",
... | Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
:rtype: ``list`` | [
"Given",
"the",
"username",
"of",
"a",
"PyPI",
"user",
"return",
"a",
"list",
"of",
"all",
"of",
"the",
"user",
"s",
"projects",
"from",
"the",
"XMLRPC",
"interface",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L153-L167 |
jantman/pypi-download-stats | pypi_download_stats/runner.py | main | def main(args=None):
"""
Main entry point
"""
# parse args
if args is None:
args = parse_args(sys.argv[1:])
# set logging level
if args.verbose > 1:
set_log_debug()
elif args.verbose == 1:
set_log_info()
outpath = os.path.abspath(os.path.expanduser(args.out_... | python | def main(args=None):
"""
Main entry point
"""
# parse args
if args is None:
args = parse_args(sys.argv[1:])
# set logging level
if args.verbose > 1:
set_log_debug()
elif args.verbose == 1:
set_log_info()
outpath = os.path.abspath(os.path.expanduser(args.out_... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"# parse args",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"parse_args",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
"# set logging level",
"if",
"args",
".",
"verbose",
">",
"1",
":",
"se... | Main entry point | [
"Main",
"entry",
"point"
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L170-L205 |
jantman/pypi-download-stats | pypi_download_stats/graphs.py | FancyAreaGraph.generate_graph | def generate_graph(self):
"""
Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple
"""
logger.debug('Generating graph for %s', self._gr... | python | def generate_graph(self):
"""
Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple
"""
logger.debug('Generating graph for %s', self._gr... | [
"def",
"generate_graph",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating graph for %s'",
",",
"self",
".",
"_graph_id",
")",
"# tools to use",
"tools",
"=",
"[",
"PanTool",
"(",
")",
",",
"BoxZoomTool",
"(",
")",
",",
"WheelZoomTool",
"(",
... | Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple | [
"Generate",
"the",
"graph",
";",
"return",
"a",
"2",
"-",
"tuple",
"of",
"strings",
"script",
"to",
"place",
"in",
"the",
"head",
"of",
"the",
"HTML",
"document",
"and",
"div",
"content",
"for",
"the",
"graph",
"itself",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/graphs.py#L88-L153 |
jantman/pypi-download-stats | pypi_download_stats/graphs.py | FancyAreaGraph._line_for_patches | def _line_for_patches(self, data, chart, renderer, series_name):
"""
Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the... | python | def _line_for_patches(self, data, chart, renderer, series_name):
"""
Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the... | [
"def",
"_line_for_patches",
"(",
"self",
",",
"data",
",",
"chart",
",",
"renderer",
",",
"series_name",
")",
":",
"# @TODO this method needs a major refactor",
"# get the original x and y values, and color",
"xvals",
"=",
"deepcopy",
"(",
"renderer",
".",
"data_source",
... | Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the line to
:type chart: bokeh.charts.Chart
:param renderer: GlyphRender... | [
"Add",
"a",
"line",
"along",
"the",
"top",
"edge",
"of",
"a",
"Patch",
"in",
"a",
"stacked",
"Area",
"Chart",
";",
"return",
"the",
"new",
"Glyph",
"for",
"addition",
"to",
"HoverTool",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/graphs.py#L155-L240 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._get_cache_dates | def _get_cache_dates(self):
"""
Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtyp... | python | def _get_cache_dates(self):
"""
Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtyp... | [
"def",
"_get_cache_dates",
"(",
"self",
")",
":",
"all_dates",
"=",
"self",
".",
"cache",
".",
"get_dates_for_project",
"(",
"self",
".",
"project_name",
")",
"dates",
"=",
"[",
"]",
"last_date",
"=",
"None",
"for",
"val",
"in",
"sorted",
"(",
"all_dates",... | Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtype: ``list`` | [
"Get",
"s",
"list",
"of",
"dates",
"(",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
")",
"present",
"in",
"cache",
"beginning",
"with",
"the",
"longest",
"contiguous",
"set",
"of",
"dates",
"that",
"isn",
"t",
"missing",
"more",
"than",
... | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L68-L98 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._is_empty_cache_record | def _is_empty_cache_record(self, rec):
"""
Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool
"""
... | python | def _is_empty_cache_record(self, rec):
"""
Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool
"""
... | [
"def",
"_is_empty_cache_record",
"(",
"self",
",",
"rec",
")",
":",
"# these are taken from DataQuery.query_one_table()",
"for",
"k",
"in",
"[",
"'by_version'",
",",
"'by_file_type'",
",",
"'by_installer'",
",",
"'by_implementation'",
",",
"'by_system'",
",",
"'by_distr... | Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool | [
"Return",
"True",
"if",
"the",
"specified",
"cache",
"record",
"has",
"no",
"data",
"False",
"otherwise",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L100-L121 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._cache_get | def _cache_get(self, date):
"""
Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict
"""
if date in self.cache_data:
log... | python | def _cache_get(self, date):
"""
Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict
"""
if date in self.cache_data:
log... | [
"def",
"_cache_get",
"(",
"self",
",",
"date",
")",
":",
"if",
"date",
"in",
"self",
".",
"cache_data",
":",
"logger",
".",
"debug",
"(",
"'Using class-cached data for date %s'",
",",
"date",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
")",
"return",
"self",
... | Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict | [
"Return",
"cache",
"data",
"for",
"the",
"specified",
"day",
";",
"cache",
"locally",
"in",
"this",
"class",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L123-L140 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._compound_column_value | def _compound_column_value(k1, k2):
"""
Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str
"""
k1 = ProjectStats._column_value(k1)... | python | def _compound_column_value(k1, k2):
"""
Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str
"""
k1 = ProjectStats._column_value(k1)... | [
"def",
"_compound_column_value",
"(",
"k1",
",",
"k2",
")",
":",
"k1",
"=",
"ProjectStats",
".",
"_column_value",
"(",
"k1",
")",
"k2",
"=",
"ProjectStats",
".",
"_column_value",
"(",
"k2",
")",
"if",
"k1",
"==",
"'unknown'",
"and",
"k2",
"==",
"'unknown... | Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str | [
"Like",
":",
"py",
":",
"meth",
":",
"~",
".",
"_column_value",
"but",
"collapses",
"two",
"unknowns",
"into",
"one",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L176-L189 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._shorten_version | def _shorten_version(ver, num_components=2):
"""
If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) ver... | python | def _shorten_version(ver, num_components=2):
"""
If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) ver... | [
"def",
"_shorten_version",
"(",
"ver",
",",
"num_components",
"=",
"2",
")",
":",
"parts",
"=",
"ver",
".",
"split",
"(",
"'.'",
")",
"if",
"len",
"(",
"parts",
")",
"<=",
"num_components",
":",
"return",
"ver",
"return",
"'.'",
".",
"join",
"(",
"pa... | If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) version
:rtype: str | [
"If",
"ver",
"is",
"a",
"dot",
"-",
"separated",
"string",
"with",
"at",
"least",
"(",
"num_components",
"+",
"1",
")",
"components",
"return",
"only",
"the",
"first",
"two",
".",
"Else",
"return",
"the",
"original",
"string",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L192-L205 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_version_data | def per_version_data(self):
"""
Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | python | def per_version_data(self):
"""
Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | [
"def",
"per_version_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"if",
"len",
"(",
"data",
"[",
"'by_version'",
"]",
")",... | Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict | [
"Return",
"download",
"data",
"by",
"version",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L208-L222 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_file_type_data | def per_file_type_data(self):
"""
Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data... | python | def per_file_type_data(self):
"""
Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data... | [
"def",
"per_file_type_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"if",
"len",
"(",
"data",
"[",
"'by_file_type'",
"]",
... | Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict | [
"Return",
"download",
"data",
"by",
"file",
"type",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L225-L239 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_installer_data | def per_installer_data(self):
"""
Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in sel... | python | def per_installer_data(self):
"""
Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in sel... | [
"def",
"per_installer_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
... | Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict | [
"Return",
"download",
"data",
"by",
"installer",
"name",
"and",
"version",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L242-L263 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_implementation_data | def per_implementation_data(self):
"""
Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict
"""
ret = {}
... | python | def per_implementation_data(self):
"""
Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict
"""
ret = {}
... | [
"def",
"per_implementation_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"fo... | Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict | [
"Return",
"download",
"data",
"by",
"python",
"impelementation",
"name",
"and",
"version",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L266-L287 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_system_data | def per_system_data(self):
"""
Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = self._... | python | def per_system_data(self):
"""
Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = self._... | [
"def",
"per_system_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"self",
".",
"... | Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict | [
"Return",
"download",
"data",
"by",
"system",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L290-L307 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_country_data | def per_country_data(self):
"""
Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | python | def per_country_data(self):
"""
Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | [
"def",
"per_country_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
"... | Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict | [
"Return",
"download",
"data",
"by",
"country",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L310-L327 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.per_distro_data | def per_distro_data(self):
"""
Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in self.cache_d... | python | def per_distro_data(self):
"""
Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in self.cache_d... | [
"def",
"per_distro_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
"d... | Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict | [
"Return",
"download",
"data",
"by",
"distro",
"name",
"and",
"version",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L330-L354 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.downloads_per_day | def downloads_per_day(self):
"""
Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int
"""
count, num_days = self._downloads_for_num_days(7)
res = ceil(count / num_days)
... | python | def downloads_per_day(self):
"""
Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int
"""
count, num_days = self._downloads_for_num_days(7)
res = ceil(count / num_days)
... | [
"def",
"downloads_per_day",
"(",
"self",
")",
":",
"count",
",",
"num_days",
"=",
"self",
".",
"_downloads_for_num_days",
"(",
"7",
")",
"res",
"=",
"ceil",
"(",
"count",
"/",
"num_days",
")",
"logger",
".",
"debug",
"(",
"\"Downloads per day = (%d / %d) = %d\... | Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int | [
"Return",
"the",
"number",
"of",
"downloads",
"per",
"day",
"averaged",
"over",
"the",
"past",
"7",
"days",
"of",
"data",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L357-L368 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats.downloads_per_week | def downloads_per_week(self):
"""
Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int
"""
if len(self.cache_dates) < 7:
logger.error("Only... | python | def downloads_per_week(self):
"""
Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int
"""
if len(self.cache_dates) < 7:
logger.error("Only... | [
"def",
"downloads_per_week",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"cache_dates",
")",
"<",
"7",
":",
"logger",
".",
"error",
"(",
"\"Only have %d days of data; cannot calculate \"",
"\"downloads per week\"",
",",
"len",
"(",
"self",
".",
"cache_... | Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int | [
"Return",
"the",
"number",
"of",
"downloads",
"in",
"the",
"last",
"7",
"days",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L371-L385 |
jantman/pypi-download-stats | pypi_download_stats/projectstats.py | ProjectStats._downloads_for_num_days | def _downloads_for_num_days(self, num_days):
"""
Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than... | python | def _downloads_for_num_days(self, num_days):
"""
Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than... | [
"def",
"_downloads_for_num_days",
"(",
"self",
",",
"num_days",
")",
":",
"logger",
".",
"debug",
"(",
"\"Getting download total for last %d days\"",
",",
"num_days",
")",
"dates",
"=",
"self",
".",
"cache_dates",
"logger",
".",
"debug",
"(",
"\"Cache has %d days of... | Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than requested).
:param num_days: number of days of data to ... | [
"Given",
"a",
"number",
"of",
"days",
"of",
"historical",
"data",
"to",
"look",
"at",
"(",
"starting",
"with",
"today",
"and",
"working",
"backwards",
")",
"return",
"the",
"total",
"number",
"of",
"downloads",
"for",
"that",
"time",
"range",
"and",
"the",... | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L406-L429 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._get_project_id | def _get_project_id(self):
"""
Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str
"""
fpath = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', None)
if fpath is None:
raise Exception(... | python | def _get_project_id(self):
"""
Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str
"""
fpath = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', None)
if fpath is None:
raise Exception(... | [
"def",
"_get_project_id",
"(",
"self",
")",
":",
"fpath",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'GOOGLE_APPLICATION_CREDENTIALS'",
",",
"None",
")",
"if",
"fpath",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'ERROR: No project ID specified, and '",
"'G... | Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str | [
"Get",
"our",
"projectId",
"from",
"the",
"GOOGLE_APPLICATION_CREDENTIALS",
"creds",
"JSON",
"file",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L94-L110 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._get_bigquery_service | def _get_bigquery_service(self):
"""
Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a c... | python | def _get_bigquery_service(self):
"""
Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a c... | [
"def",
"_get_bigquery_service",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Getting Google Credentials'",
")",
"credentials",
"=",
"GoogleCredentials",
".",
"get_application_default",
"(",
")",
"logger",
".",
"debug",
"(",
"'Building BigQuery service instance'... | Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a credentials JSON file.
:return: authenticated... | [
"Connect",
"to",
"the",
"BigQuery",
"service",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L112-L130 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._get_download_table_ids | def _get_download_table_ids(self):
"""
Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list``
"""
all_table_names = [] # matching per-date table names
logger.info('Querying for all tables in dataset')
... | python | def _get_download_table_ids(self):
"""
Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list``
"""
all_table_names = [] # matching per-date table names
logger.info('Querying for all tables in dataset')
... | [
"def",
"_get_download_table_ids",
"(",
"self",
")",
":",
"all_table_names",
"=",
"[",
"]",
"# matching per-date table names",
"logger",
".",
"info",
"(",
"'Querying for all tables in dataset'",
")",
"tables",
"=",
"self",
".",
"service",
".",
"tables",
"(",
")",
"... | Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list`` | [
"Get",
"a",
"list",
"of",
"PyPI",
"downloads",
"table",
"(",
"sharded",
"per",
"day",
")",
"IDs",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L132-L164 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._datetime_for_table_name | def _datetime_for_table_name(self, table_name):
"""
Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rty... | python | def _datetime_for_table_name(self, table_name):
"""
Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rty... | [
"def",
"_datetime_for_table_name",
"(",
"self",
",",
"table_name",
")",
":",
"m",
"=",
"self",
".",
"_table_re",
".",
"match",
"(",
"table_name",
")",
"dt",
"=",
"datetime",
".",
"strptime",
"(",
"m",
".",
"group",
"(",
"1",
")",
",",
"'%Y%m%d'",
")",
... | Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rtype: datetime.datetime | [
"Return",
"a",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
"object",
"for",
"the",
"date",
"of",
"the",
"data",
"in",
"the",
"specified",
"table",
"name",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L166-L178 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._run_query | def _run_query(self, query):
"""
Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list``
"""
query_request = self.service.jobs()
... | python | def _run_query(self, query):
"""
Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list``
"""
query_request = self.service.jobs()
... | [
"def",
"_run_query",
"(",
"self",
",",
"query",
")",
":",
"query_request",
"=",
"self",
".",
"service",
".",
"jobs",
"(",
")",
"logger",
".",
"debug",
"(",
"'Running query: %s'",
",",
"query",
")",
"start",
"=",
"datetime",
".",
"now",
"(",
")",
"resp"... | Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list`` | [
"Run",
"one",
"query",
"against",
"BigQuery",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L191-L222 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._get_newest_ts_in_table | def _get_newest_ts_in_table(self, table_name):
"""
Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int
"""
logger.debug(
... | python | def _get_newest_ts_in_table(self, table_name):
"""
Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int
"""
logger.debug(
... | [
"def",
"_get_newest_ts_in_table",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"debug",
"(",
"'Querying for newest timestamp in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT TIMESTAMP_TO_SEC(MAX(timestamp)) AS max_ts %s;\"",
"%",
"(",
"self",
".",
... | Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int | [
"Return",
"the",
"timestamp",
"for",
"the",
"newest",
"record",
"in",
"the",
"given",
"table",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L248-L266 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._query_by_installer | def _query_by_installer(self, table_name):
"""
Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a di... | python | def _query_by_installer(self, table_name):
"""
Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a di... | [
"def",
"_query_by_installer",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by installer in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.installer.name, \"",
"\"details.installer.version, COUNT(*)... | Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a dict of installer names to dicts of installer
version t... | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"installer",
"for",
"one",
"day",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L320-L356 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._query_by_system | def _query_by_system(self, table_name):
"""
Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of sys... | python | def _query_by_system(self, table_name):
"""
Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of sys... | [
"def",
"_query_by_system",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by system in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.system.name, COUNT(*) as dl_count \"",
"\"%s \"",
"\"%s \"",
... | Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of system names to download count.
:rtype: dict | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"system",
"for",
"one",
"day",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L397-L422 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._query_by_distro | def _query_by_distro(self, table_name):
"""
Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a di... | python | def _query_by_distro(self, table_name):
"""
Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a di... | [
"def",
"_query_by_distro",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by distro in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.distro.name, \"",
"\"details.distro.version, COUNT(*) as dl_count... | Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a dict of distro names to dicts of distro version to
d... | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"OS",
"distribution",
"for",
"one",
"day",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L424-L459 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery.query_one_table | def query_one_table(self, table_name):
"""
Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str
"""
table_date = self._datetime_for_table_name(table_name)
logger.info('Running a... | python | def query_one_table(self, table_name):
"""
Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str
"""
table_date = self._datetime_for_table_name(table_name)
logger.info('Running a... | [
"def",
"query_one_table",
"(",
"self",
",",
"table_name",
")",
":",
"table_date",
"=",
"self",
".",
"_datetime_for_table_name",
"(",
"table_name",
")",
"logger",
".",
"info",
"(",
"'Running all queries for date table: %s (%s)'",
",",
"table_name",
",",
"table_date",
... | Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str | [
"Run",
"all",
"queries",
"for",
"the",
"given",
"table",
"name",
"(",
"date",
")",
"and",
"update",
"the",
"cache",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L487-L527 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery._have_cache_for_date | def _have_cache_for_date(self, dt):
"""
Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date... | python | def _have_cache_for_date(self, dt):
"""
Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date... | [
"def",
"_have_cache_for_date",
"(",
"self",
",",
"dt",
")",
":",
"for",
"p",
"in",
"self",
".",
"projects",
":",
"if",
"self",
".",
"cache",
".",
"get",
"(",
"p",
",",
"dt",
")",
"is",
"None",
":",
"return",
"False",
"return",
"True"
] | Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date, False
otherwise
:rtype: bool | [
"Return",
"True",
"if",
"we",
"have",
"cached",
"data",
"for",
"all",
"projects",
"for",
"the",
"specified",
"datetime",
".",
"Return",
"False",
"otherwise",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L529-L543 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery.backfill_history | def backfill_history(self, num_days, available_table_names):
"""
Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date... | python | def backfill_history(self, num_days, available_table_names):
"""
Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date... | [
"def",
"backfill_history",
"(",
"self",
",",
"num_days",
",",
"available_table_names",
")",
":",
"if",
"num_days",
"==",
"-",
"1",
":",
"# skip the first date, under the assumption that data may be",
"# incomplete",
"logger",
".",
"info",
"(",
"'Backfilling all available ... | Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date tables
:type available_table_names: ``list`` | [
"Backfill",
"historical",
"data",
"for",
"days",
"that",
"are",
"missing",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L545-L580 |
jantman/pypi-download-stats | pypi_download_stats/dataquery.py | DataQuery.run_queries | def run_queries(self, backfill_num_days=7):
"""
Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int
"""
available_tables = self._get_download_table_ids... | python | def run_queries(self, backfill_num_days=7):
"""
Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int
"""
available_tables = self._get_download_table_ids... | [
"def",
"run_queries",
"(",
"self",
",",
"backfill_num_days",
"=",
"7",
")",
":",
"available_tables",
"=",
"self",
".",
"_get_download_table_ids",
"(",
")",
"logger",
".",
"debug",
"(",
"'Found %d available download tables: %s'",
",",
"len",
"(",
"available_tables",
... | Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int | [
"Run",
"the",
"data",
"queries",
"for",
"the",
"specified",
"projects",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L582-L597 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | filter_data_columns | def filter_data_columns(data):
"""
Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned b... | python | def filter_data_columns(data):
"""
Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned b... | [
"def",
"filter_data_columns",
"(",
"data",
")",
":",
"keys",
"=",
"set",
"(",
")",
"for",
"dt",
",",
"d",
"in",
"data",
".",
"items",
"(",
")",
":",
"for",
"k",
"in",
"d",
":",
"keys",
".",
"add",
"(",
"k",
")",
"return",
"sorted",
"(",
"[",
... | Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned by ProjectStats attributes
:type data: d... | [
"Given",
"a",
"dict",
"of",
"data",
"such",
"as",
"those",
"in",
":",
"py",
":",
"class",
":",
"~",
".",
"ProjectStats",
"attributes",
"made",
"up",
"of",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
"keys",
"and",
"values",
"of",
"dict... | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L352-L367 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._generate_html | def _generate_html(self):
"""
Generate the HTML for the specified graphs.
:return:
:rtype:
"""
logger.debug('Generating templated HTML')
env = Environment(
loader=PackageLoader('pypi_download_stats', 'templates'),
extensions=['jinja2.ext.l... | python | def _generate_html(self):
"""
Generate the HTML for the specified graphs.
:return:
:rtype:
"""
logger.debug('Generating templated HTML')
env = Environment(
loader=PackageLoader('pypi_download_stats', 'templates'),
extensions=['jinja2.ext.l... | [
"def",
"_generate_html",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating templated HTML'",
")",
"env",
"=",
"Environment",
"(",
"loader",
"=",
"PackageLoader",
"(",
"'pypi_download_stats'",
",",
"'templates'",
")",
",",
"extensions",
"=",
"[",
... | Generate the HTML for the specified graphs.
:return:
:rtype: | [
"Generate",
"the",
"HTML",
"for",
"the",
"specified",
"graphs",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L93-L123 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._data_dict_to_bokeh_chart_data | def _data_dict_to_bokeh_chart_data(self, data):
"""
Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` prop... | python | def _data_dict_to_bokeh_chart_data(self, data):
"""
Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` prop... | [
"def",
"_data_dict_to_bokeh_chart_data",
"(",
"self",
",",
"data",
")",
":",
"labels",
"=",
"[",
"]",
"# find all the data keys",
"keys",
"=",
"set",
"(",
")",
"for",
"date",
"in",
"data",
":",
"for",
"k",
"in",
"data",
"[",
"date",
"]",
":",
"keys",
"... | Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` property
:type data: dict
:return: 2-tuple of data dict,... | [
"Take",
"a",
"dictionary",
"of",
"data",
"as",
"returned",
"by",
"the",
":",
"py",
":",
"class",
":",
"~",
".",
"ProjectStats",
"per_",
"*",
"_data",
"properties",
"return",
"a",
"2",
"-",
"tuple",
"of",
"data",
"dict",
"and",
"x",
"labels",
"list",
... | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L125-L154 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._limit_data | def _limit_data(self, data):
"""
Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last... | python | def _limit_data(self, data):
"""
Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last... | [
"def",
"_limit_data",
"(",
"self",
",",
"data",
")",
":",
"if",
"len",
"(",
"data",
".",
"keys",
"(",
")",
")",
"<=",
"10",
":",
"logger",
".",
"debug",
"(",
"\"Data has less than 10 keys; not limiting\"",
")",
"return",
"data",
"# average last 7 days of each ... | Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last 7 days.
:rtype: dict | [
"Find",
"the",
"per",
"-",
"day",
"average",
"of",
"each",
"series",
"in",
"the",
"data",
"over",
"the",
"last",
"7",
"days",
";",
"drop",
"all",
"but",
"the",
"top",
"10",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L156-L195 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._generate_graph | def _generate_graph(self, name, title, stats_data, y_name):
"""
Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: ... | python | def _generate_graph(self, name, title, stats_data, y_name):
"""
Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: ... | [
"def",
"_generate_graph",
"(",
"self",
",",
"name",
",",
"title",
",",
"stats_data",
",",
"y_name",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating chart data for %s graph'",
",",
"name",
")",
"orig_data",
",",
"labels",
"=",
"self",
".",
"_data_dict_to_bo... | Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: str
:param stats_data: data dict from ``self._stats``
:type stat... | [
"Generate",
"a",
"downloads",
"graph",
";",
"append",
"it",
"to",
"self",
".",
"_graphs",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L197-L223 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._generate_badges | def _generate_badges(self):
"""
Generate download badges. Append them to ``self._badges``.
"""
daycount = self._stats.downloads_per_day
day = self._generate_badge('Downloads', '%d/day' % daycount)
self._badges['per-day'] = day
weekcount = self._stats.downloads_per... | python | def _generate_badges(self):
"""
Generate download badges. Append them to ``self._badges``.
"""
daycount = self._stats.downloads_per_day
day = self._generate_badge('Downloads', '%d/day' % daycount)
self._badges['per-day'] = day
weekcount = self._stats.downloads_per... | [
"def",
"_generate_badges",
"(",
"self",
")",
":",
"daycount",
"=",
"self",
".",
"_stats",
".",
"downloads_per_day",
"day",
"=",
"self",
".",
"_generate_badge",
"(",
"'Downloads'",
",",
"'%d/day'",
"%",
"daycount",
")",
"self",
".",
"_badges",
"[",
"'per-day'... | Generate download badges. Append them to ``self._badges``. | [
"Generate",
"download",
"badges",
".",
"Append",
"them",
"to",
"self",
".",
"_badges",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L225-L243 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator._generate_badge | def _generate_badge(self, subject, status):
"""
Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str... | python | def _generate_badge(self, subject, status):
"""
Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str... | [
"def",
"_generate_badge",
"(",
"self",
",",
"subject",
",",
"status",
")",
":",
"url",
"=",
"'https://img.shields.io/badge/%s-%s-brightgreen.svg'",
"'?style=flat&maxAge=3600'",
"%",
"(",
"subject",
",",
"status",
")",
"logger",
".",
"debug",
"(",
"\"Getting badge for ... | Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str | [
"Generate",
"SVG",
"for",
"one",
"badge",
"via",
"shields",
".",
"io",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L245-L264 |
jantman/pypi-download-stats | pypi_download_stats/outputgenerator.py | OutputGenerator.generate | def generate(self):
"""
Generate all output types and write to disk.
"""
logger.info('Generating graphs')
self._generate_graph(
'by-version',
'Downloads by Version',
self._stats.per_version_data,
'Version'
)
self._ge... | python | def generate(self):
"""
Generate all output types and write to disk.
"""
logger.info('Generating graphs')
self._generate_graph(
'by-version',
'Downloads by Version',
self._stats.per_version_data,
'Version'
)
self._ge... | [
"def",
"generate",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"'Generating graphs'",
")",
"self",
".",
"_generate_graph",
"(",
"'by-version'",
",",
"'Downloads by Version'",
",",
"self",
".",
"_stats",
".",
"per_version_data",
",",
"'Version'",
")",
"s... | Generate all output types and write to disk. | [
"Generate",
"all",
"output",
"types",
"and",
"write",
"to",
"disk",
"."
] | train | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L266-L325 |
cdgriffith/Reusables | reusables/dt.py | datetime_format | def datetime_format(desired_format, datetime_instance=None, *args, **kwargs):
"""
Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March... | python | def datetime_format(desired_format, datetime_instance=None, *args, **kwargs):
"""
Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March... | [
"def",
"datetime_format",
"(",
"desired_format",
",",
"datetime_instance",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"strf",
",",
"exp",
"in",
"datetime_regex",
".",
"datetime",
".",
"format",
".",
"items",
"(",
")",
":",
... | Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March already!"
:param desired_format: string to add datetime details too
:param dateti... | [
"Replaces",
"format",
"style",
"phrases",
"(",
"listed",
"in",
"the",
"dt_exps",
"dictionary",
")",
"with",
"this",
"datetime",
"instance",
"s",
"information",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L55-L75 |
cdgriffith/Reusables | reusables/dt.py | datetime_from_iso | def datetime_from_iso(iso_string):
"""
Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object
... | python | def datetime_from_iso(iso_string):
"""
Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object
... | [
"def",
"datetime_from_iso",
"(",
"iso_string",
")",
":",
"try",
":",
"assert",
"datetime_regex",
".",
"datetime",
".",
"datetime",
".",
"match",
"(",
"iso_string",
")",
".",
"groups",
"(",
")",
"[",
"0",
"]",
"except",
"(",
"ValueError",
",",
"AssertionErr... | Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object | [
"Create",
"a",
"DateTime",
"object",
"from",
"a",
"ISO",
"string"
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L78-L97 |
cdgriffith/Reusables | reusables/dt.py | now | def now(utc=False, tz=None):
"""
Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not ... | python | def now(utc=False, tz=None):
"""
Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not ... | [
"def",
"now",
"(",
"utc",
"=",
"False",
",",
"tz",
"=",
"None",
")",
":",
"return",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"if",
"utc",
"else",
"datetime",
".",
"datetime",
".",
"now",
"(",
"tz",
"=",
"tz",
")"
] | Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not local
:param tz: TimeZone as specifie... | [
"Get",
"a",
"current",
"DateTime",
"object",
".",
"By",
"default",
"is",
"local",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L100-L116 |
cdgriffith/Reusables | reusables/process_helpers.py | run | def run(command, input=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=None, copy_local_env=False, **kwargs):
"""
Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the s... | python | def run(command, input=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=None, copy_local_env=False, **kwargs):
"""
Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the s... | [
"def",
"run",
"(",
"command",
",",
"input",
"=",
"None",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",
"PIPE",
",",
"timeout",
"=",
"None",
",",
"copy_local_env",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":"... | Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the same on each version / interpreter as before.
.. code:: python
reusables.run('echo "hello world!', shell=True)
# CPython 3.... | [
"Cross",
"platform",
"compatible",
"subprocess",
"with",
"CompletedProcess",
"return",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/process_helpers.py#L18-L97 |
cdgriffith/Reusables | reusables/process_helpers.py | run_in_pool | def run_in_pool(target, iterable, threaded=True, processes=4,
asynchronous=False, target_kwargs=None):
""" Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1... | python | def run_in_pool(target, iterable, threaded=True, processes=4,
asynchronous=False, target_kwargs=None):
""" Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1... | [
"def",
"run_in_pool",
"(",
"target",
",",
"iterable",
",",
"threaded",
"=",
"True",
",",
"processes",
"=",
"4",
",",
"asynchronous",
"=",
"False",
",",
"target_kwargs",
"=",
"None",
")",
":",
"my_pool",
"=",
"pool",
".",
"ThreadPool",
"if",
"threaded",
"... | Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1, 4, 9, 16, 25]
:param target: function to run
:param iterable: positional arg to pass to function
:param threade... | [
"Run",
"a",
"set",
"of",
"iterables",
"to",
"a",
"function",
"in",
"a",
"Threaded",
"or",
"MP",
"Pool",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/process_helpers.py#L100-L133 |
cdgriffith/Reusables | reusables/namespace.py | tree_view | def tree_view(dictionary, level=0, sep="| "):
"""
View a dictionary as a tree.
"""
return "".join(["{0}{1}\n{2}".format(sep * level, k,
tree_view(v, level + 1, sep=sep) if isinstance(v, dict)
else "") for k, v in dictionary.items()]) | python | def tree_view(dictionary, level=0, sep="| "):
"""
View a dictionary as a tree.
"""
return "".join(["{0}{1}\n{2}".format(sep * level, k,
tree_view(v, level + 1, sep=sep) if isinstance(v, dict)
else "") for k, v in dictionary.items()]) | [
"def",
"tree_view",
"(",
"dictionary",
",",
"level",
"=",
"0",
",",
"sep",
"=",
"\"| \"",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"[",
"\"{0}{1}\\n{2}\"",
".",
"format",
"(",
"sep",
"*",
"level",
",",
"k",
",",
"tree_view",
"(",
"v",
",",
"l... | View a dictionary as a tree. | [
"View",
"a",
"dictionary",
"as",
"a",
"tree",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L132-L138 |
cdgriffith/Reusables | reusables/namespace.py | Namespace.to_dict | def to_dict(self, in_dict=None):
"""
Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace
"""
in_dict = in_dict if in_dict else self
out_dic... | python | def to_dict(self, in_dict=None):
"""
Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace
"""
in_dict = in_dict if in_dict else self
out_dic... | [
"def",
"to_dict",
"(",
"self",
",",
"in_dict",
"=",
"None",
")",
":",
"in_dict",
"=",
"in_dict",
"if",
"in_dict",
"else",
"self",
"out_dict",
"=",
"dict",
"(",
")",
"for",
"k",
",",
"v",
"in",
"in_dict",
".",
"items",
"(",
")",
":",
"if",
"isinstan... | Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace | [
"Turn",
"the",
"Namespace",
"and",
"sub",
"Namespaces",
"back",
"into",
"a",
"native",
"python",
"dictionary",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L111-L125 |
cdgriffith/Reusables | reusables/namespace.py | ConfigNamespace.list | def list(self, item, default=None, spliter=",", strip=True, mod=None):
""" Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str ... | python | def list(self, item, default=None, spliter=",", strip=True, mod=None):
""" Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str ... | [
"def",
"list",
"(",
"self",
",",
"item",
",",
"default",
"=",
"None",
",",
"spliter",
"=",
"\",\"",
",",
"strip",
"=",
"True",
",",
"mod",
"=",
"None",
")",
":",
"try",
":",
"item",
"=",
"self",
".",
"__getattr__",
"(",
"item",
")",
"except",
"At... | Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str on
:param strip: clean the list with the `strip`
:return: list of i... | [
"Return",
"value",
"of",
"key",
"as",
"a",
"list"
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L220-L241 |
cdgriffith/Reusables | reusables/web.py | download | def download(url, save_to_file=True, save_dir=".", filename=None,
block_size=64000, overwrite=False, quiet=False):
"""
Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
... | python | def download(url, save_to_file=True, save_dir=".", filename=None,
block_size=64000, overwrite=False, quiet=False):
"""
Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
... | [
"def",
"download",
"(",
"url",
",",
"save_to_file",
"=",
"True",
",",
"save_dir",
"=",
"\".\"",
",",
"filename",
"=",
"None",
",",
"block_size",
"=",
"64000",
",",
"overwrite",
"=",
"False",
",",
"quiet",
"=",
"False",
")",
":",
"if",
"save_to_file",
"... | Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
:param save_dir: location of saved file, default is current working dir
:param filename: filename to save as
:param block_size: do... | [
"Download",
"a",
"given",
"URL",
"to",
"either",
"file",
"or",
"memory"
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L31-L93 |
cdgriffith/Reusables | reusables/web.py | url_to_ips | def url_to_ips(url, port=None, ipv6=False, connect_type=socket.SOCK_STREAM,
proto=socket.IPPROTO_TCP, flags=0):
"""
Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:194... | python | def url_to_ips(url, port=None, ipv6=False, connect_type=socket.SOCK_STREAM,
proto=socket.IPPROTO_TCP, flags=0):
"""
Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:194... | [
"def",
"url_to_ips",
"(",
"url",
",",
"port",
"=",
"None",
",",
"ipv6",
"=",
"False",
",",
"connect_type",
"=",
"socket",
".",
"SOCK_STREAM",
",",
"proto",
"=",
"socket",
".",
"IPPROTO_TCP",
",",
"flags",
"=",
"0",
")",
":",
"try",
":",
"results",
"=... | Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:1946']
:param url: hostname to resolve to IP addresses
:param port: port to send to getaddrinfo
:param ipv6: Return IPv6 address ... | [
"Provide",
"a",
"list",
"of",
"IP",
"addresses",
"uses",
"socket",
".",
"getaddrinfo"
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L137-L166 |
cdgriffith/Reusables | reusables/web.py | ip_to_url | def ip_to_url(ip_addr):
"""
Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
... | python | def ip_to_url(ip_addr):
"""
Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
... | [
"def",
"ip_to_url",
"(",
"ip_addr",
")",
":",
"try",
":",
"return",
"socket",
".",
"gethostbyaddr",
"(",
"ip_addr",
")",
"[",
"0",
"]",
"except",
"(",
"socket",
".",
"gaierror",
",",
"socket",
".",
"herror",
")",
":",
"logger",
".",
"exception",
"(",
... | Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
# None
reusables.ip_to_u... | [
"Resolve",
"a",
"hostname",
"based",
"off",
"an",
"IP",
"address",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L187-L210 |
cdgriffith/Reusables | reusables/web.py | ThreadedServer.start | def start(self):
"""Create a background thread for httpd and serve 'forever'"""
self._process = threading.Thread(target=self._background_runner)
self._process.start() | python | def start(self):
"""Create a background thread for httpd and serve 'forever'"""
self._process = threading.Thread(target=self._background_runner)
self._process.start() | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"_process",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_background_runner",
")",
"self",
".",
"_process",
".",
"start",
"(",
")"
] | Create a background thread for httpd and serve 'forever | [
"Create",
"a",
"background",
"thread",
"for",
"httpd",
"and",
"serve",
"forever"
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L126-L129 |
cdgriffith/Reusables | reusables/log.py | get_stream_handler | def get_stream_handler(stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format:... | python | def get_stream_handler(stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format:... | [
"def",
"get_stream_handler",
"(",
"stream",
"=",
"sys",
".",
"stderr",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
")",
":",
"sh",
"=",
"logging",
".",
"StreamHandler",
"(",
"stream",
")",
"sh",
"."... | Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format: formatter to use
:return: stream handler | [
"Returns",
"a",
"set",
"up",
"stream",
"handler",
"to",
"add",
"to",
"a",
"logger",
"."
] | train | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L46-L59 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.