<commit_before># -*- coding: utf-8 -*-
"""
Display Graphite metrics.

Configuration parameters:
    cache_timeout: how often we refresh this module in seconds.
        (default 120)
    datapoint_selection: when multiple data points are returned,
        use "max" or "min" to determine which one to display.
        (default "max")
    format: you MUST use placeholders here to display data, see below.
        (default '')
    graphite_url: URL to your graphite server. (default '')
    http_timeout: HTTP query timeout to graphite.
        (default 10)
    proxy: You can configure the proxy with HTTP or HTTPS.
        (default: None)
        examples:
            proxy = 'https://myproxy.example.com:1234/'
            proxy = 'http://user:passwd@myproxy.example.com/'
            proxy = 'socks5://user:passwd@host:port'
        (proxy_socks is available after an 'pip install requests[socks]')
    targets: semicolon separated list of targets to query graphite for.
        (default '')
    threshold_bad: numerical threshold,
        if set will send a notification and colorize the output.
        (default None)
    threshold_degraded: numerical threshold,
        if set will send a notification and colorize the output.
        (default None)
    timespan: time range to query graphite for.
        (default "-2minutes")
    value_comparator: choose between "max" and "min" to compare thresholds
        to the data point value.
        (default "max")
    value_format: pretty format long numbers with "K", "M" etc.
        (default True)
    value_round: round values so they're not displayed as floats.
        (default True)

Dynamic format placeholders:
        The "format" parameter placeholders are dynamically based on the data points
        names returned by the "targets" query to graphite.

    For example if your target is "carbon.agents.localhost-a.memUsage", you'd get
    a JSON result like this:
        {"target": "carbon.agents.localhost-a.memUsage", "datapoints": [[19693568.0, 1463663040]]}

    So the placeholder you could use on your "format" config is:
        format = "{carbon.agents.localhost-a.memUsage}"

    TIP: use aliases !
        targets = "alias(carbon.agents.localhost-a.memUsage, 'local_memuse')"
        format = "local carbon mem usage: {local_memuse} bytes"

Color options:
    color_bad: threshold_bad has been exceeded
    color_degraded: threshold_degraded has been exceeded

@author ultrabug
"""
from requests import get
from syslog import syslog, LOG_INFO


def format_value(num, value_round=True):
    for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
        if abs(num) < 1000.0:
            if value_round:
                return '%1.0f%s' % (num, unit)
            else:
                return '%3.1f%s' % (num, unit)
        num /= 1000.0
    if value_round:
        return '%.0f%s' % (num, 'Y')
    else:
        return '%.1f%s' % (num, 'Y')


class Py3status:
    """
    """
    cache_timeout = 120
    datapoint_selection = 'max'
    format = ''
    graphite_url = ''
    proxy = None
    http_timeout = 10
    targets = ''
    threshold_bad = None
    threshold_degraded = None
    timespan = '-2minutes'
    value_comparator = 'max'
    value_format = True
    value_round = True
<commit_msg>fix graphite for tests in master<commit_after># -*- coding: utf-8 -*-
"""
Display Graphite metrics.

Configuration parameters:
    cache_timeout: how often we refresh this module in seconds.
        (default 120)
    datapoint_selection: when multiple data points are returned,
        use "max" or "min" to determine which one to display.
        (default "max")
    format: you MUST use placeholders here to display data, see below.
        (default '')
    graphite_url: URL to your graphite server. (default '')
    http_timeout: HTTP query timeout to graphite.
        (default 10)
    proxy: You can configure the proxy with HTTP or HTTPS.
        (default: None)
        examples:
            proxy = 'https://myproxy.example.com:1234/'
            proxy = 'http://user:passwd@myproxy.example.com/'
            proxy = 'socks5://user:passwd@host:port'
        (proxy_socks is available after an 'pip install requests[socks]')
        (default None)
    targets: semicolon separated list of targets to query graphite for.
        (default '')
    threshold_bad: numerical threshold,
        if set will send a notification and colorize the output.
        (default None)
    threshold_degraded: numerical threshold,
        if set will send a notification and colorize the output.
        (default None)
    timespan: time range to query graphite for.
        (default "-2minutes")
    value_comparator: choose between "max" and "min" to compare thresholds
        to the data point value.
        (default "max")
    value_format: pretty format long numbers with "K", "M" etc.
        (default True)
    value_round: round values so they're not displayed as floats.
        (default True)

Dynamic format placeholders:
        The "format" parameter placeholders are dynamically based on the data points
        names returned by the "targets" query to graphite.

    For example if your target is "carbon.agents.localhost-a.memUsage", you'd get
    a JSON result like this:
        {"target": "carbon.agents.localhost-a.memUsage", "datapoints": [[19693568.0, 1463663040]]}

    So the placeholder you could use on your "format" config is:
        format = "{carbon.agents.localhost-a.memUsage}"

    TIP: use aliases !
        targets = "alias(carbon.agents.localhost-a.memUsage, 'local_memuse')"
        format = "local carbon mem usage: {local_memuse} bytes"

Color options:
    color_bad: threshold_bad has been exceeded
    color_degraded: threshold_degraded has been exceeded

@author ultrabug
"""
from requests import get
from syslog import syslog, LOG_INFO


def format_value(num, value_round=True):
    for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
        if abs(num) < 1000.0:
            if value_round:
                return '%1.0f%s' % (num, unit)
            else:
                return '%3.1f%s' % (num, unit)
        num /= 1000.0
    if value_round:
        return '%.0f%s' % (num, 'Y')
    else:
        return '%.1f%s' % (num, 'Y')


class Py3status:
    """
    """
    cache_timeout = 120
    datapoint_selection = 'max'
    format = ''
    graphite_url = ''
    http_timeout = 10
    proxy = None
    targets = ''
    threshold_bad = None
    threshold_degraded = None
    timespan = '-2minutes'
    value_comparator = 'max'
    value_format = True
    value_round = True

{'fraction_non_alphanumeric': 0.1006079027355623, 'fraction_numerical': 0.01641337386018237, 'mean_word_length': 2.596174863387978, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4125736', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1879, 'n_words': 677}