Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.12 #660

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/api/v1/circular_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
CircularAverageQueryParams,
PivotQueryParams,
LimitOffsetQueryParams,
PaginationRow,
)
import src.api.v1.common

Expand Down Expand Up @@ -61,15 +62,35 @@ def circular_average_events_get(
)

data = circular_average.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
else:
return ResampleInterpolateResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
except Exception as e:
logging.error(str(e))
Expand Down
22 changes: 22 additions & 0 deletions src/api/v1/circular_standard_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
PivotQueryParams,
LimitOffsetQueryParams,
CircularAverageQueryParams,
PaginationRow,
)
import src.api.v1.common

Expand Down Expand Up @@ -61,16 +62,37 @@ def circular_standard_deviation_events_get(
)

data = circular_standard_deviation.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
else:
return ResampleInterpolateResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)

except Exception as e:
logging.error(str(e))
raise HTTPException(status_code=400, detail=str(e))
Expand Down
21 changes: 21 additions & 0 deletions src/api/v1/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
InterpolateQueryParams,
PivotQueryParams,
LimitOffsetQueryParams,
PaginationRow,
)
import src.api.v1.common

Expand Down Expand Up @@ -62,15 +63,35 @@ def interpolate_events_get(
)

data = interpolate.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
else:
return ResampleInterpolateResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
except Exception as e:
logging.error(str(e))
Expand Down
21 changes: 21 additions & 0 deletions src/api/v1/interpolation_at_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
InterpolationAtTimeQueryParams,
PivotQueryParams,
LimitOffsetQueryParams,
PaginationRow,
)
import src.api.v1.common

Expand All @@ -56,15 +57,35 @@ def interpolation_at_time_events_get(
)

data = interpolation_at_time.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

if parameters.get("pivot") == True:
return PivotResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
else:
return ResampleInterpolateResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
except Exception as e:
logging.error(str(e))
Expand Down
20 changes: 20 additions & 0 deletions src/api/v1/latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
LatestResponse,
LimitOffsetQueryParams,
HTTPError,
PaginationRow,
)
from src.api.auth.azuread import oauth2_scheme
from src.api.FastAPIApp import api_v1_router
Expand All @@ -47,9 +48,28 @@ def latest_retrieval_get(
)

data = latest.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

return LatestResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
except Exception as e:
logging.error(str(e))
Expand Down
21 changes: 21 additions & 0 deletions src/api/v1/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MetadataResponse,
LimitOffsetQueryParams,
HTTPError,
PaginationRow,
)
from src.api.auth.azuread import oauth2_scheme
from src.api.FastAPIApp import api_v1_router
Expand All @@ -47,10 +48,30 @@ def metadata_retrieval_get(
)

data = metadata.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

return MetadataResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)

except Exception as e:
logging.error(str(e))
raise HTTPException(status_code=400, detail=str(e))
Expand Down
12 changes: 12 additions & 0 deletions src/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class LatestRow(BaseModel):
GoodValueType: Union[str, None]


class PaginationRow(BaseModel):
limit: Union[int, None]
offset: Union[int, None]
next: Union[int, None]


class RawRow(BaseModel):
EventTime: datetime
TagName: str
Expand All @@ -90,20 +96,23 @@ class MetadataResponse(BaseModel):
None, alias="schema", serialization_alias="schema"
)
data: List[MetadataRow]
pagination: Union[PaginationRow, None]


class LatestResponse(BaseModel):
field_schema: FieldSchema = Field(
None, alias="schema", serialization_alias="schema"
)
data: List[LatestRow]
pagination: Union[PaginationRow, None]


class RawResponse(BaseModel):
field_schema: FieldSchema = Field(
None, alias="schema", serialization_alias="schema"
)
data: List[RawRow]
pagination: Union[PaginationRow, None]


class ResampleInterpolateRow(BaseModel):
Expand All @@ -123,20 +132,23 @@ class ResampleInterpolateResponse(BaseModel):
None, alias="schema", serialization_alias="schema"
)
data: List[ResampleInterpolateRow]
pagination: Union[PaginationRow, None]


class SummaryResponse(BaseModel):
field_schema: FieldSchema = Field(
None, alias="schema", serialization_alias="schema"
)
data: List[SummaryRow]
pagination: Union[PaginationRow, None]


class PivotResponse(BaseModel):
field_schema: FieldSchema = Field(
None, alias="schema", serialization_alias="schema"
)
data: List[PivotRow]
pagination: Union[PaginationRow, None]


class HTTPError(BaseModel):
Expand Down
22 changes: 21 additions & 1 deletion src/api/v1/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandas.io.json import build_table_schema
from fastapi import Query, HTTPException, Depends, Body
import nest_asyncio
from src.sdk.python.rtdip_sdk.queries.time_series import raw
from src.sdk.python.rtdip_sdk.queries.time_series import raw, summary
from src.api.v1.models import (
BaseHeaders,
BaseQueryParams,
Expand All @@ -28,6 +28,7 @@
TagsBodyParams,
LimitOffsetQueryParams,
HTTPError,
PaginationRow,
)
from src.api.auth.azuread import oauth2_scheme
from src.api.FastAPIApp import api_v1_router
Expand All @@ -53,9 +54,28 @@ def raw_events_get(
)

data = raw.get(connection, parameters)

pagination = None

if (
limit_offset_parameters.limit is not None
and limit_offset_parameters.offset is not None
):
next = None

if len(data.index) == limit_offset_parameters.limit:
next = limit_offset_parameters.offset + limit_offset_parameters.limit

pagination = PaginationRow(
limit=limit_offset_parameters.limit,
offset=limit_offset_parameters.offset,
next=next,
)

return RawResponse(
schema=build_table_schema(data, index=False, primary_key=False),
data=data.replace({np.nan: None}).to_dict(orient="records"),
pagination=pagination,
)
except Exception as e:
logging.error(str(e))
Expand Down
Loading
Loading