Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Point72_csp-gateway /csp_gateway /utils /csp.py
| from datetime import datetime, timedelta | |
| from typing import TypeVar, get_args, get_origin | |
| import csp | |
| from csp import Outputs, ts | |
| from csp.impl.types.tstype import TsType, isTsType | |
| from deprecation import deprecated | |
| T = TypeVar("T") | |
| K = TypeVar("K") | |
| V = TypeVar("V") | |
| __all__ = ( | |
| "_get_dict_basket_key_type", | |
| "_get_dict_basket_value_tstype", | |
| "_get_dict_basket_value_type", | |
| "_is_dict_basket", | |
| "_is_list_basket", | |
| "get_args", | |
| "get_dict_basket_key_type", | |
| "get_dict_basket_value_tstype", | |
| "get_dict_basket_value_type", | |
| "get_origin", | |
| "is_dict_basket", | |
| "is_list_basket", | |
| "set_alarm_and_fetch_alarm_time", | |
| "to_list", | |
| ) | |
| def is_dict_basket(val: type) -> bool: | |
| return get_origin(val) is dict and isTsType(get_args(val)[1]) | |
| def is_list_basket(val: type) -> bool: | |
| return get_origin(val) is list and isTsType(get_args(val)[0]) | |
| def get_dict_basket_key_type(val: type) -> type: | |
| if not is_dict_basket(val): | |
| raise TypeError(f"object is not a Dict Basket but is of type: {type(val)}") | |
| return get_args(val)[0] | |
| def get_dict_basket_value_tstype(val: type) -> TsType: | |
| if not is_dict_basket(val): | |
| raise TypeError(f"object is not a Dict Basket but is of type: {type(val)}") | |
| return get_args(val)[1] | |
| def get_dict_basket_value_type(val: type) -> type: | |
| return get_dict_basket_value_tstype(val).typ | |
| def _is_dict_basket(val: type) -> bool: | |
| return is_dict_basket(val) | |
| def _is_list_basket(val: type) -> bool: | |
| return is_list_basket(val) | |
| def _get_dict_basket_key_type(val: type) -> type: | |
| return get_dict_basket_key_type(val) | |
| def _get_dict_basket_value_tstype(val: type) -> TsType: | |
| return get_dict_basket_value_tstype(val) | |
| def _get_dict_basket_value_type(val: type) -> type: | |
| return get_dict_basket_value_type(val) | |
| def to_list(x: ts["T"]) -> ts[list["T"]]: | |
| if csp.ticked(x): | |
| return [x] | |
| def set_alarm_and_fetch_alarm_time(time: datetime | timedelta) -> Outputs(alarm_time=ts[datetime], alarm_ticked=ts[bool]): | |
| with csp.alarms(): | |
| engine_start: ts[bool] = csp.alarm(bool) | |
| alarm: ts[bool] = csp.alarm(bool) | |
| with csp.state(): | |
| s_time = None | |
| with csp.start(): | |
| csp.schedule_alarm(engine_start, timedelta(), True) | |
| csp.schedule_alarm(alarm, time, True) | |
| if isinstance(time, datetime): | |
| s_time = time | |
| else: | |
| s_time = csp.now() + time | |
| if csp.ticked(engine_start): | |
| csp.output(alarm_time=s_time) | |
| if csp.ticked(alarm): | |
| csp.output(alarm_ticked=True) | |
Xet Storage Details
- Size:
- 2.88 kB
- Xet hash:
- c48d25facad935b3f9e97553c8f705158240042b039f3f3495ffc85146ab7d37
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.