|
| 1 | +from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options |
| 2 | +import pandas as pd |
| 3 | +import numpy as np |
| 4 | +import datetime |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +wco = write_client_options(write_options=SYNCHRONOUS) |
| 9 | + |
| 10 | + |
| 11 | +with InfluxDBClient3( |
| 12 | + token="", |
| 13 | + host="eu-central-1-1.aws.cloud2.influxdata.com", |
| 14 | + org="6a841c0c08328fb1", |
| 15 | + database="pokemon-codex", write_client_options=wco, debug=True) as client: |
| 16 | + |
| 17 | + now = datetime.datetime.now(datetime.timezone.utc) |
| 18 | + |
| 19 | + data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1")\ |
| 20 | + .field("caught", "charizard")\ |
| 21 | + .field("level", 10).field("attack", 30)\ |
| 22 | + .field("defense", 40).field("hp", 200)\ |
| 23 | + .field("speed", 10)\ |
| 24 | + .field("type1", "fire").field("type2", "flying")\ |
| 25 | + .time(now) |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + try: |
| 30 | + client.write(data) |
| 31 | + except Exception as e: |
| 32 | + print(f"Error writing point: {e}") |
| 33 | + |
| 34 | + data = [] |
| 35 | + # Adding first point |
| 36 | + data.append( |
| 37 | + Point("caught") |
| 38 | + .tag("trainer", "ash") |
| 39 | + .tag("id", "0006") |
| 40 | + .tag("num", "1") |
| 41 | + .field("caught", "charizard") |
| 42 | + .field("level", 10) |
| 43 | + .field("attack", 30) |
| 44 | + .field("defense", 40) |
| 45 | + .field("hp", 200) |
| 46 | + .field("speed", 10) |
| 47 | + .field("type1", "fire") |
| 48 | + .field("type2", "flying") |
| 49 | + .time(now) |
| 50 | + ) |
| 51 | + |
| 52 | + # Adding second point |
| 53 | + data.append( |
| 54 | + Point("caught") |
| 55 | + .tag("trainer", "ash") |
| 56 | + .tag("id", "0007") |
| 57 | + .tag("num", "2") |
| 58 | + .field("caught", "bulbasaur") |
| 59 | + .field("level", 12) |
| 60 | + .field("attack", 31) |
| 61 | + .field("defense", 31) |
| 62 | + .field("hp", 190) |
| 63 | + .field("speed", 11) |
| 64 | + .field("type1", "grass") |
| 65 | + .field("type2", "poison") |
| 66 | + .time(now) |
| 67 | + ) |
| 68 | + |
| 69 | + # Adding third point |
| 70 | + data.append( |
| 71 | + Point("caught") |
| 72 | + .tag("trainer", "ash") |
| 73 | + .tag("id", "0008") |
| 74 | + .tag("num", "3") |
| 75 | + .field("caught", "squirtle") |
| 76 | + .field("level", 13) |
| 77 | + .field("attack", 29) |
| 78 | + .field("defense", 40) |
| 79 | + .field("hp", 180) |
| 80 | + .field("speed", 13) |
| 81 | + .field("type1", "water") |
| 82 | + .field("type2", None) |
| 83 | + .time(now) |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | + try: |
| 88 | + client.write(data) |
| 89 | + except Exception as e: |
| 90 | + print(f"Error writing point: {e}") |
| 91 | + |
| 92 | + |
0 commit comments