This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Useful celery config. | |
| app = Celery('tasks', | |
| broker='redis://localhost:6379', | |
| backend='redis://localhost:6379') | |
| app.conf.update( | |
| CELERY_TASK_RESULT_EXPIRES=3600, | |
| CELERY_QUEUES=( | |
| Queue('default', routing_key='tasks.#'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from influxdb_client.client.flux_table import FluxStructureEncoder | |
| tables = query_api.query('from(bucket:"my-bucket") |> range(start: -10m)') | |
| output = json.dumps(tables, cls=FluxStructureEncoder, indent=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data_frame = query_api.query_data_frame('from(bucket:"my-bucket") ' | |
| '|> range(start: -10m) ' | |
| '|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") ' | |
| '|> keep(columns: ["location", "temperature"])') | |
| print(data_frame.to_string()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| csv_result = query_api.query_csv('from(bucket:"my-bucket") |> range(start: -10m)', | |
| dialect=Dialect(header=False, delimiter=",", comment_prefix="#", annotations=[], | |
| date_time_format="RFC3339")) | |
| for csv_line in csv_result: | |
| if not len(csv_line) == 0: | |
| print(f'Temperature in {csv_line[9]} is {csv_line[6]}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p = {"_start": datetime.timedelta(hours=-1), | |
| "_location": "Prague", | |
| "_desc": True, | |
| "_floatParam": 25.1, | |
| "_every": datetime.timedelta(minutes=5) | |
| } | |
| tables = query_api.query(''' | |
| from(bucket:"my-bucket") |> range(start: _start) | |
| |> filter(fn: (r) => r["_measurement"] == "my_measurement") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tables = query_api.query('from(bucket:"my-bucket") |> range(start: -10m)') | |
| for table in tables: | |
| print(table) | |
| for record in table.records: | |
| print(record.values) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _now = datetime.now(UTC) | |
| _data_frame = pd.DataFrame(data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]], | |
| index=[_now, _now + timedelta(hours=1)], | |
| columns=["location", "water_level"]) | |
| _write_client.write("my-bucket", "my-org", record=_data_frame, data_frame_measurement_name='h2o_feet', | |
| data_frame_tag_columns=['location']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _write_client.write("my-bucket", "my-org", {"measurement": "h2o_feet", "tags": {"location": "coyote_creek"}, | |
| "fields": {"water_level": 1.0}, "time": 1}) | |
| _write_client.write("my-bucket", "my-org", [{"measurement": "h2o_feet", "tags": {"location": "coyote_creek"}, | |
| "fields": {"water_level": 2.0}, "time": 2}, | |
| {"measurement": "h2o_feet", "tags": {"location": "coyote_creek"}, | |
| "fields": {"water_level": 3.0}, "time": 3}]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _write_client.write("my-bucket", "my-org", | |
| Point("h2o_feet").tag("location", "coyote_creek").field("water_level", 4.0).time(4)) | |
| _write_client.write("my-bucket", "my-org", | |
| [Point("h2o_feet").tag("location", "coyote_creek").field("water_level", 5.0).time(5), | |
| Point("h2o_feet").tag("location", "coyote_creek").field("water_level", 6.0).time(6)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Write Line Protocol formatted as string | |
| """ | |
| _write_client.write("my-bucket", "my-org", "h2o_feet,location=coyote_creek water_level=1.0 1") | |
| _write_client.write("my-bucket", "my-org", ["h2o_feet,location=coyote_creek water_level=2.0 2", | |
| "h2o_feet,location=coyote_creek water_level=3.0 3"]) | |
| """ | |
| Write Line Protocol formatted as byte array | |
| """ |
NewerOlder