Coverage for fingerprint_server_sdk / models / velocity_data.py: 75%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 18:41 +0000

1""" 

2Server API 

3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. 

4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. 

5 

6The version of the OpenAPI document: 4 

7Contact: support@fingerprint.com 

8Generated by OpenAPI Generator (https://openapi-generator.tech) 

9 

10Do not edit the class manually. 

11""" # noqa: E501 

12 

13from __future__ import annotations 

14 

15import json 

16import pprint 

17import re # noqa: F401 

18from typing import Any, ClassVar, Optional 

19 

20from pydantic import BaseModel, ConfigDict, Field, StrictInt 

21from typing_extensions import Self 

22 

23 

24class VelocityData(BaseModel): 

25 """ 

26 Is absent if the velocity data could not be generated for the visitor Id. 

27 """ 

28 

29 var_5_minutes: StrictInt = Field( 

30 description='Count for the last 5 minutes of velocity data, from the time of the event. ', 

31 alias='5_minutes', 

32 ) 

33 var_1_hour: StrictInt = Field( 

34 description='Count for the last 1 hour of velocity data, from the time of the event. ', 

35 alias='1_hour', 

36 ) 

37 var_24_hours: Optional[StrictInt] = Field( 

38 default=None, 

39 description="The `24_hours` interval of `distinct_ip`, `distinct_linked_id`, `distinct_country`, `distinct_ip_by_linked_id` and `distinct_visitor_id_by_linked_id` will be omitted if the number of `events` for the visitor Id in the last 24 hours (`events.['24_hours']`) is higher than 20.000. ", 

40 alias='24_hours', 

41 ) 

42 __properties: ClassVar[list[str]] = ['5_minutes', '1_hour', '24_hours'] 

43 

44 model_config = ConfigDict( 

45 populate_by_name=True, 

46 validate_assignment=True, 

47 protected_namespaces=(), 

48 ) 

49 

50 def to_str(self) -> str: 

51 """Returns the string representation of the model using alias""" 

52 return pprint.pformat(self.model_dump(by_alias=True)) 

53 

54 def to_json(self) -> str: 

55 """Returns the JSON representation of the model using alias""" 

56 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

57 return json.dumps(self.to_dict()) 

58 

59 @classmethod 

60 def from_json(cls, json_str: str) -> Optional[Self]: 

61 """Create an instance of VelocityData from a JSON string""" 

62 return cls.from_dict(json.loads(json_str)) 

63 

64 def to_dict(self) -> dict[str, Any]: 

65 """Return the dictionary representation of the model using alias. 

66 

67 This has the following differences from calling pydantic's 

68 `self.model_dump(by_alias=True)`: 

69 

70 * `None` is only added to the output dict for nullable fields that 

71 were set at model initialization. Other fields with value `None` 

72 are ignored. 

73 """ 

74 excluded_fields: set[str] = set([]) 

75 

76 _dict = self.model_dump( 

77 by_alias=True, 

78 exclude=excluded_fields, 

79 exclude_none=True, 

80 ) 

81 return _dict 

82 

83 @classmethod 

84 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

85 """Create an instance of VelocityData from a dict""" 

86 if obj is None: 

87 return None 

88 

89 if not isinstance(obj, dict): 

90 return cls.model_validate(obj) 

91 

92 _obj = cls.model_validate( 

93 { 

94 '5_minutes': obj.get('5_minutes'), 

95 '1_hour': obj.get('1_hour'), 

96 '24_hours': obj.get('24_hours'), 

97 } 

98 ) 

99 return _obj