-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathone_candidate.py
More file actions
107 lines (89 loc) · 5.17 KB
/
one_candidate.py
File metadata and controls
107 lines (89 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# coding: utf-8
"""
Generated by: https://openapi-generator.tech
"""
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from regula.documentreader.webclient.gen.models.fdsid_list import FDSIDList
from regula.documentreader.webclient.gen.models.rfid_location import RfidLocation
from typing import Optional, Set
from typing_extensions import Self
class OneCandidate(BaseModel):
"""
Contains information about one document type candidate
""" # noqa: E501
document_name: Optional[StrictStr] = Field(default=None, description="Document name", alias="DocumentName")
id: StrictInt = Field(description="Unique document type template identifier (Regula's internal numeric code)", alias="ID")
p: Union[Annotated[float, Field(le=1, strict=True, ge=0)], Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(description="A measure of the likelihood of correct recognition in the analysis of this type of document", alias="P")
rotated180: StrictInt = Field(description="Indicates if the document of the given type is rotated by 180 degrees", alias="Rotated180")
rfid_presence: RfidLocation = Field(alias="RFID_Presence")
fdsid_list: Optional[FDSIDList] = Field(default=None, alias="FDSIDList")
necessary_lights: StrictInt = Field(description="Combination of lighting scheme identifiers (Light enum) required to conduct OCR for this type of document", alias="NecessaryLights")
check_authenticity: StrictInt = Field(description="Set of authentication options provided for this type of document (combination of Authenticity enum)", alias="CheckAuthenticity")
uv_exp: StrictInt = Field(description="The required exposure value of the camera when receiving images of a document of this type for a UV lighting scheme", alias="UVExp")
authenticity_necessary_lights: StrictInt = Field(description="Combination of lighting scheme identifiers (combination of Light enum) needed to perform all authenticity checks specified in CheckAuthenticity", alias="AuthenticityNecessaryLights")
ovi_exp: Union[StrictFloat, StrictInt] = Field(description="Camera exposure value necessary when obtaining document images of the given type for AXIAL lighting scheme", alias="OVIExp")
rotation_angle: Optional[StrictInt] = Field(default=None, alias="RotationAngle")
__properties: ClassVar[List[str]] = ["DocumentName", "ID", "P", "Rotated180", "RFID_Presence", "FDSIDList", "NecessaryLights", "CheckAuthenticity", "UVExp", "AuthenticityNecessaryLights", "OVIExp", "RotationAngle"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of OneCandidate from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of fdsid_list
if self.fdsid_list:
_dict['FDSIDList'] = self.fdsid_list.to_dict()
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of OneCandidate from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"DocumentName": obj.get("DocumentName"),
"ID": obj.get("ID"),
"P": obj.get("P"),
"Rotated180": obj.get("Rotated180"),
"RFID_Presence": obj.get("RFID_Presence"),
"FDSIDList": FDSIDList.from_dict(obj["FDSIDList"]) if obj.get("FDSIDList") is not None else None,
"NecessaryLights": obj.get("NecessaryLights"),
"CheckAuthenticity": obj.get("CheckAuthenticity"),
"UVExp": obj.get("UVExp"),
"AuthenticityNecessaryLights": obj.get("AuthenticityNecessaryLights"),
"OVIExp": obj.get("OVIExp"),
"RotationAngle": obj.get("RotationAngle")
})
return _obj