-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: nearly done with waveform, rest api causing problems
- Loading branch information
1 parent
d9fd87c
commit 2fc7114
Showing
11 changed files
with
141 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import enum | ||
|
||
from pvi._format.dls import DLSFormatter | ||
from pvi.device import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
from typing import Callable | ||
from fastcs.datatypes import Bool, DataType, Enum, Float, Int, String, T, WaveForm | ||
|
||
REST_ALLOWED_DATATYPES = (Bool, DataType, Enum, Float, Int, String) | ||
|
||
|
||
def convert_datatype(datatype: DataType[T]) -> type: | ||
match datatype: | ||
case WaveForm(): | ||
return list | ||
case _: | ||
return datatype.dtype | ||
|
||
|
||
def get_cast_method_to_rest_type(datatype: DataType[T]) -> Callable[[T], object]: | ||
match datatype: | ||
case WaveForm(): | ||
|
||
def cast_to_rest_type(value) -> list: | ||
return value.tolist() | ||
case datatype if issubclass(type(datatype), REST_ALLOWED_DATATYPES): | ||
|
||
def cast_to_rest_type(value): | ||
return datatype.validate(value) | ||
case _: | ||
raise ValueError(f"Unsupported datatype {datatype}") | ||
|
||
return cast_to_rest_type | ||
|
||
|
||
def get_cast_method_from_rest_type(datatype: DataType[T]) -> Callable[[object], T]: | ||
match datatype: | ||
case WaveForm(): | ||
|
||
def cast_from_rest_type(value) -> T: | ||
return datatype.validate(np.array(value, dtype=datatype.array_dtype)) | ||
case datatype if issubclass(type(datatype), REST_ALLOWED_DATATYPES): | ||
|
||
def cast_from_rest_type(value) -> T: | ||
return datatype.validate(value) | ||
case _: | ||
raise ValueError(f"Unsupported datatype {datatype}") | ||
|
||
return cast_from_rest_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters