11import copy
2- from typing import Optional , List , Dict , Any , Union
3- from . models import MetricsDataFormat , MetricsHistoricalDataStep
2+ from typing import Any , Dict , List , Optional , Union
3+
44from .metrics_shared import OpenPAYGOMetricsShared
5+ from .models import MetricsDataFormat , MetricsHistoricalDataStep
56
67
78class MetricsRequestHandler (object ):
89 def __init__ (
9- self , serial_number : str , data_format : Optional [Union [Dict [str , Any ], MetricsDataFormat ]] = None , secret_key : Optional [str ] = None , auth_method : Optional [str ] = None
10+ self ,
11+ serial_number : str ,
12+ data_format : Optional [Union [Dict [str , Any ], MetricsDataFormat ]] = None ,
13+ secret_key : Optional [str ] = None ,
14+ auth_method : Optional [str ] = None ,
1015 ) -> None :
1116 self .secret_key = secret_key
1217 self .auth_method = auth_method
@@ -15,12 +20,18 @@ def __init__(
1520 }
1621 if data_format is not None :
1722 if isinstance (data_format , dict ):
18- self .data_format : Optional [Dict [str , Any ]] = MetricsDataFormat .model_validate (data_format ).model_dump (exclude_none = True )
23+ self .data_format : Optional [Dict [str , Any ]] = (
24+ MetricsDataFormat .model_validate (data_format ).model_dump (
25+ exclude_none = True
26+ )
27+ )
1928 else :
20- self .data_format : Optional [Dict [str , Any ]] = data_format .model_dump (exclude_none = True )
29+ self .data_format : Optional [Dict [str , Any ]] = data_format .model_dump (
30+ exclude_none = True
31+ )
2132 else :
2233 self .data_format : Optional [Dict [str , Any ]] = None
23-
34+
2435 if self .data_format :
2536 if self .data_format .get ("id" ):
2637 self .request_dict ["data_format_id" ] = self .data_format .get ("id" )
@@ -38,15 +49,19 @@ def set_timestamp(self, timestamp: int) -> None:
3849 def set_data (self , data : Dict [str , Any ]) -> None :
3950 self .data = data
4051
41- def set_historical_data (self , historical_data : List [Union [Dict [str , Any ], MetricsHistoricalDataStep ]]) -> None :
52+ def set_historical_data (
53+ self , historical_data : List [Union [Dict [str , Any ], MetricsHistoricalDataStep ]]
54+ ) -> None :
4255 validated_historical_data = []
4356 for time_step in historical_data :
4457 if isinstance (time_step , dict ):
45- step = MetricsHistoricalDataStep .model_validate (time_step ).model_dump (exclude_none = True , mode = 'json' )
58+ step = MetricsHistoricalDataStep .model_validate (time_step ).model_dump (
59+ exclude_none = True , mode = "json"
60+ )
4661 else :
47- step = time_step .model_dump (exclude_none = True , mode = ' json' )
62+ step = time_step .model_dump (exclude_none = True , mode = " json" )
4863 validated_historical_data .append (step )
49-
64+
5065 if self .data_format and not self .data_format .get ("historical_data_interval" ):
5166 for time_step in validated_historical_data :
5267 if not time_step .get ("timestamp" ):
0 commit comments