# Path: biggraphite/metric.py
# _UTF8_CODEC = codecs.getencoder("utf8")
# _UUID_NAMESPACE = uuid.UUID("{00000000-1111-2222-3333-444444444444}")
# _NAN = float("nan")
# METADATA_INSTANCES_COUNT = prometheus_client.Gauge(
#     "bg_metadata_instances_count", "Number of metadata actively used"
# )
#     _STR_RE = re.compile(
#         r"^(?P<points>[\d]+)\*(?P<precision>[\d]+)s(?P<type>(_0|_aggr))?$"
#     )
#     _DEFAULT_AGGREGATOR = Aggregator.average
#     _DEFAULT_RETENTION = Retention.from_string("86400*1s:10080*60s")
#     _DEFAULT_XFILESFACTOR = 0.5
#     _XFILESFACTOR_PRECISION = 2
# class Error(Exception):
# class InvalidArgumentError(Error):
# class Metric(object):
# class Aggregator(enum.Enum):
# class Stage(object):
# class Retention(object):
# class MetricMetadata(object):
#     def __init__(
#         self, name, id, metadata, created_on=None, updated_on=None, read_on=None
#     ):
#     def as_string_dict(self):
#     def __getattr__(self, name):
#     def __dir__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# def encode_metric_name(name):
# def make_metric_with_defaults(
#     name, metadata, created_on=None, updated_on=None, read_on=None
# ):
# def make_metric(name, metadata, created_on, updated_on, read_on):
# def sanitize_metric_name(name):
# def _components_from_name(metric_name):
#     def __init__(self, carbon_name):
#     def merge(self, values=[], counts=[], newest_first=False):
#     def _merge_average(self, values, counts, values_newest_first):
#     def _merge_last(self, values, counts, values_newest_first):
#     def _merge_maximum(self, values, counts, values_newest_first):
#     def _merge_minimum(self, values, counts, values_newest_first):
#     def _merge_total(self, values, counts, values_newest_first):
#     def aggregate(self, values=[], counts=[], newest_first=False):
#     def _aggregate_average(self, values, counts, values_newest_first):
#     def _aggregate_last(self, values, counts, values_newest_first):
#     def _aggregate_maximum(self, values, counts, values_newest_first):
#     def _aggregate_minimum(self, values, counts, values_newest_first):
#     def _aggregate_total(self, values, counts, values_newest_first):
#     def from_carbon_name(cls, name):
#     def carbon_name(self):
#     def from_config_name(cls, name):
#     def from_name(cls, name):
#     def __sum_and_count(values, counts):
#     def __min_and_max(values):
#     def __init__(self, points, precision, stage0=False):
#     def __str__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def as_string(self):
#     def as_full_string(self):
#     def duration_ms(self):
#     def epoch(self, timestamp):
#     def from_string(cls, s):
#     def precision_ms(self):
#     def round_down(self, timestamp):
#     def round_up(self, timestamp):
#     def step(self, timestamp):
#     def step_ms(self, timestamp_ms):
#     def aggregated(self):
#     def __init__(self, stages):
#     def __getitem__(self, n):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_string(self):
#     def from_string(cls, string):
#     def duration(self):
#     def stage0(self):
#     def downsampled_stages(self):
#     def from_carbon(cls, elem):
#     def find_stage_for_ts(self, searched, now):
#     def align_time_window(self, start_time, end_time, now, shift=False):
#     def points(self):
#     def __init__(self, aggregator=None, retention=None, carbon_xfilesfactor=None):
#     def __setattr__(self, name, value):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_json(self):
#     def as_string_dict(self):
#     def create(cls, aggregator=None, retention=None, carbon_xfilesfactor=None):
#     def get_metadata_instances_count(cls):
#     def from_json(cls, s):
#     def from_string_dict(cls, d):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


import datetime
import time
from biggraphite import metric as bg_metric
from biggraphite.cli import command




class CommandWrite(command.BaseCommand):
    """Write points."""

    NAME = "write"
    HELP = "write a point to a given metric, creating it if it does not exist."

    def add_arguments(self, parser):
        """Add custom arguments."""
        parser.add_argument("metric", help="Name of the metric to update.")
        parser.add_argument("value", help="Value to write at the select time.")
        parser.add_argument(
            "-t",
            "--timestamp",
            help="Timestamp at which to write the new point.",
            action=command.ParseDateTimeArg,
            default=datetime.datetime.now(),
            required=False,
        )
        parser.add_argument(
            "-c",
            "--count",
            help="Count associated with the value to be written.",
            default=1,
            required=False,
        )
        # TODO(d.forest): support for writing directly a chosen stage

# Path: biggraphite/metric.py
# _UTF8_CODEC = codecs.getencoder("utf8")
# _UUID_NAMESPACE = uuid.UUID("{00000000-1111-2222-3333-444444444444}")
# _NAN = float("nan")
# METADATA_INSTANCES_COUNT = prometheus_client.Gauge(
#     "bg_metadata_instances_count", "Number of metadata actively used"
# )
#     _STR_RE = re.compile(
#         r"^(?P<points>[\d]+)\*(?P<precision>[\d]+)s(?P<type>(_0|_aggr))?$"
#     )
#     _DEFAULT_AGGREGATOR = Aggregator.average
#     _DEFAULT_RETENTION = Retention.from_string("86400*1s:10080*60s")
#     _DEFAULT_XFILESFACTOR = 0.5
#     _XFILESFACTOR_PRECISION = 2
# class Error(Exception):
# class InvalidArgumentError(Error):
# class Metric(object):
# class Aggregator(enum.Enum):
# class Stage(object):
# class Retention(object):
# class MetricMetadata(object):
#     def __init__(
#         self, name, id, metadata, created_on=None, updated_on=None, read_on=None
#     ):
#     def as_string_dict(self):
#     def __getattr__(self, name):
#     def __dir__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# def encode_metric_name(name):
# def make_metric_with_defaults(
#     name, metadata, created_on=None, updated_on=None, read_on=None
# ):
# def make_metric(name, metadata, created_on, updated_on, read_on):
# def sanitize_metric_name(name):
# def _components_from_name(metric_name):
#     def __init__(self, carbon_name):
#     def merge(self, values=[], counts=[], newest_first=False):
#     def _merge_average(self, values, counts, values_newest_first):
#     def _merge_last(self, values, counts, values_newest_first):
#     def _merge_maximum(self, values, counts, values_newest_first):
#     def _merge_minimum(self, values, counts, values_newest_first):
#     def _merge_total(self, values, counts, values_newest_first):
#     def aggregate(self, values=[], counts=[], newest_first=False):
#     def _aggregate_average(self, values, counts, values_newest_first):
#     def _aggregate_last(self, values, counts, values_newest_first):
#     def _aggregate_maximum(self, values, counts, values_newest_first):
#     def _aggregate_minimum(self, values, counts, values_newest_first):
#     def _aggregate_total(self, values, counts, values_newest_first):
#     def from_carbon_name(cls, name):
#     def carbon_name(self):
#     def from_config_name(cls, name):
#     def from_name(cls, name):
#     def __sum_and_count(values, counts):
#     def __min_and_max(values):
#     def __init__(self, points, precision, stage0=False):
#     def __str__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def as_string(self):
#     def as_full_string(self):
#     def duration_ms(self):
#     def epoch(self, timestamp):
#     def from_string(cls, s):
#     def precision_ms(self):
#     def round_down(self, timestamp):
#     def round_up(self, timestamp):
#     def step(self, timestamp):
#     def step_ms(self, timestamp_ms):
#     def aggregated(self):
#     def __init__(self, stages):
#     def __getitem__(self, n):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_string(self):
#     def from_string(cls, string):
#     def duration(self):
#     def stage0(self):
#     def downsampled_stages(self):
#     def from_carbon(cls, elem):
#     def find_stage_for_ts(self, searched, now):
#     def align_time_window(self, start_time, end_time, now, shift=False):
#     def points(self):
#     def __init__(self, aggregator=None, retention=None, carbon_xfilesfactor=None):
#     def __setattr__(self, name, value):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_json(self):
#     def as_string_dict(self):
#     def create(cls, aggregator=None, retention=None, carbon_xfilesfactor=None):
#     def get_metadata_instances_count(cls):
#     def from_json(cls, s):
#     def from_string_dict(cls, d):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


# Path: biggraphite/cli/command_write.py
import datetime
import time
from biggraphite import metric as bg_metric
from biggraphite.cli import command





class CommandWrite(command.BaseCommand):
    """Write points."""

    NAME = "write"
    HELP = "write a point to a given metric, creating it if it does not exist."

    def add_arguments(self, parser):
        """Add custom arguments."""
        parser.add_argument("metric", help="Name of the metric to update.")
        parser.add_argument("value", help="Value to write at the select time.")
        parser.add_argument(
            "-t",
            "--timestamp",
            help="Timestamp at which to write the new point.",
            action=command.ParseDateTimeArg,
            default=datetime.datetime.now(),
            required=False,
        )
        parser.add_argument(
            "-c",
            "--count",
            help="Count associated with the value to be written.",
            default=1,
            required=False,
        )
        # TODO(d.forest): support for writing directly a chosen stage

        aggregators = ", ".join([str(v.value) for v in bg_metric.Aggregator])