Skip to content

Commit

Permalink
fix logging and models
Browse files Browse the repository at this point in the history
  • Loading branch information
Treesarj committed Jul 10, 2024
1 parent 817b038 commit 721d114
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 19 additions & 5 deletions oteapi_dlite/strategies/oceanlab_influx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import dlite
import influxdb_client
import jinja2
from fastapi import logger
import logging
from oteapi.models import AttrDict, HostlessAnyUrl, ParserConfig, ResourceConfig
from pandas import DataFrame
from pydantic import Field, SecretStr
from pydantic import BaseModel, Field, SecretStr
from pydantic.dataclasses import dataclass

from oteapi_dlite.models import DLiteSessionUpdate
Expand All @@ -21,6 +21,16 @@
from typing import Literal
else:
from typing_extensions import Literal
logger = logging.getLogger(__name__)


class Measurement(BaseModel):
"""Measurement and field value from the Influx DB"""

measurement: Annotated[str, Field(description="The measurement name")]
field: Annotated[
str, Field(description="The measurement's field in the DB")
]


class InfluxParseParseConfig(AttrDict):
Expand Down Expand Up @@ -93,7 +103,7 @@ class InfluxParseParseConfig(AttrDict):
list[Measurement],
Field(description="Measurement and field values as a list."),
] = [
Measurement(_)
Measurement(**_)
for _ in [
{
"measurement": "ctd_conductivity_munkholmen",
Expand Down Expand Up @@ -188,11 +198,15 @@ def get(self) -> InfluxParserUpdate:
env = jinja2.Environment(loader=jinja2.BaseLoader, autoescape=True)
env.globals.update(enumerate=enumerate, str=str)
bucket = f"{config.DATABASE}/{config.RETPOLICY}"
print("config.measurements")
print([measurement.dict() for measurement in config.measurements])
configuration = {
"bucket": bucket,
"timeRange": config.time_range,
"limitSize": config.size_limit,
"measurements": config.measurements.model_dump(),
"limitSize": str(config.size_limit),
"measurements": [
measurement.dict() for measurement in config.measurements
],
}
tmpl = env.from_string(TEMPLATE)
flux_query = tmpl.render(configuration).strip()
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cachetools>=5.3.3
DLite-Python>=0.4.5,<1.0
fastapi>=0.111.0
influxdb_client>=1.44.0
jinja2>=3.1.4
numpy>=1.21,<2
Expand Down

0 comments on commit 721d114

Please sign in to comment.