U
vi4 @ sT d Z ddlZddlZddlmZ ddlmZmZmZ ddlm Z ddl
mZ ddlm
Z
ddlmZ ejdejd ZejZed
ddd
ddZed
dddd
ddZedddZzddlZdZW n ek
r dZY nX G dd deZdd Z dd Z!edddZ"d*edd d!Z#edd"d#Z$edd$d%Z%efd&d'Z&d(d) Z'dS )+z/Point data structure to represent LineProtocol. N)int)datetime timedeltatimezone)Decimal)Integral)get_date_helper)WritePrecision)tzz\,z\ z\nz\tz\r),
z\=)r =r r
r r z\"z\\)"\TFc @ s e Zd ZdZedd ZeefeedddZ dd Z
efd d
Zdd Zd
d Z
dddZedd Zedd Zdd Zdd ZdS )Pointz
Point defines the values that will be written to the database.
Ref: https://docs.influxdata.com/influxdb/latest/reference/key-concepts/data-elements/#point
c C s t | }|S )z3Create a new Point with specified measurement name.)r )measurementp r S/opt/alt/python38/lib/python3.8/site-packages/influxdb_client/client/write/point.pyr 6 s zPoint.measurement)
dictionarywrite_precisionc
K sJ | dd}|dkr$| | dd }t|}| dd}|dk rd|D ]}|| krD||| | qDn*d| kr| d D ]\}}||| qx| dd}|dk r|D ]} | | kr|| | | qn"| d D ]\} }
|| |
q| d d
}|| kr|j| | |d | di }d| kr.| d }ttd
d | |_|S )a,
Initialize point from 'dict' structure.
The expected dict structure is:
- measurement
- tags
- fields
- time
Example:
.. code-block:: python
# Use default dictionary structure
dict_structure = {
"measurement": "h2o_feet",
"tags": {"location": "coyote_creek"},
"fields": {"water_level": 1.0},
"time": 1
}
point = Point.from_dict(dict_structure, WritePrecision.NS)
Example:
.. code-block:: python
# Use custom dictionary structure
dictionary = {
"name": "sensor_pt859",
"location": "warehouse_125",
"version": "2021.06.05.5874",
"pressure": 125,
"temperature": 10,
"created": 1632208639,
}
point = Point.from_dict(dictionary,
write_precision=WritePrecision.S,
record_measurement_key="name",
record_time_key="created",
record_tag_keys=["location", "version"],
record_field_keys=["pressure", "temperature"])
Int Types:
The following example shows how to configure the types of integers fields.
It is useful when you want to serialize integers always as ``float`` to avoid ``field type conflict``
or use ``unsigned 64-bit integer`` as the type for serialization.
.. code-block:: python
# Use custom dictionary structure
dict_structure = {
"measurement": "h2o_feet",
"tags": {"location": "coyote_creek"},
"fields": {
"water_level": 1.0,
"some_counter": 108913123234
},
"time": 1
}
point = Point.from_dict(dict_structure, field_types={"some_counter": "uint"})
:param dictionary: dictionary for serialize into data Point
:param write_precision: sets the precision for the supplied time values
:key record_measurement_key: key of dictionary with specified measurement
:key record_measurement_name: static measurement name for data Point
:key record_time_key: key of dictionary with specified timestamp
:key record_tag_keys: list of dictionary keys to use as a tag
:key record_field_keys: list of dictionary keys to use as a field
:key field_types: optional dictionary to specify types of serialized fields. Currently, is supported customization for integer types.
Possible integers types:
- ``int`` - serialize integers as "**Signed 64-bit integers**" - ``9223372036854775807i`` (default behaviour)
- ``uint`` - serialize integers as "**Unsigned 64-bit integers**" - ``9223372036854775807u``
- ``float`` - serialize integers as "**IEEE-754 64-bit floating-point numbers**". Useful for unify number types in your pipeline to avoid field type conflict - ``9223372036854775807``
The ``field_types`` can be also specified as part of incoming dictionary. For more info see an example above.
:return: new data point
Zrecord_measurement_nameNZrecord_measurement_keyr record_tag_keystagsrecord_field_keysfieldsrecord_time_keytime)r field_typesc S s, | d | d dkrdn| d dkr&dndfS )Nr r iZuintu r )itemr r r