Skip to content

Commit

Permalink
feat(main): possible to define now tags if you write a dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
karlTGA committed Apr 29, 2021
1 parent fcdee7d commit 476676e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
14 changes: 8 additions & 6 deletions gewv_timeseries_client/timeseries_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from influxdb_client import InfluxDBClient
from influxdb_client.client.write.point import Point
from influxdb_client.rest import ApiException
from influxdb_client.client.flux_table import FluxTable
from datetime import datetime
Expand Down Expand Up @@ -83,34 +84,35 @@ def get_dataframe(self, **kwargs):

return df

def write_points(self, points):
pass
def write_points(self, project: str, points: List[Point]):
self._write_api.write(bucket=project, record=points)

def write_a_dataframe(
self,
project: str,
measurement_name: str,
dataframe: pd.DataFrame,
tags: Dict[str, str] = None,
tag_columns: List[str] = [],
additional_tags: Dict[str, str] = None,
):
"""
Write a pandas dataframe to the influx db. You can define some
tags, that are appended to every entry.
"""

if tags is None:
if additional_tags is None:
self._write_api.write(
bucket=project,
record=dataframe,
data_frame_measurement_name=measurement_name,
data_frame_tag_columns=tag_columns,
)
return

tags_dataframe = pd.DataFrame(index=dataframe.index)
tag_columns = []

# create the dataframe with the tags
for tag_name, tag in tags.items():
for tag_name, tag in additional_tags.items():
tag_columns.append(tag_name)
tags_dataframe[tag_name] = [tag] * len(dataframe)

Expand Down
29 changes: 22 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions poetry.toml

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ commitizen = "^2.1.0"
python-semantic-release = "^7.2.2"
flake8 = "^3.8.3"
pytest-asyncio = "^0.14.0"
python-dotenv = "^0.17.0"

[tool.semantic_release]
version_variable = "gewv_timeseries_client/__init__.py:__version__"
Expand Down

0 comments on commit 476676e

Please sign in to comment.