Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
wiperf / usr / local / lib / python3.7 / dist-packages / influxdb / __pycache__ / helper.cpython-37.pyc
Size: Mime:
B

§:0]Úbã@sxdZddlmZddlmZddlmZddlmZddlmZmZddl	m	Z	ddl
mZdd	lZGd
d„de
ƒZd	S)zHelper class for InfluxDB.é)Úabsolute_import)Údivision)Úprint_function)Úunicode_literals)Ú
namedtupleÚdefaultdict)Údatetime)ÚwarnNcs^eZdZdZdZ‡fdd„Zdd„Zeddd	„ƒZed
d„ƒZ	edd
„ƒZ
edd„ƒZ‡Z
S)ÚSeriesHelperaïSubclass this helper eases writing data points in bulk.

    All data points are immutable, ensuring they do not get overwritten.
    Each subclass can write to its own database.
    The time series names can also be based on one or more defined fields.
    The field "time" can be specified when creating a point, and may be any of
    the time types supported by the client (i.e. str, datetime, int).
    If the time is not specified, the current system time (utc) will be used.

    Annotated example::

        class MySeriesHelper(SeriesHelper):
            class Meta:
                # Meta class stores time series helper configuration.
                series_name = 'events.stats.{server_name}'
                # Series name must be a string, curly brackets for dynamic use.
                fields = ['time', 'server_name']
                # Defines all the fields in this time series.
                ### Following attributes are optional. ###
                client = TestSeriesHelper.client
                # Client should be an instance of InfluxDBClient.
                :warning: Only used if autocommit is True.
                bulk_size = 5
                # Defines the number of data points to write simultaneously.
                # Only applicable if autocommit is True.
                autocommit = True
                # If True and no bulk_size, then will set bulk_size to 1.
                retention_policy = 'your_retention_policy'
                # Specify the retention policy for the data points
                time_precision = "h"|"m"|s"|"ms"|"u"|"ns"
                # Default is ns (nanoseconds)
                # Setting time precision while writing point
                # You should also make sure time is set in the given precision

    Fc	sð|jsàd|_yt|dƒ}Wn$tk
r@td |j¡ƒ‚YnXxNdD]F}yt|d|t||ƒƒWqHtk
rŒtd ||j¡ƒ‚YqHXqHWt|ddƒ|_t|d	d
ƒ|_ddd
dddd
g}|j|krâtd |jd |¡¡ƒ‚t|dd
ƒ|_	t|dd
ƒ|_
|jr|j
std |j¡ƒ‚y:t|dƒ|_|jdkrV|jrVtd |j¡ƒd|_Wntk
rtd|_YnX|jsŽtd |j¡ƒt
tƒ|_d|jkr°|j d¡t|jdg|j|jƒ|_dt|jƒ|jj_tt|ƒ |¡S)zÂInitialize class attributes for subsequent constructor calls.

        :note: *args and **kwargs are not explicitly used in this function,
        but needed for Python 2 compatibility.
        TZMetazMissing Meta class in {0}.)Úseries_nameÚfieldsÚtagsÚ_zMissing {0} in {1} Meta class.Z
autocommitFÚtime_precisionNÚhÚmÚsÚmsÚuÚnsz9In {0}, time_precision is set, but invalid use any of {}.ú,Úretention_policyÚclientz8In {0}, autocommit is set to True, but no client is set.Z	bulk_sizeéz<Definition of bulk_size in {0} forced to 1, was less than 1.éÿÿÿÿzIDefinition of bulk_size in {0} has no affect because autocommit is false.Útime)N)Ú__initialized__ÚgetattrÚAttributeErrorÚformatÚ__name__ÚsetattrÚ_autocommitÚ_time_precisionÚjoinÚ_retention_policyÚ_clientÚ
_bulk_sizer	rÚlistÚ_datapointsÚ_fieldsÚremoverÚ_tagsÚ_typeÚlenÚ__new__Ú__defaults__Úsuperr
)ÚclsÚargsÚkwargsZ_metaÚattrZallowed_time_precisions)Ú	__class__©ú5/tmp/pip-install-4lg_ekbd/influxdb/influxdb/helper.pyr/7sb






zSeriesHelper.__new__cKsÐ|j}| d| ¡¡}t|jƒ}t|jƒ}t| ¡ƒ}||ksTtd |j| ¡¡ƒ‚|||ksvtd |||¡ƒ‚|j	|j
jf|Ž |jfd|i|—Ž¡|j
rÌtdd„|j	 ¡Dƒƒ|jkrÌ| ¡dS)zÁCall to constructor creates a new data point.

        :note: Data points written when `bulk_size` is reached per Helper.
        :warning: Data points are *immutable* (`namedtuples`).
        rz<Expected arguments to contain all tags {0}, instead got {1}.z(Got arguments not in tags or fields: {0}css|]}t|ƒVqdS)N)r.)Ú.0Zseriesr7r7r8ú	<genexpr>“sz(SeriesHelper.__init__.<locals>.<genexpr>N)r6ÚpopÚ_current_timestampÚsetr,r*ÚkeysÚ	NameErrorrr)Z_series_nameÚappendr-r"ÚsumÚvaluesr'Úcommit)ÚselfÚkwr2Ú	timestampr
rr>r7r7r8Ú__init__ys$

zSeriesHelper.__init__NcCs.|s
|j}|j| ¡|j|jd}| ¡|S)aCommit everything from datapoints via the client.

        :param client: InfluxDBClient instance for writing points to InfluxDB.
        :attention: any provided client will supersede the class client.
        :return: result of client.write_points.
        )rr)r&Zwrite_pointsÚ_json_body_r#r%Ú_reset_)r2rZrtnr7r7r8rC—s
zSeriesHelper.commitc	Cs¬g}|js| ¡x”t |j¡D]„\}}xz|D]r}|iit|dƒdœ}x,|jD]"}t||ƒ}|dk	rN||d|<qNWx |jD]}t||ƒ|d|<q|W| |¡q.Wq W|S)zcReturn the JSON body of given datapoints.

        :return: JSON body of these datapoints.
        r)Zmeasurementrr
rNrr
)	rrIÚsixÚ	iteritemsr)rr*r,r@)	r2ÚjsonrÚdataZpointZ
json_pointÚfieldÚvalueÚtagr7r7r8rHªs"

zSeriesHelper._json_body_cCsttƒ|_dS)zReset data storage.N)rr(r))r2r7r7r8rIÇszSeriesHelper._reset_cCst ¡S)N)rÚutcnowr7r7r7r8r<ÌszSeriesHelper._current_timestamp)N)r Ú
__module__Ú__qualname__Ú__doc__rr/rGÚclassmethodrCrHrIÚstaticmethodr<Ú
__classcell__r7r7)r6r8r
s#Br
)rTÚ
__future__rrrrÚcollectionsrrrÚwarningsr	rJÚobjectr
r7r7r7r8Ú<module>s