1010
1111class SeriesHelper (object ):
1212
13- '''
13+ """
1414 Subclassing this helper eases writing data points in bulk.
1515 All data points are immutable, insuring they do not get overwritten.
1616 Each subclass can write to its own database.
1717 The time series names can also be based on one or more defined fields.
1818
19- Annotated example:
20- ```
21- class MySeriesHelper(SeriesHelper):
22- class Meta:
23- # Meta class stores time series helper configuration.
24- series_name = 'events.stats.{server_name}'
25- # Series name must be a string, curly brackets for dynamic use.
26- fields = ['time', 'server_name']
27- # Defines all the fields in this time series.
28- ### Following attributes are optional. ###
29- client = TestSeriesHelper.client
30- # Client should be an instance of InfluxDBClient.
31- :warning: Only used if autocommit is True.
32- bulk_size = 5
33- # Defines the number of data points to write simultaneously.
34- :warning: Only applicable if autocommit is True.
35- autocommit = True
36- # If True and no bulk_size, then will set bulk_size to 1.
37-
38- # The following will create *five* (immutable) data points.
39- # Since bulk_size is set to 5, upon the fifth construction call, all data
40- # points will be written on the wire via MySeriesHelper.Meta.client.
41- MySeriesHelper(server_name='us.east-1', time=159)
42- MySeriesHelper(server_name='us.east-1', time=158)
43- MySeriesHelper(server_name='us.east-1', time=157)
44- MySeriesHelper(server_name='us.east-1', time=156)
45- MySeriesHelper(server_name='us.east-1', time=155)
46-
47- # If autocommit None or False, one must call commit to write datapoints.
48- # To manually submit data points which are not yet written, call commit:
49- MySeriesHelper.commit()
50-
51- # To inspect the JSON which will be written, call _json_body_():
52- MySeriesHelper._json_body_()
53- ```
54- '''
19+ Annotated example::
20+
21+ class MySeriesHelper(SeriesHelper):
22+ class Meta:
23+ # Meta class stores time series helper configuration.
24+ series_name = 'events.stats.{server_name}'
25+ # Series name must be a string, curly brackets for dynamic use.
26+ fields = ['time', 'server_name']
27+ # Defines all the fields in this time series.
28+ ### Following attributes are optional. ###
29+ client = TestSeriesHelper.client
30+ # Client should be an instance of InfluxDBClient.
31+ :warning: Only used if autocommit is True.
32+ bulk_size = 5
33+ # Defines the number of data points to write simultaneously.
34+ # Only applicable if autocommit is True.
35+ autocommit = True
36+ # If True and no bulk_size, then will set bulk_size to 1.
37+
38+ """
5539 __initialized__ = False
5640
5741 def __new__ (cls , * args , ** kwargs ):
58- '''
42+ """
5943 Initializes class attributes for subsequent constructor calls.
44+
6045 :note: *args and **kwargs are not explicitly used in this function,
6146 but needed for Python 2 compatibility.
62- '''
47+ """
6348 if not cls .__initialized__ :
6449 cls .__initialized__ = True
6550 try :
@@ -107,11 +92,12 @@ def __new__(cls, *args, **kwargs):
10792 return super (SeriesHelper , cls ).__new__ (cls )
10893
10994 def __init__ (self , ** kw ):
110- '''
95+ """
11196 Constructor call creates a new data point. All fields must be present.
97+
11298 :note: Data points written when `bulk_size` is reached per Helper.
11399 :warning: Data points are *immutable* (`namedtuples`).
114- '''
100+ """
115101 cls = self .__class__
116102
117103 if sorted (cls ._fields ) != sorted (kw .keys ()):
@@ -127,12 +113,13 @@ def __init__(self, **kw):
127113
128114 @classmethod
129115 def commit (cls , client = None ):
130- '''
116+ """
131117 Commit everything from datapoints via the client.
118+
132119 :param client: InfluxDBClient instance for writing points to InfluxDB.
133120 :attention: any provided client will supersede the class client.
134- :return result of client.write_points.
135- '''
121+ :return: result of client.write_points.
122+ """
136123 if not client :
137124 client = cls ._client
138125 rtn = client .write_points (cls ._json_body_ ())
@@ -141,9 +128,9 @@ def commit(cls, client=None):
141128
142129 @classmethod
143130 def _json_body_ (cls ):
144- '''
131+ """
145132 :return: JSON body of these datapoints.
146- '''
133+ """
147134 json = []
148135 for series_name , data in six .iteritems (cls ._datapoints ):
149136 json .append ({'name' : series_name ,
@@ -155,7 +142,7 @@ def _json_body_(cls):
155142
156143 @classmethod
157144 def _reset_ (cls ):
158- '''
145+ """
159146 Reset data storage.
160- '''
147+ """
161148 cls ._datapoints = defaultdict (list )
0 commit comments