1
- from typing import List , Optional , Sequence
1
+ from typing import Sequence
2
2
3
3
from primary .services .summary_vector_statistics import VectorStatistics
4
- from primary .services .sumo_access .summary_access import VectorMetadata
4
+ from primary .services .sumo_access .summary_access import RealizationVector
5
5
from primary .services .utils .statistic_function import StatisticFunction
6
+ from primary .services .summary_delta_vectors import RealizationDeltaVector
7
+ from primary .services .summary_derived_vectors import DerivedVectorType , DerivedRealizationVector
6
8
from . import schemas
7
9
8
10
11
+ def to_api_derived_vector_type (derived_type : DerivedVectorType ) -> schemas .DerivedVectorType :
12
+ """
13
+ Create API DerivedVectorType from service layer DerivedVectorType
14
+ """
15
+ return schemas .DerivedVectorType (derived_type .value )
16
+
17
+
18
+ def to_api_derived_vector_info (derived_type : DerivedVectorType , source_vector : str ) -> schemas .DerivedVectorInfo :
19
+ """
20
+ Create API DerivedVectorInfo from service layer DerivedVectorInfo
21
+ """
22
+ return schemas .DerivedVectorInfo (
23
+ type = to_api_derived_vector_type (derived_type ),
24
+ sourceVector = source_vector ,
25
+ )
26
+
27
+
28
+ def realization_vector_list_to_api_vector_realization_data_list (
29
+ realization_vector_list : list [RealizationVector ],
30
+ ) -> list [schemas .VectorRealizationData ]:
31
+ """
32
+ Create API VectorRealizationData list from service layer RealizationVector list
33
+ """
34
+ return [
35
+ schemas .VectorRealizationData (
36
+ realization = real_vec .realization ,
37
+ timestampsUtcMs = real_vec .timestamps_utc_ms ,
38
+ values = real_vec .values ,
39
+ unit = real_vec .metadata .unit ,
40
+ isRate = real_vec .metadata .is_rate ,
41
+ )
42
+ for real_vec in realization_vector_list
43
+ ]
44
+
45
+
46
+ def derived_vector_realizations_to_api_vector_realization_data_list (
47
+ derived_realization_vector_list : list [DerivedRealizationVector ], derived_vector_info : schemas .DerivedVectorInfo
48
+ ) -> list [schemas .VectorRealizationData ]:
49
+ """
50
+ Create API VectorRealizationData list from service layer DerivedRealizationVector list and derived vector info
51
+ """
52
+ return [
53
+ schemas .VectorRealizationData (
54
+ realization = real_vec .realization ,
55
+ timestampsUtcMs = real_vec .timestamps_utc_ms ,
56
+ values = real_vec .values ,
57
+ unit = real_vec .unit ,
58
+ isRate = real_vec .is_rate ,
59
+ derivedVectorInfo = derived_vector_info ,
60
+ )
61
+ for real_vec in derived_realization_vector_list
62
+ ]
63
+
64
+
65
+ def realization_delta_vector_list_to_api_vector_realization_data_list (
66
+ realization_delta_vector_list : list [RealizationDeltaVector ],
67
+ derived_vector_info : schemas .DerivedVectorInfo | None = None ,
68
+ ) -> list [schemas .VectorRealizationData ]:
69
+ """
70
+ Create API VectorRealizationData list from service layer RealizationVector list
71
+
72
+ Optional derived_vector_info is included in the API VectorRealizationData if provided
73
+ """
74
+ return [
75
+ schemas .VectorRealizationData (
76
+ realization = real_vec .realization ,
77
+ timestampsUtcMs = real_vec .timestamps_utc_ms ,
78
+ values = real_vec .values ,
79
+ unit = real_vec .unit ,
80
+ isRate = real_vec .is_rate ,
81
+ derivedVectorInfo = derived_vector_info ,
82
+ )
83
+ for real_vec in realization_delta_vector_list
84
+ ]
85
+
86
+
9
87
def to_service_statistic_functions (
10
- api_stat_funcs : Optional [ Sequence [schemas .StatisticFunction ]] ,
11
- ) -> Optional [ List [ StatisticFunction ]] :
88
+ api_stat_funcs : Sequence [schemas .StatisticFunction ] | None = None ,
89
+ ) -> list [ StatisticFunction ] | None :
12
90
"""
13
91
Convert incoming list of API statistic function enum values to service layer StatisticFunction enums,
14
92
also accounting for the case where the list is None
15
93
"""
16
94
if api_stat_funcs is None :
17
95
return None
18
96
19
- service_stat_funcs : List [StatisticFunction ] = []
97
+ service_stat_funcs : list [StatisticFunction ] = []
20
98
for api_func_enum in api_stat_funcs :
21
99
service_func_enum = StatisticFunction .from_string_value (api_func_enum .value )
22
100
if service_func_enum :
@@ -26,36 +104,44 @@ def to_service_statistic_functions(
26
104
27
105
28
106
def to_api_vector_statistic_data (
29
- vector_statistics : VectorStatistics , vector_metadata : VectorMetadata
107
+ vector_statistics : VectorStatistics ,
108
+ is_rate : bool ,
109
+ unit : str ,
110
+ derived_vector_info : schemas .DerivedVectorInfo | None = None ,
30
111
) -> schemas .VectorStatisticData :
31
112
"""
32
113
Create API VectorStatisticData from service layer VectorStatistics
33
114
"""
34
115
value_objects = _create_statistic_value_object_list (vector_statistics )
35
116
ret_data = schemas .VectorStatisticData (
36
117
realizations = vector_statistics .realizations ,
37
- timestamps_utc_ms = vector_statistics .timestamps_utc_ms ,
38
- value_objects = value_objects ,
39
- unit = vector_metadata .unit ,
40
- is_rate = vector_metadata .is_rate ,
118
+ timestampsUtcMs = vector_statistics .timestamps_utc_ms ,
119
+ valueObjects = value_objects ,
120
+ unit = unit ,
121
+ isRate = is_rate ,
122
+ derivedVectorInfo = derived_vector_info ,
41
123
)
42
124
43
125
return ret_data
44
126
45
127
46
128
def to_api_delta_ensemble_vector_statistic_data (
47
- vector_statistics : VectorStatistics , is_rate : bool , unit : str
129
+ vector_statistics : VectorStatistics ,
130
+ is_rate : bool ,
131
+ unit : str ,
132
+ derived_vector_info : schemas .DerivedVectorInfo | None = None ,
48
133
) -> schemas .VectorStatisticData :
49
134
"""
50
135
Create API VectorStatisticData from service layer VectorStatistics
51
136
"""
52
137
value_objects = _create_statistic_value_object_list (vector_statistics )
53
138
ret_data = schemas .VectorStatisticData (
54
139
realizations = vector_statistics .realizations ,
55
- timestamps_utc_ms = vector_statistics .timestamps_utc_ms ,
56
- value_objects = value_objects ,
140
+ timestampsUtcMs = vector_statistics .timestamps_utc_ms ,
141
+ valueObjects = value_objects ,
57
142
unit = unit ,
58
- is_rate = is_rate ,
143
+ isRate = is_rate ,
144
+ derivedVectorInfo = derived_vector_info ,
59
145
)
60
146
61
147
return ret_data
@@ -71,6 +157,6 @@ def _create_statistic_value_object_list(vector_statistics: VectorStatistics) ->
71
157
if service_func_enum is not None :
72
158
value_arr = vector_statistics .values_dict .get (service_func_enum )
73
159
if value_arr is not None :
74
- value_objects .append (schemas .StatisticValueObject (statistic_function = api_func_enum , values = value_arr ))
160
+ value_objects .append (schemas .StatisticValueObject (statisticFunction = api_func_enum , values = value_arr ))
75
161
76
162
return value_objects
0 commit comments