diff --git a/.circleci/config.yml b/.circleci/config.yml index 406373f..a1a7b58 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -154,7 +154,7 @@ jobs: name: Checks style consistency across examples. command: | pip install flake8 --user - flake8 Examples/ + flake8 examples/ check-twine: docker: - image: << pipeline.parameters.default-python-image >> diff --git a/Examples/__init__.py b/Examples/__init__.py deleted file mode 100644 index af2bb72..0000000 --- a/Examples/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# used mainly to resolve local utility helpers like config.py diff --git a/Examples/cloud_dedicated_query.py b/Examples/cloud_dedicated_query.py deleted file mode 100644 index 38e5ae7..0000000 --- a/Examples/cloud_dedicated_query.py +++ /dev/null @@ -1,15 +0,0 @@ -from config import Config -import influxdb_client_3 as InfluxDBClient3 - -config = Config() - -client = InfluxDBClient3.InfluxDBClient3( - token=config.token, - host=config.host, - database=config.database) - -table = client.query( - query="SELECT * FROM flight WHERE time > now() - 4h", - language="influxql") - -print(table.to_pandas()) diff --git a/Examples/cloud_dedicated_write.py b/Examples/cloud_dedicated_write.py deleted file mode 100644 index f51422e..0000000 --- a/Examples/cloud_dedicated_write.py +++ /dev/null @@ -1,48 +0,0 @@ -from config import Config -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import WriteOptions -import pandas as pd -import numpy as np - -config = Config() - -client = InfluxDBClient3.InfluxDBClient3( - token=config.token, - host=config.host, - database=config.database, - write_options=WriteOptions( - batch_size=500, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - max_close_wait=300_000, - exponential_base=2, - write_type='batching')) - - -# Create a dataframe -df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) - - -# Create a range of datetime values -dates = pd.date_range(start='2024-09-08', end='2024-09-09', freq='5min') - -# Create a DataFrame with random data and datetime index -df = pd.DataFrame( - np.random.randn( - len(dates), - 3), - index=dates, - columns=[ - 'Column 1', - 'Column 2', - 'Column 3']) -df['tagkey'] = 'Hello World' - -print(df) - -# Write the DataFrame to InfluxDB -client.write(df, data_frame_measurement_name='table', - data_frame_tag_columns=['tagkey']) diff --git a/Examples/community/custom_url.py b/Examples/community/custom_url.py deleted file mode 100644 index e356334..0000000 --- a/Examples/community/custom_url.py +++ /dev/null @@ -1,103 +0,0 @@ -import random - -import pandas as pd - -from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=100, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -client = InfluxDBClient3( - token="", - host="https://eu-central-1-1.aws.cloud2.influxdata.com:442", - database="pokemon-codex", enable_gzip=True, write_client_options=wco, write_port_overwrite=443, - query_port_overwrite=443) - -now = pd.Timestamp.now(tz='UTC').floor('ms') - -# Lists of possible trainers -trainers = ["ash", "brock", "misty", "gary", "jessie", "james"] - -# Read the CSV into a DataFrame -pokemon_df = pd.read_csv( - "https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv") # noqa: E501 - -# Creating an empty list to store the data -data = [] - -# Dictionary to keep track of the number of times each trainer has caught each Pokémon -trainer_pokemon_counts = {} - -# Number of entries we want to create -num_entries = 1000 - -# Generating random data -for i in range(num_entries): - trainer = random.choice(trainers) - - # Randomly select a row from pokemon_df - random_pokemon = pokemon_df.sample().iloc[0] - caught = random_pokemon['Name'] - - # Count the number of times this trainer has caught this Pokémon - if (trainer, caught) in trainer_pokemon_counts: - trainer_pokemon_counts[(trainer, caught)] += 1 - else: - trainer_pokemon_counts[(trainer, caught)] = 1 - - # Get the number for this combination of trainer and Pokémon - num = trainer_pokemon_counts[(trainer, caught)] - - entry = { - "trainer": trainer, - "id": f"{0000 + random_pokemon['#']:04d}", - "num": str(num), - "caught": caught, - "level": random.randint(5, 20), - "attack": random_pokemon['Attack'], - "defense": random_pokemon['Defense'], - "hp": random_pokemon['HP'], - "speed": random_pokemon['Speed'], - "type1": random_pokemon['Type 1'], - "type2": random_pokemon['Type 2'], - "timestamp": now - } - data.append(entry) - -# Convert the list of dictionaries to a DataFrame -caught_pokemon_df = pd.DataFrame(data).set_index('timestamp') - -# Print the DataFrame -print(caught_pokemon_df) - -try: - client.write(caught_pokemon_df, data_frame_measurement_name='caught', - data_frame_tag_columns=['trainer', 'id', 'num']) -except Exception as e: - print(f"Error writing point: {e}") diff --git a/Examples/config.py b/Examples/config.py deleted file mode 100644 index 5ab1b49..0000000 --- a/Examples/config.py +++ /dev/null @@ -1,12 +0,0 @@ -import os -import json - - -class Config: - def __init__(self): - self.host = os.getenv('INFLUXDB_HOST') or 'https://us-east-1-1.aws.cloud2.influxdata.com/' - self.token = os.getenv('INFLUXDB_TOKEN') or 'my-token' - self.database = os.getenv('INFLUXDB_DATABASE') or 'my-db' - - def __str__(self): - return json.dumps(self.__dict__) diff --git a/Examples/example.csv b/Examples/example.csv deleted file mode 100644 index 0ab1db8..0000000 --- a/Examples/example.csv +++ /dev/null @@ -1,489 +0,0 @@ -Date,VIX Open,VIX High,VIX Low,VIX Close,host,region -2021-05-05,13.48,15.82,13.43,13.98,412df,US -2021-05-06,13.29,14.06,13.11,14.05,412df,US -2021-05-09,14.11,14.56,13.53,13.75,412df,US -2021-05-10,14.05,15.11,14.03,14.91,412df,US -2021-05-11,14.69,15.8,14.31,14.45,412df,US -2021-05-12,14.43,16.23,14.16,16.12,412df,US -2021-05-13,15.88,17.7,15.4,16.32,412df,US -2021-05-16,16.87,16.87,15.67,15.68,412df,US -2021-05-17,15.92,16.21,14.45,14.57,412df,US -2021-05-18,14.11,14.13,13.3,13.63,412df,US -2021-05-19,13.35,14.02,13.25,13.32,412df,US -2021-05-20,13.57,13.73,13.07,13.14,412df,US -2021-05-23,13.38,13.45,12.75,12.95,412df,US -2021-05-24,13.12,13.3,12.53,12.69,412df,US -2021-05-25,12.83,13.11,12.58,12.58,412df,US -2021-05-26,12.23,12.38,11.65,12.24,412df,US -2021-05-27,12.06,12.43,12.06,12.15,412df,US -2021-05-31,12.69,13.45,12.67,13.29,412df,US -2021-06-01,13.34,13.34,12.17,12.36,412df,US -2021-06-02,12.35,12.43,11.8,11.84,412df,US -2021-06-03,11.78,12.49,11.52,12.15,412df,US -2021-06-06,12.68,13,12.21,12.28,412df,US -2021-06-07,12.22,12.43,11.47,12.39,412df,US -2021-06-08,12.05,12.83,12.05,12.7,412df,US -2021-06-09,12.69,13.07,12.06,12.08,412df,US -2021-06-10,12.16,12.4,11.9,11.96,412df,US -2021-06-13,12.12,12.12,11.31,11.65,412df,US -2021-06-14,11.65,12.02,11.52,11.79,412df,US -2021-06-15,11.22,11.96,11.05,11.46,412df,US -2021-06-16,11.24,11.36,11.04,11.15,412df,US -2021-06-17,10.83,11.64,10.78,11.48,412df,US -2021-06-20,12.51,12.53,11.31,11.47,412df,US -2021-06-21,11.52,11.67,11.01,11.08,412df,US -2021-06-22,10.96,11.31,10.81,11.05,412df,US -2021-06-23,11.19,12.13,10.96,12.13,412df,US -2021-06-24,12.27,12.32,11.95,12.18,412df,US -2021-06-27,12.73,12.78,12.38,12.52,412df,US -2021-06-28,12.31,12.31,11.55,11.58,412df,US -2021-06-29,11.54,11.78,11.44,11.77,412df,US -2021-06-30,11.72,12.1,11.5,12.04,412df,US -2021-07-01,11.75,11.92,11.38,11.4,412df,US -2021-07-05,12.41,12.41,11.53,11.68,412df,US -2021-07-06,11.67,12.33,11.54,12.27,412df,US -2021-07-07,13.91,13.92,12.48,12.49,412df,US -2021-07-08,12.24,12.29,11.09,11.45,412df,US -2021-07-11,10.96,11.41,10.53,11.28,412df,US -2021-07-12,11.03,11.37,10.85,10.95,412df,US -2021-07-13,11.09,11.44,10.8,10.84,412df,US -2021-07-14,10.87,11.13,10.5,10.81,412df,US -2021-07-15,10.61,10.9,10.13,10.33,412df,US -2021-07-18,11.09,11.09,10.77,10.77,412df,US -2021-07-19,10.63,10.79,10.36,10.45,412df,US -2021-07-20,10.8,10.94,9.88,10.23,412df,US -2021-07-21,10.23,11.21,10.23,10.97,412df,US -2021-07-22,11.01,11.05,10.51,10.52,412df,US -2021-07-25,11.12,11.28,10.7,11.1,412df,US -2021-07-26,11.11,11.25,10.92,10.99,412df,US -2021-07-27,11.03,11.03,10.34,10.36,412df,US -2021-07-28,10.4,10.58,10.27,10.52,412df,US -2021-07-29,10.24,11.73,10.24,11.57,412df,US -2021-08-01,11.75,12.23,11.36,12.08,412df,US -2021-08-02,12,12.03,11.69,11.75,412df,US -2021-08-03,11.9,12.01,11.62,11.83,412df,US -2021-08-04,12.12,12.57,11.99,12.52,412df,US -2021-08-05,11.82,12.92,11.82,12.48,412df,US -2021-08-08,12.56,13.29,12.56,13.21,412df,US -2021-08-09,12.25,12.78,12.24,12.4,412df,US -2021-08-10,12.03,12.56,11.51,12.38,412df,US -2021-08-11,12.34,12.94,11.88,12.42,412df,US -2021-08-12,12.36,12.98,12.18,12.74,412df,US -2021-08-15,12.87,12.99,12.08,12.26,412df,US -2021-08-16,12.37,13.89,12.28,13.52,412df,US -2021-08-17,13.35,13.76,12.78,13.3,412df,US -2021-08-18,13.47,13.88,13.01,13.42,412df,US -2021-08-19,12.84,13.85,12.61,13.42,412df,US -2021-08-22,13.67,13.89,13.2,13.42,412df,US -2021-08-23,13.63,14.05,13.3,13.34,412df,US -2021-08-24,13.56,14.18,13,14.17,412df,US -2021-08-25,13.92,14.12,13.66,13.73,412df,US -2021-08-26,13.79,14.2,13.65,13.72,412df,US -2021-08-29,14.34,14.41,13.38,13.52,412df,US -2021-08-30,13.49,14.18,13.47,13.65,412df,US -2021-08-31,13.37,13.63,12.56,12.6,412df,US -2021-09-01,12.86,13.37,12.31,13.15,412df,US -2021-09-02,13.21,13.72,13.03,13.57,412df,US -2021-09-06,14.17,14.18,12.9,12.93,412df,US -2021-09-07,13.06,13.2,12.44,12.52,412df,US -2021-09-08,12.72,12.94,12.37,12.93,412df,US -2021-09-09,12.46,12.65,11.96,11.98,412df,US -2021-09-12,11.66,11.89,11.45,11.65,412df,US -2021-09-13,11.76,12.48,11.75,12.39,412df,US -2021-09-14,12.79,13.26,12.67,12.91,412df,US -2021-09-15,12.72,13.17,12.28,12.49,412df,US -2021-09-16,11.89,11.93,11.07,11.22,412df,US -2021-09-19,12.17,12.46,12.04,12.14,412df,US -2021-09-20,12.23,12.96,11.83,12.64,412df,US -2021-09-21,13.07,13.91,12.96,13.79,412df,US -2021-09-22,13.85,14.39,13.31,13.33,412df,US -2021-09-23,13.64,13.88,12.75,12.96,412df,US -2021-09-26,13.27,13.47,12.64,13.04,412df,US -2021-09-27,13.06,13.46,12.51,12.76,412df,US -2021-09-28,12.6,12.98,12.37,12.63,412df,US -2021-09-29,12.92,13.23,12.15,12.24,412df,US -2021-09-30,12.42,12.44,11.92,11.92,412df,US -2021-10-03,12.37,12.62,11.98,12.46,412df,US -2021-10-04,12.5,13.21,12.11,13.2,412df,US -2021-10-05,13.15,14.58,12.97,14.55,412df,US -2021-10-06,14.53,15.63,14.04,14.96,412df,US -2021-10-07,14.56,14.82,14.3,14.59,412df,US -2021-10-10,14.93,15.61,14.87,15.55,412df,US -2021-10-11,15.35,15.7,15.06,15.63,412df,US -2021-10-12,15.56,16.27,15.04,16.22,412df,US -2021-10-13,16.32,17.19,15.98,16.47,412df,US -2021-10-14,15.99,16.03,14.83,14.87,412df,US -2021-10-17,15.3,15.3,14.58,14.67,412df,US -2021-10-18,14.92,15.4,14.79,15.33,412df,US -2021-10-19,15.63,15.86,13.47,13.5,412df,US -2021-10-20,14.18,16.19,13.98,16.11,412df,US -2021-10-21,15.53,16.27,15.26,16.13,412df,US -2021-10-24,16.18,16.44,14.61,14.74,412df,US -2021-10-25,14.96,15.3,14.2,14.53,412df,US -2021-10-26,14.8,14.88,13.72,14.59,412df,US -2021-10-27,14.73,16.3,14.57,16.02,412df,US -2021-10-28,15.45,15.61,14.11,14.25,412df,US -2021-10-31,14.04,15.39,13.93,15.32,412df,US -2021-11-01,14.85,15.66,14.65,14.85,412df,US -2021-11-02,14.99,14.99,13.38,13.48,412df,US -2021-11-03,13.12,13.23,12.5,13,412df,US -2021-11-04,12.88,13.62,12.69,13.17,412df,US -2021-11-07,13.11,13.65,12.76,13.1,412df,US -2021-11-08,13.61,13.61,13.04,13.08,412df,US -2021-11-09,13.14,13.36,12.42,12.8,412df,US -2021-11-10,12.68,13.17,11.73,11.9,412df,US -2021-11-11,11.82,11.96,11.63,11.63,412df,US -2021-11-14,11.99,12.34,11.77,12.18,412df,US -2021-11-15,12.16,12.69,11.7,12.23,412df,US -2021-11-16,12.22,12.68,12.17,12.26,412df,US -2021-11-17,11.92,12.2,11.25,11.25,412df,US -2021-11-18,11.19,11.67,10.96,11.12,412df,US -2021-11-21,11.18,11.38,10.71,10.82,412df,US -2021-11-22,11.01,11.1,10.5,10.6,412df,US -2021-11-23,10.96,11.03,10.67,10.96,412df,US -2021-11-25,11.04,11.24,10.88,10.88,412df,US -2021-11-28,11.34,11.99,11.33,11.84,412df,US -2021-11-29,11.77,11.96,11.61,11.89,412df,US -2021-11-30,11.84,12.13,11.55,12.06,412df,US -2021-12-01,12.09,12.23,11.14,11.24,412df,US -2021-12-02,11.1,11.23,10.94,11.01,412df,US -2021-12-05,11.45,11.68,11.4,11.6,412df,US -2021-12-06,11.16,11.59,10.96,11.52,412df,US -2021-12-07,11.49,12.44,11.45,12.18,412df,US -2021-12-08,11.88,12.41,11.73,12.21,412df,US -2021-12-09,11.91,12.2,11.56,11.69,412df,US -2021-12-12,10.86,11.81,10.83,11.47,412df,US -2021-12-13,10.57,11.42,10.57,11.11,412df,US -2021-12-14,10.75,10.79,10.39,10.48,412df,US -2021-12-15,10.66,11.11,10.37,10.73,412df,US -2021-12-16,10.7,10.75,10.15,10.68,412df,US -2021-12-19,11.11,11.38,10.65,11.38,412df,US -2021-12-20,11.32,11.45,11,11.19,412df,US -2021-12-21,10.71,11.07,10.34,10.81,412df,US -2021-12-22,10.82,10.89,10.28,10.29,412df,US -2021-12-23,10.37,10.48,10.24,10.27,412df,US -2021-12-27,10.97,11.65,10.83,11.57,412df,US -2021-12-28,11.55,11.64,11.26,11.35,412df,US -2021-12-29,11.36,11.67,11.14,11.61,412df,US -2021-12-30,11.96,12.07,11.55,12.07,412df,US -2022-01-03,12.25,12.51,10.99,11.14,412df,US -2022-01-04,11.22,11.71,10.97,11.37,412df,US -2022-01-05,11.43,11.84,11.31,11.31,412df,US -2022-01-06,11.23,11.5,10.81,11,412df,US -2022-01-09,11.35,11.35,10.98,11.13,412df,US -2022-01-10,11.39,11.39,10.84,10.86,412df,US -2022-01-11,11.03,11.16,10.83,10.94,412df,US -2022-01-12,10.98,11.38,10.94,11.2,412df,US -2022-01-13,11.4,11.61,11.11,11.23,412df,US -2022-01-17,12.13,12.46,11.87,11.91,412df,US -2022-01-18,12.62,12.7,12.2,12.25,412df,US -2022-01-19,12.12,12.34,11.65,11.98,412df,US -2022-01-20,12.1,14.56,11.89,14.56,412df,US -2022-01-23,14.44,14.48,13.58,13.93,412df,US -2022-01-24,13.79,13.83,13.14,13.31,412df,US -2022-01-25,12.95,13.38,12.62,12.87,412df,US -2022-01-26,12.89,12.91,12.19,12.42,412df,US -2022-01-27,12.27,12.33,11.72,11.97,412df,US -2022-01-30,12.22,12.46,12.07,12.39,412df,US -2022-01-31,12.45,13.06,12.45,12.95,412df,US -2022-02-01,13.03,13.03,12.34,12.36,412df,US -2022-02-02,12.54,13.47,12.48,13.23,412df,US -2022-02-03,13.37,13.7,12.64,12.96,412df,US -2022-02-06,13.43,13.43,12.99,13.04,412df,US -2022-02-07,13.2,13.67,12.97,13.59,412df,US -2022-02-08,13.41,13.61,12.76,12.83,412df,US -2022-02-09,12.56,13.15,12.27,13.12,412df,US -2022-02-10,13.35,13.73,12.69,12.87,412df,US -2022-02-13,13.34,13.7,13.05,13.35,412df,US -2022-02-14,13.09,13.15,12.01,12.25,412df,US -2022-02-15,12.43,12.95,12.21,12.31,412df,US -2022-02-16,12.19,12.29,11.13,11.48,412df,US -2022-02-17,11.64,12.21,11.52,12.01,412df,US -2022-02-21,12.36,12.64,12.28,12.41,412df,US -2022-02-22,12.27,12.3,11.68,11.88,412df,US -2022-02-23,11.86,11.97,11.58,11.87,412df,US -2022-02-24,11.94,12.06,11.42,11.46,412df,US -2022-02-27,11.79,11.83,11.4,11.59,412df,US -2022-02-28,11.74,12.36,11.71,12.34,412df,US -2022-03-01,12.05,12.07,11.52,11.54,412df,US -2022-03-02,11.79,11.95,11.56,11.72,412df,US -2022-03-03,12.03,12.1,11.36,11.96,412df,US -2022-03-06,12.22,12.91,12.22,12.74,412df,US -2022-03-07,12.92,13.34,12.64,12.66,412df,US -2022-03-08,12.83,13.34,12.26,12.32,412df,US -2022-03-09,12.21,12.69,12.01,12.68,412df,US -2022-03-10,12.52,12.6,11.79,11.85,412df,US -2022-03-13,11.72,11.75,10.89,11.37,412df,US -2022-03-14,11.61,11.72,10.53,10.74,412df,US -2022-03-15,11.17,11.54,10.98,11.35,413df,US -2022-03-16,10.59,12.05,10.57,11.98,413df,US -2022-03-17,11.56,12.2,11.53,12.12,413df,US -2022-03-20,12.11,12.21,10.79,11.79,413df,US -2022-03-21,11.71,11.89,11.17,11.62,413df,US -2022-03-22,11.71,11.79,11.11,11.21,413df,US -2022-03-23,11.19,11.57,11.11,11.17,413df,US -2022-03-24,11.23,11.48,11.09,11.19,413df,US -2022-03-27,11.46,11.72,11.41,11.46,413df,US -2022-03-28,11.69,11.9,11.38,11.58,413df,US -2022-03-29,11.46,11.57,10.79,10.95,413df,US -2022-03-30,11.03,11.73,10.7,11.57,413df,US -2022-03-31,11.42,11.65,11.27,11.39,413df,US -2022-04-03,11.47,11.62,11.03,11.57,413df,US -2022-04-04,11.66,11.8,11.09,11.14,413df,US -2022-04-05,11.24,11.36,11.06,11.13,413df,US -2022-04-06,11.34,11.74,11.25,11.45,413df,US -2022-04-07,11.44,12.31,11.2,12.26,413df,US -2022-04-10,12.44,12.49,12.04,12.19,413df,US -2022-04-11,12.09,13.06,12.06,13,413df,US -2022-04-12,13.08,13.09,12.66,12.76,413df,US -2022-04-13,12.93,13,12.28,12.38,413df,US -2022-04-17,12.8,13.02,12.27,12.58,413df,US -2022-04-18,12.55,12.55,11.31,11.4,413df,US -2022-04-19,11.52,11.8,11.23,11.32,413df,US -2022-04-20,11.3,11.67,11.02,11.64,413df,US -2022-04-21,11.24,11.98,11.19,11.59,413df,US -2022-04-24,12.26,12.42,11.67,11.75,413df,US -2022-04-25,11.71,12.19,11.59,11.75,413df,US -2022-04-26,11.76,11.79,11.34,11.76,413df,US -2022-04-27,12.27,12.52,11.55,11.84,413df,US -2022-04-28,12.13,12.13,11.42,11.59,413df,US -2022-05-01,11.83,12.59,11.75,12.54,413df,US -2022-05-02,12.2,12.27,11.93,11.99,413df,US -2022-05-03,12.21,12.45,11.95,11.99,413df,US -2022-05-04,11.92,12.16,11.71,11.86,413df,US -2022-05-05,11.39,11.62,11.18,11.62,413df,US -2022-05-08,11.98,12.06,11.81,12,413df,US -2022-05-09,12.1,12.15,11.88,11.99,413df,US -2022-05-10,12.22,12.32,11.78,11.78,413df,US -2022-05-11,12.33,12.92,11.99,12.49,413df,US -2022-05-12,12.71,14.26,12.71,14.19,413df,US -2022-05-15,15.12,15.13,13.44,13.57,413df,US -2022-05-16,13.49,13.61,12.98,13.35,413df,US -2022-05-17,13.83,16.26,13.39,16.26,413df,US -2022-05-18,15.54,17.09,14.96,16.99,413df,US -2022-05-19,16.16,18.01,15.9,17.18,413df,US -2022-05-22,18.55,19.62,16.73,17.72,413df,US -2022-05-23,16.7,18.26,15.36,18.26,413df,US -2022-05-24,17.87,19.87,17.13,17.36,413df,US -2022-05-25,16.67,16.67,15.31,15.5,413df,US -2022-05-26,14.92,15.04,14.26,14.26,413df,US -2022-05-30,15.39,18.72,15.39,18.66,413df,US -2022-05-31,18.09,18.09,16.41,16.44,413df,US -2022-06-01,16.47,16.56,14.48,14.52,413df,US -2022-06-02,14.17,14.97,13.92,14.32,413df,US -2022-06-05,14.97,17.14,14.97,16.65,413df,US -2022-06-06,16.72,18.56,16.65,17.34,413df,US -2022-06-07,17.21,17.86,16.07,17.8,413df,US -2022-06-08,17.92,20.75,17.88,18.35,413df,US -2022-06-09,17.9,18.45,17.07,18.12,413df,US -2022-06-12,18.13,21.25,17.89,20.96,413df,US -2022-06-13,20.95,23.81,20.27,23.81,413df,US -2022-06-14,23.45,23.49,21.45,21.46,413df,US -2022-06-15,21.05,21.14,15.65,15.9,413df,US -2022-06-16,16.56,18.13,16.52,17.25,413df,US -2022-06-19,16.06,18.1,15.73,17.83,413df,US -2022-06-20,17.52,17.65,16.39,16.69,413df,US -2022-06-21,16.67,16.72,14.88,15.52,413df,US -2022-06-22,15.95,16.66,15.56,15.88,413df,US -2022-06-23,16.41,16.58,14.94,15.89,413df,US -2022-06-26,16.55,16.61,15.49,15.62,413df,US -2022-06-27,15.58,16.55,15.27,16.4,413df,US -2022-06-28,16.02,17,15.78,15.79,413df,US -2022-06-29,15.28,15.3,12.93,13.03,413df,US -2022-06-30,12.9,13.47,12.74,13.08,413df,US -2022-07-03,13.29,13.51,12.77,13.05,413df,US -2022-07-05,13.92,14.77,13.86,14.15,413df,US -2022-07-06,14.04,14.04,13.25,13.65,413df,US -2022-07-07,13.9,14.45,13.43,13.97,413df,US -2022-07-10,14.17,14.5,13.67,14.02,413df,US -2022-07-11,14.31,14.68,13.1,13.14,413df,US -2022-07-12,13.39,14.85,13.26,14.49,413df,US -2022-07-13,15.17,17.83,15.17,17.79,413df,US -2022-07-14,17.57,18.79,17.28,18.05,413df,US -2022-07-17,18.73,18.76,17.75,18.64,413df,US -2022-07-18,18.2,19.58,17.66,17.74,413df,US -2022-07-19,17.62,17.62,14.47,15.55,413df,US -2022-07-20,15.1,16.37,14.87,16.21,413df,US -2022-07-21,16.23,17.56,16.23,17.4,413df,US -2022-07-24,17.08,17.08,14.89,14.98,413df,US -2022-07-25,15.44,15.68,14.31,14.85,413df,US -2022-07-26,15.04,15.21,14.09,14.62,413df,US -2022-07-27,14.26,15.39,14.07,14.94,413df,US -2022-07-28,14.73,14.75,14.06,14.33,413df,US -2022-07-31,15.01,15.13,14.86,14.95,413df,US -2022-08-01,15.49,16.15,15.03,15.05,413df,US -2022-08-02,14.93,14.93,13.92,14.34,413df,US -2022-08-03,15.1,15.19,14.2,14.46,413df,US -2022-08-04,14.03,14.91,13.65,14.34,413df,US -2022-08-07,14.98,15.53,14.97,15.23,413df,US -2022-08-08,15.2,15.55,14.86,15.23,413df,US -2022-08-09,14.76,15.41,14.07,15.2,413df,US -2022-08-10,15.56,15.73,14.45,14.46,413df,US -2022-08-11,14.72,14.85,14.3,14.3,413df,US -2022-08-14,14.15,14.43,13.41,14.26,413df,US -2022-08-15,13.57,13.72,13.15,13.42,413df,US -2022-08-16,12.69,12.95,12.11,12.41,413df,US -2022-08-17,12.69,12.72,12.21,12.24,413df,US -2022-08-18,12.11,12.52,11.57,11.64,413df,US -2022-08-21,12.4,12.62,12.21,12.22,413df,US -2022-08-22,12.42,12.42,11.93,12.19,413df,US -2022-08-23,12.26,12.73,12.16,12.4,413df,US -2022-08-24,12.24,12.58,12.21,12.4,413df,US -2022-08-25,12.41,12.47,12.08,12.31,413df,US -2022-08-28,12.92,12.92,12.07,12.18,413df,US -2022-08-29,12.27,12.83,12.21,12.28,413df,US -2022-08-30,12.14,12.35,12.1,12.22,413df,US -2022-08-31,12.23,12.33,12.07,12.31,413df,US -2022-09-01,12.14,12.33,11.91,11.96,413df,US -2022-09-05,12.8,12.86,12.43,12.63,413df,US -2022-09-06,13.06,13.88,13.06,13.74,413df,US -2022-09-07,14.07,14.49,13.67,13.88,413df,US -2022-09-08,13.79,13.8,13.05,13.16,413df,US -2022-09-11,13.95,13.95,12.75,12.99,413df,US -2022-09-12,13.04,13.14,11.55,11.92,413df,US -2022-09-13,11.4,11.56,10.99,11.18,413df,US -2022-09-14,11.36,12.02,10.74,11.55,413df,US -2022-09-15,11.49,12.54,11.4,11.76,413df,US -2022-09-18,12.28,12.41,11.58,11.78,413df,US -2022-09-19,11.96,12.69,11.86,11.98,413df,US -2022-09-20,11.75,11.75,11.34,11.39,413df,US -2022-09-21,11.43,12.6,11.28,12.25,413df,US -2022-09-22,12.47,13.28,12.47,12.59,413df,US -2022-09-25,12.97,13.41,11.93,12.12,413df,US -2022-09-26,12.23,12.23,11.51,11.53,413df,US -2022-09-27,11.65,11.9,11.42,11.58,413df,US -2022-09-28,11.64,12.06,11.59,11.72,413df,US -2022-09-29,11.75,12.1,11.72,11.98,413df,US -2022-10-02,12.45,12.72,12.11,12.57,413df,US -2022-10-03,12.68,12.91,11.97,12.24,413df,US -2022-10-04,12.64,12.64,11.62,11.86,413df,US -2022-10-05,11.94,12.06,11.65,11.98,413df,US -2022-10-06,11.99,12.17,11.55,11.56,413df,US -2022-10-09,12.07,12.09,11.58,11.68,413df,US -2022-10-10,11.77,11.89,11.47,11.52,413df,US -2022-10-11,11.75,12.03,11.31,11.62,413df,US -2022-10-12,11.5,11.51,11.09,11.09,413df,US -2022-10-13,11.17,11.35,10.75,10.75,413df,US -2022-10-16,11.07,11.2,10.91,11.09,413df,US -2022-10-17,11.36,12.03,11.35,11.73,413df,US -2022-10-18,11.44,11.83,11.33,11.34,413df,US -2022-10-19,11.51,11.57,10.78,10.9,413df,US -2022-10-20,11.06,11.23,10.44,10.63,413df,US -2022-10-23,11.15,11.25,10.62,11.08,413df,US -2022-10-24,11.25,11.27,10.78,10.78,413df,US -2022-10-25,10.88,10.88,10.6,10.66,413df,US -2022-10-26,10.56,10.96,10.47,10.56,413df,US -2022-10-27,10.66,10.99,10.53,10.8,413df,US -2022-10-30,11.36,11.43,10.92,11.2,413df,US -2022-10-31,11.1,11.39,10.99,11.1,413df,US -2022-11-01,10.93,11.68,10.89,11.51,413df,US -2022-11-02,11.61,11.76,11.41,11.42,413df,US -2022-11-03,11.16,11.43,10.34,11.16,413df,US -2022-11-06,11.39,11.41,10.99,11.16,413df,US -2022-11-07,11.06,11.19,10.87,11.09,413df,US -2022-11-08,11.41,11.49,10.7,10.75,413df,US -2022-11-09,10.65,11.07,10.57,11.01,413df,US -2022-11-10,11.01,11.12,10.77,10.79,413df,US -2022-11-13,11.19,11.26,10.69,10.86,413df,US -2022-11-14,10.89,11.31,10.14,10.5,413df,US -2022-11-15,10.47,10.61,10.13,10.31,413df,US -2022-11-16,10.13,10.35,10.04,10.16,413df,US -2022-11-17,10.37,10.48,10.05,10.05,413df,US -2022-11-20,10.42,10.48,9.91,9.97,413df,US -2022-11-21,10.05,10.06,9.84,9.9,413df,US -2022-11-22,10.02,10.15,9.81,10.14,413df,US -2022-11-24,10.81,10.86,10.56,10.73,413df,US -2022-11-27,11.26,12.33,11.14,12.3,413df,US -2022-11-28,12.48,12.55,11.56,11.62,413df,US -2022-11-29,11.41,11.43,10.67,10.83,413df,US -2022-11-30,10.88,11.3,10.58,10.91,413df,US -2022-12-01,11.07,12.28,10.96,11.66,413df,US -2022-12-04,12.01,12.01,10.98,11.23,413df,US -2022-12-05,11.13,11.59,10.85,11.27,413df,US -2022-12-06,11.39,11.55,11.19,11.33,413df,US -2022-12-07,11.35,12.68,11.17,12.67,413df,US -2022-12-08,12.58,12.67,11.91,12.07,413df,US -2022-12-11,11.88,11.93,10.71,10.71,413df,US -2022-12-12,11.2,11.39,10.35,10.65,413df,US -2022-12-13,10.45,10.58,10.15,10.18,413df,US -2022-12-14,10.74,10.75,9.64,9.97,413df,US -2022-12-15,9.68,10.07,9.39,10.05,413df,US -2022-12-18,10.64,10.91,10.46,10.6,413df,US -2022-12-19,11.06,11.31,10.27,10.3,413df,US -2022-12-20,10.3,10.33,10.03,10.26,413df,US -2022-12-21,10.36,10.89,10.13,10.53,413df,US -2022-12-22,10.59,11.46,10.59,11.36,413df,US -2022-12-26,12.03,12.03,11.24,11.26,413df,US -2022-12-27,11.12,11.12,10.59,10.64,413df,US -2022-12-28,10.84,11.06,10.73,10.99,413df,US -2022-12-29,10.95,11.65,10.71,11.56,413df,US -2023-01-03,12.16,12.75,11.53,12.04,413df,US -2023-01-04,12.4,12.42,11.28,11.51,413df,US -2023-01-05,11.84,12.25,11.68,12.14,413df,US -2023-01-08,12.48,12.83,11.78,12,413df,US -2023-01-09,11.86,12.47,11.69,11.91,413df,US -2023-01-10,12.34,12.5,11.43,11.47,413df,US -2023-01-11,11.42,11.48,10.5,10.87,413df,US -2023-01-12,10.93,10.93,10.14,10.15,413df,US -2023-01-16,10.64,10.89,10.4,10.74,413df,US -2023-01-17,10.9,10.9,10.35,10.59,413df,US -2023-01-18,10.65,11.04,10.45,10.85,413df,US -2023-01-19,10.8,11.03,10.24,10.4,413df,US -2023-01-22,10.77,11.08,10.62,10.77,413df,US -2023-01-23,10.77,10.94,10.22,10.34,413df,US -2023-01-24,10.41,10.41,9.87,9.89,413df,US -2023-01-25,9.99,11.38,9.95,11.22,413df,US -2023-01-26,10.95,11.6,10.92,11.13,413df,US -2023-01-29,11.5,11.6,10.92,11.45,413df,US -2023-01-30,11.28,11.49,10.95,10.96,413df,US -2023-01-31,11.09,11.26,10.27,10.42,413df,US -2023-02-01,10.32,10.43,10.14,10.31,413df,US -2023-02-02,10.3,10.36,9.96,10.08,413df,US -2023-02-05,10.53,10.7,10.44,10.55,413df,US -2023-02-06,10.55,10.88,10.44,10.65,413df,US -2023-02-07,10.31,10.56,10.24,10.32,413df,US -2023-02-08,10.49,10.91,10.4,10.44,413df,US -2023-02-09,10.42,11.56,10.25,11.1,413df,US -2023-02-12,11.33,11.88,11.3,11.61,413df,US -2023-02-13,11.42,11.42,10.33,10.34,413df,US -2023-02-14,10.19,10.26,9.7,10.23,413df,US -2023-02-15,10.28,10.32,10.05,10.22,413df,US -2023-02-16,10.42,10.44,9.98,10.02,413df,US -2023-02-20,10.62,10.72,10.14,10.24,413df,US -2023-02-21,10.48,10.53,10.17,10.2,413df,US -2023-02-22,10.23,10.52,10.01,10.18,413df,US -2023-02-23,10.41,10.7,10.36,10.58,413df,US -2023-02-26,10.59,11.44,10.52,11.15,413df,US -2023-02-27,12.12,19.01,12.1,18.31,413df,US -2023-02-28,17.21,17.29,14.5,15.42,413df,US -2023-03-01,17.76,19.4,15.36,15.82,413df,US -2023-03-02,16.7,18.63,16.04,18.61,413df,US -2023-03-05,20.4,20.41,18.13,19.63,413df,US -2023-03-06,18.31,18.34,15.76,15.96,413df,US -2023-03-07,16.25,16.27,14.52,15.24,413df,US -2023-03-08,14.34,14.7,13.48,14.29,413df,US -2023-03-09,13.7,14.62,13.67,14.09,413df,US -2023-03-12,14.96,14.96,13.76,13.99,413df,US -2023-03-13,14.87,18.42,14.6,18.13,413df,US -2023-03-14,17.63,21.25,16.75,17.27,413df,US -2023-03-15,16.91,16.91,15.27,16.43,413df,US -2023-03-16,15.38,17.71,15.29,16.79,413df,US -2023-03-19,15.82,15.82,14.58,14.59,413df,US -2023-03-20,15.01,15.16,13.25,13.27,413df,US -2023-03-21,13.27,13.67,11.21,12.19,413df,US -2023-03-22,12.29,12.95,12.04,12.93,413df,US -2023-03-23,13.13,13.18,12.46,12.95,413df,US -2023-03-26,13.39,14.7,12.91,13.16,413df,US -2023-03-27,13.35,13.9,13.35,13.48,413df,US -2023-03-28,14.28,15.51,14.22,14.98,413df,US -2023-03-29,14.45,16.05,14.34,15.14,413df,US -2023-03-30,14.94,15.82,14.14,14.64,413df,US -2023-04-02,14.91,15.46,14.4,14.53,413df,US -2023-04-03,14.02,14.06,12.81,13.46,413df,US -2023-04-04,13.82,13.91,13.2,13.24,413df,US -2023-04-05,13.57,13.66,12.69,13.23,413df,US -2023-04-09,13.26,13.56,12.89,13.14,413df,US -2023-04-10,13.33,13.33,12.56,12.68,413df,US -2023-04-11,12.72,14.08,12.72,13.49,413df,US -2023-04-12,13.65,14.15,12.58,12.71,413df,US -2023-04-13,12.67,13,12.13,12.2,413df,US \ No newline at end of file diff --git a/Examples/file-import/csv_write.py b/Examples/file-import/csv_write.py deleted file mode 100644 index 7928d30..0000000 --- a/Examples/file-import/csv_write.py +++ /dev/null @@ -1,64 +0,0 @@ -import logging -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError - - -class BatchingCallback(object): - - def __init__(self): - self.write_count = 0 - - def success(self, conf, data: str): - self.write_count += 1 - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -def main() -> None: - - # allow detailed inspection - logging.basicConfig(level=logging.DEBUG) - - callback = BatchingCallback() - - write_options = WriteOptions(batch_size=100, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - - wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - - """ - token: access token generated in cloud - host: ATTN could be another AWS region or even another cloud provider - database: should have retention policy 'forever' to handle older sample data timestamps - write_client_options: see above - debug: allows low-level inspection of communications and context-manager termination - """ - with InfluxDBClient3.InfluxDBClient3( - token="INSERT_TOKEN", - host="https://us-east-1-1.aws.cloud2.influxdata.com/", - database="example_data_forever", - write_client_options=wco, - debug=True) as client: - client.write_file( - file='./out.csv', - timestamp_column='time', tag_columns=["provider", "machineID"]) - - print(f'DONE writing from csv in {callback.write_count} batch(es)') - - -if __name__ == "__main__": - main() diff --git a/Examples/file-import/feather_write.py b/Examples/file-import/feather_write.py deleted file mode 100644 index d931ca9..0000000 --- a/Examples/file-import/feather_write.py +++ /dev/null @@ -1,39 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=500, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -with InfluxDBClient3.InfluxDBClient3( - token="INSERT_TOKEN", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="python", write_client_options=wco) as client: - client.write_file( - file='./out.feather', - timestamp_column='time', tag_columns=["provider", "machineID"]) diff --git a/Examples/file-import/json_write.py b/Examples/file-import/json_write.py deleted file mode 100644 index c259bd3..0000000 --- a/Examples/file-import/json_write.py +++ /dev/null @@ -1,65 +0,0 @@ -import logging -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError - - -class BatchingCallback(object): - - def __init__(self): - self.write_count = 0 - - def success(self, conf, data: str): - self.write_count += 1 - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -def main() -> None: - - # allow detailed inspection - logging.basicConfig(level=logging.DEBUG) - - callback = BatchingCallback() - - write_options = WriteOptions(batch_size=100, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - - wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - """ - token: access token generated in cloud - host: ATTN could be another AWS region or even another cloud provider - database: should have retention policy 'forever' to handle older sample data timestamps - write_client_options: see above - debug: allows low-level inspection of communications and context-manager termination - """ - with InfluxDBClient3.InfluxDBClient3( - token="INSERT_TOKEN", - host="https://us-east-1-1.aws.cloud2.influxdata.com/", - database="example_data_forever", - write_client_options=wco, - debug=True) as client: - client.write_file( - file='./out.json', - timestamp_column='time', - tag_columns=["provider", "machineID"], - date_unit='ns') - - print(f"DONE writing from json in {callback.write_count} batch(es)") - - -if __name__ == "__main__": - main() diff --git a/Examples/file-import/orc_write.py b/Examples/file-import/orc_write.py deleted file mode 100644 index 67581c5..0000000 --- a/Examples/file-import/orc_write.py +++ /dev/null @@ -1,39 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=500, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -with InfluxDBClient3.InfluxDBClient3( - token="INSERT_TOKEN", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="python") as client: - client.write_file( - file='./out.orc', - timestamp_column='time', tag_columns=["provider", "machineID"]) diff --git a/Examples/file-import/out_orig.csv b/Examples/file-import/out_orig.csv deleted file mode 100644 index cb508b1..0000000 --- a/Examples/file-import/out_orig.csv +++ /dev/null @@ -1,163 +0,0 @@ -iox::measurement,time,host,load,machineID,power,provider,temperature,topic,vibration -machine_data,2023-06-02 16:42:42.317550714,491cc20bbe13,120.0,machine3,301.0,Smith Group,80.0,machine/machine3,310.0 -machine_data,2023-06-02 16:42:42.317757560,491cc20bbe13,23.0,machine1,183.0,"Morales, Robinson and Newman",31.0,machine/machine1,78.0 -machine_data,2023-06-02 16:42:42.317787898,491cc20bbe13,13.0,machine2,198.0,Thomas and Sons,34.0,machine/machine2,73.0 -machine_data,2023-06-02 16:42:43.318452979,491cc20bbe13,120.0,machine3,307.0,Smith Group,81.0,machine/machine3,332.0 -machine_data,2023-06-02 16:42:43.318733897,491cc20bbe13,23.0,machine1,191.0,"Morales, Robinson and Newman",30.0,machine/machine1,53.0 -machine_data,2023-06-02 16:42:43.318895072,491cc20bbe13,13.0,machine2,197.0,Thomas and Sons,31.0,machine/machine2,56.0 -machine_data,2023-06-02 16:42:44.319014820,491cc20bbe13,120.0,machine3,302.0,Smith Group,87.0,machine/machine3,406.0 -machine_data,2023-06-02 16:42:44.319289702,491cc20bbe13,23.0,machine1,194.0,"Morales, Robinson and Newman",31.0,machine/machine1,65.0 -machine_data,2023-06-02 16:42:44.319743319,491cc20bbe13,13.0,machine2,192.0,Thomas and Sons,34.0,machine/machine2,64.0 -machine_data,2023-06-02 16:42:45.319492285,491cc20bbe13,120.0,machine3,312.0,Smith Group,83.0,machine/machine3,460.0 -machine_data,2023-06-02 16:42:45.319953921,491cc20bbe13,23.0,machine1,199.0,"Morales, Robinson and Newman",29.0,machine/machine1,69.0 -machine_data,2023-06-02 16:42:45.319985284,491cc20bbe13,13.0,machine2,188.0,Thomas and Sons,29.0,machine/machine2,72.0 -machine_data,2023-06-02 16:42:46.319917712,491cc20bbe13,120.0,machine3,317.0,Smith Group,90.0,machine/machine3,363.0 -machine_data,2023-06-02 16:42:46.320373453,491cc20bbe13,23.0,machine1,183.0,"Morales, Robinson and Newman",34.0,machine/machine1,69.0 -machine_data,2023-06-02 16:42:46.320760737,491cc20bbe13,13.0,machine2,184.0,Thomas and Sons,31.0,machine/machine2,78.0 -machine_data,2023-06-02 16:42:47.320548979,491cc20bbe13,120.0,machine3,303.0,Smith Group,80.0,machine/machine3,419.0 -machine_data,2023-06-02 16:42:47.320966397,491cc20bbe13,23.0,machine1,181.0,"Morales, Robinson and Newman",30.0,machine/machine1,71.0 -machine_data,2023-06-02 16:42:47.321006298,491cc20bbe13,13.0,machine2,186.0,Thomas and Sons,31.0,machine/machine2,60.0 -machine_data,2023-06-02 16:42:48.321265346,491cc20bbe13,120.0,machine3,305.0,Smith Group,89.0,machine/machine3,367.0 -machine_data,2023-06-02 16:42:48.321382477,491cc20bbe13,23.0,machine1,197.0,"Morales, Robinson and Newman",33.0,machine/machine1,54.0 -machine_data,2023-06-02 16:42:48.321535645,491cc20bbe13,13.0,machine2,195.0,Thomas and Sons,30.0,machine/machine2,68.0 -machine_data,2023-06-02 16:42:49.321847629,491cc20bbe13,120.0,machine3,317.0,Smith Group,86.0,machine/machine3,334.0 -machine_data,2023-06-02 16:42:49.322119417,491cc20bbe13,13.0,machine2,188.0,Thomas and Sons,29.0,machine/machine2,71.0 -machine_data,2023-06-02 16:42:49.322147172,491cc20bbe13,23.0,machine1,184.0,"Morales, Robinson and Newman",34.0,machine/machine1,71.0 -machine_data,2023-06-02 16:42:50.322698923,491cc20bbe13,120.0,machine3,302.0,Smith Group,87.0,machine/machine3,407.0 -machine_data,2023-06-02 16:42:50.323173071,491cc20bbe13,23.0,machine1,193.0,"Morales, Robinson and Newman",32.0,machine/machine1,59.0 -machine_data,2023-06-02 16:42:50.323237285,491cc20bbe13,13.0,machine2,182.0,Thomas and Sons,30.0,machine/machine2,72.0 -machine_data,2023-06-02 16:42:51.323193568,491cc20bbe13,120.0,machine3,303.0,Smith Group,90.0,machine/machine3,343.0 -machine_data,2023-06-02 16:42:51.323662012,491cc20bbe13,13.0,machine2,188.0,Thomas and Sons,31.0,machine/machine2,67.0 -machine_data,2023-06-02 16:42:51.323725850,491cc20bbe13,23.0,machine1,187.0,"Morales, Robinson and Newman",30.0,machine/machine1,69.0 -machine_data,2023-06-02 16:42:52.323837298,491cc20bbe13,120.0,machine3,319.0,Smith Group,89.0,machine/machine3,406.0 -machine_data,2023-06-02 16:42:52.324179952,491cc20bbe13,23.0,machine1,192.0,"Morales, Robinson and Newman",31.0,machine/machine1,65.0 -machine_data,2023-06-02 16:42:52.324204211,491cc20bbe13,13.0,machine2,193.0,Thomas and Sons,34.0,machine/machine2,61.0 -machine_data,2023-06-02 16:42:53.324457761,491cc20bbe13,120.0,machine3,306.0,Smith Group,81.0,machine/machine3,432.0 -machine_data,2023-06-02 16:42:53.324791324,491cc20bbe13,23.0,machine1,196.0,"Morales, Robinson and Newman",30.0,machine/machine1,59.0 -machine_data,2023-06-02 16:42:53.324822237,491cc20bbe13,13.0,machine2,184.0,Thomas and Sons,30.0,machine/machine2,62.0 -machine_data,2023-06-02 16:42:54.324940162,491cc20bbe13,120.0,machine3,319.0,Smith Group,87.0,machine/machine3,473.0 -machine_data,2023-06-02 16:42:54.325470257,491cc20bbe13,23.0,machine1,183.0,"Morales, Robinson and Newman",29.0,machine/machine1,69.0 -machine_data,2023-06-02 16:42:54.325535111,491cc20bbe13,13.0,machine2,184.0,Thomas and Sons,34.0,machine/machine2,72.0 -machine_data,2023-06-02 16:42:55.325452588,491cc20bbe13,120.0,machine3,308.0,Smith Group,88.0,machine/machine3,478.0 -machine_data,2023-06-02 16:42:55.326241988,491cc20bbe13,23.0,machine1,180.0,"Morales, Robinson and Newman",32.0,machine/machine1,67.0 -machine_data,2023-06-02 16:42:55.326458954,491cc20bbe13,13.0,machine2,181.0,Thomas and Sons,34.0,machine/machine2,53.0 -machine_data,2023-06-02 16:42:56.325962575,491cc20bbe13,120.0,machine3,301.0,Smith Group,89.0,machine/machine3,366.0 -machine_data,2023-06-02 16:42:56.326547488,491cc20bbe13,23.0,machine1,194.0,"Morales, Robinson and Newman",33.0,machine/machine1,77.0 -machine_data,2023-06-02 16:42:56.326817078,491cc20bbe13,13.0,machine2,182.0,Thomas and Sons,33.0,machine/machine2,54.0 -machine_data,2023-06-02 16:42:57.326651847,491cc20bbe13,120.0,machine3,316.0,Smith Group,82.0,machine/machine3,446.0 -machine_data,2023-06-02 16:42:57.326903277,491cc20bbe13,23.0,machine1,186.0,"Morales, Robinson and Newman",32.0,machine/machine1,57.0 -machine_data,2023-06-02 16:42:57.327169455,491cc20bbe13,13.0,machine2,183.0,Thomas and Sons,33.0,machine/machine2,50.0 -machine_data,2023-06-02 16:42:58.327381372,491cc20bbe13,120.0,machine3,303.0,Smith Group,83.0,machine/machine3,329.0 -machine_data,2023-06-02 16:42:58.327785814,491cc20bbe13,13.0,machine2,189.0,Thomas and Sons,31.0,machine/machine2,54.0 -machine_data,2023-06-02 16:42:58.328075202,491cc20bbe13,23.0,machine1,184.0,"Morales, Robinson and Newman",34.0,machine/machine1,67.0 -machine_data,2023-06-02 16:42:59.328107312,491cc20bbe13,120.0,machine3,300.0,Smith Group,90.0,machine/machine3,446.0 -machine_data,2023-06-02 16:42:59.328697178,491cc20bbe13,13.0,machine2,196.0,Thomas and Sons,32.0,machine/machine2,51.0 -machine_data,2023-06-02 16:42:59.328842456,491cc20bbe13,23.0,machine1,183.0,"Morales, Robinson and Newman",30.0,machine/machine1,56.0 -machine_data,2023-06-02 16:43:00.328689987,491cc20bbe13,120.0,machine3,300.0,Smith Group,81.0,machine/machine3,460.0 -machine_data,2023-06-02 16:43:00.328730602,491cc20bbe13,13.0,machine2,180.0,Thomas and Sons,34.0,machine/machine2,57.0 -machine_data,2023-06-02 16:43:00.329187607,491cc20bbe13,23.0,machine1,187.0,"Morales, Robinson and Newman",33.0,machine/machine1,70.0 -machine_data,2023-06-02 16:43:01.329623051,491cc20bbe13,13.0,machine2,194.0,Thomas and Sons,33.0,machine/machine2,79.0 -machine_data,2023-06-02 16:43:01.329737661,491cc20bbe13,120.0,machine3,314.0,Smith Group,85.0,machine/machine3,441.0 -machine_data,2023-06-02 16:43:01.329994500,491cc20bbe13,23.0,machine1,196.0,"Morales, Robinson and Newman",34.0,machine/machine1,70.0 -machine_data,2023-06-02 16:43:02.330561375,491cc20bbe13,13.0,machine2,182.0,Thomas and Sons,31.0,machine/machine2,66.0 -machine_data,2023-06-02 16:43:02.330611344,491cc20bbe13,120.0,machine3,304.0,Smith Group,89.0,machine/machine3,455.0 -machine_data,2023-06-02 16:43:02.330943808,491cc20bbe13,23.0,machine1,186.0,"Morales, Robinson and Newman",29.0,machine/machine1,77.0 -machine_data,2023-06-02 16:43:03.331222016,491cc20bbe13,120.0,machine3,319.0,Smith Group,90.0,machine/machine3,459.0 -machine_data,2023-06-02 16:43:03.331373671,491cc20bbe13,23.0,machine1,196.0,"Morales, Robinson and Newman",29.0,machine/machine1,60.0 -machine_data,2023-06-02 16:43:03.331578703,491cc20bbe13,13.0,machine2,195.0,Thomas and Sons,34.0,machine/machine2,60.0 -machine_data,2023-06-02 16:43:04.331723999,491cc20bbe13,120.0,machine3,311.0,Smith Group,80.0,machine/machine3,493.0 -machine_data,2023-06-02 16:43:04.332158179,491cc20bbe13,23.0,machine1,198.0,"Morales, Robinson and Newman",31.0,machine/machine1,71.0 -machine_data,2023-06-02 16:43:04.332222502,491cc20bbe13,13.0,machine2,188.0,Thomas and Sons,34.0,machine/machine2,72.0 -machine_data,2023-06-02 16:43:05.332522723,491cc20bbe13,120.0,machine3,305.0,Smith Group,89.0,machine/machine3,442.0 -machine_data,2023-06-02 16:43:05.332606103,491cc20bbe13,23.0,machine1,189.0,"Morales, Robinson and Newman",33.0,machine/machine1,71.0 -machine_data,2023-06-02 16:43:05.332956871,491cc20bbe13,13.0,machine2,191.0,Thomas and Sons,34.0,machine/machine2,76.0 -machine_data,2023-06-02 16:43:06.332934234,491cc20bbe13,120.0,machine3,313.0,Smith Group,87.0,machine/machine3,470.0 -machine_data,2023-06-02 16:43:06.333179737,491cc20bbe13,13.0,machine2,193.0,Thomas and Sons,29.0,machine/machine2,74.0 -machine_data,2023-06-02 16:43:06.333464546,491cc20bbe13,23.0,machine1,193.0,"Morales, Robinson and Newman",31.0,machine/machine1,61.0 -machine_data,2023-06-02 16:43:07.333538813,491cc20bbe13,120.0,machine3,303.0,Smith Group,86.0,machine/machine3,443.0 -machine_data,2023-06-02 16:43:07.333592979,491cc20bbe13,13.0,machine2,197.0,Thomas and Sons,33.0,machine/machine2,62.0 -machine_data,2023-06-02 16:43:07.333964542,491cc20bbe13,23.0,machine1,197.0,"Morales, Robinson and Newman",29.0,machine/machine1,70.0 -machine_data,2023-06-02 16:43:08.333966919,491cc20bbe13,120.0,machine3,308.0,Smith Group,84.0,machine/machine3,330.0 -machine_data,2023-06-02 16:43:08.334168052,491cc20bbe13,13.0,machine2,195.0,Thomas and Sons,31.0,machine/machine2,73.0 -machine_data,2023-06-02 16:43:08.334236775,491cc20bbe13,23.0,machine1,184.0,"Morales, Robinson and Newman",30.0,machine/machine1,73.0 -machine_data,2023-06-02 16:43:09.334998961,491cc20bbe13,120.0,machine3,303.0,Smith Group,88.0,machine/machine3,395.0 -machine_data,2023-06-02 16:43:09.335091622,491cc20bbe13,21.0,machine2,193.0,Thomas and Sons,34.0,machine/machine2,72.0 -machine_data,2023-06-02 16:43:09.335117396,491cc20bbe13,51.0,machine1,201.0,"Morales, Robinson and Newman",37.0,machine/machine1,90.0 -machine_data,2023-06-02 16:43:10.335359448,491cc20bbe13,53.0,machine3,209.0,Smith Group,36.0,machine/machine3,89.0 -machine_data,2023-06-02 16:43:10.335917983,491cc20bbe13,21.0,machine2,189.0,Thomas and Sons,32.0,machine/machine2,58.0 -machine_data,2023-06-02 16:43:10.335961039,491cc20bbe13,51.0,machine1,203.0,"Morales, Robinson and Newman",38.0,machine/machine1,85.0 -machine_data,2023-06-02 16:43:11.335865097,491cc20bbe13,53.0,machine3,211.0,Smith Group,39.0,machine/machine3,83.0 -machine_data,2023-06-02 16:43:11.336300844,491cc20bbe13,21.0,machine2,194.0,Thomas and Sons,29.0,machine/machine2,58.0 -machine_data,2023-06-02 16:43:11.336354602,491cc20bbe13,51.0,machine1,205.0,"Morales, Robinson and Newman",38.0,machine/machine1,85.0 -machine_data,2023-06-02 16:43:12.336856584,491cc20bbe13,53.0,machine3,213.0,Smith Group,37.0,machine/machine3,88.0 -machine_data,2023-06-02 16:43:12.337596930,491cc20bbe13,21.0,machine2,193.0,Thomas and Sons,32.0,machine/machine2,55.0 -machine_data,2023-06-02 16:43:12.337627620,491cc20bbe13,51.0,machine1,203.0,"Morales, Robinson and Newman",36.0,machine/machine1,81.0 -machine_data,2023-06-02 16:43:13.337427240,491cc20bbe13,53.0,machine3,206.0,Smith Group,38.0,machine/machine3,80.0 -machine_data,2023-06-02 16:43:13.337811242,491cc20bbe13,21.0,machine2,184.0,Thomas and Sons,32.0,machine/machine2,73.0 -machine_data,2023-06-02 16:43:13.337874112,491cc20bbe13,51.0,machine1,201.0,"Morales, Robinson and Newman",40.0,machine/machine1,81.0 -machine_data,2023-06-02 16:43:14.337992849,491cc20bbe13,53.0,machine3,217.0,Smith Group,39.0,machine/machine3,89.0 -machine_data,2023-06-02 16:43:14.338326166,491cc20bbe13,21.0,machine2,198.0,Thomas and Sons,34.0,machine/machine2,63.0 -machine_data,2023-06-02 16:43:14.338634931,491cc20bbe13,51.0,machine1,205.0,"Morales, Robinson and Newman",37.0,machine/machine1,81.0 -machine_data,2023-06-02 16:43:15.339009274,491cc20bbe13,53.0,machine3,210.0,Smith Group,40.0,machine/machine3,80.0 -machine_data,2023-06-02 16:43:15.339100441,491cc20bbe13,51.0,machine1,206.0,"Morales, Robinson and Newman",38.0,machine/machine1,90.0 -machine_data,2023-06-02 16:43:15.339762188,491cc20bbe13,21.0,machine2,188.0,Thomas and Sons,30.0,machine/machine2,55.0 -machine_data,2023-06-02 16:43:16.340230361,491cc20bbe13,51.0,machine1,201.0,"Morales, Robinson and Newman",38.0,machine/machine1,84.0 -machine_data,2023-06-02 16:43:16.340650516,491cc20bbe13,21.0,machine2,184.0,Thomas and Sons,33.0,machine/machine2,64.0 -machine_data,2023-06-02 16:43:16.340991256,491cc20bbe13,53.0,machine3,203.0,Smith Group,37.0,machine/machine3,84.0 -machine_data,2023-06-02 16:43:17.341908770,491cc20bbe13,53.0,machine3,211.0,Smith Group,40.0,machine/machine3,84.0 -machine_data,2023-06-02 16:43:17.342360815,491cc20bbe13,51.0,machine1,215.0,"Morales, Robinson and Newman",38.0,machine/machine1,86.0 -machine_data,2023-06-02 16:43:17.342426363,491cc20bbe13,21.0,machine2,194.0,Thomas and Sons,33.0,machine/machine2,62.0 -machine_data,2023-06-02 16:43:18.342445484,491cc20bbe13,53.0,machine3,201.0,Smith Group,36.0,machine/machine3,90.0 -machine_data,2023-06-02 16:43:18.342768157,491cc20bbe13,21.0,machine2,197.0,Thomas and Sons,30.0,machine/machine2,53.0 -machine_data,2023-06-02 16:43:18.342799655,491cc20bbe13,51.0,machine1,211.0,"Morales, Robinson and Newman",36.0,machine/machine1,87.0 -machine_data,2023-06-02 16:43:19.342914561,491cc20bbe13,53.0,machine3,206.0,Smith Group,40.0,machine/machine3,80.0 -machine_data,2023-06-02 16:43:19.343415645,491cc20bbe13,21.0,machine2,196.0,Thomas and Sons,33.0,machine/machine2,53.0 -machine_data,2023-06-02 16:43:19.343478737,491cc20bbe13,51.0,machine1,220.0,"Morales, Robinson and Newman",36.0,machine/machine1,89.0 -machine_data,2023-06-02 16:43:20.343479811,491cc20bbe13,53.0,machine3,216.0,Smith Group,36.0,machine/machine3,84.0 -machine_data,2023-06-02 16:43:20.344124763,491cc20bbe13,21.0,machine2,193.0,Thomas and Sons,32.0,machine/machine2,77.0 -machine_data,2023-06-02 16:43:20.344153596,491cc20bbe13,51.0,machine1,200.0,"Morales, Robinson and Newman",35.0,machine/machine1,89.0 -machine_data,2023-06-02 16:43:21.343964197,491cc20bbe13,53.0,machine3,212.0,Smith Group,35.0,machine/machine3,86.0 -machine_data,2023-06-02 16:43:21.344617756,491cc20bbe13,21.0,machine2,183.0,Thomas and Sons,33.0,machine/machine2,64.0 -machine_data,2023-06-02 16:43:21.344685120,491cc20bbe13,51.0,machine1,209.0,"Morales, Robinson and Newman",35.0,machine/machine1,86.0 -machine_data,2023-06-02 16:43:22.344825564,491cc20bbe13,53.0,machine3,205.0,Smith Group,39.0,machine/machine3,87.0 -machine_data,2023-06-02 16:43:22.345135145,491cc20bbe13,21.0,machine2,184.0,Thomas and Sons,31.0,machine/machine2,60.0 -machine_data,2023-06-02 16:43:22.345167055,491cc20bbe13,51.0,machine1,220.0,"Morales, Robinson and Newman",38.0,machine/machine1,81.0 -machine_data,2023-06-02 16:43:23.345437181,491cc20bbe13,53.0,machine3,200.0,Smith Group,37.0,machine/machine3,86.0 -machine_data,2023-06-02 16:43:23.345506574,491cc20bbe13,51.0,machine1,214.0,"Morales, Robinson and Newman",37.0,machine/machine1,86.0 -machine_data,2023-06-02 16:43:23.345564703,491cc20bbe13,21.0,machine2,193.0,Thomas and Sons,33.0,machine/machine2,62.0 -machine_data,2023-06-02 16:43:24.346349521,491cc20bbe13,53.0,machine3,210.0,Smith Group,37.0,machine/machine3,85.0 -machine_data,2023-06-02 16:43:24.346383833,491cc20bbe13,51.0,machine1,211.0,"Morales, Robinson and Newman",37.0,machine/machine1,87.0 -machine_data,2023-06-02 16:43:24.346401291,491cc20bbe13,21.0,machine2,193.0,Thomas and Sons,32.0,machine/machine2,54.0 -machine_data,2023-06-02 16:43:25.346821289,491cc20bbe13,53.0,machine3,220.0,Smith Group,37.0,machine/machine3,89.0 -machine_data,2023-06-02 16:43:25.346921797,491cc20bbe13,21.0,machine2,190.0,Thomas and Sons,34.0,machine/machine2,75.0 -machine_data,2023-06-02 16:43:25.347491870,491cc20bbe13,51.0,machine1,214.0,"Morales, Robinson and Newman",39.0,machine/machine1,83.0 -machine_data,2023-06-02 16:43:26.347838431,491cc20bbe13,21.0,machine2,186.0,Thomas and Sons,29.0,machine/machine2,79.0 -machine_data,2023-06-02 16:43:26.348427616,491cc20bbe13,51.0,machine1,200.0,"Morales, Robinson and Newman",40.0,machine/machine1,85.0 -machine_data,2023-06-02 16:43:26.348455741,491cc20bbe13,53.0,machine3,205.0,Smith Group,40.0,machine/machine3,80.0 -machine_data,2023-06-02 16:43:27.348535696,491cc20bbe13,21.0,machine2,189.0,Thomas and Sons,34.0,machine/machine2,79.0 -machine_data,2023-06-02 16:43:27.349173287,491cc20bbe13,51.0,machine1,215.0,"Morales, Robinson and Newman",36.0,machine/machine1,86.0 -machine_data,2023-06-02 16:43:27.349217288,491cc20bbe13,53.0,machine3,213.0,Smith Group,39.0,machine/machine3,83.0 -machine_data,2023-06-02 16:43:28.348964054,491cc20bbe13,21.0,machine2,191.0,Thomas and Sons,31.0,machine/machine2,63.0 -machine_data,2023-06-02 16:43:28.349958403,491cc20bbe13,51.0,machine1,211.0,"Morales, Robinson and Newman",35.0,machine/machine1,84.0 -machine_data,2023-06-02 16:43:28.350213700,491cc20bbe13,53.0,machine3,201.0,Smith Group,38.0,machine/machine3,81.0 -machine_data,2023-06-02 16:43:29.349501656,491cc20bbe13,21.0,machine2,190.0,Thomas and Sons,30.0,machine/machine2,70.0 -machine_data,2023-06-02 16:43:29.350320992,491cc20bbe13,51.0,machine1,209.0,"Morales, Robinson and Newman",35.0,machine/machine1,88.0 -machine_data,2023-06-02 16:43:29.350858026,491cc20bbe13,53.0,machine3,204.0,Smith Group,36.0,machine/machine3,82.0 -machine_data,2023-06-02 16:43:30.350640276,491cc20bbe13,21.0,machine2,197.0,Thomas and Sons,30.0,machine/machine2,55.0 -machine_data,2023-06-02 16:43:30.351158057,491cc20bbe13,51.0,machine1,214.0,"Morales, Robinson and Newman",36.0,machine/machine1,90.0 -machine_data,2023-06-02 16:43:30.351331667,491cc20bbe13,53.0,machine3,210.0,Smith Group,39.0,machine/machine3,85.0 -machine_data,2023-06-02 16:43:31.351859842,491cc20bbe13,21.0,machine2,188.0,Thomas and Sons,29.0,machine/machine2,65.0 -machine_data,2023-06-02 16:43:31.352098083,491cc20bbe13,51.0,machine1,214.0,"Morales, Robinson and Newman",35.0,machine/machine1,86.0 -machine_data,2023-06-02 16:43:31.352141060,491cc20bbe13,53.0,machine3,213.0,Smith Group,37.0,machine/machine3,84.0 -machine_data,2023-06-02 16:43:32.352201239,491cc20bbe13,21.0,machine2,195.0,Thomas and Sons,32.0,machine/machine2,56.0 -machine_data,2023-06-02 16:43:32.352517261,491cc20bbe13,51.0,machine1,205.0,"Morales, Robinson and Newman",37.0,machine/machine1,84.0 -machine_data,2023-06-02 16:43:32.352589820,491cc20bbe13,53.0,machine3,215.0,Smith Group,36.0,machine/machine3,85.0 -machine_data,2023-06-02 16:43:33.352642145,491cc20bbe13,21.0,machine2,187.0,Thomas and Sons,34.0,machine/machine2,68.0 -machine_data,2023-06-02 16:43:33.353162708,491cc20bbe13,51.0,machine1,218.0,"Morales, Robinson and Newman",35.0,machine/machine1,82.0 -machine_data,2023-06-02 16:43:33.353192522,491cc20bbe13,53.0,machine3,205.0,Smith Group,36.0,machine/machine3,89.0 -machine_data,2023-06-02 16:43:34.353255548,491cc20bbe13,21.0,machine2,197.0,Thomas and Sons,31.0,machine/machine2,50.0 -machine_data,2023-06-02 16:43:34.353521359,491cc20bbe13,51.0,machine1,205.0,"Morales, Robinson and Newman",38.0,machine/machine1,80.0 -machine_data,2023-06-02 16:43:34.353592745,491cc20bbe13,53.0,machine3,202.0,Smith Group,38.0,machine/machine3,83.0 -machine_data,2023-06-02 16:43:35.353829588,491cc20bbe13,21.0,machine2,186.0,Thomas and Sons,30.0,machine/machine2,68.0 -machine_data,2023-06-02 16:43:35.354477346,491cc20bbe13,53.0,machine3,215.0,Smith Group,36.0,machine/machine3,84.0 -machine_data,2023-06-02 16:43:35.354644118,491cc20bbe13,51.0,machine1,206.0,"Morales, Robinson and Newman",38.0,machine/machine1,85.0 diff --git a/Examples/file-import/out_orig.json b/Examples/file-import/out_orig.json deleted file mode 100644 index 91c31d8..0000000 --- a/Examples/file-import/out_orig.json +++ /dev/null @@ -1 +0,0 @@ -[{"iox::measurement":"machine_data","time":1685724162317550714,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":301.0,"provider":"Smith Group","temperature":80.0,"topic":"machine\/machine3","vibration":310.0},{"iox::measurement":"machine_data","time":1685724162317757560,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":183.0,"provider":"Morales, Robinson and Newman","temperature":31.0,"topic":"machine\/machine1","vibration":78.0},{"iox::measurement":"machine_data","time":1685724162317787898,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":198.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":73.0},{"iox::measurement":"machine_data","time":1685724163318452979,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":307.0,"provider":"Smith Group","temperature":81.0,"topic":"machine\/machine3","vibration":332.0},{"iox::measurement":"machine_data","time":1685724163318733897,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":191.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":53.0},{"iox::measurement":"machine_data","time":1685724163318895072,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":197.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":56.0},{"iox::measurement":"machine_data","time":1685724164319014820,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":302.0,"provider":"Smith Group","temperature":87.0,"topic":"machine\/machine3","vibration":406.0},{"iox::measurement":"machine_data","time":1685724164319289702,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":194.0,"provider":"Morales, Robinson and Newman","temperature":31.0,"topic":"machine\/machine1","vibration":65.0},{"iox::measurement":"machine_data","time":1685724164319743319,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":192.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":64.0},{"iox::measurement":"machine_data","time":1685724165319492285,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":312.0,"provider":"Smith Group","temperature":83.0,"topic":"machine\/machine3","vibration":460.0},{"iox::measurement":"machine_data","time":1685724165319953921,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":199.0,"provider":"Morales, Robinson and Newman","temperature":29.0,"topic":"machine\/machine1","vibration":69.0},{"iox::measurement":"machine_data","time":1685724165319985284,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":72.0},{"iox::measurement":"machine_data","time":1685724166319917712,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":317.0,"provider":"Smith Group","temperature":90.0,"topic":"machine\/machine3","vibration":363.0},{"iox::measurement":"machine_data","time":1685724166320373453,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":183.0,"provider":"Morales, Robinson and Newman","temperature":34.0,"topic":"machine\/machine1","vibration":69.0},{"iox::measurement":"machine_data","time":1685724166320760737,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":78.0},{"iox::measurement":"machine_data","time":1685724167320548979,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":303.0,"provider":"Smith Group","temperature":80.0,"topic":"machine\/machine3","vibration":419.0},{"iox::measurement":"machine_data","time":1685724167320966397,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":181.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":71.0},{"iox::measurement":"machine_data","time":1685724167321006298,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":186.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":60.0},{"iox::measurement":"machine_data","time":1685724168321265346,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":305.0,"provider":"Smith Group","temperature":89.0,"topic":"machine\/machine3","vibration":367.0},{"iox::measurement":"machine_data","time":1685724168321382477,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":197.0,"provider":"Morales, Robinson and Newman","temperature":33.0,"topic":"machine\/machine1","vibration":54.0},{"iox::measurement":"machine_data","time":1685724168321535645,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":195.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":68.0},{"iox::measurement":"machine_data","time":1685724169321847629,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":317.0,"provider":"Smith Group","temperature":86.0,"topic":"machine\/machine3","vibration":334.0},{"iox::measurement":"machine_data","time":1685724169322119417,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":71.0},{"iox::measurement":"machine_data","time":1685724169322147172,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":184.0,"provider":"Morales, Robinson and Newman","temperature":34.0,"topic":"machine\/machine1","vibration":71.0},{"iox::measurement":"machine_data","time":1685724170322698923,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":302.0,"provider":"Smith Group","temperature":87.0,"topic":"machine\/machine3","vibration":407.0},{"iox::measurement":"machine_data","time":1685724170323173071,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":193.0,"provider":"Morales, Robinson and Newman","temperature":32.0,"topic":"machine\/machine1","vibration":59.0},{"iox::measurement":"machine_data","time":1685724170323237285,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":182.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":72.0},{"iox::measurement":"machine_data","time":1685724171323193568,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":303.0,"provider":"Smith Group","temperature":90.0,"topic":"machine\/machine3","vibration":343.0},{"iox::measurement":"machine_data","time":1685724171323662012,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":67.0},{"iox::measurement":"machine_data","time":1685724171323725850,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":187.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":69.0},{"iox::measurement":"machine_data","time":1685724172323837298,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":319.0,"provider":"Smith Group","temperature":89.0,"topic":"machine\/machine3","vibration":406.0},{"iox::measurement":"machine_data","time":1685724172324179952,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":192.0,"provider":"Morales, Robinson and Newman","temperature":31.0,"topic":"machine\/machine1","vibration":65.0},{"iox::measurement":"machine_data","time":1685724172324204211,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":61.0},{"iox::measurement":"machine_data","time":1685724173324457761,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":306.0,"provider":"Smith Group","temperature":81.0,"topic":"machine\/machine3","vibration":432.0},{"iox::measurement":"machine_data","time":1685724173324791324,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":196.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":59.0},{"iox::measurement":"machine_data","time":1685724173324822237,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":62.0},{"iox::measurement":"machine_data","time":1685724174324940162,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":319.0,"provider":"Smith Group","temperature":87.0,"topic":"machine\/machine3","vibration":473.0},{"iox::measurement":"machine_data","time":1685724174325470257,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":183.0,"provider":"Morales, Robinson and Newman","temperature":29.0,"topic":"machine\/machine1","vibration":69.0},{"iox::measurement":"machine_data","time":1685724174325535111,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":72.0},{"iox::measurement":"machine_data","time":1685724175325452588,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":308.0,"provider":"Smith Group","temperature":88.0,"topic":"machine\/machine3","vibration":478.0},{"iox::measurement":"machine_data","time":1685724175326241988,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":180.0,"provider":"Morales, Robinson and Newman","temperature":32.0,"topic":"machine\/machine1","vibration":67.0},{"iox::measurement":"machine_data","time":1685724175326458954,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":181.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":53.0},{"iox::measurement":"machine_data","time":1685724176325962575,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":301.0,"provider":"Smith Group","temperature":89.0,"topic":"machine\/machine3","vibration":366.0},{"iox::measurement":"machine_data","time":1685724176326547488,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":194.0,"provider":"Morales, Robinson and Newman","temperature":33.0,"topic":"machine\/machine1","vibration":77.0},{"iox::measurement":"machine_data","time":1685724176326817078,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":182.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":54.0},{"iox::measurement":"machine_data","time":1685724177326651847,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":316.0,"provider":"Smith Group","temperature":82.0,"topic":"machine\/machine3","vibration":446.0},{"iox::measurement":"machine_data","time":1685724177326903277,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":186.0,"provider":"Morales, Robinson and Newman","temperature":32.0,"topic":"machine\/machine1","vibration":57.0},{"iox::measurement":"machine_data","time":1685724177327169455,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":183.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":50.0},{"iox::measurement":"machine_data","time":1685724178327381372,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":303.0,"provider":"Smith Group","temperature":83.0,"topic":"machine\/machine3","vibration":329.0},{"iox::measurement":"machine_data","time":1685724178327785814,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":189.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":54.0},{"iox::measurement":"machine_data","time":1685724178328075202,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":184.0,"provider":"Morales, Robinson and Newman","temperature":34.0,"topic":"machine\/machine1","vibration":67.0},{"iox::measurement":"machine_data","time":1685724179328107312,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":300.0,"provider":"Smith Group","temperature":90.0,"topic":"machine\/machine3","vibration":446.0},{"iox::measurement":"machine_data","time":1685724179328697178,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":196.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":51.0},{"iox::measurement":"machine_data","time":1685724179328842456,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":183.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":56.0},{"iox::measurement":"machine_data","time":1685724180328689987,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":300.0,"provider":"Smith Group","temperature":81.0,"topic":"machine\/machine3","vibration":460.0},{"iox::measurement":"machine_data","time":1685724180328730602,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":180.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":57.0},{"iox::measurement":"machine_data","time":1685724180329187607,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":187.0,"provider":"Morales, Robinson and Newman","temperature":33.0,"topic":"machine\/machine1","vibration":70.0},{"iox::measurement":"machine_data","time":1685724181329623051,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":194.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":79.0},{"iox::measurement":"machine_data","time":1685724181329737661,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":314.0,"provider":"Smith Group","temperature":85.0,"topic":"machine\/machine3","vibration":441.0},{"iox::measurement":"machine_data","time":1685724181329994500,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":196.0,"provider":"Morales, Robinson and Newman","temperature":34.0,"topic":"machine\/machine1","vibration":70.0},{"iox::measurement":"machine_data","time":1685724182330561375,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":182.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":66.0},{"iox::measurement":"machine_data","time":1685724182330611344,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":304.0,"provider":"Smith Group","temperature":89.0,"topic":"machine\/machine3","vibration":455.0},{"iox::measurement":"machine_data","time":1685724182330943808,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":186.0,"provider":"Morales, Robinson and Newman","temperature":29.0,"topic":"machine\/machine1","vibration":77.0},{"iox::measurement":"machine_data","time":1685724183331222016,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":319.0,"provider":"Smith Group","temperature":90.0,"topic":"machine\/machine3","vibration":459.0},{"iox::measurement":"machine_data","time":1685724183331373671,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":196.0,"provider":"Morales, Robinson and Newman","temperature":29.0,"topic":"machine\/machine1","vibration":60.0},{"iox::measurement":"machine_data","time":1685724183331578703,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":195.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":60.0},{"iox::measurement":"machine_data","time":1685724184331723999,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":311.0,"provider":"Smith Group","temperature":80.0,"topic":"machine\/machine3","vibration":493.0},{"iox::measurement":"machine_data","time":1685724184332158179,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":198.0,"provider":"Morales, Robinson and Newman","temperature":31.0,"topic":"machine\/machine1","vibration":71.0},{"iox::measurement":"machine_data","time":1685724184332222502,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":72.0},{"iox::measurement":"machine_data","time":1685724185332522723,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":305.0,"provider":"Smith Group","temperature":89.0,"topic":"machine\/machine3","vibration":442.0},{"iox::measurement":"machine_data","time":1685724185332606103,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":189.0,"provider":"Morales, Robinson and Newman","temperature":33.0,"topic":"machine\/machine1","vibration":71.0},{"iox::measurement":"machine_data","time":1685724185332956871,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":191.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":76.0},{"iox::measurement":"machine_data","time":1685724186332934234,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":313.0,"provider":"Smith Group","temperature":87.0,"topic":"machine\/machine3","vibration":470.0},{"iox::measurement":"machine_data","time":1685724186333179737,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":74.0},{"iox::measurement":"machine_data","time":1685724186333464546,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":193.0,"provider":"Morales, Robinson and Newman","temperature":31.0,"topic":"machine\/machine1","vibration":61.0},{"iox::measurement":"machine_data","time":1685724187333538813,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":303.0,"provider":"Smith Group","temperature":86.0,"topic":"machine\/machine3","vibration":443.0},{"iox::measurement":"machine_data","time":1685724187333592979,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":197.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":62.0},{"iox::measurement":"machine_data","time":1685724187333964542,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":197.0,"provider":"Morales, Robinson and Newman","temperature":29.0,"topic":"machine\/machine1","vibration":70.0},{"iox::measurement":"machine_data","time":1685724188333966919,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":308.0,"provider":"Smith Group","temperature":84.0,"topic":"machine\/machine3","vibration":330.0},{"iox::measurement":"machine_data","time":1685724188334168052,"host":"491cc20bbe13","load":13.0,"machineID":"machine2","power":195.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":73.0},{"iox::measurement":"machine_data","time":1685724188334236775,"host":"491cc20bbe13","load":23.0,"machineID":"machine1","power":184.0,"provider":"Morales, Robinson and Newman","temperature":30.0,"topic":"machine\/machine1","vibration":73.0},{"iox::measurement":"machine_data","time":1685724189334998961,"host":"491cc20bbe13","load":120.0,"machineID":"machine3","power":303.0,"provider":"Smith Group","temperature":88.0,"topic":"machine\/machine3","vibration":395.0},{"iox::measurement":"machine_data","time":1685724189335091622,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":72.0},{"iox::measurement":"machine_data","time":1685724189335117396,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":201.0,"provider":"Morales, Robinson and Newman","temperature":37.0,"topic":"machine\/machine1","vibration":90.0},{"iox::measurement":"machine_data","time":1685724190335359448,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":209.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":89.0},{"iox::measurement":"machine_data","time":1685724190335917983,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":189.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":58.0},{"iox::measurement":"machine_data","time":1685724190335961039,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":203.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":85.0},{"iox::measurement":"machine_data","time":1685724191335865097,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":211.0,"provider":"Smith Group","temperature":39.0,"topic":"machine\/machine3","vibration":83.0},{"iox::measurement":"machine_data","time":1685724191336300844,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":194.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":58.0},{"iox::measurement":"machine_data","time":1685724191336354602,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":205.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":85.0},{"iox::measurement":"machine_data","time":1685724192336856584,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":213.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":88.0},{"iox::measurement":"machine_data","time":1685724192337596930,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":55.0},{"iox::measurement":"machine_data","time":1685724192337627620,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":203.0,"provider":"Morales, Robinson and Newman","temperature":36.0,"topic":"machine\/machine1","vibration":81.0},{"iox::measurement":"machine_data","time":1685724193337427240,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":206.0,"provider":"Smith Group","temperature":38.0,"topic":"machine\/machine3","vibration":80.0},{"iox::measurement":"machine_data","time":1685724193337811242,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":73.0},{"iox::measurement":"machine_data","time":1685724193337874112,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":201.0,"provider":"Morales, Robinson and Newman","temperature":40.0,"topic":"machine\/machine1","vibration":81.0},{"iox::measurement":"machine_data","time":1685724194337992849,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":217.0,"provider":"Smith Group","temperature":39.0,"topic":"machine\/machine3","vibration":89.0},{"iox::measurement":"machine_data","time":1685724194338326166,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":198.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":63.0},{"iox::measurement":"machine_data","time":1685724194338634931,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":205.0,"provider":"Morales, Robinson and Newman","temperature":37.0,"topic":"machine\/machine1","vibration":81.0},{"iox::measurement":"machine_data","time":1685724195339009274,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":210.0,"provider":"Smith Group","temperature":40.0,"topic":"machine\/machine3","vibration":80.0},{"iox::measurement":"machine_data","time":1685724195339100441,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":206.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":90.0},{"iox::measurement":"machine_data","time":1685724195339762188,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":55.0},{"iox::measurement":"machine_data","time":1685724196340230361,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":201.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":84.0},{"iox::measurement":"machine_data","time":1685724196340650516,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":64.0},{"iox::measurement":"machine_data","time":1685724196340991256,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":203.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":84.0},{"iox::measurement":"machine_data","time":1685724197341908770,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":211.0,"provider":"Smith Group","temperature":40.0,"topic":"machine\/machine3","vibration":84.0},{"iox::measurement":"machine_data","time":1685724197342360815,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":215.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":86.0},{"iox::measurement":"machine_data","time":1685724197342426363,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":194.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":62.0},{"iox::measurement":"machine_data","time":1685724198342445484,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":201.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":90.0},{"iox::measurement":"machine_data","time":1685724198342768157,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":197.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":53.0},{"iox::measurement":"machine_data","time":1685724198342799655,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":211.0,"provider":"Morales, Robinson and Newman","temperature":36.0,"topic":"machine\/machine1","vibration":87.0},{"iox::measurement":"machine_data","time":1685724199342914561,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":206.0,"provider":"Smith Group","temperature":40.0,"topic":"machine\/machine3","vibration":80.0},{"iox::measurement":"machine_data","time":1685724199343415645,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":196.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":53.0},{"iox::measurement":"machine_data","time":1685724199343478737,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":220.0,"provider":"Morales, Robinson and Newman","temperature":36.0,"topic":"machine\/machine1","vibration":89.0},{"iox::measurement":"machine_data","time":1685724200343479811,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":216.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":84.0},{"iox::measurement":"machine_data","time":1685724200344124763,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":77.0},{"iox::measurement":"machine_data","time":1685724200344153596,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":200.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":89.0},{"iox::measurement":"machine_data","time":1685724201343964197,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":212.0,"provider":"Smith Group","temperature":35.0,"topic":"machine\/machine3","vibration":86.0},{"iox::measurement":"machine_data","time":1685724201344617756,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":183.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":64.0},{"iox::measurement":"machine_data","time":1685724201344685120,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":209.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":86.0},{"iox::measurement":"machine_data","time":1685724202344825564,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":205.0,"provider":"Smith Group","temperature":39.0,"topic":"machine\/machine3","vibration":87.0},{"iox::measurement":"machine_data","time":1685724202345135145,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":184.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":60.0},{"iox::measurement":"machine_data","time":1685724202345167055,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":220.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":81.0},{"iox::measurement":"machine_data","time":1685724203345437181,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":200.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":86.0},{"iox::measurement":"machine_data","time":1685724203345506574,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":214.0,"provider":"Morales, Robinson and Newman","temperature":37.0,"topic":"machine\/machine1","vibration":86.0},{"iox::measurement":"machine_data","time":1685724203345564703,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":33.0,"topic":"machine\/machine2","vibration":62.0},{"iox::measurement":"machine_data","time":1685724204346349521,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":210.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":85.0},{"iox::measurement":"machine_data","time":1685724204346383833,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":211.0,"provider":"Morales, Robinson and Newman","temperature":37.0,"topic":"machine\/machine1","vibration":87.0},{"iox::measurement":"machine_data","time":1685724204346401291,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":193.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":54.0},{"iox::measurement":"machine_data","time":1685724205346821289,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":220.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":89.0},{"iox::measurement":"machine_data","time":1685724205346921797,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":190.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":75.0},{"iox::measurement":"machine_data","time":1685724205347491870,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":214.0,"provider":"Morales, Robinson and Newman","temperature":39.0,"topic":"machine\/machine1","vibration":83.0},{"iox::measurement":"machine_data","time":1685724206347838431,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":186.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":79.0},{"iox::measurement":"machine_data","time":1685724206348427616,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":200.0,"provider":"Morales, Robinson and Newman","temperature":40.0,"topic":"machine\/machine1","vibration":85.0},{"iox::measurement":"machine_data","time":1685724206348455741,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":205.0,"provider":"Smith Group","temperature":40.0,"topic":"machine\/machine3","vibration":80.0},{"iox::measurement":"machine_data","time":1685724207348535696,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":189.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":79.0},{"iox::measurement":"machine_data","time":1685724207349173287,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":215.0,"provider":"Morales, Robinson and Newman","temperature":36.0,"topic":"machine\/machine1","vibration":86.0},{"iox::measurement":"machine_data","time":1685724207349217288,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":213.0,"provider":"Smith Group","temperature":39.0,"topic":"machine\/machine3","vibration":83.0},{"iox::measurement":"machine_data","time":1685724208348964054,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":191.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":63.0},{"iox::measurement":"machine_data","time":1685724208349958403,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":211.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":84.0},{"iox::measurement":"machine_data","time":1685724208350213700,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":201.0,"provider":"Smith Group","temperature":38.0,"topic":"machine\/machine3","vibration":81.0},{"iox::measurement":"machine_data","time":1685724209349501656,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":190.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":70.0},{"iox::measurement":"machine_data","time":1685724209350320992,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":209.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":88.0},{"iox::measurement":"machine_data","time":1685724209350858026,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":204.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":82.0},{"iox::measurement":"machine_data","time":1685724210350640276,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":197.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":55.0},{"iox::measurement":"machine_data","time":1685724210351158057,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":214.0,"provider":"Morales, Robinson and Newman","temperature":36.0,"topic":"machine\/machine1","vibration":90.0},{"iox::measurement":"machine_data","time":1685724210351331667,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":210.0,"provider":"Smith Group","temperature":39.0,"topic":"machine\/machine3","vibration":85.0},{"iox::measurement":"machine_data","time":1685724211351859842,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":188.0,"provider":"Thomas and Sons","temperature":29.0,"topic":"machine\/machine2","vibration":65.0},{"iox::measurement":"machine_data","time":1685724211352098083,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":214.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":86.0},{"iox::measurement":"machine_data","time":1685724211352141060,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":213.0,"provider":"Smith Group","temperature":37.0,"topic":"machine\/machine3","vibration":84.0},{"iox::measurement":"machine_data","time":1685724212352201239,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":195.0,"provider":"Thomas and Sons","temperature":32.0,"topic":"machine\/machine2","vibration":56.0},{"iox::measurement":"machine_data","time":1685724212352517261,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":205.0,"provider":"Morales, Robinson and Newman","temperature":37.0,"topic":"machine\/machine1","vibration":84.0},{"iox::measurement":"machine_data","time":1685724212352589820,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":215.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":85.0},{"iox::measurement":"machine_data","time":1685724213352642145,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":187.0,"provider":"Thomas and Sons","temperature":34.0,"topic":"machine\/machine2","vibration":68.0},{"iox::measurement":"machine_data","time":1685724213353162708,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":218.0,"provider":"Morales, Robinson and Newman","temperature":35.0,"topic":"machine\/machine1","vibration":82.0},{"iox::measurement":"machine_data","time":1685724213353192522,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":205.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":89.0},{"iox::measurement":"machine_data","time":1685724214353255548,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":197.0,"provider":"Thomas and Sons","temperature":31.0,"topic":"machine\/machine2","vibration":50.0},{"iox::measurement":"machine_data","time":1685724214353521359,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":205.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":80.0},{"iox::measurement":"machine_data","time":1685724214353592745,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":202.0,"provider":"Smith Group","temperature":38.0,"topic":"machine\/machine3","vibration":83.0},{"iox::measurement":"machine_data","time":1685724215353829588,"host":"491cc20bbe13","load":21.0,"machineID":"machine2","power":186.0,"provider":"Thomas and Sons","temperature":30.0,"topic":"machine\/machine2","vibration":68.0},{"iox::measurement":"machine_data","time":1685724215354477346,"host":"491cc20bbe13","load":53.0,"machineID":"machine3","power":215.0,"provider":"Smith Group","temperature":36.0,"topic":"machine\/machine3","vibration":84.0},{"iox::measurement":"machine_data","time":1685724215354644118,"host":"491cc20bbe13","load":51.0,"machineID":"machine1","power":206.0,"provider":"Morales, Robinson and Newman","temperature":38.0,"topic":"machine\/machine1","vibration":85.0}] \ No newline at end of file diff --git a/Examples/file-import/parquet_write.py b/Examples/file-import/parquet_write.py deleted file mode 100644 index b7a3c70..0000000 --- a/Examples/file-import/parquet_write.py +++ /dev/null @@ -1,40 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=500, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -with InfluxDBClient3.InfluxDBClient3( - token="INSERT_TOKEN", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="python", - write_client_options=wco) as client: - client.write_file( - file='./out.parquet', - timestamp_column='time', tag_columns=["provider", "machineID"]) diff --git a/Examples/file-import/write_file_parse_options.py b/Examples/file-import/write_file_parse_options.py deleted file mode 100644 index 282a9cc..0000000 --- a/Examples/file-import/write_file_parse_options.py +++ /dev/null @@ -1,42 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError, file_parser_options - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=500, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -with InfluxDBClient3.InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="python", write_client_options=wco) as client: - fpo = file_parser_options(columns=["time", "machineID", "vibration"]) - - client.write_file( - file='./out.parquet', - timestamp_column='time', tag_columns=["provider", "machineID"], measurement_name='machine_data', - file_parser_options=fpo) diff --git a/Examples/flight_options_example.py b/Examples/flight_options_example.py deleted file mode 100644 index d30470d..0000000 --- a/Examples/flight_options_example.py +++ /dev/null @@ -1,22 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import flight_client_options - - -with open("./cert.pem", 'rb') as f: - cert = f.read() -print(cert) - - -client = InfluxDBClient3.InfluxDBClient3( - token="", - host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io", - database="flightdemo", - flight_client_options=flight_client_options( - tls_root_certs=cert)) - - -table = client.query( - query="SELECT * FROM flight WHERE time > now() - 4h", - language="influxql") - -print(table.to_pandas()) diff --git a/Examples/pandas_write.py b/Examples/pandas_write.py deleted file mode 100644 index ead33cc..0000000 --- a/Examples/pandas_write.py +++ /dev/null @@ -1,34 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 -import pandas as pd -import numpy as np - -client = InfluxDBClient3.InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="") - - -# Create a dataframe -df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) - - -# Create a range of datetime values -dates = pd.date_range(start='2023-03-01', end='2023-03-29', freq='5min') - -# Create a DataFrame with random data and datetime index -df = pd.DataFrame( - np.random.randn( - len(dates), - 3), - index=dates, - columns=[ - 'Column 1', - 'Column 2', - 'Column 3']) -df['tagkey'] = 'Hello World' - -print(df) - -# Write the DataFrame to InfluxDB -client.write(df, data_frame_measurement_name='table', - data_frame_tag_columns=['tagkey']) diff --git a/Examples/pokemon-trainer/basic-query.py b/Examples/pokemon-trainer/basic-query.py deleted file mode 100644 index 08b50ba..0000000 --- a/Examples/pokemon-trainer/basic-query.py +++ /dev/null @@ -1,14 +0,0 @@ -from influxdb_client_3 import InfluxDBClient3 - -client = InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex") - -sql = '''SELECT * FROM caught WHERE trainer = 'ash' AND time >= now() - interval '1 hour' LIMIT 5''' -table = client.query(query=sql, language='sql', mode='all') -print(table) - -influxql = '''SELECT * FROM caught WHERE trainer = 'ash' AND time > now() - 1h LIMIT 5''' -table = client.query(query=influxql, language='influxql', mode='pandas') -print(table) diff --git a/Examples/pokemon-trainer/basic-write-errorhandling.py b/Examples/pokemon-trainer/basic-write-errorhandling.py deleted file mode 100644 index 14be2c9..0000000 --- a/Examples/pokemon-trainer/basic-write-errorhandling.py +++ /dev/null @@ -1,73 +0,0 @@ -import datetime - -from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options - -wco = write_client_options(write_options=SYNCHRONOUS) - -with InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex", write_client_options=wco) as client: - now = datetime.datetime.now(datetime.timezone.utc) - - data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1") \ - .field("caught", "charizard") \ - .field("level", 10).field("attack", 30) \ - .field("defense", 40).field("hp", 200) \ - .field("speed", 10) \ - .field("type1", "fire").field("type2", "flying") \ - .time(now) - - data = [] - # Adding first point - data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0006") - .tag("num", "1") - .field("caught", "charizard") - .field("level", 10) - .field("attack", 30) - .field("defense", 40) - .field("hp", 200) - .field("speed", 10) - .field("type1", "fire") - .field("type2", "flying") - .time(now) - ) - - # Bad point - data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0008") - .tag("num", "3") - .field("caught", "squirtle") - .field("level", 13) - .field("attack", 29) - .field("defense", 40) - .field("hp", 180) - .field("speed", 13) - .field("type1", "water") - .field("type2", None) - .time(now) - ) - - try: - client.write(data) - except Exception as e: - print(f"Error writing point: {e}") - - # Good Query - try: - table = client.query(query='''SELECT * FROM "caught" WHERE time > now() - 5m''', language='influxql') - print(table) - except Exception as e: - print(f"Error querying data: {e}") - - # Bad Query - not a sql query - try: - table = client.query(query='''SELECT * FROM "caught" WHERE time > now() - 5m''', language='sql') - print(table) - except Exception as e: - print(f"Error querying data: {e}") diff --git a/Examples/pokemon-trainer/basic-write-writeoptions.py b/Examples/pokemon-trainer/basic-write-writeoptions.py deleted file mode 100644 index 97bc399..0000000 --- a/Examples/pokemon-trainer/basic-write-writeoptions.py +++ /dev/null @@ -1,83 +0,0 @@ -import datetime - -from influxdb_client_3 import InfluxDBClient3, Point, SYNCHRONOUS, write_client_options - -wco = write_client_options(write_options=SYNCHRONOUS) - -with InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex", - write_client_options=wco, - debug=True) as client: - now = datetime.datetime.now(datetime.timezone.utc) - - data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1") \ - .field("caught", "charizard") \ - .field("level", 10).field("attack", 30) \ - .field("defense", 40).field("hp", 200) \ - .field("speed", 10) \ - .field("type1", "fire").field("type2", "flying") \ - .time(now) - - try: - client.write(data) - except Exception as e: - print(f"Error writing point: {e}") - - data = [] - # Adding first point - data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0006") - .tag("num", "1") - .field("caught", "charizard") - .field("level", 10) - .field("attack", 30) - .field("defense", 40) - .field("hp", 200) - .field("speed", 10) - .field("type1", "fire") - .field("type2", "flying") - .time(now) - ) - - # Adding second point - data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0007") - .tag("num", "2") - .field("caught", "bulbasaur") - .field("level", 12) - .field("attack", 31) - .field("defense", 31) - .field("hp", 190) - .field("speed", 11) - .field("type1", "grass") - .field("type2", "poison") - .time(now) - ) - - # Adding third point - data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0008") - .tag("num", "3") - .field("caught", "squirtle") - .field("level", 13) - .field("attack", 29) - .field("defense", 40) - .field("hp", 180) - .field("speed", 13) - .field("type1", "water") - .field("type2", None) - .time(now) - ) - - try: - client.write(data) - except Exception as e: - print(f"Error writing point: {e}") diff --git a/Examples/pokemon-trainer/basic-write.py b/Examples/pokemon-trainer/basic-write.py deleted file mode 100644 index ee91797..0000000 --- a/Examples/pokemon-trainer/basic-write.py +++ /dev/null @@ -1,80 +0,0 @@ -import datetime - -from influxdb_client_3 import InfluxDBClient3, Point - -client = InfluxDBClient3( - token="mGbL-OJ2kxYqvbIL9jQOOg2VJLhf16hh-xn-XJe3RUKrI5cewOAy80L5cVIzG0vh7dLLckZkpYfvExgoMBXLFA==", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex") - -now = datetime.datetime.now(datetime.timezone.utc) - -data = Point("caught").tag("trainer", "ash").tag("id", "0006").tag("num", "1") \ - .field("caught", "charizard") \ - .field("level", 10).field("attack", 30) \ - .field("defense", 40).field("hp", 200) \ - .field("speed", 10) \ - .field("type1", "fire").field("type2", "flying") \ - .time(now) - -try: - client.write(data) -except Exception as e: - print(f"Error writing point: {e}") - -data = [] -# Adding first point -data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0006") - .tag("num", "1") - .field("caught", "charizard") - .field("level", 10) - .field("attack", 30) - .field("defense", 40) - .field("hp", 200) - .field("speed", 10) - .field("type1", "fire") - .field("type2", "flying") - .time(now) -) - -# Adding second point -data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0007") - .tag("num", "2") - .field("caught", "bulbasaur") - .field("level", 12) - .field("attack", 31) - .field("defense", 31) - .field("hp", 190) - .field("speed", 11) - .field("type1", "grass") - .field("type2", "poison") - .time(now) -) - -# Adding third point -data.append( - Point("caught") - .tag("trainer", "ash") - .tag("id", "0008") - .tag("num", "3") - .field("caught", "squirtle") - .field("level", 13) - .field("attack", 29) - .field("defense", 40) - .field("hp", 180) - .field("speed", 13) - .field("type1", "water") - .field("type2", None) - .time(now) -) - -try: - client.write(data) -except Exception as e: - print(f"Error writing point: {e}") diff --git a/Examples/pokemon-trainer/cookbook.ipynb b/Examples/pokemon-trainer/cookbook.ipynb deleted file mode 100644 index caa956a..0000000 --- a/Examples/pokemon-trainer/cookbook.ipynb +++ /dev/null @@ -1,6077 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# The Pokemon Cookbook\n", - "This cookbook teaches you the concepts of the InfluxDB 3.0 Python Client library using a novel example of Pokemon data. The scenerio is to keep track of each trainer and the number of different pokemon they have caught.\n", - "\n", - "

\n", - "\n", - "

" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# Here we include all the imports required from influxdb_client_3\n", - "from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options\n", - "import pandas as pd\n", - "import random" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Writing Data\n", - "The first step is to write data into InfluxDB. We will use the `write_api` to write data into InfluxDB. In this example we are going to utilise `batching mode` to write data in batches. This is the most efficient way to write data into InfluxDB. To do this we are going to first setup some paramters for our client." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "# This class handles the callbacks for the batching\n", - "class BatchingCallback(object):\n", - "\n", - " def success(self, conf, data: str):\n", - " print(f\"Written batch: {conf}\")\n", - "\n", - " def error(self, conf, data: str, exception: InfluxDBError):\n", - " print(f\"Cannot write batch: {conf}, data: {data} due: {exception}\")\n", - "\n", - " def retry(self, conf, data: str, exception: InfluxDBError):\n", - " print(f\"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}\")\n", - "\n", - "callback = BatchingCallback()\n", - "\n", - "# This is the configuration for the batching. This is wrapped in a WriteOptions object. Within this example you\n", - "# can see the different options that can be set for the batching.\n", - "# Batch size is the number of points to write before the batch is written to the server.\n", - "# Flush interval is the time in milliseconds to wait before the batch is written to the server.\n", - "# Jitter interval is the time in milliseconds to wait before the batch is written to the server.\n", - "# Retry interval is the time in milliseconds to wait before retrying a failed batch.\n", - "# Max retries is the maximum number of times to retry a failed batch.\n", - "# exponential base is the base for the exponential retry delay.\n", - "write_options = WriteOptions(batch_size=100,\n", - " flush_interval=10_000,\n", - " jitter_interval=2_000,\n", - " retry_interval=5_000,\n", - " max_retries=5,\n", - " max_retry_delay=30_000,\n", - " exponential_base=2)\n", - "\n", - "\n", - "# This is the configuration for the write client. This is wrapped in a WriteClientOptions object.\n", - "# As you can see we incldue the BatchingCallback object we created earlier, plus the write_options.\n", - "wco = write_client_options(success_callback=callback.success,\n", - " error_callback=callback.error,\n", - " retry_callback=callback.retry,\n", - " write_options=write_options\n", - " )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Client Setup\n", - "Now that we have done the inital configurations of our write paramters its time to include these within our client initalization. The InfluxDB 3.0 Client can both write and query data. For now we will use it to write data based upon our configuration." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# In this example we are using the InfluxDBClient3 object to connect to the InfluxDB Cloud instance.\n", - "# We are also passing in the write_client_options we created earlier.\n", - "# The token and host are required to connect to the InfluxDB Serverless instance.\n", - "# Note: that Org is optional with Dedicated instances.\n", - "client = InfluxDBClient3(\n", - " token=\"phVXVXPBZ12vyNvVGJJX6vngFa4zyCYIzgDTYRJsPyIUSi3r78agctL2ksCH1GlUxtIWdGFWL5ScxQxUnbQOAQ==\",\n", - " host=\"eu-central-1-1.aws.cloud2.influxdata.com\",\n", - " database=\"pokemon-codex\", enable_gzip=True, write_client_options=wco)\n", - "\n", - "now = pd.Timestamp.now(tz='UTC').floor('ms')\n", - "\n", - "# Lists of possible trainers\n", - "trainers = [\"ash\", \"brock\", \"misty\", \"gary\", \"jessie\", \"james\"]\n", - "\n", - "# Read the CSV into a DataFrame. (Credit to @ritchie46 for the dataset)\n", - "pokemon_df = pd.read_csv(\"./pokemon.csv\")\n", - "\n", - "# Creating an empty list to store the data\n", - "data = []\n", - "\n", - "# Dictionary to keep track of the number of times each trainer has caught each Pokémon\n", - "trainer_pokemon_counts = {}\n", - "\n", - "# Number of entries we want to create\n", - "num_entries = 1000" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Generate some data\n", - "Now that we have our client setup lets start generating some data we can write to InfluxDB. Following the Pokemon example we will create a list of trainers and the number of pokemon they have caught. Trainers will catch pokemon randomly selected from our list stored within the Pandas DataFrame `pokemon_df`." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
traineridnumnamelevelattackdefensehpspeedtype1type2
timestamp
2023-07-27 10:44:44.001000+00:00ash01041Cubone950955035GroundNaN
2023-07-27 10:44:44.001000+00:00brock01461Moltres19100909090FireFlying
2023-07-27 10:44:44.001000+00:00jessie00711Victreebel6105658070GrassPoison
2023-07-27 10:44:44.001000+00:00jessie00701Weepinbell1990506555GrassPoison
2023-07-27 10:44:44.001000+00:00brock01021Exeggcute1340806040GrassPsychic
....................................
2023-07-27 10:44:44.001000+00:00james01385Omanyte20401003535RockWater
2023-07-27 10:44:44.001000+00:00misty00563Mankey2080354070FightingNaN
2023-07-27 10:44:44.001000+00:00gary01342Vaporeon7656013065WaterNaN
2023-07-27 10:44:44.001000+00:00jessie00012Bulbasaur749494545GrassPoison
2023-07-27 10:44:44.001000+00:00james01113Rhyhorn985958025GroundRock
\n", - "

1000 rows × 11 columns

\n", - "
" - ], - "text/plain": [ - " trainer id num name level attack \\\n", - "timestamp \n", - "2023-07-27 10:44:44.001000+00:00 ash 0104 1 Cubone 9 50 \n", - "2023-07-27 10:44:44.001000+00:00 brock 0146 1 Moltres 19 100 \n", - "2023-07-27 10:44:44.001000+00:00 jessie 0071 1 Victreebel 6 105 \n", - "2023-07-27 10:44:44.001000+00:00 jessie 0070 1 Weepinbell 19 90 \n", - "2023-07-27 10:44:44.001000+00:00 brock 0102 1 Exeggcute 13 40 \n", - "... ... ... .. ... ... ... \n", - "2023-07-27 10:44:44.001000+00:00 james 0138 5 Omanyte 20 40 \n", - "2023-07-27 10:44:44.001000+00:00 misty 0056 3 Mankey 20 80 \n", - "2023-07-27 10:44:44.001000+00:00 gary 0134 2 Vaporeon 7 65 \n", - "2023-07-27 10:44:44.001000+00:00 jessie 0001 2 Bulbasaur 7 49 \n", - "2023-07-27 10:44:44.001000+00:00 james 0111 3 Rhyhorn 9 85 \n", - "\n", - " defense hp speed type1 type2 \n", - "timestamp \n", - "2023-07-27 10:44:44.001000+00:00 95 50 35 Ground NaN \n", - "2023-07-27 10:44:44.001000+00:00 90 90 90 Fire Flying \n", - "2023-07-27 10:44:44.001000+00:00 65 80 70 Grass Poison \n", - "2023-07-27 10:44:44.001000+00:00 50 65 55 Grass Poison \n", - "2023-07-27 10:44:44.001000+00:00 80 60 40 Grass Psychic \n", - "... ... ... ... ... ... \n", - "2023-07-27 10:44:44.001000+00:00 100 35 35 Rock Water \n", - "2023-07-27 10:44:44.001000+00:00 35 40 70 Fighting NaN \n", - "2023-07-27 10:44:44.001000+00:00 60 130 65 Water NaN \n", - "2023-07-27 10:44:44.001000+00:00 49 45 45 Grass Poison \n", - "2023-07-27 10:44:44.001000+00:00 95 80 25 Ground Rock \n", - "\n", - "[1000 rows x 11 columns]" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "from IPython.display import display, HTML\n", - "\n", - "# Generating random data\n", - "for i in range(num_entries):\n", - " trainer = random.choice(trainers)\n", - " \n", - " # Randomly select a row from pokemon_df\n", - " random_pokemon = pokemon_df.sample().iloc[0]\n", - " caught = random_pokemon['Name']\n", - " \n", - " # Count the number of times this trainer has caught this Pokémon\n", - " if (trainer, caught) in trainer_pokemon_counts:\n", - " trainer_pokemon_counts[(trainer, caught)] += 1\n", - " else:\n", - " trainer_pokemon_counts[(trainer, caught)] = 1\n", - " \n", - " # Get the number for this combination of trainer and Pokémon\n", - " num = trainer_pokemon_counts[(trainer, caught)]\n", - "\n", - " entry = {\n", - " \"trainer\": trainer,\n", - " \"id\": f\"{0000 + random_pokemon['#']:04d}\",\n", - " \"num\": str(num),\n", - " \"name\": caught,\n", - " \"level\": random.randint(5, 20),\n", - " \"attack\": random_pokemon['Attack'],\n", - " \"defense\": random_pokemon['Defense'],\n", - " \"hp\": random_pokemon['HP'],\n", - " \"speed\": random_pokemon['Speed'],\n", - " \"type1\": random_pokemon['Type 1'],\n", - " \"type2\": random_pokemon['Type 2'],\n", - " \"timestamp\": now\n", - " }\n", - " data.append(entry)\n", - "\n", - "# Convert the list of dictionaries to a DataFrame\n", - "caught_pokemon_df = pd.DataFrame(data).set_index('timestamp')\n", - "\n", - "# Print the DataFrame\n", - "display(caught_pokemon_df)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write Data to InfluxDB\n", - "We will now write our newley created trainer data to InfluxDB. To do this we simply call client.write and pass in our dataframe. We then provide a static measurement name of `caught`. We also provide a series of tags to help identify our data. In this case we use the columns `['trainer', 'id', 'num']`. Note that we didn't provide our time column this is due to the fact we set this column as our `dataframe_index`. This means that the index column will be used as the time column." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n" - ] - } - ], - "source": [ - "import time\n", - "\n", - "try:\n", - " client.write(caught_pokemon_df, data_frame_measurement_name='caught',\n", - " data_frame_tag_columns=['trainer', 'id', 'num'])\n", - "except Exception as e:\n", - " print(f\"Error writing point: {e}\")\n", - "\n", - "# Wait for the batch to be written\n", - "time.sleep(2)\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Querying Data\n", - "We have now stored 1000 registered pokemon catches within InfluxDB. We can now query this data using the InfluxDB 3.0 Python Client to gain some insights into our data. We are going to use Plotly to visualise our data." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
table_catalogtable_schematable_namecolumn_namedata_typeis_nullable
0publicioxcaughtattackInt64YES
1publicioxcaughtdefenseInt64YES
2publicioxcaughthpInt64YES
3publicioxcaughtidDictionary(Int32, Utf8)YES
4publicioxcaughtlevelInt64YES
5publicioxcaughtnameUtf8YES
6publicioxcaughtnumDictionary(Int32, Utf8)YES
7publicioxcaughtspeedInt64YES
8publicioxcaughttimeTimestamp(Nanosecond, None)NO
9publicioxcaughttrainerDictionary(Int32, Utf8)YES
10publicioxcaughttype1Utf8YES
11publicioxcaughttype2Utf8YES
\n", - "
" - ], - "text/plain": [ - " table_catalog table_schema table_name column_name \\\n", - "0 public iox caught attack \n", - "1 public iox caught defense \n", - "2 public iox caught hp \n", - "3 public iox caught id \n", - "4 public iox caught level \n", - "5 public iox caught name \n", - "6 public iox caught num \n", - "7 public iox caught speed \n", - "8 public iox caught time \n", - "9 public iox caught trainer \n", - "10 public iox caught type1 \n", - "11 public iox caught type2 \n", - "\n", - " data_type is_nullable \n", - "0 Int64 YES \n", - "1 Int64 YES \n", - "2 Int64 YES \n", - "3 Dictionary(Int32, Utf8) YES \n", - "4 Int64 YES \n", - "5 Utf8 YES \n", - "6 Dictionary(Int32, Utf8) YES \n", - "7 Int64 YES \n", - "8 Timestamp(Nanosecond, None) NO \n", - "9 Dictionary(Int32, Utf8) YES \n", - "10 Utf8 YES \n", - "11 Utf8 YES " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# These are just some library imports for Plotly so we can make use of the interactive graphs.\n", - "import plotly.express as px\n", - "import plotly.io as pio\n", - "pio.renderers.default = \"vscode\"\n", - "\n", - "# Lets start with a simple query to understand our schema.\n", - "query = '''SHOW COLUMNS FROM caught'''\n", - "\n", - "# We can use the query method to run a query against the database.\n", - "# Under the hood this creates a flight ticket and uses the FlightClient to run the query.\n", - "# For this example we are using the pandas mode, which will return a pandas DataFrame.\n", - "# Language also allows us to specify the query language, in this case we are using SQL.\n", - "table = client.query(query=query, language='sql', mode='pandas')\n", - "\n", - "display(table)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Simple InfluxQL Query\n", - "The first query we will run is a simple InfluxQL query to get the number of pokemon caught by each trainer. We will then use Plotly to visualise this data." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "config": { - "plotlyServerURL": "https://plot.ly" - }, - "data": [ - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "ash", - "marker": { - "color": "#636efa", - "pattern": { - "shape": "" - } - }, - "name": "ash", - "offsetgroup": "ash", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash" - ], - "xaxis": "x", - "y": [ - 146 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "brock", - "marker": { - "color": "#EF553B", - "pattern": { - "shape": "" - } - }, - "name": "brock", - "offsetgroup": "brock", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "brock" - ], - "xaxis": "x", - "y": [ - 172 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "gary", - "marker": { - "color": "#00cc96", - "pattern": { - "shape": "" - } - }, - "name": "gary", - "offsetgroup": "gary", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "gary" - ], - "xaxis": "x", - "y": [ - 162 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "james", - "marker": { - "color": "#ab63fa", - "pattern": { - "shape": "" - } - }, - "name": "james", - "offsetgroup": "james", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "james" - ], - "xaxis": "x", - "y": [ - 162 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "jessie", - "marker": { - "color": "#FFA15A", - "pattern": { - "shape": "" - } - }, - "name": "jessie", - "offsetgroup": "jessie", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie" - ], - "xaxis": "x", - "y": [ - 155 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "trainer=%{x}
count=%{y}", - "legendgroup": "misty", - "marker": { - "color": "#19d3f3", - "pattern": { - "shape": "" - } - }, - "name": "misty", - "offsetgroup": "misty", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "misty" - ], - "xaxis": "x", - "y": [ - 166 - ], - "yaxis": "y" - } - ], - "layout": { - "barmode": "relative", - "legend": { - "title": { - "text": "trainer" - }, - "tracegroupgap": 0 - }, - "template": { - "data": { - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "choropleth": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "choropleth" - } - ], - "contour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "contour" - } - ], - "contourcarpet": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "contourcarpet" - } - ], - "heatmap": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmap" - } - ], - "heatmapgl": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmapgl" - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "histogram2d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2d" - } - ], - "histogram2dcontour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2dcontour" - } - ], - "mesh3d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "mesh3d" - } - ], - "parcoords": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "parcoords" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "scatter3d": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatter3d" - } - ], - "scattercarpet": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattercarpet" - } - ], - "scattergeo": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergeo" - } - ], - "scattergl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergl" - } - ], - "scattermapbox": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattermapbox" - } - ], - "scatterpolar": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolar" - } - ], - "scatterpolargl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolargl" - } - ], - "scatterternary": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterternary" - } - ], - "surface": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "surface" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ] - }, - "layout": { - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "autotypenumbers": "strict", - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ], - "sequential": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ] - }, - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "geo": { - "bgcolor": "white", - "lakecolor": "white", - "landcolor": "#E5ECF6", - "showlakes": true, - "showland": true, - "subunitcolor": "white" - }, - "hoverlabel": { - "align": "left" - }, - "hovermode": "closest", - "mapbox": { - "style": "light" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "ternary": { - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "title": { - "x": 0.05 - }, - "xaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - }, - "yaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - } - } - }, - "title": { - "text": "Number of Pokémon caught in the last hour" - }, - "xaxis": { - "anchor": "y", - "categoryarray": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "categoryorder": "array", - "domain": [ - 0, - 1 - ], - "title": { - "text": "trainer" - } - }, - "yaxis": { - "anchor": "x", - "domain": [ - 0, - 1 - ], - "title": { - "text": "count" - } - } - } - } - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Lets start with a simple query to understand our schema.\n", - "query = '''SELECT count(\"name\") FROM caught WHERE time > now() - 1h GROUP BY trainer'''\n", - "\n", - "# We can use the query method to run a query against the database.\n", - "# Under the hood this creates a flight ticket and uses the FlightClient to run the query.\n", - "# For this example we are using the pandas mode, which will return a pandas DataFrame.\n", - "# Language also allows us to specify the query language, in this case we are using SQL.\n", - "table = client.query(query=query, language='influxql', mode='pandas')\n", - "\n", - "fig1 = px.bar(table, x=\"trainer\", y=\"count\",color='trainer' ,title='Number of Pokémon caught in the last hour')\n", - "fig1.show()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "config": { - "plotlyServerURL": "https://plot.ly" - }, - "data": [ - { - "alignmentgroup": "True", - "hovertemplate": "type1=Bug
trainer=%{x}
count=%{y}", - "legendgroup": "Bug", - "marker": { - "color": "#636efa", - "pattern": { - "shape": "" - } - }, - "name": "Bug", - "offsetgroup": "Bug", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 13, - 19, - 12, - 13, - 14, - 13 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Electric
trainer=%{x}
count=%{y}", - "legendgroup": "Electric", - "marker": { - "color": "#EF553B", - "pattern": { - "shape": "" - } - }, - "name": "Electric", - "offsetgroup": "Electric", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 7, - 13, - 11, - 5, - 8, - 6 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fairy
trainer=%{x}
count=%{y}", - "legendgroup": "Fairy", - "marker": { - "color": "#00cc96", - "pattern": { - "shape": "" - } - }, - "name": "Fairy", - "offsetgroup": "Fairy", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 3, - 5, - 2, - 3, - 2, - 4 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fighting
trainer=%{x}
count=%{y}", - "legendgroup": "Fighting", - "marker": { - "color": "#ab63fa", - "pattern": { - "shape": "" - } - }, - "name": "Fighting", - "offsetgroup": "Fighting", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 4, - 7, - 9, - 10, - 9, - 12 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fire
trainer=%{x}
count=%{y}", - "legendgroup": "Fire", - "marker": { - "color": "#FFA15A", - "pattern": { - "shape": "" - } - }, - "name": "Fire", - "offsetgroup": "Fire", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 20, - 16, - 12, - 13, - 13, - 4 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ghost
trainer=%{x}
count=%{y}", - "legendgroup": "Ghost", - "marker": { - "color": "#19d3f3", - "pattern": { - "shape": "" - } - }, - "name": "Ghost", - "offsetgroup": "Ghost", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 3, - 4, - 1, - 6, - 3, - 2 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Grass
trainer=%{x}
count=%{y}", - "legendgroup": "Grass", - "marker": { - "color": "#FF6692", - "pattern": { - "shape": "" - } - }, - "name": "Grass", - "offsetgroup": "Grass", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 12, - 13, - 12, - 11, - 11, - 14 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ground
trainer=%{x}
count=%{y}", - "legendgroup": "Ground", - "marker": { - "color": "#B6E880", - "pattern": { - "shape": "" - } - }, - "name": "Ground", - "offsetgroup": "Ground", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 4, - 7, - 10, - 12, - 7, - 9 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ice
trainer=%{x}
count=%{y}", - "legendgroup": "Ice", - "marker": { - "color": "#FF97FF", - "pattern": { - "shape": "" - } - }, - "name": "Ice", - "offsetgroup": "Ice", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 3, - 2, - 1, - 1, - 4, - 1 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Normal
trainer=%{x}
count=%{y}", - "legendgroup": "Normal", - "marker": { - "color": "#FECB52", - "pattern": { - "shape": "" - } - }, - "name": "Normal", - "offsetgroup": "Normal", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 19, - 24, - 21, - 14, - 22, - 29 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Poison
trainer=%{x}
count=%{y}", - "legendgroup": "Poison", - "marker": { - "color": "#636efa", - "pattern": { - "shape": "" - } - }, - "name": "Poison", - "offsetgroup": "Poison", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 12, - 13, - 12, - 17, - 11, - 15 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Psychic
trainer=%{x}
count=%{y}", - "legendgroup": "Psychic", - "marker": { - "color": "#EF553B", - "pattern": { - "shape": "" - } - }, - "name": "Psychic", - "offsetgroup": "Psychic", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 7, - 6, - 8, - 10, - 6, - 7 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Rock
trainer=%{x}
count=%{y}", - "legendgroup": "Rock", - "marker": { - "color": "#00cc96", - "pattern": { - "shape": "" - } - }, - "name": "Rock", - "offsetgroup": "Rock", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 11, - 9, - 11, - 15, - 16, - 12 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Water
trainer=%{x}
count=%{y}", - "legendgroup": "Water", - "marker": { - "color": "#ab63fa", - "pattern": { - "shape": "" - } - }, - "name": "Water", - "offsetgroup": "Water", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "brock", - "gary", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 28, - 32, - 39, - 32, - 25, - 36 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Dragon
trainer=%{x}
count=%{y}", - "legendgroup": "Dragon", - "marker": { - "color": "#FFA15A", - "pattern": { - "shape": "" - } - }, - "name": "Dragon", - "offsetgroup": "Dragon", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "brock", - "gary", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 2, - 1, - 4, - 2 - ], - "yaxis": "y" - } - ], - "layout": { - "barmode": "group", - "legend": { - "title": { - "text": "type1" - }, - "tracegroupgap": 0 - }, - "template": { - "data": { - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "choropleth": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "choropleth" - } - ], - "contour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "contour" - } - ], - "contourcarpet": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "contourcarpet" - } - ], - "heatmap": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmap" - } - ], - "heatmapgl": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmapgl" - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "histogram2d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2d" - } - ], - "histogram2dcontour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2dcontour" - } - ], - "mesh3d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "mesh3d" - } - ], - "parcoords": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "parcoords" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "scatter3d": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatter3d" - } - ], - "scattercarpet": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattercarpet" - } - ], - "scattergeo": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergeo" - } - ], - "scattergl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergl" - } - ], - "scattermapbox": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattermapbox" - } - ], - "scatterpolar": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolar" - } - ], - "scatterpolargl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolargl" - } - ], - "scatterternary": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterternary" - } - ], - "surface": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "surface" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ] - }, - "layout": { - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "autotypenumbers": "strict", - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ], - "sequential": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ] - }, - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "geo": { - "bgcolor": "white", - "lakecolor": "white", - "landcolor": "#E5ECF6", - "showlakes": true, - "showland": true, - "subunitcolor": "white" - }, - "hoverlabel": { - "align": "left" - }, - "hovermode": "closest", - "mapbox": { - "style": "light" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "ternary": { - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "title": { - "x": 0.05 - }, - "xaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - }, - "yaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - } - } - }, - "title": { - "text": "Number of Pokémon caught in the last hour grouped by type" - }, - "xaxis": { - "anchor": "y", - "domain": [ - 0, - 1 - ], - "title": { - "text": "trainer" - } - }, - "yaxis": { - "anchor": "x", - "domain": [ - 0, - 1 - ], - "title": { - "text": "count" - } - } - } - } - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Lets start with a simple query to understand our schema.\n", - "query = '''SELECT count(\"name\") FROM caught WHERE time > now() - 1h GROUP BY trainer,type1'''\n", - "\n", - "# We can use the query method to run a query against the database.\n", - "# Under the hood this creates a flight ticket and uses the FlightClient to run the query.\n", - "# For this example we are using the pandas mode, which will return a pandas DataFrame.\n", - "# Language also allows us to specify the query language, in this case we are using SQL.\n", - "table = client.query(query=query, language='influxql' , mode='pandas')\n", - "\n", - "fig2 = px.bar(table, x=\"trainer\", y=\"count\", color='type1', barmode= 'group', title='Number of Pokémon caught in the last hour grouped by type')\n", - "fig2.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Working with Arrow tables\n", - "So within the last section we discussed converting returned queries directly to Pandas Dataframes. However, we can also utilise their raw format, Arrow tables. Arrow tables are a columnar format that is more efficient for working with data.\n", - "\n", - "Lets first start by adding more data with a random timestamp between now and 1 hour ago" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
traineridnumnamelevelattackdefensehpspeedtype1type2
timestamp
2023-07-27 10:13:38.242000+00:00james00151Beedrill890406575BugPoison
2023-07-27 10:24:38.242000+00:00misty01013Electrode17507060140ElectricNaN
2023-07-27 10:10:38.242000+00:00brock00253Pikachu1055403590ElectricNaN
2023-07-27 10:47:38.242000+00:00misty01352Jolteon20656065130ElectricNaN
2023-07-27 10:14:38.242000+00:00ash00222Fearow13906565100NormalFlying
....................................
2023-07-27 10:40:38.242000+00:00james013310Eevee1355505555NormalNaN
2023-07-27 10:11:38.242000+00:00james011012Weezing10901206560PoisonNaN
2023-07-27 10:19:38.242000+00:00james00728Tentacool540354070WaterPoison
2023-07-27 10:18:38.242000+00:00brock011017Weezing12901206560PoisonNaN
2023-07-27 10:30:38.242000+00:00misty009416Gengar11656060110GhostPoison
\n", - "

10000 rows × 11 columns

\n", - "
" - ], - "text/plain": [ - " trainer id num name level attack \\\n", - "timestamp \n", - "2023-07-27 10:13:38.242000+00:00 james 0015 1 Beedrill 8 90 \n", - "2023-07-27 10:24:38.242000+00:00 misty 0101 3 Electrode 17 50 \n", - "2023-07-27 10:10:38.242000+00:00 brock 0025 3 Pikachu 10 55 \n", - "2023-07-27 10:47:38.242000+00:00 misty 0135 2 Jolteon 20 65 \n", - "2023-07-27 10:14:38.242000+00:00 ash 0022 2 Fearow 13 90 \n", - "... ... ... .. ... ... ... \n", - "2023-07-27 10:40:38.242000+00:00 james 0133 10 Eevee 13 55 \n", - "2023-07-27 10:11:38.242000+00:00 james 0110 12 Weezing 10 90 \n", - "2023-07-27 10:19:38.242000+00:00 james 0072 8 Tentacool 5 40 \n", - "2023-07-27 10:18:38.242000+00:00 brock 0110 17 Weezing 12 90 \n", - "2023-07-27 10:30:38.242000+00:00 misty 0094 16 Gengar 11 65 \n", - "\n", - " defense hp speed type1 type2 \n", - "timestamp \n", - "2023-07-27 10:13:38.242000+00:00 40 65 75 Bug Poison \n", - "2023-07-27 10:24:38.242000+00:00 70 60 140 Electric NaN \n", - "2023-07-27 10:10:38.242000+00:00 40 35 90 Electric NaN \n", - "2023-07-27 10:47:38.242000+00:00 60 65 130 Electric NaN \n", - "2023-07-27 10:14:38.242000+00:00 65 65 100 Normal Flying \n", - "... ... .. ... ... ... \n", - "2023-07-27 10:40:38.242000+00:00 50 55 55 Normal NaN \n", - "2023-07-27 10:11:38.242000+00:00 120 65 60 Poison NaN \n", - "2023-07-27 10:19:38.242000+00:00 35 40 70 Water Poison \n", - "2023-07-27 10:18:38.242000+00:00 120 65 60 Poison NaN \n", - "2023-07-27 10:30:38.242000+00:00 60 60 110 Ghost Poison \n", - "\n", - "[10000 rows x 11 columns]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n" - ] - } - ], - "source": [ - "num_entries = 10000 # You can reduce this if required. The more data the more interesting the results.\n", - "now = pd.Timestamp.now(tz='UTC').floor('ms')\n", - "data = []\n", - "\n", - "\n", - "# Generating random data\n", - "for i in range(num_entries):\n", - " # Randomise the timestamp\n", - " timestamp = now - pd.Timedelta(minutes=random.randint(0, 60))\n", - " trainer = random.choice(trainers)\n", - " \n", - " # Randomly select a row from pokemon_df\n", - " random_pokemon = pokemon_df.sample().iloc[0]\n", - " caught = random_pokemon['Name']\n", - " \n", - " # Count the number of times this trainer has caught this Pokémon\n", - " if (trainer, caught) in trainer_pokemon_counts:\n", - " trainer_pokemon_counts[(trainer, caught)] += 1\n", - " else:\n", - " trainer_pokemon_counts[(trainer, caught)] = 1\n", - " \n", - " # Get the number for this combination of trainer and Pokémon\n", - " num = trainer_pokemon_counts[(trainer, caught)]\n", - "\n", - " entry = {\n", - " \"trainer\": trainer,\n", - " \"id\": f\"{0000 + random_pokemon['#']:04d}\",\n", - " \"num\": str(num),\n", - " \"name\": caught,\n", - " \"level\": random.randint(5, 20),\n", - " \"attack\": random_pokemon['Attack'],\n", - " \"defense\": random_pokemon['Defense'],\n", - " \"hp\": random_pokemon['HP'],\n", - " \"speed\": random_pokemon['Speed'],\n", - " \"type1\": random_pokemon['Type 1'],\n", - " \"type2\": random_pokemon['Type 2'],\n", - " \"timestamp\": timestamp\n", - " }\n", - " data.append(entry)\n", - "\n", - "# Convert the list of dictionaries to a DataFrame\n", - "caught_pokemon_df = pd.DataFrame(data).set_index('timestamp')\n", - "\n", - "# Print the DataFrame\n", - "display(caught_pokemon_df)\n", - "\n", - "try:\n", - " client.write(caught_pokemon_df, data_frame_measurement_name='kanto',\n", - " data_frame_tag_columns=['trainer', 'id', 'num'])\n", - "except Exception as e:\n", - " print(f\"Error writing point: {e}\")\n", - "\n", - "# Wait for the batch to be written\n", - "time.sleep(5)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now lets return the result as an Arrow table. We can recreate he same aggregation we did on server side with the pyarrow library. the `mode='all'` parameter tells InfluxDB to return all data within the query result as a Arrow table. We can then use the `to_pandas()` method to convert the Arrow table to a Pandas DataFrame." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "pyarrow.Table\n", - "iox::measurement: string not null\n", - "time: timestamp[ns] not null\n", - "attack: int64\n", - "defense: int64\n", - "hp: int64\n", - "id: string\n", - "level: int64\n", - "name: string\n", - "num: string\n", - "speed: int64\n", - "trainer: string\n", - "type1: string\n", - "type2: string\n", - "----\n", - "iox::measurement: [[\"kanto\",\"kanto\",\"kanto\",\"kanto\",\"kanto\",...,\"kanto\",\"kanto\",\"kanto\",\"kanto\",\"kanto\"],[\"kanto\",\"kanto\",\"kanto\",\"kanto\",\"kanto\",...,\"kanto\",\"kanto\",\"kanto\",\"kanto\",\"kanto\"]]\n", - "time: [[2023-07-27 09:48:38.242000000,2023-07-27 09:48:38.242000000,2023-07-27 09:48:38.242000000,2023-07-27 09:48:38.242000000,2023-07-27 09:48:38.242000000,...,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000],[2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,2023-07-27 10:38:38.242000000,...,2023-07-27 10:48:38.242000000,2023-07-27 10:48:38.242000000,2023-07-27 10:48:38.242000000,2023-07-27 10:48:38.242000000,2023-07-27 10:48:38.242000000]]\n", - "attack: [[82,82,100,64,64,...,60,85,85,100,100],[47,72,45,41,41,...,64,64,134,134,110]]\n", - "defense: [[83,83,123,58,58,...,44,69,69,110,110],[52,57,48,40,40,...,45,45,95,95,90]]\n", - "hp: [[80,80,80,58,58,...,35,60,60,75,75],[55,61,70,38,38,...,41,41,91,91,106]]\n", - "id: [[\"0003\",\"0003\",\"0003\",\"0005\",\"0005\",...,\"0023\",\"0024\",\"0024\",\"0028\",\"0028\"],[\"0029\",\"0033\",\"0035\",\"0037\",\"0037\",...,\"0147\",\"0147\",\"0149\",\"0149\",\"0150\"]]\n", - "level: [[9,9,18,18,12,...,15,5,8,15,5],[11,15,10,16,19,...,10,11,16,6,17]]\n", - "name: [[\"Venusaur\",\"Venusaur\",\"VenusaurMega Venusaur\",\"Charmeleon\",\"Charmeleon\",...,\"Ekans\",\"Arbok\",\"Arbok\",\"Sandslash\",\"Sandslash\"],[\"Nidoran♀\",\"Nidorino\",\"Clefairy\",\"Vulpix\",\"Vulpix\",...,\"Dratini\",\"Dratini\",\"Dragonite\",\"Dragonite\",\"Mewtwo\"]]\n", - "num: [[\"4\",\"6\",\"8\",\"11\",\"3\",...,\"12\",\"6\",\"7\",\"7\",\"7\"],[\"8\",\"6\",\"16\",\"1\",\"10\",...,\"1\",\"3\",\"3\",\"5\",\"11\"]]\n", - "speed: [[80,80,80,80,80,...,55,80,80,65,65],[41,65,35,65,65,...,50,50,80,80,130]]\n", - "...\n" - ] - }, - { - "data": { - "application/vnd.plotly.v1+json": { - "config": { - "plotlyServerURL": "https://plot.ly" - }, - "data": [ - { - "alignmentgroup": "True", - "hovertemplate": "type1=Grass
trainer=%{x}
name_count=%{y}", - "legendgroup": "Grass", - "marker": { - "color": "#636efa", - "pattern": { - "shape": "" - } - }, - "name": "Grass", - "offsetgroup": "Grass", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "misty", - "gary", - "james", - "brock", - "jessie" - ], - "xaxis": "x", - "y": [ - 121, - 137, - 134, - 129, - 130, - 138 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fire
trainer=%{x}
name_count=%{y}", - "legendgroup": "Fire", - "marker": { - "color": "#EF553B", - "pattern": { - "shape": "" - } - }, - "name": "Fire", - "offsetgroup": "Fire", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "james", - "brock", - "ash", - "jessie", - "misty", - "gary" - ], - "xaxis": "x", - "y": [ - 153, - 151, - 128, - 142, - 132, - 161 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Water
trainer=%{x}
name_count=%{y}", - "legendgroup": "Water", - "marker": { - "color": "#00cc96", - "pattern": { - "shape": "" - } - }, - "name": "Water", - "offsetgroup": "Water", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "misty", - "james", - "brock", - "gary", - "ash", - "jessie" - ], - "xaxis": "x", - "y": [ - 333, - 323, - 324, - 283, - 315, - 345 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Bug
trainer=%{x}
name_count=%{y}", - "legendgroup": "Bug", - "marker": { - "color": "#ab63fa", - "pattern": { - "shape": "" - } - }, - "name": "Bug", - "offsetgroup": "Bug", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "james", - "misty", - "ash", - "brock", - "gary", - "jessie" - ], - "xaxis": "x", - "y": [ - 160, - 147, - 157, - 142, - 140, - 154 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Normal
trainer=%{x}
name_count=%{y}", - "legendgroup": "Normal", - "marker": { - "color": "#FFA15A", - "pattern": { - "shape": "" - } - }, - "name": "Normal", - "offsetgroup": "Normal", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie", - "gary", - "ash", - "brock", - "james", - "misty" - ], - "xaxis": "x", - "y": [ - 240, - 261, - 231, - 239, - 237, - 230 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Electric
trainer=%{x}
name_count=%{y}", - "legendgroup": "Electric", - "marker": { - "color": "#19d3f3", - "pattern": { - "shape": "" - } - }, - "name": "Electric", - "offsetgroup": "Electric", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie", - "gary", - "misty", - "brock", - "james", - "ash" - ], - "xaxis": "x", - "y": [ - 90, - 107, - 85, - 88, - 102, - 97 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Poison
trainer=%{x}
name_count=%{y}", - "legendgroup": "Poison", - "marker": { - "color": "#FF6692", - "pattern": { - "shape": "" - } - }, - "name": "Poison", - "offsetgroup": "Poison", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "misty", - "jessie", - "james", - "brock", - "ash", - "gary" - ], - "xaxis": "x", - "y": [ - 147, - 138, - 154, - 147, - 154, - 137 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fairy
trainer=%{x}
name_count=%{y}", - "legendgroup": "Fairy", - "marker": { - "color": "#B6E880", - "pattern": { - "shape": "" - } - }, - "name": "Fairy", - "offsetgroup": "Fairy", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie", - "brock", - "gary", - "james", - "misty", - "ash" - ], - "xaxis": "x", - "y": [ - 20, - 12, - 25, - 20, - 21, - 20 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ground
trainer=%{x}
name_count=%{y}", - "legendgroup": "Ground", - "marker": { - "color": "#FF97FF", - "pattern": { - "shape": "" - } - }, - "name": "Ground", - "offsetgroup": "Ground", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "ash", - "jessie", - "misty", - "gary", - "james", - "brock" - ], - "xaxis": "x", - "y": [ - 70, - 87, - 85, - 63, - 87, - 64 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Fighting
trainer=%{x}
name_count=%{y}", - "legendgroup": "Fighting", - "marker": { - "color": "#FECB52", - "pattern": { - "shape": "" - } - }, - "name": "Fighting", - "offsetgroup": "Fighting", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "gary", - "ash", - "brock", - "james", - "jessie", - "misty" - ], - "xaxis": "x", - "y": [ - 63, - 65, - 69, - 75, - 65, - 90 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Psychic
trainer=%{x}
name_count=%{y}", - "legendgroup": "Psychic", - "marker": { - "color": "#636efa", - "pattern": { - "shape": "" - } - }, - "name": "Psychic", - "offsetgroup": "Psychic", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "gary", - "brock", - "jessie", - "james", - "ash", - "misty" - ], - "xaxis": "x", - "y": [ - 85, - 92, - 66, - 83, - 70, - 72 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Rock
trainer=%{x}
name_count=%{y}", - "legendgroup": "Rock", - "marker": { - "color": "#EF553B", - "pattern": { - "shape": "" - } - }, - "name": "Rock", - "offsetgroup": "Rock", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie", - "ash", - "brock", - "gary", - "misty", - "james" - ], - "xaxis": "x", - "y": [ - 113, - 97, - 82, - 102, - 97, - 90 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ghost
trainer=%{x}
name_count=%{y}", - "legendgroup": "Ghost", - "marker": { - "color": "#00cc96", - "pattern": { - "shape": "" - } - }, - "name": "Ghost", - "offsetgroup": "Ghost", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "gary", - "jessie", - "ash", - "brock", - "misty", - "james" - ], - "xaxis": "x", - "y": [ - 45, - 44, - 40, - 44, - 38, - 44 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Dragon
trainer=%{x}
name_count=%{y}", - "legendgroup": "Dragon", - "marker": { - "color": "#ab63fa", - "pattern": { - "shape": "" - } - }, - "name": "Dragon", - "offsetgroup": "Dragon", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "james", - "jessie", - "gary", - "misty", - "ash", - "brock" - ], - "xaxis": "x", - "y": [ - 33, - 39, - 34, - 31, - 47, - 27 - ], - "yaxis": "y" - }, - { - "alignmentgroup": "True", - "hovertemplate": "type1=Ice
trainer=%{x}
name_count=%{y}", - "legendgroup": "Ice", - "marker": { - "color": "#FFA15A", - "pattern": { - "shape": "" - } - }, - "name": "Ice", - "offsetgroup": "Ice", - "orientation": "v", - "showlegend": true, - "textposition": "auto", - "type": "bar", - "x": [ - "jessie", - "misty", - "ash", - "james", - "gary", - "brock" - ], - "xaxis": "x", - "y": [ - 22, - 14, - 28, - 15, - 14, - 22 - ], - "yaxis": "y" - } - ], - "layout": { - "barmode": "group", - "legend": { - "title": { - "text": "type1" - }, - "tracegroupgap": 0 - }, - "template": { - "data": { - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "choropleth": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "choropleth" - } - ], - "contour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "contour" - } - ], - "contourcarpet": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "contourcarpet" - } - ], - "heatmap": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmap" - } - ], - "heatmapgl": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmapgl" - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "histogram2d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2d" - } - ], - "histogram2dcontour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2dcontour" - } - ], - "mesh3d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "mesh3d" - } - ], - "parcoords": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "parcoords" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "scatter3d": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatter3d" - } - ], - "scattercarpet": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattercarpet" - } - ], - "scattergeo": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergeo" - } - ], - "scattergl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergl" - } - ], - "scattermapbox": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattermapbox" - } - ], - "scatterpolar": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolar" - } - ], - "scatterpolargl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolargl" - } - ], - "scatterternary": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterternary" - } - ], - "surface": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "surface" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ] - }, - "layout": { - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "autotypenumbers": "strict", - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ], - "sequential": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ] - }, - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "geo": { - "bgcolor": "white", - "lakecolor": "white", - "landcolor": "#E5ECF6", - "showlakes": true, - "showland": true, - "subunitcolor": "white" - }, - "hoverlabel": { - "align": "left" - }, - "hovermode": "closest", - "mapbox": { - "style": "light" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "ternary": { - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "title": { - "x": 0.05 - }, - "xaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - }, - "yaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - } - } - }, - "title": { - "text": "Number of Pokémon caught in the last hour grouped by type" - }, - "xaxis": { - "anchor": "y", - "domain": [ - 0, - 1 - ], - "title": { - "text": "trainer" - } - }, - "yaxis": { - "anchor": "x", - "domain": [ - 0, - 1 - ], - "title": { - "text": "name_count" - } - } - } - } - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "table = client.query(query='''SELECT * FROM kanto ORDER BY time''', language='influxql', mode='all')\n", - "print(table)\n", - "\n", - "# PyArrow Aggregation\n", - "aggregation = table.group_by([\"trainer\", \"type1\"]).aggregate([(\"name\", \"count\")]).to_pandas()\n", - "fig3 = px.bar(aggregation, x=\"trainer\", y=\"name_count\", color='type1', barmode= 'group', title='Number of Pokémon caught in the last hour grouped by type')\n", - "fig3.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Saving to file\n", - "We can also save our query results to file. This is useful if we want to save our data for later use. We can save our data in a number of formats including CSV, JSON, Parquet and Apache Arrow. Lets save our data as a parquet file." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "import pyarrow.parquet as pq\n", - "\n", - "# Write the table to a parquet file\n", - "pq.write_table(table, 'kanto.parquet')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Uploading a file to InfluxDB\n", - "This allows to show show off another feature of the InfluxDB 3.0 Python Client. We can parse our file directly to InfluxDB. This is useful if we want to upload data from a local file. Lets upload our parquet file to InfluxDB." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n", - "Written batch: ('pokemon-codex', '6a841c0c08328fb1', 'ns')\n" - ] - } - ], - "source": [ - "client.write_file('kanto.parquet', measurement_name='kanto2', database='pokemon-codex', timestamp_column='time', tag_columns=['trainer', 'id', 'num'])\n", - "time.sleep(2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Group by time query\n", - "Finally lets run a group by time query to get the number of pokemon caught by each trainer over the last hour grouped into 10 minute intervals. We will then use Plotly to visualise this data." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.plotly.v1+json": { - "config": { - "plotlyServerURL": "https://plot.ly" - }, - "data": [ - { - "hovertemplate": "trainer=ash
time=%{x}
count=%{y}", - "legendgroup": "ash", - "line": { - "color": "#636efa", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "ash", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 204, - 252, - 256, - 265, - 265, - 270, - 0 - ], - "yaxis": "y" - }, - { - "hovertemplate": "trainer=brock
time=%{x}
count=%{y}", - "legendgroup": "brock", - "line": { - "color": "#EF553B", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "brock", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 211, - 286, - 280, - 260, - 261, - 235, - 0 - ], - "yaxis": "y" - }, - { - "hovertemplate": "trainer=gary
time=%{x}
count=%{y}", - "legendgroup": "gary", - "line": { - "color": "#00cc96", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "gary", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 223, - 302, - 275, - 276, - 255, - 231, - 0 - ], - "yaxis": "y" - }, - { - "hovertemplate": "trainer=james
time=%{x}
count=%{y}", - "legendgroup": "james", - "line": { - "color": "#ab63fa", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "james", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 236, - 275, - 286, - 277, - 280, - 256, - 0 - ], - "yaxis": "y" - }, - { - "hovertemplate": "trainer=jessie
time=%{x}
count=%{y}", - "legendgroup": "jessie", - "line": { - "color": "#FFA15A", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "jessie", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 204, - 261, - 265, - 290, - 293, - 265, - 0 - ], - "yaxis": "y" - }, - { - "hovertemplate": "trainer=misty
time=%{x}
count=%{y}", - "legendgroup": "misty", - "line": { - "color": "#19d3f3", - "dash": "solid" - }, - "marker": { - "symbol": "circle" - }, - "mode": "lines", - "name": "misty", - "orientation": "v", - "showlegend": true, - "type": "scatter", - "x": [ - "2023-07-27T09:50:00", - "2023-07-27T10:00:00", - "2023-07-27T10:10:00", - "2023-07-27T10:20:00", - "2023-07-27T10:30:00", - "2023-07-27T10:40:00", - "2023-07-27T10:50:00" - ], - "xaxis": "x", - "y": [ - 215, - 276, - 266, - 268, - 270, - 265, - 0 - ], - "yaxis": "y" - } - ], - "layout": { - "legend": { - "title": { - "text": "trainer" - }, - "tracegroupgap": 0 - }, - "template": { - "data": { - "bar": [ - { - "error_x": { - "color": "#2a3f5f" - }, - "error_y": { - "color": "#2a3f5f" - }, - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "bar" - } - ], - "barpolar": [ - { - "marker": { - "line": { - "color": "#E5ECF6", - "width": 0.5 - }, - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "barpolar" - } - ], - "carpet": [ - { - "aaxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "baxis": { - "endlinecolor": "#2a3f5f", - "gridcolor": "white", - "linecolor": "white", - "minorgridcolor": "white", - "startlinecolor": "#2a3f5f" - }, - "type": "carpet" - } - ], - "choropleth": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "choropleth" - } - ], - "contour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "contour" - } - ], - "contourcarpet": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "contourcarpet" - } - ], - "heatmap": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmap" - } - ], - "heatmapgl": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "heatmapgl" - } - ], - "histogram": [ - { - "marker": { - "pattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - } - }, - "type": "histogram" - } - ], - "histogram2d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2d" - } - ], - "histogram2dcontour": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "histogram2dcontour" - } - ], - "mesh3d": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "type": "mesh3d" - } - ], - "parcoords": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "parcoords" - } - ], - "pie": [ - { - "automargin": true, - "type": "pie" - } - ], - "scatter": [ - { - "fillpattern": { - "fillmode": "overlay", - "size": 10, - "solidity": 0.2 - }, - "type": "scatter" - } - ], - "scatter3d": [ - { - "line": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatter3d" - } - ], - "scattercarpet": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattercarpet" - } - ], - "scattergeo": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergeo" - } - ], - "scattergl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattergl" - } - ], - "scattermapbox": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scattermapbox" - } - ], - "scatterpolar": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolar" - } - ], - "scatterpolargl": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterpolargl" - } - ], - "scatterternary": [ - { - "marker": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "type": "scatterternary" - } - ], - "surface": [ - { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - }, - "colorscale": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "type": "surface" - } - ], - "table": [ - { - "cells": { - "fill": { - "color": "#EBF0F8" - }, - "line": { - "color": "white" - } - }, - "header": { - "fill": { - "color": "#C8D4E3" - }, - "line": { - "color": "white" - } - }, - "type": "table" - } - ] - }, - "layout": { - "annotationdefaults": { - "arrowcolor": "#2a3f5f", - "arrowhead": 0, - "arrowwidth": 1 - }, - "autotypenumbers": "strict", - "coloraxis": { - "colorbar": { - "outlinewidth": 0, - "ticks": "" - } - }, - "colorscale": { - "diverging": [ - [ - 0, - "#8e0152" - ], - [ - 0.1, - "#c51b7d" - ], - [ - 0.2, - "#de77ae" - ], - [ - 0.3, - "#f1b6da" - ], - [ - 0.4, - "#fde0ef" - ], - [ - 0.5, - "#f7f7f7" - ], - [ - 0.6, - "#e6f5d0" - ], - [ - 0.7, - "#b8e186" - ], - [ - 0.8, - "#7fbc41" - ], - [ - 0.9, - "#4d9221" - ], - [ - 1, - "#276419" - ] - ], - "sequential": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ], - "sequentialminus": [ - [ - 0, - "#0d0887" - ], - [ - 0.1111111111111111, - "#46039f" - ], - [ - 0.2222222222222222, - "#7201a8" - ], - [ - 0.3333333333333333, - "#9c179e" - ], - [ - 0.4444444444444444, - "#bd3786" - ], - [ - 0.5555555555555556, - "#d8576b" - ], - [ - 0.6666666666666666, - "#ed7953" - ], - [ - 0.7777777777777778, - "#fb9f3a" - ], - [ - 0.8888888888888888, - "#fdca26" - ], - [ - 1, - "#f0f921" - ] - ] - }, - "colorway": [ - "#636efa", - "#EF553B", - "#00cc96", - "#ab63fa", - "#FFA15A", - "#19d3f3", - "#FF6692", - "#B6E880", - "#FF97FF", - "#FECB52" - ], - "font": { - "color": "#2a3f5f" - }, - "geo": { - "bgcolor": "white", - "lakecolor": "white", - "landcolor": "#E5ECF6", - "showlakes": true, - "showland": true, - "subunitcolor": "white" - }, - "hoverlabel": { - "align": "left" - }, - "hovermode": "closest", - "mapbox": { - "style": "light" - }, - "paper_bgcolor": "white", - "plot_bgcolor": "#E5ECF6", - "polar": { - "angularaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "radialaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "scene": { - "xaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "yaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - }, - "zaxis": { - "backgroundcolor": "#E5ECF6", - "gridcolor": "white", - "gridwidth": 2, - "linecolor": "white", - "showbackground": true, - "ticks": "", - "zerolinecolor": "white" - } - }, - "shapedefaults": { - "line": { - "color": "#2a3f5f" - } - }, - "ternary": { - "aaxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "baxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - }, - "bgcolor": "#E5ECF6", - "caxis": { - "gridcolor": "white", - "linecolor": "white", - "ticks": "" - } - }, - "title": { - "x": 0.05 - }, - "xaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - }, - "yaxis": { - "automargin": true, - "gridcolor": "white", - "linecolor": "white", - "ticks": "", - "title": { - "standoff": 15 - }, - "zerolinecolor": "white", - "zerolinewidth": 2 - } - } - }, - "title": { - "text": "Number of Pokémon caught in the last hour grouped by trainer and time" - }, - "xaxis": { - "anchor": "y", - "domain": [ - 0, - 1 - ], - "title": { - "text": "time" - } - }, - "yaxis": { - "anchor": "x", - "domain": [ - 0, - 1 - ], - "title": { - "text": "count" - } - } - } - } - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "query='''SELECT count(\"name\") FROM kanto2 WHERE time > now() - 1h GROUP BY time(10m),trainer'''\n", - "table = client.query(query=query, language='influxql', mode='all')\n", - "\n", - "fig4 = px.line(table, x=\"time\", y=\"count\", color='trainer', title='Number of Pokémon caught in the last hour grouped by trainer and time')\n", - "fig4.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Conclusion\n", - "We have now covered the basics of the InfluxDB 3.0 Python Client. I hope you found this novel cook book informative and fun. If you have any questions, bugs or feature requests please raise an issue on the [GitHub repo](https://github.com/InfluxCommunity/influxdb3-python/issues)\n", - "\n", - "\n", - "

\n", - "\n", - "

" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".venv", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.4" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Examples/pokemon-trainer/kanto.parquet b/Examples/pokemon-trainer/kanto.parquet deleted file mode 100644 index 5995714..0000000 Binary files a/Examples/pokemon-trainer/kanto.parquet and /dev/null differ diff --git a/Examples/pokemon-trainer/pandas-write.py b/Examples/pokemon-trainer/pandas-write.py deleted file mode 100644 index 76f57e0..0000000 --- a/Examples/pokemon-trainer/pandas-write.py +++ /dev/null @@ -1,73 +0,0 @@ -import random - -import pandas as pd - -from influxdb_client_3 import InfluxDBClient3 - -client = InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex") - -now = pd.Timestamp.now(tz='UTC').floor('ms') - -# Lists of possible trainers -trainers = ["ash", "brock", "misty", "gary", "jessie", "james"] - -# Read the CSV into a DataFrame -pokemon_df = pd.read_csv( - "https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv") # noqa: E501 - -# Creating an empty list to store the data -data = [] - -# Dictionary to keep track of the number of times each trainer has caught each Pokémon -trainer_pokemon_counts = {} - -# Number of entries we want to create -num_entries = 100 - -# Generating random data -for i in range(num_entries): - trainer = random.choice(trainers) - - # Randomly select a row from pokemon_df - random_pokemon = pokemon_df.sample().iloc[0] - caught = random_pokemon['Name'] - - # Count the number of times this trainer has caught this Pokémon - if (trainer, caught) in trainer_pokemon_counts: - trainer_pokemon_counts[(trainer, caught)] += 1 - else: - trainer_pokemon_counts[(trainer, caught)] = 1 - - # Get the number for this combination of trainer and Pokémon - num = trainer_pokemon_counts[(trainer, caught)] - - entry = { - "trainer": trainer, - "id": f"{0000 + random_pokemon['#']:04d}", - "num": str(num), - "caught": caught, - "level": random.randint(5, 20), - "attack": random_pokemon['Attack'], - "defense": random_pokemon['Defense'], - "hp": random_pokemon['HP'], - "speed": random_pokemon['Speed'], - "type1": random_pokemon['Type 1'], - "type2": random_pokemon['Type 2'], - "timestamp": now - } - data.append(entry) - -# Convert the list of dictionaries to a DataFrame -caught_pokemon_df = pd.DataFrame(data).set_index('timestamp') - -# Print the DataFrame -print(caught_pokemon_df) - -try: - client.write(caught_pokemon_df, data_frame_measurement_name='caught', - data_frame_tag_columns=['trainer', 'id', 'num']) -except Exception as e: - print(f"Error writing point: {e}") diff --git a/Examples/pokemon-trainer/write-batching-flight-calloptions.py b/Examples/pokemon-trainer/write-batching-flight-calloptions.py deleted file mode 100644 index 6f3b87f..0000000 --- a/Examples/pokemon-trainer/write-batching-flight-calloptions.py +++ /dev/null @@ -1,108 +0,0 @@ -import random - -import pandas as pd - -from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options - -now = pd.Timestamp.now(tz='UTC').floor('ms') -two_days_ago = now - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=100, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -client = InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - enable_gzip=True, write_client_options=wco) - -now = pd.Timestamp.now(tz='UTC').floor('ms') - -# Lists of possible trainers -trainers = ["ash", "brock", "misty", "gary", "jessie", "james"] - -# Read the CSV into a DataFrame -pokemon_df = pd.read_csv( - "https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv") # noqa: E501 - -# Creating an empty list to store the data -data = [] - -# Dictionary to keep track of the number of times each trainer has caught each Pokémon -trainer_pokemon_counts = {} - -# Number of entries we want to create -num_entries = 1000 - -# Generating random data -for i in range(num_entries): - trainer = random.choice(trainers) - - # Randomly select a row from pokemon_df - random_pokemon = pokemon_df.sample().iloc[0] - caught = random_pokemon['Name'] - - # Count the number of times this trainer has caught this Pokémon - if (trainer, caught) in trainer_pokemon_counts: - trainer_pokemon_counts[(trainer, caught)] += 1 - else: - trainer_pokemon_counts[(trainer, caught)] = 1 - - # Get the number for this combination of trainer and Pokémon - num = trainer_pokemon_counts[(trainer, caught)] - - entry = { - "trainer": trainer, - "id": f"{0000 + random_pokemon['#']:04d}", - "num": str(num), - "caught": caught, - "level": random.randint(5, 20), - "attack": random_pokemon['Attack'], - "defense": random_pokemon['Defense'], - "hp": random_pokemon['HP'], - "speed": random_pokemon['Speed'], - "type1": random_pokemon['Type 1'], - "type2": random_pokemon['Type 2'], - "timestamp": two_days_ago - } - data.append(entry) - -# Convert the list of dictionaries to a DataFrame -caught_pokemon_df = pd.DataFrame(data).set_index('timestamp') - -# Print the DataFrame -# print(caught_pokemon_df) - - -# Query -try: - table = client.query(query='''SELECT * FROM caught WHERE time >= now() - 30m''', database='pokemon-codex', - timeout=90.0, language='sql', mode='pandas') - print(table) -except Exception as e: - print(f"Error querying points: {e}") diff --git a/Examples/pokemon-trainer/write-batching.py b/Examples/pokemon-trainer/write-batching.py deleted file mode 100644 index f6fa180..0000000 --- a/Examples/pokemon-trainer/write-batching.py +++ /dev/null @@ -1,101 +0,0 @@ -import random - -import pandas as pd - -from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options - - -class BatchingCallback(object): - - def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") - - def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") - - def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") - - -callback = BatchingCallback() - -write_options = WriteOptions(batch_size=100, - flush_interval=10_000, - jitter_interval=2_000, - retry_interval=5_000, - max_retries=5, - max_retry_delay=30_000, - exponential_base=2) - -wco = write_client_options(success_callback=callback.success, - error_callback=callback.error, - retry_callback=callback.retry, - write_options=write_options - ) - -client = InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="pokemon-codex", enable_gzip=True, write_client_options=wco) - -now = pd.Timestamp.now(tz='UTC').floor('ms') - -# Lists of possible trainers -trainers = ["ash", "brock", "misty", "gary", "jessie", "james"] - -# Read the CSV into a DataFrame -pokemon_df = pd.read_csv("https://gist.githubusercontent.com/ritchie46/cac6b337ea52281aa23c049250a4ff03/raw/89a957ff3919d90e6ef2d34235e6bf22304f3366/pokemon.csv") # noqa: E501 - -# Creating an empty list to store the data -data = [] - -# Dictionary to keep track of the number of times each trainer has caught each Pokémon -trainer_pokemon_counts = {} - -# Number of entries we want to create -num_entries = 1000 - -# Generating random data -for i in range(num_entries): - trainer = random.choice(trainers) - - # Randomly select a row from pokemon_df - random_pokemon = pokemon_df.sample().iloc[0] - caught = random_pokemon['Name'] - - # Count the number of times this trainer has caught this Pokémon - if (trainer, caught) in trainer_pokemon_counts: - trainer_pokemon_counts[(trainer, caught)] += 1 - else: - trainer_pokemon_counts[(trainer, caught)] = 1 - - # Get the number for this combination of trainer and Pokémon - num = trainer_pokemon_counts[(trainer, caught)] - - entry = { - "trainer": trainer, - "id": f"{0000 + random_pokemon['#']:04d}", - "num": str(num), - "caught": caught, - "level": random.randint(5, 20), - "attack": random_pokemon['Attack'], - "defense": random_pokemon['Defense'], - "hp": random_pokemon['HP'], - "speed": random_pokemon['Speed'], - "type1": random_pokemon['Type 1'], - "type2": random_pokemon['Type 2'], - "timestamp": now - } - data.append(entry) - -# Convert the list of dictionaries to a DataFrame -caught_pokemon_df = pd.DataFrame(data).set_index('timestamp') - -# Print the DataFrame -print(caught_pokemon_df) - -try: - client.write(caught_pokemon_df, data_frame_measurement_name='caught', - data_frame_tag_columns=['trainer', 'id', 'num']) -except Exception as e: - print(f"Error writing point: {e}") diff --git a/Examples/query_type.py b/Examples/query_type.py deleted file mode 100644 index 4a37b7a..0000000 --- a/Examples/query_type.py +++ /dev/null @@ -1,54 +0,0 @@ -import influxdb_client_3 as InfluxDBClient3 - -client = InfluxDBClient3.InfluxDBClient3( - token="", - host="eu-central-1-1.aws.cloud2.influxdata.com", - database="factory") - - -# Chunk mode provides a FlightReader object that can be used to read chunks of data. -reader = client.query( - query="SELECT * FROM machine_data WHERE time > now() - 2h", - language="influxql", mode="chunk") - -try: - while True: - batch, buff = reader.read_chunk() - print("batch:") - print(batch.to_pandas()) -except StopIteration: - print("No more chunks to read") - - -# Pandas mode provides a Pandas DataFrame object. -df = client.query( - query="SELECT * FROM machine_data WHERE time > now() - 2h", - language="influxql", mode="pandas") - -print("pandas:") -print(df) - -# All mode provides an Arrow Table object. -table = client.query( - query="SELECT * FROM machine_data WHERE time > now() - 2h", - language="influxql", mode="all") - -print("table:") -print(table) - -# Print the schema of the table -table = client.query( - query="SELECT * FROM machine_data WHERE time > now() - 2h", - language="influxql", mode="schema") - -print("schema:") -print(table) - -# Convert this reader into a regular RecordBatchReader -reader = client.query( - query="SELECT * FROM machine_data WHERE time > now() - 2h", - language="influxql", mode="reader") - -print("reader:") -for batch in reader: - print(batch.to_pandas()) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..a7b7d82 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,92 @@ +## InfluxDB 3 Python Examples + +First time users will likely want to study the examples in the `./core` directory. Users who work with __Jupyter__ notebooks may want to take a look at `basic-write-query.ipynb` in the `./jupyter` directory. + +### Underlying principles + +InfluxDB 3 uses two transports: one for writing data and another for querying. For __writes__ a standard _HTTP REST_ style client is used internally. __Queries__ on the other hand make use of an HTTP/2.0 and a _[gRPC](https://grpc.io/docs/what-is-grpc/introduction/)_ compliant client under _[Apache Arrow Flight](https://arrow.apache.org/cookbook/py/flight.html)_. + +Most of the examples found here are functional and should be runnable against an InfluxDB 3 database whether in the cloud or locally using for example InfluxDB 3 Core. They have been revised and tested against the InfluxDB 3 Core product. + +Some more advanced examples contain only illustrative code that can be reused in your license compliant applications. Whether an example is intended to be simply _illustrative_ or _functional_ is noted in comments at the start of each example file. + +__Configuration__ + +Functional examples make use of the three basic environment variables. + +* `INFLUXDB_HOST` - host URL to connect to an InfluxDB 3 database. +* `INFLUXDB_DATABASE` - default database to be used with the examples. +* `INFLUXDB_TOKEN` - a token associated with read and write permissions to the default database and any additional databases that might be used with the examples. + +These need to be set before running any example. + +It is recommended to run examples using a python virtual environment. + +For example... + +```bash +$ python -m venv venv +$ source ./venv/bin/activate +``` + +Before running any functional examples, ensure that the influxdb3-python project is installed. From the `influxdb3-python` project root run... + +```bash +$ pip install . +``` + +A few of the examples depend on libraries not included in influxdb3-python. The `examples/prep.py` script will install any missing example dependencies and set functional examples as executable. + +```bash +$ python examples/prep.py +``` + +Functional examples can now be executed from the command line. + +e.g. + +```bash +$ examples/core/basic_write.py +First point written to InfluxDB! +Write success: 3 points! +``` + +### Writing data + +Basic examples can be found in the `./examples/core` directory. + + * `basic_write.py` - shows the essentials of using the `Point` class and making simple writes. + * `basic_ssl.py` - shows how to handle special SSL/TLS situations. + * `timeouts.py` - shows how to set and leverage timeout values. + +Richer examples can be found in the `./examples/write` directory. + + * `batching.py` - shows how to make use of the _batching_ API for writing long-running data sets. + * `fileimport.py` - shows how to import data to an InfluxDB 3 database directly from a number of other standard database formats. + * _Note_ - To refresh the source data used in the example, please run `./examples/write/source_data/updater.py` beforehand. + * `handle_http_error.py` - shows error handling on writes. + * `pandas_write.py` - shows how to write pandas dataframes directly to an InfluxDB 3 database. + * `writeoptions.py` - shows the core options API for writes. + +### Querying data + +Basic examples can be found in the `./examples/core` directory. + + * `basic_query.py` - shows the essentials of querying an InfluxDB 3 database. + * `basic_ssl.py` - shows how to handle special SSL/TLS situations. + * `timeouts.py` - shows how to set and leverage timeout values. + +Richer examples can be found in the `./examples/query` directory. + + * `flight_options.py` - shows how to set options on the query transport. + * `handle_query_error.py` - shows basic error handling. + * `query_async.py` - shows basic usage of the asynchronous query API. + * `query_modes.py` - when making a query, different modes return data in different types of structures. This example shows which modes return which structured formats. + * `query_with_middleware.py` - when making a query it is possible to insert special headers into the HTTP layer using middleware. This example shows how to do this. + +### Advanced examples + +These can be found in `./examples/advanced` + + * `database_transfer.py` - illustrates writing datapoints from one database to another. + * `downsample.py` - shows how to read data from one measurement, reduce it to a smaller data set, and then write the new data set as a new measurement. diff --git a/Examples/community/database_transfer.py b/examples/advanced/database_transfer.py similarity index 77% rename from Examples/community/database_transfer.py rename to examples/advanced/database_transfer.py index 478532b..19d497c 100644 --- a/Examples/community/database_transfer.py +++ b/examples/advanced/database_transfer.py @@ -1,7 +1,14 @@ +""" +database_transfer.py - is an illustrative examples showing how to copy data from one Influxdb 3 database to another. +""" +import os import time -import influxdb_client_3 as InfluxDBClient3 -from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError +from influxdb_client_3 import InfluxDBClient3, write_client_options, WriteOptions, InfluxDBError + +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' class BatchingCallback(object): @@ -16,11 +23,9 @@ def retry(self, conf, data: str, exception: InfluxDBError): print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") -# InfluxDB connection details -token = "" +# Data management details dbfrom = "a" dbto = "b" -url = "eu-central-1-1.aws.cloud2.influxdata.com" measurement = "airSensors" taglist = [] @@ -41,9 +46,10 @@ def retry(self, conf, data: str, exception: InfluxDBError): ) # Opening InfluxDB client with a batch size of 5k points or flush interval # of 10k ms and gzip compression -with InfluxDBClient3.InfluxDBClient3(token=token, - host=url, - enable_gzip=True, write_client_options=wco) as _client: +with InfluxDBClient3(token=TOKEN, + host=HOST, + enable_gzip=True, + write_client_options=wco) as _client: query = f"SHOW TAG KEYS FROM {measurement}" tags = _client.query(query=query, language="influxql", database=dbfrom) tags = tags.to_pydict() diff --git a/examples/advanced/downsample.py b/examples/advanced/downsample.py new file mode 100644 index 0000000..283888f --- /dev/null +++ b/examples/advanced/downsample.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +""" +downsample.py - is a functional example showing how to reduce a larger measurement set to a smaller one +by averaging values across a given time window. +""" +import datetime +import os +import random + +import pandas as pd + +from influxdb_client_3 import InfluxDBClient3, InfluxDBError, WriteOptions, write_client_options + +dir_path = os.path.dirname(os.path.realpath(__file__)) + +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + + +class BatchingCallback(object): + + def success(self, conf, data: str): + print(f"Written batch: {conf}, data: {data}") + + def error(self, conf, data: str, exception: InfluxDBError): + print(f"Cannot write batch: {conf}, data: {data} due: {exception}") + + def retry(self, conf, data: str, exception: InfluxDBError): + print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") + + +callback = BatchingCallback() + +write_options = WriteOptions(batch_size=100, + flush_interval=10_000, + jitter_interval=2_000, + retry_interval=5_000, + max_retries=5, + max_retry_delay=30_000, + exponential_base=2) + +wco = write_client_options(success_callback=callback.success, + error_callback=callback.error, + retry_callback=callback.retry, + write_options=write_options + ) + +now = pd.Timestamp.now(tz='UTC').floor('ms') + +current = now - datetime.timedelta(days=1) + +# Lists of possible trainers +trainers = ["ash", "brock", "misty", "gary", "jessie", "james"] + +# Read the CSV into a DataFrame +pokemon_df = pd.read_csv( + f"{dir_path}/../write/source_data/pokemon.csv" +) + +# Creating an empty list to store the original data +data = [] + +# Dictionary to keep track of the number of times each trainer has caught each Pokémon +trainer_pokemon_counts = {} + +# Number of entries we want to create +num_entries = 1000 + +# use a first client to write the prep data +with InfluxDBClient3( + token=TOKEN, + host=HOST, + database=DATABASE, + enable_gzip=True, + write_client_options=wco) as prep_client: + + # Generating random data + for i in range(num_entries): + trainer = random.choice(trainers) + + # Randomly select a row from pokemon_df + random_pokemon = pokemon_df.sample().iloc[0] + caught = random_pokemon['Name'] + + # Count the number of times this trainer has caught this Pokémon + if (trainer, caught) in trainer_pokemon_counts: + trainer_pokemon_counts[(trainer, caught)] += 1 + else: + trainer_pokemon_counts[(trainer, caught)] = 1 + + # Get the number for this combination of trainer and Pokémon + num = trainer_pokemon_counts[(trainer, caught)] + + entry = { + "trainer": trainer, + "id": f"{0000 + random_pokemon['#']:04d}", + "num": num, + "caught": caught, + "level": random.randint(5, 20), + "attack": random_pokemon['Attack'], + "defense": random_pokemon['Defense'], + "hp": random_pokemon['HP'], + "speed": random_pokemon['Speed'], + "type1": random_pokemon['Type 1'], + "type2": random_pokemon['Type 2'], + "legendary": random_pokemon['Legendary'], + "timestamp": current + } + data.append(entry) + current = current + datetime.timedelta(seconds=int((24 * 60 * 60) / num_entries)) + + # Convert the list of dictionaries to a DataFrame + caught_pokemon_df = pd.DataFrame(data).set_index('timestamp') + + # Print the DataFrame + print(caught_pokemon_df) + + # Write the data directly from the DataFrame + # taking care to specify the measurement name and tags + try: + prep_client.write(caught_pokemon_df, data_frame_measurement_name='monsters_caught', + data_frame_tag_columns=['trainer', 'id', 'type1', 'type2', "legendary", "caught"]) + except Exception as e: + print(f"Error writing point: {e}") + +# Now query just written data and downsample +with InfluxDBClient3( + token=TOKEN, + host=HOST, + database=DATABASE, enable_gzip=True, write_client_options=wco) as ds_client: + + # downsample data to average number of catches per quarter-hour + sql = ("SELECT date_bin('15 minutes', \"time\") as window_start, \n" + "AVG(\"num\") as avg\n" + "FROM monsters_caught\n" + "WHERE \"time\" >= now() - interval '1 day'\n" + "GROUP BY window_start\n" + "ORDER BY window_start ASC" + ) + + # Query directly to a pandas DataFrame + interim_df = ds_client.query(sql, language="sql", mode="pandas") + + # Modify the DataFrame to make the columns Influx friendly + interim_df.rename(columns={'window_start': 'timestamp'}, inplace=True) + interim_df["context"] = pd.Series('demo', index=interim_df.index) + + interim_df.set_index('timestamp', inplace=True) + + # Write the downsampled DataFrame to a new measurement in the database + try: + ds_client.write(interim_df, data_frame_measurement_name='caught_avg', + data_frame_tag_columns=['context']) + except Exception as e: + print(f"Error writing down sampled point: {e}") diff --git a/examples/core/basic_query.py b/examples/core/basic_query.py new file mode 100644 index 0000000..a91a8b4 --- /dev/null +++ b/examples/core/basic_query.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +""" +basic_query.py - is a functional example that shows the simplest ways in which to query data from an influxdb3 database. + +It should be run after running basic_write.py, which prepares the measurements queried here. + +For more information on working with query modes see the `query/query_modes.py` example. +""" +import os +from influxdb_client_3 import InfluxDBClient3 + +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + +client = InfluxDBClient3( + token=TOKEN, + host=HOST, + database=DATABASE,) + +measurement = "basic_caught" + +print("Querying with sql to Arrow Table") +sql = f'''SELECT * FROM {measurement} WHERE trainer = 'ash' AND time >= now() - interval '1 hour' LIMIT 5''' +table = client.query(query=sql, language='sql', mode='all') +print(table) + +print("Querying with influxql to pandas DataFrame") +influxql = f'''SELECT * FROM {measurement} WHERE trainer = 'ash' AND time > now() - 1h LIMIT 5''' +table = client.query(query=influxql, language='influxql', mode='pandas') +print(table) + +client.close() diff --git a/Examples/basic_ssl_example.py b/examples/core/basic_ssl.py similarity index 75% rename from Examples/basic_ssl_example.py rename to examples/core/basic_ssl.py index 1667f78..3ef86b6 100644 --- a/Examples/basic_ssl_example.py +++ b/examples/core/basic_ssl.py @@ -1,11 +1,25 @@ +#!/usr/bin/env python3 +""" +basic_ssl.py is a functional example that shows how to work with non-standard SSL configurations. + +Please NOTE, as this is an SSL example it needs to be run over an HTTPS transport. Running with a local +Influxdb3 Core deployment over HTTP is of little use. When running this example, please either... + + * deploy Influxdb3 Core / Enterprise locally over HTTPS. + (see https://docs.influxdata.com/influxdb3/core/reference/config-options/#security) + * use an Influxdb3 Cloud account. +""" import os import time import pyarrow -from config import Config from influxdb_client_3 import InfluxDBClient3 +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + bad_cert = """-----BEGIN CERTIFICATE----- MIIFDTCCAvWgAwIBAgIUYzpfisy9xLrhiZd+D9vOdzC3+iswDQYJKoZIhvcNAQEL BQAwFjEUMBIGA1UEAwwLdGVzdGhvc3QuaW8wHhcNMjUwMjI4MTM1NTMyWhcNMzUw @@ -57,20 +71,19 @@ def print_results(results: list): def main() -> None: print("Main") temp_cert_file = "temp_cert.pem" - conf = Config() - write_and_query_with_explicit_sys_cert(conf) + write_and_query_with_explicit_sys_cert() write_cert(bad_cert, temp_cert_file) - query_with_verify_ssl_off(conf, temp_cert_file) + query_with_verify_ssl_off(temp_cert_file) remove_cert(temp_cert_file) -def write_and_query_with_explicit_sys_cert(conf): +def write_and_query_with_explicit_sys_cert(): print("\nwrite and query with typical linux system cert\n") - with InfluxDBClient3(token=conf.token, - host=conf.host, - database=conf.database, + with InfluxDBClient3(token=TOKEN, + host=HOST, + database=DATABASE, ssl_ca_cert="/etc/ssl/certs/ca-certificates.crt", verify_ssl=True) as _client: now = time.time_ns() @@ -82,14 +95,14 @@ def write_and_query_with_explicit_sys_cert(conf): print_results(reader.to_pylist()) -def query_with_verify_ssl_off(conf, cert): +def query_with_verify_ssl_off(cert): print("\nquerying with verify_ssl off\n") # Note that the passed root cert above is bad # Switch verify_ssl to True to throw SSL_ERROR_SSL - with InfluxDBClient3(token=conf.token, - host=conf.host, - database=conf.database, + with InfluxDBClient3(token=TOKEN, + host=HOST, + database=DATABASE, ssl_ca_cert=cert, verify_ssl=False) as _client: diff --git a/examples/core/basic_write.py b/examples/core/basic_write.py new file mode 100644 index 0000000..c399a74 --- /dev/null +++ b/examples/core/basic_write.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +""" +basic_write.py - is a functional example showing the simplest ways +in which to write data to an influxdb3 database using Point objects. + +After successfully running this example try basic_query.py to verify the results. +""" +import datetime +import os + +from influxdb_client_3 import InfluxDBClient3, Point + +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + +client = InfluxDBClient3( + token=TOKEN, + host=HOST, + database=DATABASE,) + +now = datetime.datetime.now(datetime.timezone.utc) + +measurement = "basic_caught" + +data = Point(measurement).tag("trainer", "ash").tag("id", "0006").tag("num", "1") \ + .field("caught", "charizard") \ + .field("level", 10).field("attack", 30) \ + .field("defense", 40).field("hp", 200) \ + .field("speed", 10) \ + .field("type1", "fire").field("type2", "flying") \ + .time(now) + +try: + client.write(data) + print("First point written to InfluxDB!") +except Exception as e: + print(f"Error writing point: {e}") + +data = [Point(measurement) # first point + .tag("trainer", "ash") + .tag("id", "0006") + .tag("num", "1") + .field("caught", "charizard") + .field("level", 10) + .field("attack", 30) + .field("defense", 40) + .field("hp", 200) + .field("speed", 10) + .field("type1", "fire") + .field("type2", "flying") + .time(now), + + Point(measurement) # second point + .tag("trainer", "ash") + .tag("id", "0007") + .tag("num", "2") + .field("caught", "bulbasaur") + .field("level", 12) + .field("attack", 31) + .field("defense", 31) + .field("hp", 190) + .field("speed", 11) + .field("type1", "grass") + .field("type2", "poison") + .time(now), + + Point(measurement) # third point + .tag("trainer", "ash") + .tag("id", "0008") + .tag("num", "3") + .field("caught", "squirtle") + .field("level", 13) + .field("attack", 29) + .field("defense", 40) + .field("hp", 180) + .field("speed", 13) + .field("type1", "water") + .field("type2", None) + .time(now) + ] + +try: + client.write(data) + print(f"Write success: {len(data)} points!") +except Exception as e: + print(f"Error writing point: {e}") +finally: + client.close() diff --git a/Examples/timeouts.py b/examples/core/timeouts.py similarity index 83% rename from Examples/timeouts.py rename to examples/core/timeouts.py index 70b8ff1..ff10ef4 100644 --- a/Examples/timeouts.py +++ b/examples/core/timeouts.py @@ -1,25 +1,24 @@ #!/usr/bin/env python3 -import sys -import time - -from influxdb_client_3 import InfluxDBClient3, write_client_options - """ -This example shows how to set query and write timeouts. +timeouts.py - is a functional example that shows how to set query and write timeouts. + They can be set directly using arguments (write_timeout, query_timeout) in the client constructor. They can also be overridden in write and query calls. To trigger timeout and deadline expired exceptions, reset the timeout values in the examples or supply new values as command line parameters. -Be sure to update the host, token a database values below, before running this example. +Be sure to update INFLUXDB_HOST, INFLUXDB_DATABASE and INFLUXDB_TOKEN environment variables, +before running this example. """ +import os +import sys +import time + +from influxdb_client_3 import InfluxDBClient3, write_client_options DEFAULT_WRITE_TIMEOUT = 30_000 # in milliseconds DEFAULT_QUERY_TIMEOUT = 120_000 # in milliseconds -DEFAULT_HOST = 'http://localhost:8181' -DEFAULT_TOKEN = 'my-token' -DEFAULT_DATABASE = 'test-data' def handle_write_error_cb(rd, rt, rx): @@ -27,12 +26,17 @@ def handle_write_error_cb(rd, rt, rx): def main(w_to: int, q_to: int) -> None: + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + print(f"main {w_to}, {q_to}") lp_data = "timeout_example,location=terra fVal=3.14,iVal=42i" with InfluxDBClient3( - host=DEFAULT_HOST, - token=DEFAULT_TOKEN, - database=DEFAULT_DATABASE, + host=host, + token=token, + database=database, write_timeout=w_to, query_timeout=q_to, write_client_options=write_client_options( diff --git a/examples/jupyter/basic-write-query.ipynb b/examples/jupyter/basic-write-query.ipynb new file mode 100644 index 0000000..87c184a --- /dev/null +++ b/examples/jupyter/basic-write-query.ipynb @@ -0,0 +1,222 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "ba2e56cae6ed4007", + "metadata": {}, + "source": [ + "## Influxdb3 Python basic usage\n", + "\n", + "This jupyter notebook illustrates the basics of writing and querying data with an Influxdb3 database using the Influxdb3 python client. Code cells need to be run step by step in the order in which they are presented.\n", + "\n", + "1. Start by setting up the basic connection values that match your server or account." + ] + }, + { + "cell_type": "code", + "id": "7df36b5af8ac161e", + "metadata": {}, + "source": [ + "%env INFLUXDB_HOST=http://localhost:8181\n", + "%env INFLUXDB_TOKEN=\n", + "%env INFLUXDB_DATABASE=my_db\n", + "from influxdb_client_3 import InfluxDBClient3, Point, WritePrecision, InfluxDBError, WriteOptions, write_client_options" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "95bc0c8ac612b91a", + "metadata": {}, + "source": "2. Next, setup a basic sensor class for generating test data. This simple class will generate readings using the built-in Influxdb3 Python `Point` class. Using the `Point` class for writes is recommended in basic applications even though the client `write()` method handles other types of data." + }, + { + "cell_type": "code", + "id": "532b67ce851fe031", + "metadata": {}, + "source": [ + "class Sensor:\n", + "\n", + " def __init__(self, location, model, id):\n", + " self._location = location\n", + " self._model = model\n", + " self._id = id\n", + "\n", + " def point_reading(self, _measurement, temperature, humidity, pressure, timestamp) -> Point:\n", + " return (Point(_measurement)\n", + " .tag(\"location\", self._location)\n", + " .tag(\"model\", self._model)\n", + " .tag(\"id\", self._id)\n", + " .field(\"temperature\", temperature)\n", + " .field(\"humidity\", humidity)\n", + " .field(\"pressure\", pressure)\n", + " .time(timestamp)\n", + " )\n" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "40ac0ffee0bcaefa", + "metadata": {}, + "source": [ + "3. Create a client instance. Please note that this client is instantiated using default values only. WriteOptions and QueryOptions can also be added at this step. For simplicity of illustration they have been omitted." + ] + }, + { + "cell_type": "code", + "id": "fefbdd206fedf89f", + "metadata": {}, + "source": [ + "import logging\n", + "import os\n", + "\n", + "logging.basicConfig(level=logging.INFO)\n", + "\n", + "logging.info(\"Using\\n\"\n", + " \"INFLUXDB_HOST={}\\n\"\n", + " \"INFLUXDB_DATABASE={}\".format(os.environ[\"INFLUXDB_HOST\"], os.environ[\"INFLUXDB_DATABASE\"]))\n", + "\n", + "client = InfluxDBClient3(\n", + " host= os.environ[\"INFLUXDB_HOST\"],\n", + " token=os.environ[\"INFLUXDB_TOKEN\"],\n", + " database=os.environ[\"INFLUXDB_DATABASE\"]\n", + ")\n", + "\n", + "logging.info(\"Have client {}\".format(client))\n" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "64228a6a65db2dfc", + "metadata": {}, + "source": [ + "4. Generate data points and write them to the database." + ] + }, + { + "cell_type": "code", + "id": "1613427c088c1a56", + "metadata": {}, + "source": [ + "import random\n", + "from datetime import datetime, timezone, timedelta\n", + "\n", + "sensors = [Sensor(\"entry_hall\", \"R2D2\", \"a2026001\"),\n", + " Sensor(\"conf01\", \"C3PO\", \"a2026002\"),\n", + " Sensor(\"conf02\", \"R2D2\", \"a2026004\"),\n", + " Sensor(\"hall_west\", \"C3PO\", \"a2026005\"),\n", + " Sensor(\"hall_east\", \"ROBBIE\", \"b2025255\"),\n", + " ]\n", + "\n", + "measurement = \"sensor_test\"\n", + "samplesize = 1000\n", + "interval = 10 # seconds\n", + "\n", + "now = datetime.now(timezone.utc)\n", + "ts = now - timedelta(seconds=(interval * samplesize))\n", + "\n", + "data = []\n", + "\n", + "while ts < now:\n", + " for sensor in sensors:\n", + " data.append(\n", + " sensor.point_reading(\n", + " _measurement=measurement,\n", + " temperature=random.uniform(10.0,35.0),\n", + " humidity=random.uniform(50.0,100.0),\n", + " pressure=random.uniform(26.0,32.0),\n", + " timestamp=ts\n", + " )\n", + " )\n", + " ts = ts + timedelta(seconds=interval)\n", + "try:\n", + " client.write(data)\n", + " logging.info(f\"Write successful!\")\n", + "except InfluxDBError as e:\n", + " logging.error(\"InfluxDB error: {}\".format(e))\n" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "3422e2abc73a174", + "metadata": {}, + "source": [ + "Now query" + ] + }, + { + "cell_type": "code", + "id": "8a2fb254614ccc27", + "metadata": {}, + "source": [ + "sql = f\"SELECT time, location, model, temperature FROM {measurement} WHERE location = 'hall_east' ORDER BY time DESC\"\n", + "\n", + "table = []\n", + "\n", + "try:\n", + " table = client.query(query=sql, language=\"sql\", mode=\"pandas\")\n", + " print(table)\n", + "except InfluxDBError as e:\n", + " print(\"InfluxDB error: {}\".format(e))" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "1788e61d03b7f8c5", + "metadata": {}, + "source": [ + "Sample results plot below." + ] + }, + { + "cell_type": "code", + "id": "b56ff2f6e600ed01", + "metadata": {}, + "source": [ + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "\n", + "temps = table.get(\"temperature\")\n", + "times = table.get(\"time\")\n", + "\n", + "plt.plot(times, temps)\n", + "plt.title(f\"Temperature in hall_east\")\n", + "plt.xlabel(\"Time\")\n", + "plt.ylabel(\"Temperature\")\n", + "plt.show()" + ], + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/prep.py b/examples/prep.py new file mode 100644 index 0000000..6dbbac6 --- /dev/null +++ b/examples/prep.py @@ -0,0 +1,48 @@ +import os +import subprocess +import sys + +""" +Installs extra packages needed by some examples. + +Sets functional examples with shebang headers as executable. +""" + +extra_packages = [ + 'numpy', + 'pandas', + 'bson', + 'matplotlib', + 'pytz' +] + + +def set_functional_examples_executable(): + dir_path = os.path.dirname(os.path.realpath(__file__)) + for root, dirs, files in os.walk(dir_path): + root.split(os.sep) + for file in files: + with (open(os.path.join(root, file), "r")) as input_file: + try: + head = [next(input_file) for _ in range(1)] + if head[0].startswith("#!/"): + os.chmod(input_file.name, 0o775) + except UnicodeDecodeError: + continue + + +def install_extra_packages(): + for package in extra_packages: + subprocess.check_call([sys.executable, "-m", "pip", "install", f"{package}"]) + + +def main(): + print(f"Installing extra packages {extra_packages}") + install_extra_packages() + + print("Setting functional examples executable") + set_functional_examples_executable() + + +if __name__ == "__main__": + main() diff --git a/examples/query/flight_options.py b/examples/query/flight_options.py new file mode 100644 index 0000000..a12a75c --- /dev/null +++ b/examples/query/flight_options.py @@ -0,0 +1,40 @@ +""" +flight_options.py - is an illustrative example of how to set low level options for the Arrow Flight client +and even for its internal gRPC client. + +Note that the query transport of Influxdb3 is built on top of Arrow Flight, so `flight_client_options` in +a broad sense is synonymous with setting low level "Query API Options". +""" +import os + +from influxdb_client_3 import InfluxDBClient3, flight_client_options + +dir_path = os.path.dirname(os.path.realpath(__file__)) + +with open(f"{dir_path}/cert.pem", 'rb') as f: + cert = f.read() +print(cert) + +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + +client = InfluxDBClient3( + token=TOKEN, + host=HOST, + database=DATABASE, + flight_client_options=flight_client_options( # Options passed directly to the underlying Arrow flight client + tls_root_certs=cert, # Use a non-standard root certificate + disable_server_verification=True, # N.B. unsafe - for illustration here + generic_options=[ # options to be passed to the gRPC client used by Arrow flight + ("grpc.keepalive_time_ms", 300000), + ("grpc.keepalive_timeout_ms", 20000), + ] + ) +) + +table = client.query( + query="SELECT * FROM flight WHERE time > now() - 4h", + language="influxql") + +print(table.to_pandas()) diff --git a/Examples/handle_query_error.py b/examples/query/handle_query_error.py similarity index 51% rename from Examples/handle_query_error.py rename to examples/query/handle_query_error.py index f0086d0..2b1bd1b 100644 --- a/Examples/handle_query_error.py +++ b/examples/query/handle_query_error.py @@ -1,11 +1,12 @@ +#!/usr/bin/env python3 """ -Demonstrates handling error when querying InfluxDB. +handle_query_error.py - Is a functional example that demonstrates handling error when querying InfluxDB. """ import logging -from config import Config -from influxdb_client_3.exceptions import InfluxDB3ClientQueryError +import os -import influxdb_client_3 as InfluxDBClient3 +from influxdb_client_3 import InfluxDBClient3 +from influxdb_client_3.exceptions import InfluxDB3ClientQueryError def main() -> None: @@ -13,13 +14,16 @@ def main() -> None: Main function :return: """ - config = Config() + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) - client = InfluxDBClient3.InfluxDBClient3( - host=config.host, - token=config.token, - database=config.database + client = InfluxDBClient3( + host=host, + token=token, + database=database ) try: diff --git a/Examples/query_async.py b/examples/query/query_async.py similarity index 75% rename from Examples/query_async.py rename to examples/query/query_async.py index 77bff4b..8917e90 100644 --- a/Examples/query_async.py +++ b/examples/query/query_async.py @@ -1,4 +1,10 @@ +#!/usr/bin/env python3 +""" +query_async.py - is a functional example that shows how to run a query and process results in one coroutine +while calculating a Fibonacci series in a parallel coroutine. +""" import asyncio +import os import random import time @@ -6,10 +12,8 @@ from influxdb_client_3 import InfluxDBClient3 -from config import Config - -async def fibio(iterations, grit=0.5): +async def fibo(iterations, grit=0.5): """ example coroutine to run parallel with query_async :param iterations: @@ -67,18 +71,22 @@ async def query_data(client: InfluxDBClient3, measurement): async def main(): - config = Config() + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + client = InfluxDBClient3( - host=config.host, - token=config.token, - database=config.database, + host=host, + token=token, + database=database, ) measurement = 'example_uav' write_data(client, measurement) # run both coroutines simultaneously - result = await asyncio.gather(fibio(10, 0.2), query_data(client, measurement)) - print(f"fibio sequence = {result[0]}") + result = await asyncio.gather(fibo(10, 0.2), query_data(client, measurement)) + print(f"fibonacci sequence = {result[0]}") print(f"data set =\n{result[1]}") diff --git a/examples/query/query_modes.py b/examples/query/query_modes.py new file mode 100644 index 0000000..4b8674a --- /dev/null +++ b/examples/query/query_modes.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +""" +query_modes.py - is a functional example that shows how to use different modes when executing queries. +""" +import os + +import pytz +import numpy as np + +from datetime import datetime, timedelta + +from influxdb_client_3 import InfluxDBClient3, Point + + +def prep_data(client: InfluxDBClient3, measurement: str): + now = datetime.now(tz=pytz.utc) + current = now - timedelta(minutes=5) + + points = [] + + while current < now: + points.append(Point(measurement) + .tag('model', np.random.choice(['R2D2', 'C3PO', 'ROBBIE', 'HAL'])) + .field('mV', np.random.uniform(low=0, high=1000)) + .field('mA', np.random.uniform(low=0, high=1000)) + .field('dBm', np.random.uniform(low=-10, high=10)) + .time(current)) + current += timedelta(seconds=10) + + client.write(points) + + +def query_chunk(client: InfluxDBClient3, influxql_query: str): + # Chunk mode provides a FlightReader object that can be used to read chunks of data. + reader = client.query( + query=influxql_query, + language="influxql", mode="chunk") + + try: + while True: + batch, buff = reader.read_chunk() + print("batch:") + print(batch.to_pandas()) + except StopIteration: + print("No more chunks to read") + + +def query_pandas(client: InfluxDBClient3, influxql_query: str): + # Pandas mode provides a Pandas DataFrame object. + df = client.query( + query=influxql_query, + language="influxql", mode="pandas") + + print("pandas:") + print(df) + + +def query_all(client: InfluxDBClient3, influxql_query: str): + # All mode provides an Arrow Table object. + table = client.query( + query=influxql_query, + language="influxql", mode="all") + + print("table:") + print(table) + + +def query_schema(client: InfluxDBClient3, influxql_query: str): + # Print the schema of the table + table = client.query( + query=influxql_query, + language="influxql", mode="schema") + + print("schema:") + print(table) + + +def query_reader(client: InfluxDBClient3, influxql_query: str): + # Convert this reader into a regular RecordBatchReader + reader = client.query( + query=influxql_query, + language="influxql", mode="reader") + + print("reader:") + for batch in reader: + print(batch.to_pandas()) + + +def main(): + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + + measurement = "machine_data" + + influxql = f"SELECT * FROM {measurement} WHERE time > now() - 5m" + with InfluxDBClient3( + host=host, + database=database, + token=token + ) as client: + prep_data(client, measurement) + print("\n=== Querying Chunks ===\n") + query_chunk(client, influxql) + print("\n=== Querying Pandas ===\n") + query_pandas(client, influxql) + print("\n=== Querying All ===\n") + query_all(client, influxql) + print("\n=== Querying Schema ===\n") + query_schema(client, influxql) + print("\n=== Querying Reader ===\n") + query_reader(client, influxql) + + +if __name__ == "__main__": + main() diff --git a/Examples/query_with_middleware.py b/examples/query/query_with_middleware.py similarity index 68% rename from Examples/query_with_middleware.py rename to examples/query/query_with_middleware.py index e9f3d7f..0fe8c30 100644 --- a/Examples/query_with_middleware.py +++ b/examples/query/query_with_middleware.py @@ -1,6 +1,11 @@ +""" +query_with_middleware.py - is an illustrative example of how to add Arrow Flight middleware +when initializing a client. +""" +import os + from pyarrow import flight -from config import Config from influxdb_client_3 import InfluxDBClient3, flight_client_options @@ -20,12 +25,15 @@ def start_call(self, info): return ModifyHeaderClientMiddleware() -config = Config() +HOST = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' +TOKEN = os.getenv('INFLUXDB_TOKEN') or 'my-token' +DATABASE = os.getenv('INFLUXDB_DATABASE') or 'my-db' + middleware = [ModifyHeaderClientMiddlewareFactory()] client = InfluxDBClient3( - host=config.host, - token=config.token, - database=config.database, + host=HOST, + token=TOKEN, + database=DATABASE, flight_client_options=flight_client_options(middleware=middleware) ) diff --git a/Examples/batching_example.py b/examples/write/batching.py similarity index 83% rename from Examples/batching_example.py rename to examples/write/batching.py index 87f907e..d74de82 100644 --- a/Examples/batching_example.py +++ b/examples/write/batching.py @@ -1,4 +1,10 @@ +#!/usr/bin/env python3 +""" +batching.py - is a functional example that shows how to set up and use WriteType.batching, +which is the default WriteType when instantiating a WriteOptions object. +""" import datetime +import os import random import time @@ -7,11 +13,11 @@ import influxdb_client_3 as InfluxDBClient3 from influxdb_client_3 import write_client_options, WritePrecision, WriteOptions, InfluxDBError -from config import Config - class BatchingCallback(object): - + """ + Prepare callbacks to be used to handle batching states. + """ def __init__(self): self.write_status_msg = None self.write_count = 0 @@ -19,16 +25,16 @@ def __init__(self): self.start = time.time_ns() def success(self, conf, data: str): - print(f"Written batch: {conf}, data: {data}") + print(f"Written batch: {conf}, data: {len(data)} bytes") self.write_count += 1 self.write_status_msg = f"SUCCESS: {self.write_count} writes" def error(self, conf, data: str, exception: InfluxDBError): - print(f"Cannot write batch: {conf}, data: {data} due: {exception}") + print(f"Cannot write batch: {conf}, data: {len(data)} bytes, due_to: {exception}") self.write_status_msg = f"FAILURE - cause: {exception}" def retry(self, conf, data: str, exception: InfluxDBError): - print(f"Retryable error occurs for batch: {conf}, data: {data} retry: {exception}") + print(f"Retryable error occurs for batch: {conf}, data: {len(data)} bytes, retry: {exception}") self.retry_count += 1 def elapsed(self) -> int: @@ -36,7 +42,10 @@ def elapsed(self) -> int: def main() -> None: - conf = Config() + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' # Creating 5.000 gatewayId values as MongoDB ObjectIDs gatewayIds = [ObjectId() for x in range(0, 100)] @@ -45,10 +54,10 @@ def main() -> None: precision = 2 # Setting timestamp for first sensor reading - sample_window_days = 7 - now = datetime.datetime.now() + sample_window_days = 0.25 + now = datetime.datetime.now(datetime.timezone.utc) now = now - datetime.timedelta(days=sample_window_days) - target_sample_count = sample_window_days * 24 * 60 * 6 + target_sample_count = int(sample_window_days * 24 * 60 * 6) callback = BatchingCallback() @@ -68,9 +77,9 @@ def main() -> None: # Opening InfluxDB client with a batch size of 5k points or flush interval # of 10k ms and gzip compression - with InfluxDBClient3.InfluxDBClient3(token=conf.token, - host=conf.host, - database=conf.database, + with InfluxDBClient3.InfluxDBClient3(token=token, + host=host, + database=database, enable_gzip=True, write_client_options=wco) as _client: # Creating iterator for one hour worth of data (6 sensor readings per diff --git a/examples/write/fileimport.py b/examples/write/fileimport.py new file mode 100644 index 0000000..bb7b405 --- /dev/null +++ b/examples/write/fileimport.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +""" +fileimport.py - is a functional example that shows how to import data directly to Influxdb3 +from other common database types. + +The template databases used for this example can be found in `examples/write/source_data`. To create +fresh databases with current timestamps please run the helper file `examples/write/source_data/updater.py` +before running fileimport.py. +""" +import logging +import os + +import influxdb_client_3 as InfluxDBClient3 +from influxdb_client_3 import write_client_options, WriteOptions, InfluxDBError + + +dir_path = os.path.dirname(os.path.realpath(__file__)) + +data_types = ["csv", "json", "feather", "orc", "parquet"] + + +class BatchingCallback(object): + + def __init__(self): + self.write_count = 0 + + def success(self, conf, data: bytes): + self.write_count += 1 + print(f"Written batch: {conf}, data: {bytes(data)} bytes") + + def error(self, conf, data: bytes, exception: InfluxDBError): + print(f"Cannot write batch: {conf}, data: {data} due: {exception}") + + def retry(self, conf, data: bytes, exception: InfluxDBError): + print(f"Retryable error occurred for batch: {conf}, data: {bytes(data)} bytes, retry: {exception}") + + +def main(file_types=("csv",)) -> None: + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + + # allow detailed inspection + if file_types is None: + file_types = ["csv"] + logging.basicConfig(level=logging.DEBUG) + + callback = BatchingCallback() + + write_options = WriteOptions(batch_size=100, + flush_interval=10_000, + jitter_interval=2_000, + retry_interval=5_000, + max_retries=5, + max_retry_delay=30_000, + exponential_base=2) + + wco = write_client_options(success_callback=callback.success, + error_callback=callback.error, + retry_callback=callback.retry, + write_options=write_options + ) + + """ + Note: + debug: allows low-level inspection of communications and of context-manager termination + """ + with InfluxDBClient3.InfluxDBClient3( + token=token, + host=host, + database=database, + write_client_options=wco, + debug=True) as client: + + for _ftype in file_types: + if _ftype not in data_types: + logging.error(f"File type {_ftype} not supported.") + continue + + logging.info(f"Writing from DB file of type: {_ftype}") + source_file = f"{dir_path}/source_data/out_update.{_ftype}" + if not (os.path.exists(source_file) and os.path.isfile(source_file)): + logging.error(f"Source DB file {source_file} not found.") + logging.error(" TIP!: Perhaps source_data/updater.py needs to be run.") + continue + # write data from file + client.write_file( + file=source_file, + timestamp_column='time', tag_columns=["provider", "machineID"]) + + print(f'DONE writing from {file_types} in {callback.write_count} batch(es)') + + +if __name__ == "__main__": + main(("feather", "parquet", "orc", "csv", "json")) diff --git a/Examples/handle_http_error.py b/examples/write/handle_http_error.py similarity index 71% rename from Examples/handle_http_error.py rename to examples/write/handle_http_error.py index fd0571f..2ef28a6 100644 --- a/Examples/handle_http_error.py +++ b/examples/write/handle_http_error.py @@ -1,8 +1,9 @@ +#!/usr/bin/env python3 """ -Demonstrates handling response error headers on error. +handle_http_error.py - is a functional example that demonstrates handling response error headers on error. """ import logging -from config import Config +import os import influxdb_client_3 as InfluxDBClient3 @@ -12,13 +13,16 @@ def main() -> None: Main function :return: """ - config = Config() + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) client = InfluxDBClient3.InfluxDBClient3( - host=config.host, - token=config.token, - database=config.database + host=host, + token=token, + database=database ) # write with empty field results in HTTP 400 error diff --git a/examples/write/pandas_write.py b/examples/write/pandas_write.py new file mode 100644 index 0000000..5da5a19 --- /dev/null +++ b/examples/write/pandas_write.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +""" +pandas_write.py - is a functional example that demonstrates how to write data to Influxdb3 +directly from a pandas DataFrame. +""" +import os +import pandas as pd +import numpy as np + +import influxdb_client_3 as InfluxDBClient3 + + +def main(): + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + + with InfluxDBClient3.InfluxDBClient3( + token=token, + host=host, + database=database) as client: + + # Create a dataframe + df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) + + # Create a range of datetime values + now = pd.Timestamp.now(tz="utc").floor(freq="min") + start = now - pd.Timedelta(days=30) + + dates = pd.date_range(start=start, end=now, freq='5min') + + # Create a DataFrame with random data and datetime index + df = pd.DataFrame( + np.random.randn( + len(dates), + 3), + index=dates, + columns=[ + 'Column 1', + 'Column 2', + 'Column 3']) + df['tagkey'] = 'Hello World' + + print(df) + + # Write the DataFrame to InfluxDB + # Please note the keyword values used to declare + # the measurement name and which DataFrame columns + # will be written as tags. + try: + client.write(df, data_frame_measurement_name='pd_table', + data_frame_tag_columns=['tagkey']) + print("Write Success!") + except Exception as e: + print(f"Write failure: {e}") + + +if __name__ == '__main__': + main() diff --git a/Examples/file-import/out.csv b/examples/write/source_data/out.csv similarity index 100% rename from Examples/file-import/out.csv rename to examples/write/source_data/out.csv diff --git a/Examples/file-import/out.feather b/examples/write/source_data/out.feather similarity index 100% rename from Examples/file-import/out.feather rename to examples/write/source_data/out.feather diff --git a/Examples/file-import/out.json b/examples/write/source_data/out.json similarity index 100% rename from Examples/file-import/out.json rename to examples/write/source_data/out.json diff --git a/Examples/file-import/out.orc b/examples/write/source_data/out.orc similarity index 100% rename from Examples/file-import/out.orc rename to examples/write/source_data/out.orc diff --git a/Examples/file-import/out.parquet b/examples/write/source_data/out.parquet similarity index 100% rename from Examples/file-import/out.parquet rename to examples/write/source_data/out.parquet diff --git a/Examples/pokemon-trainer/pokemon.csv b/examples/write/source_data/pokemon.csv similarity index 100% rename from Examples/pokemon-trainer/pokemon.csv rename to examples/write/source_data/pokemon.csv diff --git a/examples/write/source_data/updater.py b/examples/write/source_data/updater.py new file mode 100644 index 0000000..d033b63 --- /dev/null +++ b/examples/write/source_data/updater.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +import pandas as pd +import time +import logging +import random +import numpy as np +import os + +dir_path = os.path.dirname(os.path.realpath(__file__)) + + +def update_measurement_name(source: pd.DataFrame, measurement_name: str): + count = 0 + for _ in source["iox::measurement"]: + source.loc[count, "iox::measurement"] = measurement_name + count += 1 + + +def update_timestamps(source: pd.DataFrame): + + now = time.time_ns() + interval = 333_000_000 # ns + grit = random.randrange(0, 1_000_000) + interval = interval + grit + current = np.int64(now - interval * len(source["time"])) + ts_type = type(source['time'][0]).__name__ + + count = 0 + for _ in source['time']: + if ts_type in ["int", "int32", "int64"]: + source.loc[count, "time"] = current + else: + source.loc[count, "time"] = pd.Timestamp(current).__str__() + count += 1 + current = current + interval + + if ts_type in ["int", "int32", "int64"]: + source["time"] = source["time"].astype("int64") + + +def feather_update(): + logging.info("Updating feather") + f_df = pd.read_feather(f"{dir_path}/out.feather") + update_timestamps(f_df) + update_measurement_name(f_df, "machine_data_feather") + f_df.to_feather(f"{dir_path}/out_update.feather") + + +def orc_update(): + logging.info("Updating orc") + o_df = pd.read_orc(f"{dir_path}/out.orc") + update_timestamps(o_df) + update_measurement_name(o_df, "machine_data_orc") + o_df.to_orc(f"{dir_path}/out_update.orc", index=False) + + +def parquet_update(): + logging.info("Updating parquet") + p_df = pd.read_parquet(f"{dir_path}/out.parquet") + update_timestamps(p_df) + update_measurement_name(p_df, "machine_data_parquet") + p_df.to_parquet(f"{dir_path}/out_update.parquet", index=False) + + +def csv_update(): + logging.info("Updating csv") + csv_df = pd.read_csv(f"{dir_path}/out.csv") + update_timestamps(csv_df) + csv_df.to_csv(f"{dir_path}/out_update.csv", index=False) + + +def json_update(): + logging.info("Updating json") + json_df = pd.read_json(f"{dir_path}/out.json") + update_timestamps(json_df) + json_df.to_json(f"{dir_path}/out_update.json", orient='records', index=False) + + +if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) + feather_update() + orc_update() + parquet_update() + csv_update() + json_update() diff --git a/examples/write/writeoptions.py b/examples/write/writeoptions.py new file mode 100644 index 0000000..77cb911 --- /dev/null +++ b/examples/write/writeoptions.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +""" +`writeoptions.py` - is a functional example, except for certain illustrative callbacks, +that shows the basic principles of setting up configuration properties for the standard +HTTP write client. +""" +import datetime +import logging +import os + +from influxdb_client_3 import (exceptions, InfluxDBClient3, Point, + WriteOptions, WritePrecision, WriteType, write_client_options) + +logger = logging.getLogger("writeoptions") + + +# An illustrative callback - see below +def error_callback(conf, data: bytes, exception: exceptions.InfluxDBError): + now = datetime.datetime.now() + logger.warning(f"[{now}] an error occurred on latest write: {exception}") + logger.warning(f" conf: {conf}") + logger.warning(f" data: {data}") + + +# An illustrative callback - see below +def success_callback(conf, data: bytes): + now = datetime.datetime.now() + logger.info(f"[{now}] data written: {len(bytes(data))} bytes") + logger.debug(f" conf: {conf}") + + +wo = WriteOptions( + write_type=WriteType.synchronous, # Type of write api to use + no_sync=False, # Whether to wait for synchronizing writes with server acknowledgements + timeout=30_000, # Time in milliseconds to wait for a post write response + write_precision=WritePrecision.MS, # Timestamp precision used when writing data points +) +""" +The WriteOptions class encapsulates basic configuration properties. + +Applicable properties will depend upon the value of the `write_type` property. This can be... + * WriteType.asynchronous + * WriteType.synchronous + * WriteType.batching (Constructor Default) - see the example `write/batching.py` for more details. +""" + +wco = write_client_options(write_options=wo, # The core WriteOptions object to use + success_callback=success_callback, # N.B. currently only used in with batching type + error_callback=error_callback, # N.B. currently only used with batching type + ) +""" +The dictionary created by the call to `write_client_options()` can add other write client properties +such as callback functions. Note that the `write_options` property is not always required, +in which case a default WriteOptions object is used internally. + +The InfluxDBClient3 constructor will leverage this dictionary when configuring the standard HTTP based write client. +""" + +measurement = 'wo_caught' + + +def main(): + + host = os.getenv('INFLUXDB_HOST') or 'http://localhost:8181' + token = os.getenv('INFLUXDB_TOKEN') or 'my-token' + database = os.getenv('INFLUXDB_DATABASE') or 'my-db' + + with InfluxDBClient3( + token=token, + host=host, + database=database, + write_client_options=wco, # write client options get passed to the client instance here. + debug=True) as client: + + now = datetime.datetime.now(datetime.timezone.utc) + + data = Point(measurement).tag("trainer", "ash").tag("id", "0006").tag("num", "1") \ + .field("caught", "charizard") \ + .field("level", 10).field("attack", 30) \ + .field("defense", 40).field("hp", 200) \ + .field("speed", 10) \ + .field("type1", "fire").field("type2", "flying") \ + .time(now) + + try: + client.write(data) + except Exception as e: + print(f"Error writing point: {e}") + + data = [Point(measurement) # point 1 + .tag("trainer", "ash") + .tag("id", "0006") + .tag("num", "1") + .field("caught", "charizard") + .field("level", 10) + .field("attack", 30) + .field("defense", 40) + .field("hp", 200) + .field("speed", 10) + .field("type1", "fire") + .field("type2", "flying") + .time(now), + + Point(measurement) # point 2 + .tag("trainer", "ash") + .tag("id", "0007") + .tag("num", "2") + .field("caught", "bulbasaur") + .field("level", 12) + .field("attack", 31) + .field("defense", 31) + .field("hp", 190) + .field("speed", 11) + .field("type1", "grass") + .field("type2", "poison") + .time(now), + + Point(measurement) # point 3 + .tag("trainer", "ash") + .tag("id", "0008") + .tag("num", "3") + .field("caught", "squirtle") + .field("level", 13) + .field("attack", 29) + .field("defense", 40) + .field("hp", 180) + .field("speed", 13) + .field("type1", "water") + .field("type2", None) + .time(now) + ] + + try: + client.write(data) + print(f"Write success: {len(data)} points!") + except Exception as e: + print(f"Error writing point: {e}") + + +if __name__ == "__main__": + main()