Skip to content

Commit

Permalink
Expose create_library_signal and create_tag (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindwe authored Jul 8, 2021
1 parent f96c3da commit 4c1419d
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def get_signal(self, request: GetSignalRequest) -> Signal:
return self._request("GET", request.name, Signal())

def create_signal(self, request: CreateSignalRequest) -> Signal:
return self._request("POST", "signals", Signal(), request.signal)
return self._request(
"POST",
f"signals?createLibrarySignal={request.create_library_signal}",
Signal(),
request.signal,
)

def delete_signal(self, request: DeleteSignalRequest) -> None:
self._request("DELETE", request.name, None)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def get_time_series(self, request: GetTimeSeriesRequest) -> TimeSeries:

def create_time_series(self, request: CreateTimeSeriesRequest) -> TimeSeries:
return self._request(
"POST", request.time_series.name, TimeSeries(), body=request.time_series
"POST",
f"{request.time_series.name}?createTag={request.create_tag}",
TimeSeries(),
body=request.time_series,
)

def update_time_series(self, request: UpdateTimeSeriesRequest) -> TimeSeries:
Expand Down
7 changes: 5 additions & 2 deletions exabel_data_sdk/client/api/signal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ def get_signal(self, name: str) -> Optional[Signal]:
raise
return Signal.from_proto(response)

def create_signal(self, signal: Signal) -> Signal:
def create_signal(self, signal: Signal, create_library_signal: bool = False) -> Signal:
"""
Create one signal and returns it.
Args:
signal: The signal to create.
create_library_signal: Set to true to add the signal to the library when created.
"""
response = self.client.create_signal(
CreateSignalRequest(signal=signal.to_proto()),
CreateSignalRequest(
signal=signal.to_proto(), create_library_signal=create_library_signal
),
)
return Signal.from_proto(response)

Expand Down
24 changes: 14 additions & 10 deletions exabel_data_sdk/client/api/time_series_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_time_series(

return self._time_series_points_to_series(time_series.points, time_series.name)

def create_time_series(self, name: str, series: pd.Series) -> None:
def create_time_series(self, name: str, series: pd.Series, create_tag: bool = False) -> None:
"""
Create a time series.
Expand All @@ -119,19 +119,23 @@ def create_time_series(self, name: str, series: pd.Series) -> None:
first version is the canonical form. The signal must be associated with the entity's type.
Args:
name: The resource name of the time series, for example
"entityTypes/ns1.type/entities/ns2.entities/signals/ns3.signal".
An alternative name for the same time series is
"signals/ns3.signal/entityTypes/ns1.type/entities/ns2.entity". The namespaces
must be empty (being global) or one of the predetermined namespaces the
customer has access to. If ns2 is not empty, it must be equals to ns3,
and if ns1 is not empty, all three namespaces must be equal.
series: The time series data
name: The resource name of the time series, for example
"entityTypes/ns1.type/entities/ns2.entities/signals/ns3.signal".
An alternative name for the same time series is
"signals/ns3.signal/entityTypes/ns1.type/entities/ns2.entity". The
namespaces must be empty (being global) or one of the predetermined
namespaces the customer has access to. If ns2 is not empty, it must be
equals to ns3, and if ns1 is not empty, all three namespaces must be equal.
series: The time series data
create_tag: Set to true to create a tag for every entity type a signal has time series
for. If a tag already exists, it will be updated when time series are
created (or deleted) regardless of the value of this flag.
"""
time_series_points = self._series_to_time_series_points(series)
self.client.create_time_series(
CreateTimeSeriesRequest(
time_series=ProtoTimeSeries(name=name, points=time_series_points)
time_series=ProtoTimeSeries(name=name, points=time_series_points),
create_tag=create_tag,
),
)

Expand Down
10 changes: 9 additions & 1 deletion exabel_data_sdk/scripts/create_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ def __init__(self, argv: Sequence[str], description: str):
default="",
help="One or more paragraphs of text description",
)
self.parser.add_argument(
"--create-library-signal",
required=False,
type=bool,
default=False,
help="Set to true to create a library signal",
)

def run_script(self, client: ExabelClient, args: argparse.Namespace) -> None:
signal = client.signal_api.create_signal(
Signal(
name=args.name,
display_name=args.display_name,
description=args.description,
)
),
create_library_signal=args.create_library_signal,
)
print("Successfully created signal:")
print(signal)
Expand Down
20 changes: 10 additions & 10 deletions exabel_data_sdk/stubs/exabel/api/data/v1/signal_service_pb2.py

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

Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ type___GetSignalRequest = GetSignalRequest

class CreateSignalRequest(google___protobuf___message___Message):
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
no_library_signal: builtin___bool = ...
create_library_signal: builtin___bool = ...
@property
def signal(self) -> exabel___api___data___v1___signal_messages_pb2___Signal: ...
def __init__(
self,
*,
signal: typing___Optional[exabel___api___data___v1___signal_messages_pb2___Signal] = None,
no_library_signal: typing___Optional[builtin___bool] = None,
create_library_signal: typing___Optional[builtin___bool] = None,
) -> None: ...
def HasField(
self, field_name: typing_extensions___Literal["signal", b"signal"]
) -> builtin___bool: ...
def ClearField(
self,
field_name: typing_extensions___Literal[
"no_library_signal", b"no_library_signal", "signal", b"signal"
"create_library_signal", b"create_library_signal", "signal", b"signal"
],
) -> None: ...

Expand Down
Loading

0 comments on commit 4c1419d

Please sign in to comment.